List of usage examples for org.apache.commons.lang ObjectUtils NULL
Null NULL
To view the source code for org.apache.commons.lang ObjectUtils NULL.
Click Source Link
Singleton used as a null
placeholder where null
has another meaning.
For example, in a HashMap
the java.util.HashMap#get(java.lang.Object) method returns null
if the Map
contains null
or if there is no matching key.
From source file:ai.grakn.graql.internal.template.TemplateVisitor.java
@Override public String visitForStatement(GraqlTemplateParser.ForStatementContext ctx) { // resolved variable String item = ctx.ID() != null ? ctx.ID().getText() : ""; Object collection = this.visit(ctx.expr()); if (!(collection instanceof List)) { return null; }/*w ww. j av a2s .co m*/ Object returnValue = ObjectUtils.NULL; for (Object object : (List) collection) { scope.assign(item, object); returnValue = concat(returnValue, this.visit(ctx.block())); scope.unassign(item); } return returnValue == ObjectUtils.NULL ? "" : returnValue.toString(); }
From source file:ai.grakn.graql.internal.template.Scope.java
/** * Retrieve the value of a key from this scope, or the parent scope if it is not present in the current one. * @param var key to retrieve/*from w ww. j a v a2 s . c o m*/ * @return value associated with the provided key */ public Object resolve(String var) { Object value = values.get(var); if (value != null) { // The variable resides in this scope return value; } else if (!isGlobalScope()) { // Let the parent scope look for the variable return parent.resolve(var); } else { // Unknown variable return ObjectUtils.NULL; } }
From source file:ch.systemsx.cisd.openbis.generic.server.authorization.DefaultReturnValueFilterTest.java
@Test public final void testApplyFilterWithNoAnnotationFound() { final LogMonitoringAppender appender = LogMonitoringAppender.addAppender(LogCategory.OPERATION, "No filter applied on method 'Object.hashCode': " + "no annotation 'ReturnValueFilter' found."); final Object filtered = defaultReturnValueFilter.applyFilter(AuthorizationTestUtil.createSession(), getAnyMethod(), ObjectUtils.NULL); appender.verifyLogHasHappened();// ww w . j av a 2 s . c o m assertEquals(ObjectUtils.NULL, filtered); }
From source file:ch.systemsx.cisd.openbis.generic.server.authorization.DefaultReturnValueFilterTest.java
@Test public final void testProceedWithValue() { final PersonPE person = AuthorizationTestUtil.createSession().tryGetPerson(); final Null value = ObjectUtils.NULL; context.checking(new Expectations() { {//w w w .j a v a2s . co m one(validator).isValid(person, value); will(returnValue(false)); } }); final Object proceeded = defaultReturnValueFilter.proceed(person, getAnyMethod(), value, validator); assertNull(proceeded); }
From source file:ai.grakn.graql.internal.template.TemplateVisitor.java
@Override public Object visitNullExpression(GraqlTemplateParser.NullExpressionContext ctx) { return ObjectUtils.NULL; }
From source file:ai.grakn.graql.internal.template.TemplateVisitor.java
@Override public String visitReplaceStatement(GraqlTemplateParser.ReplaceStatementContext ctx) { Object value = ObjectUtils.NULL; for (int i = 0; i < ctx.getChildCount(); i++) { if (ctx.macro(i) != null) { value = concat(value, this.visit(ctx.macro(i))); }//from w w w . j a v a2s .c o m if (ctx.resolve(i) != null) { value = concat(value, this.visit(ctx.resolve(i))); } } if (value == ObjectUtils.NULL) throw GraqlSyntaxException.parsingTemplateMissingKey(ctx.getText(), originalContext); Function<Object, String> formatToApply = ctx.DOLLAR() != null ? this::formatVar : this::format; String prepend = ctx.DOLLAR() != null ? ctx.DOLLAR().getText() : ""; return prepend + formatToApply.apply(value); }
From source file:com.eviware.soapui.plugins.LoaderBase.java
protected List<? extends SoapUIActionGroup> loadActionGroups(Reflections jarFileScanner) throws InstantiationException, IllegalAccessException { List<SoapUIActionGroup> actionGroups = new ArrayList<SoapUIActionGroup>(); Set<Class<?>> actionGroupClasses = jarFileScanner.getTypesAnnotatedWith(ActionGroup.class); for (Class<?> actionGroupClass : actionGroupClasses) { if (!SoapUIActionGroup.class.isAssignableFrom(actionGroupClass)) { logger.warn("Class " + actionGroupClass + " is annotated with @ActionGroup " + "but does not implement SoapUIActionGroup"); } else {/*from w w w . ja v a 2 s.c o m*/ ActionGroup annotation = actionGroupClass.getAnnotation(ActionGroup.class); SoapUIActionGroup actionGroup = createActionGroup((Class<SoapUIActionGroup>) actionGroupClass); for (ActionMapping mapping : annotation.actions()) { try { if (mapping.type() == ActionMapping.Type.SEPARATOR) { actionGroup.addMapping(SoapUIActionRegistry.SeperatorAction.SOAPUI_ACTION_ID, SoapUIActionRegistry.SeperatorAction.getDefaultMapping()); } else if (mapping.type() == ActionMapping.Type.GROUP || mapping.type() == ActionMapping.Type.INSERT) { SoapUIActionRegistry.SoapUIActionGroupAction actionListAction = new SoapUIActionRegistry.SoapUIActionGroupAction( mapping.name(), mapping.description(), mapping.groupId()); actionListAction.setInsert(mapping.type() == ActionMapping.Type.INSERT); StandaloneActionMapping actionMapping = new StandaloneActionMapping(actionListAction); actionGroup.addMapping(mapping.groupId(), actionMapping); } else if (mapping.type() == ActionMapping.Type.ACTION) { Class<?> actionClass = mapping.actionClass(); String actionId = mapping.actionId(); if (actionClass != ObjectUtils.Null.class) { if (SoapUIAction.class.isAssignableFrom(actionClass)) { SoapUIAction action = createAction((Class<SoapUIAction>) actionClass); actionRegistry.addAction(action.getId(), action); actionId = action.getId(); } else if (Action.class.isAssignableFrom(actionClass)) { Action swingAction = createObject((Class<Action>) actionClass); SoapUIAction action = new WrapperSoapUIAction(swingAction); actionRegistry.addAction(action.getId(), action); actionId = action.getId(); } } DefaultActionMapping actionMapping = new DefaultActionMapping(actionId, mapping.keyStroke(), mapping.iconPath(), actionId.equals(annotation.defaultAction()), mapping.param()); actionMapping.setToolbarAction(mapping.isToolbarAction()); actionMapping.setToolbarIndex(mapping.toolbarIndex()); if (!mapping.name().equals("")) { actionMapping.setName(mapping.name()); } if (!mapping.description().equals("")) { actionMapping.setDescription(mapping.description()); } actionGroup.addMapping(actionId, actionMapping); } } catch (Throwable e) { logger.error("Error adding actionMapping", e); } } actionGroups.add(actionGroup); } } return registerActionGroups(actionGroups); }
From source file:ai.grakn.graql.internal.template.TemplateVisitor.java
private Object concat(Object... values) { if (values.length == 1) { return values[0]; }/*from w ww . ja v a 2s.c om*/ if (values.length == 2 && values[0] == ObjectUtils.NULL) { return values[1]; } StringBuilder builder = new StringBuilder(); for (Object value : values) { builder.append(value); } return builder.toString(); }
From source file:org.apache.cocoon.auth.impl.StandardApplicationManager.java
/** * @see org.apache.cocoon.auth.ApplicationManager#login(java.lang.String, java.util.Map) *//*from w w w . jav a2s. c om*/ public User login(final String appName, final Map loginContext) throws Exception { User user = null; final Map objectModel = ContextHelper.getObjectModel(this.context); // first check, if we are already logged in if (this.isLoggedIn(appName)) { user = ApplicationUtil.getUser(objectModel); } else { final Request req = ObjectModelHelper.getRequest(objectModel); Session session = req.getSession(false); final Application app = this.getApplication(appName); LoginInfo info = null; Map loginInfos = null; if (session != null) { // is the user already logged in on the security handler? loginInfos = (Map) session.getAttribute(LOGIN_INFO_KEY); if (loginInfos != null && loginInfos.containsKey(app.getSecurityHandler().getId())) { info = (LoginInfo) loginInfos.get(app.getSecurityHandler().getId()); user = info.user; } } if (user == null) { user = app.getSecurityHandler().login(loginContext); if (user != null) { // create new login info session = req.getSession(); loginInfos = (Map) session.getAttribute(LOGIN_INFO_KEY); if (loginInfos == null) { loginInfos = new HashMap(); } info = new LoginInfo(user); loginInfos.put(app.getSecurityHandler().getId(), info); } } // user can be null, if login failed if (user != null) { info.incUsageCounter(appName); session.setAttribute(LOGIN_INFO_KEY, loginInfos); // set the user in the session session.setAttribute(USER + '-' + appName, user); objectModel.put(ApplicationManager.USER, user); // set the application in the object model objectModel.put(ApplicationManager.APPLICATION, app); // notify the application app.userDidLogin(user, loginContext); // set the application data in the session Object data = ObjectUtils.NULL; if (app.getApplicationStore() != null) { data = app.getApplicationStore().loadApplicationData(user, app); } session.setAttribute(APPLICATION_KEY_PREFIX + appName, data); objectModel.put(ApplicationManager.APPLICATION_DATA, data); // notify application app.userIsAccessing(user); } } return user; }
From source file:org.diffkit.diff.conf.DKMagicPlanBuilder.java
@SuppressWarnings("unchecked") private void resolve(DKMagicDependency<?> target_) throws IllegalAccessException, InstantiationException, InvocationTargetException { _log.debug("target_->{}", target_); if (target_ == null) return;/*from w w w . j ava 2 s . c o m*/ Object cachedResolution = this.getCachedResolution(target_); if (cachedResolution != null) { if (cachedResolution == ObjectUtils.NULL) cachedResolution = null; target_.resolve(cachedResolution); return; } Object resolution = null; DKMagicPlanRule rule = this.getRule(target_); _log.debug("rule->{}", rule); if (rule != null) { resolution = this.applyRule(rule, target_); if (resolution instanceof Class) { target_.refine((Class) resolution); _log.debug("refined dependency->{}", target_); this.resolve(target_); return; } else { target_.resolve(resolution); _log.debug("resolved dependency->{}", target_); } } else { DKMagicDependency<?>[] dependencies = null; try { dependencies = target_.getDependencies(); _log.debug("dependencies->{}", Arrays.toString(dependencies)); if (dependencies != null) { for (DKMagicDependency<?> dependency : dependencies) try { this.resolve(dependency); } catch (Exception e_) { throw new RuntimeException( String.format("Could not resolve automatically; need rule for dependency->%s", dependency), e_); } } resolution = target_.resolve(); } catch (Exception e_) { throw new RuntimeException( String.format("Could not resolve automatically; need rule for dependency->%s", target_), e_); } _log.debug("resolved dependency->{}", target_); } _log.debug("dependency->{} resolution->{}", target_, resolution); if (resolution == null) resolution = ObjectUtils.NULL; this.encacheResolution(target_, resolution); }