List of usage examples for org.apache.commons.lang ObjectUtils defaultIfNull
public static <T> T defaultIfNull(T object, T defaultValue)
Returns a default value if the object passed is null
.
ObjectUtils.defaultIfNull(null, null) = null ObjectUtils.defaultIfNull(null, "") = "" ObjectUtils.defaultIfNull(null, "zz") = "zz" ObjectUtils.defaultIfNull("abc", *) = "abc" ObjectUtils.defaultIfNull(Boolean.TRUE, *) = Boolean.TRUE
From source file:MainClass.java
public static void main(String[] args) { //Create ObjectUtilsTrial instance MyClass one = new MyClass(); MyClass two = one; //Same Reference MyClass three = new MyClass(); //New Object MyClass four = null;//from ww w.j a v a 2 s . c o m //four is null, returns DEFAULT System.out.print("1) If null return DEFAULT >>>"); System.out.println(ObjectUtils.defaultIfNull(four, "DEFAULT")); }
From source file:ObjectUtilsTrial.java
public static void main(String[] args) { // Create ObjectUtilsTrial instance String one = new String(); String two = one; // Same Reference String three = new String(); // New Object String four = null;/*from w w w .j av a2 s. co m*/ // four is null, returns DEFAULT System.out.print("1) If null return DEFAULT >>>"); System.out.println(ObjectUtils.defaultIfNull(four, "DEFAULT")); // one and two point to the same object System.out.print("2) References to the same object >>>"); System.out.println(ObjectUtils.equals(one, two)); // one and three are different objects System.out.print("3) Check object references and not values >>>"); System.out.println(ObjectUtils.equals(one, three)); // toString method gets called System.out.print("4) toSring gets invoked >>>"); System.out.println(one); // Object details displayed..toString is not called System.out.print("5) Display object details >>>"); System.out.println(ObjectUtils.identityToString(one)); // Pass null get empty string System.out.print("6) Pass null and get back an Empty string >>>"); System.out.println("**" + ObjectUtils.toString(null) + "**"); }
From source file:com.sylvanaar.idea.Lua.editor.inspections.utils.BoolUtils.java
public static boolean isTrue(LuaConditionalExpression condition) { Object value = ObjectUtils.defaultIfNull(condition.evaluate(), UNKNOWN); return value.equals(Boolean.TRUE); }
From source file:com.sylvanaar.idea.Lua.editor.inspections.utils.BoolUtils.java
public static boolean isFalse(LuaConditionalExpression condition) { Object value = ObjectUtils.defaultIfNull(condition.evaluate(), UNKNOWN); return value.equals(Boolean.FALSE); }
From source file:io.fabric8.elasticsearch.util.RequestUtils.java
public String getUser(RestRequest request) { return (String) ObjectUtils.defaultIfNull(request.header(proxyUserHeader), ""); }
From source file:io.fabric8.elasticsearch.plugin.kibana.GetResultBuilder.java
@SuppressWarnings("unchecked") public GetResultBuilder response(GetResponse response) { this.response = response; if (this.response != null) { type = (String) ObjectUtils.defaultIfNull(response.getType(), ""); id = (String) ObjectUtils.defaultIfNull(response.getId(), ""); version = (long) ObjectUtils.defaultIfNull(response.getVersion(), 0L); exists = response.isExists();/*from w w w.j a v a 2 s .com*/ responseFields = (Map<String, GetField>) ObjectUtils.defaultIfNull(response.getFields(), new HashMap<String, GetField>()); } return this; }
From source file:io.fabric8.elasticsearch.util.RequestUtils.java
public String getBearerToken(RestRequest request) { final String[] auth = ((String) ObjectUtils.defaultIfNull(request.header(AUTHORIZATION_HEADER), "")) .split(" "); if (auth.length >= 2 && "Bearer".equals(auth[0])) { return auth[1]; }//www .j av a 2 s. c o m return ""; }
From source file:io.fabric8.elasticsearch.plugin.KibanaUserReindexFilter.java
@Override public void process(RestRequest request, RestChannel channel, RestFilterChain chain) throws Exception { try {/*from w w w . ja v a 2s. co m*/ 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); } }
From source file:io.fabric8.elasticsearch.plugin.model.Project.java
@Override public String toString() { return "Project [name=" + ObjectUtils.defaultIfNull(name, "<null>") + ", uid=" + ObjectUtils.defaultIfNull(uid, "<null>") + "]"; }
From source file:com.dianping.lion.service.impl.OperationLogServiceImpl.java
private List<OperationLog> refactorConfig(List<OperationLog> logList) { User currentUser = SecurityUtils.getCurrentUser(); for (OperationLog log : logList) { OperationTypeEnum opType = log.getOpTypeEnum(); if (opType == OperationTypeEnum.Config_Edit || opType == OperationTypeEnum.API_SetConfig) { Config config = configService.findConfigByKey(log.getKey1()); boolean hasReadPrivilege = false; if (config != null) { hasReadPrivilege = privilegeDecider.hasReadConfigPrivilege(log.getProjectId(), log.getEnvId(), config.getId(), currentUser != null ? currentUser.getId() : null); } else { hasReadPrivilege = currentUser != null && (currentUser.isAdmin() || currentUser.isSA()); }// www . j av a 2 s. c o m //TODO , ? String oldValue = (String) ObjectUtils.defaultIfNull(getLogKey(log.getId(), "key3"), ""); if (opType == OperationTypeEnum.Config_Edit) { String newValue = (String) ObjectUtils.defaultIfNull(getLogKey(log.getId(), "key4"), ""); String oldCutValue = StringUtils.cutString(oldValue, 80); String newCutValue = StringUtils.cutString(newValue, 80); log.setContent("?: " + log.getKey1() + ", before[" + (hasReadPrivilege ? oldCutValue : "***") + "], after[" + (hasReadPrivilege ? newCutValue : "***") + "]"); if (hasReadPrivilege && (oldCutValue.length() != oldValue.length() || newCutValue.length() != newValue.length())) { log.setKey5("true"); } } else if (opType == OperationTypeEnum.API_SetConfig) { if (!hasReadPrivilege) { log.setContent("?: " + log.getKey1() + ", value: ***"); log.setKey1("false"); } else { log.appendContent(", before: " + StringUtils.cutString(oldValue, 80)); log.setKey1("true"); } } } else if (opType == OperationTypeEnum.Job_DSFetcher) { boolean hasReadPrivilege = privilegeDecider .hasReadDSFetchLogPrivilege(currentUser != null ? currentUser.getId() : null); log.setKey1(hasReadPrivilege ? "true" : "false"); } } return logList; }