當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。