当前位置: 首页>>代码示例>>Java>>正文


Java ObjectUtils.defaultIfNull方法代码示例

本文整理汇总了Java中org.apache.commons.lang.ObjectUtils.defaultIfNull方法的典型用法代码示例。如果您正苦于以下问题:Java ObjectUtils.defaultIfNull方法的具体用法?Java ObjectUtils.defaultIfNull怎么用?Java ObjectUtils.defaultIfNull使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.apache.commons.lang.ObjectUtils的用法示例。


在下文中一共展示了ObjectUtils.defaultIfNull方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: editNote2

import org.apache.commons.lang.ObjectUtils; //导入方法依赖的package包/类
void editNote2(Note note) {
    if (note.get_id() == null) {
        Log.d(Constants.TAG, "Adding new note");
        // if navigation is a category it will be set into note
        try {
            if (Navigation.checkNavigation(Navigation.CATEGORY) || !TextUtils.isEmpty(mainActivity.navigationTmp)) {
                String categoryId = (String) ObjectUtils.defaultIfNull(mainActivity.navigationTmp,
                        Navigation.getCategory().toString());
                note.setCategory(DbHelper.getInstance().getCategory(Long.parseLong(categoryId)));
            }
        } catch (NumberFormatException e) {
            Log.v(Constants.TAG, "Maybe was not a category!");
        }
    } else {
        Log.d(Constants.TAG, "Editing note with id: " + note.get_id());
    }

    // Current list scrolling position is saved to be restored later
    refreshListScrollPosition();

    closeFab();

    // Fragments replacing
    mainActivity.switchToDetail(note);
}
 
开发者ID:ApplicationFactory,项目名称:PEP---Notes,代码行数:26,代码来源:ListFragment.java

示例2: evaluateScript

import org.apache.commons.lang.ObjectUtils; //导入方法依赖的package包/类
/**
 * Evaluates the compiled script of a entry.
 * @param entry The configuration entry to evaluate
 * @param scopeValues All known values for script scope
 * @return The computed value
 * @throws ScriptException
 */
private Object evaluateScript(Entry<String, Map<String, Object>> entry, Map<String, Object> scopeValues) throws ScriptException {
	
	Object value = null;
	
	// executes compiled script
	if(entry.getValue().containsKey("cscript")) {
		CompiledScript cscript = (CompiledScript) entry.getValue().get("cscript");

		// Add global variables thisValue and keyName to JavaScript context
		Bindings bindings = cscript.getEngine().createBindings();
		bindings.putAll(scopeValues);
		value = cscript.eval(bindings);
	}

	// try to convert the returned value to BigDecimal
	value = ObjectUtils.defaultIfNull(
			NumberUtils.toBigDecimal(value), value);

	// round to two digits, maybe not optimal for any result
	if(value instanceof BigDecimal) {
		((BigDecimal)value).setScale(2, BigDecimal.ROUND_HALF_UP);
	}
	
	return value;
}
 
开发者ID:andrey-desman,项目名称:openhab-hdl,代码行数:33,代码来源:EBusTelegramParser.java

示例3: Entry

import org.apache.commons.lang.ObjectUtils; //导入方法依赖的package包/类
private Entry(Object message, Profiler.Entry parentEntry, Profiler.Entry firstEntry) {
    this.subEntries = new ArrayList(4);
    this.message = message;
    this.startTime = System.currentTimeMillis();
    this.parentEntry = parentEntry;
    this.firstEntry = (Profiler.Entry)ObjectUtils.defaultIfNull(firstEntry, this);
    this.baseTime = firstEntry == null ? 0L : firstEntry.startTime;
}
 
开发者ID:alibaba,项目名称:atlas,代码行数:9,代码来源:Profiler.java

示例4: matchesCommand

import org.apache.commons.lang.ObjectUtils; //导入方法依赖的package包/类
/**
 * Checks if the given command method is acceptable for the unescaped telegram
 *
 * @param command
 * @param data
 * @return
 */
public boolean matchesCommand(IEBusCommandMethod command, ByteBuffer data) {

    Byte sourceAddress = (Byte) ObjectUtils.defaultIfNull(command.getSourceAddress(), Byte.valueOf((byte) 0x00));

    Byte targetAddress = (Byte) ObjectUtils.defaultIfNull(command.getDestinationAddress(),
            Byte.valueOf((byte) 0x00));

    try {

        ByteBuffer masterTelegram = EBusCommandUtils.buildMasterTelegram(command, sourceAddress, targetAddress,
                null);

        ByteBuffer mask = command.getMasterTelegramMask();

        for (int i = 0; i < mask.limit(); i++) {
            byte b = mask.get(i);

            if (b == (byte) 0xFF) {
                if (masterTelegram.get(i) != data.get(i)) {
                    break;
                }
            }
            if (i == mask.limit() - 1) {
                return true;
            }
        }
    } catch (EBusTypeException e) {
        logger.error("error!", e);
    }

    return false;
}
 
开发者ID:csowada,项目名称:ebus,代码行数:40,代码来源:EBusCommandRegistry.java

示例5: getKibanaVersion

import org.apache.commons.lang.ObjectUtils; //导入方法依赖的package包/类
private String getKibanaVersion(RestRequest request) {
    String kbnVersion = (String) ObjectUtils.defaultIfNull(request.header(kbnVersionHeader), "");
    if (StringUtils.isEmpty(kbnVersion)) {
        return kibanaVersion;
    }
    return kbnVersion;
}
 
开发者ID:fabric8io,项目名称:openshift-elasticsearch-plugin,代码行数:8,代码来源:DynamicACLFilter.java

示例6: process

import org.apache.commons.lang.ObjectUtils; //导入方法依赖的package包/类
@Override
public void process(RestRequest request, RestChannel channel, RestFilterChain chain) throws Exception {
    try {
        OpenshiftRequestContext userContext = (OpenshiftRequestContext) 
                ObjectUtils.defaultIfNull(request.getFromContext(OPENSHIFT_REQUEST_CONTEXT), OpenshiftRequestContext.EMPTY);
        final String user = userContext.getUser();
        final String kibanaIndex = userContext.getKibanaIndex();
        final String requestedIndex = getRequestedIndex(request);

        logger.debug("user: '{}'/ requested index: '{}'/ kibana index: '{}'", user, requestedIndex, kibanaIndex);

        if (StringUtils.isNotEmpty(user) && StringUtils.isNotEmpty(requestedIndex)){
            if(requestedIndex.equalsIgnoreCase(defaultKibanaIndex)) {
                logger.debug("Request is for a kibana index. Updating to '{}' for user '{}'", kibanaIndex, user);
                // update the request URI here
                request = updateRequestIndex(request, requestedIndex, kibanaIndex);
                
                logger.debug("URI for request is '{}' after update", request.uri());
            }else if(requestedIndex.startsWith("_mget")) {
                logger.debug("_mget Request for a kibana index. Updating to '{}' for user '{}'", kibanaIndex, user);
                request = updateMGetRequest(request, ".kibana", kibanaIndex);

                logger.debug("URI for request is '{}' after update", request.uri());
            }
        }

    } catch (Exception e) {
        logger.error("Error handling request in OpenShift SearchGuard filter", e);
    } finally {
        chain.continueProcessing(request, channel);
    }
}
 
开发者ID:fabric8io,项目名称:openshift-elasticsearch-plugin,代码行数:33,代码来源:KibanaUserReindexFilter.java

示例7: checkForLockingDocument

import org.apache.commons.lang.ObjectUtils; //导入方法依赖的package包/类
/**
 * Determines if there is another maintenance document that has a lock on the same key as the given document, and
 * therefore will block the maintenance document from being submitted
 *
 * @param document - maintenance document instance to check locking for
 * @param throwExceptionIfLocked - indicates if an exception should be thrown in the case of found locking document,
 * if false only an error will be added
 */
public static void checkForLockingDocument(MaintenanceDocument document, final boolean throwExceptionIfLocked) {
    LOG.info("starting checkForLockingDocument (by MaintenanceDocument)");

    // get the docHeaderId of the blocking docs, if any are locked and blocking
    //String blockingDocId = getMaintenanceDocumentService().getLockingDocumentId(document);
    final String blockingDocId = document.getNewMaintainableObject().getLockingDocumentId();

    Maintainable maintainable = (Maintainable) ObjectUtils.defaultIfNull(document.getOldMaintainableObject(), document.getNewMaintainableObject());
    checkDocumentBlockingDocumentId(blockingDocId, throwExceptionIfLocked);
}
 
开发者ID:kuali,项目名称:kc-rice,代码行数:19,代码来源:MaintenanceUtils.java

示例8: isTrue

import org.apache.commons.lang.ObjectUtils; //导入方法依赖的package包/类
public static boolean isTrue(LuaConditionalExpression condition) {
  Object value = ObjectUtils.defaultIfNull(condition.evaluate(), UNKNOWN);
  return value.equals(Boolean.TRUE);
}
 
开发者ID:internetisalie,项目名称:lua-for-idea,代码行数:5,代码来源:BoolUtils.java

示例9: isFalse

import org.apache.commons.lang.ObjectUtils; //导入方法依赖的package包/类
public static boolean isFalse(LuaConditionalExpression condition) {
    Object value = ObjectUtils.defaultIfNull(condition.evaluate(), UNKNOWN);

    return value.equals(Boolean.FALSE);
}
 
开发者ID:internetisalie,项目名称:lua-for-idea,代码行数:6,代码来源:BoolUtils.java

示例10: getUser

import org.apache.commons.lang.ObjectUtils; //导入方法依赖的package包/类
public String getUser(RestRequest request) {
    return (String) ObjectUtils.defaultIfNull(request.header(proxyUserHeader), "");
}
 
开发者ID:fabric8io,项目名称:openshift-elasticsearch-plugin,代码行数:4,代码来源:RequestUtils.java

示例11: mergeNotes

import org.apache.commons.lang.ObjectUtils; //导入方法依赖的package包/类
public static Note mergeNotes(List<Note> notes, boolean keepMergedNotes) {

		Note mergedNote = null;
		boolean locked = false;
		StringBuilder content = new StringBuilder();
		ArrayList<Attachment> attachments = new ArrayList<>();
		Category category = null;
		String reminder = null;
		String reminderRecurrenceRule = null;
		Double latitude = null, longitude = null;

		for (Note note : notes) {

			if (mergedNote == null) {
				mergedNote = new Note();
				mergedNote.setTitle(note.getTitle());
				content.append(note.getContent());

			} else {
				if (content.length() > 0
						&& (!TextUtils.isEmpty(note.getTitle()) || !TextUtils.isEmpty(note.getContent()))) {
					content.append(System.getProperty("line.separator")).append(System.getProperty("line.separator"))
							.append(Constants.MERGED_NOTES_SEPARATOR).append(System.getProperty("line.separator"))
							.append(System.getProperty("line.separator"));
				}
				if (!TextUtils.isEmpty(note.getTitle())) {
					content.append(note.getTitle());
				}
				if (!TextUtils.isEmpty(note.getTitle()) && !TextUtils.isEmpty(note.getContent())) {
					content.append(System.getProperty("line.separator")).append(System.getProperty("line.separator"));
				}
				if (!TextUtils.isEmpty(note.getContent())) {
					content.append(note.getContent());
				}
			}

			locked = locked || note.isLocked();

			category = (Category) ObjectUtils.defaultIfNull(category, note.getCategory());

			String currentReminder = note.getAlarm();
			if (!TextUtils.isEmpty(currentReminder) && reminder == null) {
				reminder = currentReminder;
				reminderRecurrenceRule = note.getRecurrenceRule();
			}

			latitude = (Double) ObjectUtils.defaultIfNull(latitude, note.getLatitude());
			longitude = (Double) ObjectUtils.defaultIfNull(longitude, note.getLongitude());

			if (keepMergedNotes) {
				for (Attachment attachment : note.getAttachmentsList()) {
					attachments.add(StorageHelper.createAttachmentFromUri(OmniNotes.getAppContext(), attachment.getUri
							()));
				}
			} else {
				attachments.addAll(note.getAttachmentsList());
			}
		}

		// Sets merged values
		mergedNote.setContent(content.toString());
		mergedNote.setLocked(locked);
		mergedNote.setCategory(category);
		mergedNote.setAlarm(reminder);
		mergedNote.setRecurrenceRule(reminderRecurrenceRule);
		mergedNote.setLatitude(latitude);
		mergedNote.setLongitude(longitude);
		mergedNote.setAttachmentsList(attachments);

		return mergedNote;
	}
 
开发者ID:ApplicationFactory,项目名称:PEP---Notes,代码行数:72,代码来源:NotesHelper.java


注:本文中的org.apache.commons.lang.ObjectUtils.defaultIfNull方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。