List of usage examples for org.apache.commons.lang ArrayUtils contains
public static boolean contains(boolean[] array, boolean valueToFind)
Checks if the value is in the given array.
From source file:net.sourceforge.atunes.kernel.modules.player.PlayerEngineSelector.java
/** * @param availableEngines//from w ww . j av a 2s . c o m * @return */ private String selectDefaultEngine(List<AbstractPlayerEngine> availableEngines) { String selectedEngine; if (ArrayUtils.contains(engineNames, Constants.DEFAULT_ENGINE)) { selectedEngine = Constants.DEFAULT_ENGINE; } else { // If default engine is not available, then get the first engine of // map returned selectedEngine = availableEngines.iterator().next().getEngineName(); } // Update application state with this engine statePlayer.setPlayerEngine(selectedEngine); return selectedEngine; }
From source file:jef.tools.string.StringSpliter.java
/** * ?key/*from w w w. j av a 2s. c o m*/ * @param chars * @return */ public boolean expandKeyLeft(char[] chars) { boolean res = false; if (keyword == null) return res; Substring left = getLeft(); while (left.lastCharacter() != null && ArrayUtils.contains(chars, left.lastCharacter().charValue())) { left.setEnd(left.getEnd() - 1); res = true; } if (res) this.keyword = source.subAbsoultOffset(left.getEnd(), keyword.getEnd()); return res; }
From source file:com.adobe.acs.samples.events.cq5.impl.SampleSlingEventHandler.java
@Override public void handleEvent(final Event event) { boolean handleLocally = false; boolean handleWithLeader = !handleLocally; for (final String name : event.getPropertyNames()) { log.debug("{} : {}", name, event.getProperty(name)); }/* w ww.j a v a 2s .com*/ if (!ArrayUtils.contains(event.getPropertyNames(), EventUtil.PROPERTY_DISTRIBUTE)) { // This is the check for a distributed event or not; if this property does not exist, it usually // means that this event handler should process the job, as no other event handlers // will see this event. JobUtil.processJob(event, this); } else if (handleLocally && EventUtil.isLocal(event)) { // This is a distributed event (first 'if' condition failed) // If this server created the event // then only this server should process the event // This will call this's process(..) method, passing in the event obj // JobUtil.processJob(..) sends/checks for an ack for this job // Jobs guarantee the event will be processed (though doesn't guarantee the job will be // processed SUCCESSFULLY) JobUtil.processJob(event, this); } else if (handleWithLeader && this.isLeader) { // This is a distributed event (first 'if' condition failed) // If a event is distributed, you may only want to execute it the Master node in // the cluster. JobUtil.processJob(event, this); } else { // DO NOTHING! } }
From source file:games.stendhal.server.actions.equip.EquipAction.java
@Override protected void execute(final Player player, final RPAction action, final SourceObject source) { // get source and check it logger.debug("Getting entity name"); // is the entity unbound or bound to the right player? final Entity entity = source.getEntity(); final String itemName = source.getEntityName(); logger.debug("Checking if entity is bound"); if (entity instanceof Item) { final Item item = (Item) entity; if (item.isBound() && !player.isBoundTo(item)) { player.sendPrivateText("This " + itemName + " is a special reward for " + item.getBoundTo() + ". You do not deserve to use it."); return; }// ww w . ja v a 2s .c om } logger.debug("Checking destination"); // get destination and check it final DestinationObject dest = new DestinationObject(action, player); if (dest.isInvalidMoveable(player, EquipActionConsts.MAXDISTANCE, validContainerClassesList)) { // destination is not valid logger.debug("Destination is not valid"); return; } logger.debug("Equip action agreed"); // looks good if (source.moveTo(dest, player)) { int amount = source.getQuantity(); // Warn about min level if (player.equals(dest.parent) && ArrayUtils.contains(Constants.CARRYING_SLOTS, dest.slot) && !"bag".equals(dest.slot)) { if (entity instanceof Item) { int minLevel = ((Item) entity).getMinLevel(); if (minLevel > player.getLevel()) { player.sendPrivateText( "You are not experienced enough to use this item to full benefit. You are probably better off by using an item appropriate for your level instead."); } } } // players sometimes accidentally drop items into corpses, so inform about all drops into a corpse // which aren't just a movement from one corpse to another. // we could of course specifically preclude dropping into corpses, but that is undesirable. if (dest.isContainerCorpse() && !source.isContainerCorpse()) { player.sendPrivateText("For your information, you just dropped " + Grammar.quantityplnounWithHash(amount, entity.getTitle()) + " into a corpse next to you."); } if (source.isLootingRewardable()) { if (entity instanceof Item) { ((Item) entity).setFromCorpse(false); } player.incLootForItem(entity.getTitle(), amount); SingletonRepository.getAchievementNotifier().onItemLoot(player); } if (entity instanceof Item) { ((Item) entity).autobind(player.getName()); } new GameEvent(player.getName(), "equip", itemName, source.getSlot(), dest.getSlot(), Integer.toString(amount)).raise(); player.updateItemAtkDef(); } }
From source file:edu.illinois.cs.cogcomp.edison.features.lrec.TestWordConjunctionOneTwoThreeGramWindowTwo.java
@Test public final void test() throws EdisonException { // Using the 3rd constituent as a test List<Constituent> testList = ta.getView("TOKENS").getConstituents(); Constituent test = testList.get(3);/*from w w w. j a va2 s.co m*/ WordConjunctionOneTwoThreeGramWindowTwo fex = new WordConjunctionOneTwoThreeGramWindowTwo( "WordConj3GramWin2"); Set<Feature> feats = fex.getFeatures(test); String[] expected_outputs = { "WordConjunctionOneTwoThreeGramWindowTwo:-2_1(construction)", "WordConjunctionOneTwoThreeGramWindowTwo:-1_1(of)", "WordConjunctionOneTwoThreeGramWindowTwo:0_1(the)", "WordConjunctionOneTwoThreeGramWindowTwo:1_1(John)", "WordConjunctionOneTwoThreeGramWindowTwo:2_1(Smith)", "WordConjunctionOneTwoThreeGramWindowTwo:-2_2(construction_of)", "WordConjunctionOneTwoThreeGramWindowTwo:-1_2(of_the)", "WordConjunctionOneTwoThreeGramWindowTwo:0_2(the_John)", "WordConjunctionOneTwoThreeGramWindowTwo:1_2(John_Smith)", "WordConjunctionOneTwoThreeGramWindowTwo:2_2(Smith)", "WordConjunctionOneTwoThreeGramWindowTwo:-2_3(construction_of_the)", "WordConjunctionOneTwoThreeGramWindowTwo:-1_3(of_the_John)", "WordConjunctionOneTwoThreeGramWindowTwo:0_3(the_John_Smith)", "WordConjunctionOneTwoThreeGramWindowTwo:1_3(John_Smith)", "WordConjunctionOneTwoThreeGramWindowTwo:2_3(Smith)" }; if (feats == null) fail("Feats are returning NULL."); for (Feature f : feats) { assertTrue(ArrayUtils.contains(expected_outputs, f.getName())); } }
From source file:net.shopxx.shiro.realm.AuthenticationRealm.java
/** * ???/*from ww w .j av a 2 s . com*/ * * @param token * @return ?? */ @Override protected AuthenticationInfo doGetAuthenticationInfo(org.apache.shiro.authc.AuthenticationToken token) { AuthenticationToken authenticationToken = (AuthenticationToken) token; String username = authenticationToken.getUsername(); String password = new String(authenticationToken.getPassword()); String captchaId = authenticationToken.getCaptchaId(); String captcha = authenticationToken.getCaptcha(); String ip = authenticationToken.getHost(); if (!isDevModel && !captchaService.isValid(CaptchaType.adminLogin, captchaId, captcha)) { throw new UnsupportedTokenException(); } if (username != null && password != null) { Admin admin = adminService.findByUsername(username); if (admin == null) { throw new UnknownAccountException(); } if (!admin.getIsEnabled()) { throw new DisabledAccountException(); } Setting setting = SettingUtils.get(); if (admin.getIsLocked()) { if (ArrayUtils.contains(setting.getAccountLockTypes(), AccountLockType.admin)) { int loginFailureLockTime = setting.getAccountLockTime(); if (loginFailureLockTime == 0) { throw new LockedAccountException(); } Date lockedDate = admin.getLockedDate(); Date unlockDate = DateUtils.addMinutes(lockedDate, loginFailureLockTime); if (new Date().after(unlockDate)) { admin.setLoginFailureCount(0); admin.setIsLocked(false); admin.setLockedDate(null); adminService.update(admin); } else { throw new LockedAccountException(); } } else { admin.setLoginFailureCount(0); admin.setIsLocked(false); admin.setLockedDate(null); adminService.update(admin); } } if (!DigestUtils.md5Hex(password).equals(admin.getPassword())) { int loginFailureCount = admin.getLoginFailureCount() + 1; if (loginFailureCount >= setting.getAccountLockCount()) { admin.setIsLocked(true); admin.setLockedDate(new Date()); } admin.setLoginFailureCount(loginFailureCount); adminService.update(admin); throw new IncorrectCredentialsException(); } admin.setLoginIp(ip); admin.setLoginDate(new Date()); admin.setLoginFailureCount(0); adminService.update(admin); return new SimpleAuthenticationInfo(new Principal(admin.getId(), username), password, getName()); } throw new UnknownAccountException(); }
From source file:gov.nih.nci.cabig.caaers.web.rule.notification.ReviewTab.java
/** * This will return a list of Pair objects, with each pair consiting of the * <code>displayName</code> of the field and its associated <code>value</code>. * /* www . j av a 2 s . c om*/ * @param fieldGroup - An InputFieldGroup * @param command - The BeanWrapper instance wrapping {@link ReportDefinitionCommand} * @param exclusions - A list of <code>displayName</code> to be eliminated from the display. * @return List<Pair> objects. */ public List<Pair> fetchFieldValues(InputFieldGroup fieldGroup, BeanWrapper command, String... exclusions) { List<Pair> fieldList = new ArrayList<Pair>(); if (fieldGroup == null) return fieldList; for (InputField field : fieldGroup.getFields()) { if (exclusions != null && ArrayUtils.contains(exclusions, field.getDisplayName())) continue; fieldList.add(fetchFieldValue(field, command)); } return fieldList; }
From source file:edu.illinois.cs.cogcomp.edison.features.lrec.TestPOSWindowTwo.java
public final void test() throws EdisonException { log.debug("POSWindowTwo Feature Extractor"); // Using the first TA and a constituent between span of 30-40 as a test TextAnnotation ta = tas.get(2);//from w ww .j a v a 2s . c o m View TOKENS = ta.getView("TOKENS"); List<Constituent> testlist = TOKENS.getConstituentsCoveringSpan(0, 20); for (Constituent c : testlist) { log.debug(c.getSurfaceForm()); } Constituent test = testlist.get(1); log.debug("The constituent we are extracting features from in this test is: " + test.getSurfaceForm()); POSWindowTwo POSW = new POSWindowTwo("POSWindowTwo"); log.debug("Startspan is " + test.getStartSpan() + " and Endspan is " + test.getEndSpan()); Set<Feature> feats = POSW.getFeatures(test); String[] expected_outputs = { "POSWindowTwo:0(DT)", "POSWindowTwo:1(VBZ)", "POSWindowTwo:2(DT)", "POSWindowTwo:3(NN)" }; if (feats == null) { log.debug("Feats are returning NULL."); } log.debug("Printing Set of Features"); for (Feature f : feats) { assert (ArrayUtils.contains(expected_outputs, f.getName())); } // System.exit(0); }
From source file:alpha.portal.model.AdornmentTypeRange.java
/** * Checks if is valid./* ww w . j a v a2 s. co m*/ * * @param value * the value * @return true, if is valid */ public boolean isValid(final String value) { return ArrayUtils.contains(this.validStrings, value); }
From source file:eu.dime.ps.dto.Profile.java
protected void addToMap(org.ontoware.rdfreactor.schema.rdfs.Resource resource, String serviceAccountId, URI me) {/*from w w w. j a va2 s . c om*/ put("guid", "p_" + resource.asURI().toString()); List<String> items = new LinkedList<String>(); put("items", items); ClosableIterator<Statement> it = resource.getModel().findStatements(resource.asResource(), Variable.ANY, Variable.ANY); while (it.hasNext()) { Statement statement = it.next(); URI predicate = statement.getPredicate(); Node object = statement.getObject(); if (ArrayUtils.contains(ITEMS_PROPERTIES, predicate)) { if (object instanceof URI) items.add(object.asURI().toString()); } else if (predicate.equals(NAO.lastModified)) { put("lastUpdate", CalendarConverter .parseXSDDateTime_toCalendar((String) object.asDatatypeLiteral().getValue()) .getTimeInMillis()); } else if (predicate.equals(NAO.prefLabel)) { put("name", object.asLiteral().getValue()); } else if (predicate.equals(NAO.prefSymbol)) { if (object instanceof Literal) put("imageUrl", object.asLiteral().toString()); else if (object instanceof URI) put("imageUrl", object.asURI().toString()); } } it.close(); // adding said this.put("said", serviceAccountId); // Adding said if (!containsKey("said")) { put("said", ""); } if (!containsKey("name")) { put("name", "Profile " + resource.asURI().toString()); } //adding editable attribute //editable when it is di.me profile(name ends with @di.me), //not editable when it is external profile if (this.get("name").toString().endsWith("@di.me")) { put("editable", true); } else put("editable", false); }