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:com.flexive.core.security.UserTicketImpl.java
/** * Helper function for the constructor.//from w w w .j a va 2 s . com */ private void populateData() { this.dirty = false; this.creationTime = System.currentTimeMillis(); this.remoteHost = FxContext.get().getRemoteHost(); // Check ACL assignments if (assignments == null) { assignments = new ACLAssignment[0]; } // Check groups if (this.groups == null || this.groups.length == 0) { this.groups = new long[] { UserGroup.GROUP_EVERYONE }; } else { // Group everyone has to be present if (!(ArrayUtils.contains(this.groups, UserGroup.GROUP_EVERYONE))) { this.groups = ArrayUtils.add(this.groups, UserGroup.GROUP_EVERYONE); } } // Check roles if (this.roles == null) { this.roles = new Role[0]; } // Set mandator/global supervisor flag if (this.userId == Account.USER_GLOBAL_SUPERVISOR || isInRole(Role.GlobalSupervisor)) { globalSupervisor = true; } if (isInRole(Role.MandatorSupervisor)) { mandatorSupervisor = true; } }
From source file:com.autentia.wuija.persistence.impl.hibernate.HibernateGroupManagementTest.java
/** * Comprueba que en la base de datos el grupo <code>groupname</code> tiene exactamente los mismos roles que * <code>roles</code>.//w w w . j a v a2s. c o m * * @param groupname el nombre del grupo. * @param roles los roles del grupo. */ private void checkGroupRoles(String groupname, GrantedAuthority[] roles) { GrantedAuthority[] loadedRoles = groupManager.findGroupAuthorities(groupname); Assert.assertEquals("loaded roles length", roles.length, loadedRoles.length); for (GrantedAuthority loadedRole : loadedRoles) { Assert.assertTrue("roles contains loaded role " + loadedRole, ArrayUtils.contains(roles, loadedRole)); } }
From source file:com.pureinfo.srm.reports.table.MyTabeleDataHelper.java
public static String[] clearDupAndNull(String[] _before) { if (_before == null) { return null; }//from w w w .j ava 2 s . c o m String[] medial = new String[_before.length]; int n = 0; for (int i = 0; i < _before.length; i++) { if (_before[i] == null) { continue; } if (ArrayUtils.contains(medial, _before)) { continue; } medial[n++] = _before[i]; } if (n == _before.length) { return medial; } String[] result = new String[n]; for (int i = 0; i < n; i++) { result[i] = medial[i]; } return result; }
From source file:jef.tools.StringUtils.java
/** * // w w w .j a v a 2 s . c o m * * @param str * @param notremove * @return */ public static String removeCharsExcept(String str, char... notremove) { if (isEmpty(str)) return str; char chars[] = str.toCharArray(); int pos = 0; for (int i = 0; i < chars.length; i++) if (ArrayUtils.contains(notremove, chars[i])) chars[pos++] = chars[i]; return new String(chars, 0, pos); }
From source file:com.laxser.blitz.web.impl.module.ModulesBuilderImpl.java
private void registerBeanDefinitions(XmlWebApplicationContext context, List<Class<?>> classes) { DefaultListableBeanFactory bf = (DefaultListableBeanFactory) context.getBeanFactory(); String[] definedClasses = new String[bf.getBeanDefinitionCount()]; String[] definitionNames = bf.getBeanDefinitionNames(); for (int i = 0; i < definedClasses.length; i++) { String name = definitionNames[i]; definedClasses[i] = bf.getBeanDefinition(name).getBeanClassName(); }//from w ww . ja va 2 s. co m for (Class<?> clazz : classes) { // ? if (!isCandidate(clazz)) { continue; } // bean String clazzName = clazz.getName(); if (ArrayUtils.contains(definedClasses, clazzName)) { if (logger.isDebugEnabled()) { logger.debug( "Ignores bean definition because it has been exist in context: " + clazz.getName()); } continue; } // String beanName = null; if (StringUtils.isEmpty(beanName) && clazz.isAnnotationPresent(Component.class)) { beanName = clazz.getAnnotation(Component.class).value(); } if (StringUtils.isEmpty(beanName) && clazz.isAnnotationPresent(Resource.class)) { beanName = clazz.getAnnotation(Resource.class).name(); } if (StringUtils.isEmpty(beanName) && clazz.isAnnotationPresent(Service.class)) { beanName = clazz.getAnnotation(Service.class).value(); } if (StringUtils.isEmpty(beanName)) { beanName = AUTO_BEAN_NAME_PREFIX + clazz.getName(); } bf.registerBeanDefinition(beanName, new AnnotatedGenericBeanDefinition(clazz)); } }
From source file:jef.tools.StringUtils.java
/** * /*w ww . j av a 2 s .c om*/ * * @param str * @param remove * @return */ public static String removeChars(String str, char... remove) { if (isEmpty(str)) return str; char chars[] = str.toCharArray(); int pos = 0; for (int i = 0; i < chars.length; i++) if (!ArrayUtils.contains(remove, chars[i])) chars[pos++] = chars[i]; return new String(chars, 0, pos); }
From source file:com.autentia.wuija.persistence.impl.hibernate.HibernateGroupManagementTest.java
private void checkUserRoles(String userName, GrantedAuthority[] roles) { final UserDetails user = userManager.loadUserByUsername(userName); final GrantedAuthority[] authorities = user.getAuthorities(); if (log.isDebugEnabled()) { final StringBuilder builder = new StringBuilder("Checking " + userName + " authorities. Expected:"); for (GrantedAuthority authority : roles) { builder.append(" ").append(authority.getAuthority()); }// w w w . j av a 2 s. c om builder.append(", actual:"); for (GrantedAuthority authority : authorities) { builder.append(" ").append(authority.getAuthority()); } log.debug(builder); } Assert.assertEquals(userName + " authorities length", roles.length, authorities.length); for (GrantedAuthority authority : authorities) { Assert.assertTrue("roles contains authority " + authority, ArrayUtils.contains(roles, authority)); } }
From source file:com.htmlhifive.tools.jslint.library.LibraryManager.java
/** * ??????????.//from w ww . j a va2 s. co m * * @param iFile * @return ????true,????????false */ public boolean isTargetFile(IFile iFile) { return ArrayUtils.contains(getSourceFiles(), iFile); }
From source file:com.adobe.acs.commons.oak.impl.EnsureOakIndexJobHandler.java
/** * Update the oak index with the ensure definition. * * @param ensureDefinition the ensure definition * @param oakIndexes the parent oak index folder * @param forceReindex indicates if a recreate of the index is requested * @return the updated oak index resource * @throws RepositoryException/*from w ww. j a v a 2s .c om*/ * @throws IOException */ @SuppressWarnings("squid:S3776") public Resource update(final @Nonnull Resource ensureDefinition, final @Nonnull Resource oakIndexes, boolean forceReindex) throws RepositoryException, IOException { final ValueMap ensureDefinitionProperties = ensureDefinition.getValueMap(); final Resource oakIndex = oakIndexes.getChild(ensureDefinition.getName()); final Node oakIndexNode = oakIndex.adaptTo(Node.class); final Node ensureDefinitionNode = ensureDefinition.adaptTo(Node.class); if (!this.needsUpdate(ensureDefinition, oakIndex)) { if (ensureDefinitionProperties.get(PN_FORCE_REINDEX, false)) { log.info( "Skipping update... Oak Index at [ {} ] is the same as [ {} ] and forceIndex flag is ignored", oakIndex.getPath(), ensureDefinition.getPath()); } else { log.info("Skipping update... Oak Index at [ {} ] is the same as [ {} ]", oakIndex.getPath(), ensureDefinition.getPath()); } return null; } // Handle oak:QueryIndexDefinition node // Do NOT delete it as this will delete the existing index below it // Clear out existing properties final Iterator<Property> existingOakIndexProperties = copyIterator(oakIndexNode.getProperties()); while (existingOakIndexProperties.hasNext()) { final Property property = existingOakIndexProperties.next(); final String propertyName = property.getName(); if (this.ignoreProperties.contains(propertyName)) { continue; } JcrUtil.setProperty(oakIndexNode, propertyName, null); } // Add new properties final Iterator<Property> addProperties = copyIterator(ensureDefinitionNode.getProperties()); while (addProperties.hasNext()) { final Property property = addProperties.next(); if (this.ignoreProperties.contains(property.getName())) { // Skip ignored properties continue; } if (ArrayUtils.contains(NAME_PROPERTIES, property.getName()) && property.getType() != PropertyType.NAME) { log.warn("{}@{} property should be of type: Name[]", oakIndex.getPath(), property.getName()); } JcrUtil.copy(property, oakIndexNode, property.getName()); } JcrUtil.setProperty(oakIndexNode, JcrConstants.JCR_LAST_MODIFIED_BY, ENSURE_OAK_INDEX_USER_NAME); JcrUtil.setProperty(oakIndexNode, JcrConstants.JCR_LASTMODIFIED, Calendar.getInstance()); // Handle all sub-nodes (ex. Lucene Property Indexes) // Delete child nodes Iterator<Resource> children = oakIndex.listChildren(); while (children.hasNext()) { children.next().adaptTo(Node.class).remove(); } // Deep copy over child nodes children = ensureDefinition.listChildren(); while (children.hasNext()) { final Resource child = children.next(); JcrUtil.copy(child.adaptTo(Node.class), oakIndex.adaptTo(Node.class), child.getName()); } if (forceReindex) { log.info("Updated Oak Index at [ {} ] with configuration [ {} ], triggering reindex", oakIndex.getPath(), ensureDefinition.getPath()); forceRefresh(oakIndex); } else { // A reindexing should be required to make this change effective, so WARN if not present log.warn("Updated Oak Index at [ {} ] with configuration [ {} ], but no reindex requested!", oakIndex.getPath(), ensureDefinition.getPath()); } return oakIndex; }
From source file:com.flexive.tests.embedded.ConfigurationTest.java
/** * Test the global configuration/*from w ww . j a va 2 s . com*/ * * @throws Exception if an error occurred */ @Test public void globalConfiguration() throws Exception { try { FxContext.get().setGlobalAuthenticated(false); globalConfiguration.put(TestParameters.CACTUS_TEST, "test"); fail("Global configuration modifiable without global admin login!"); } catch (FxNoAccessException e) { // pass } final GlobalConfigurationEngine config = EJBLookup.getGlobalConfigurationEngine(); // check if privileges are respected for all config actions testGenericConfiguration(config); try { FxContext.get().setGlobalAuthenticated(true); testGenericConfiguration(config); } finally { FxContext.get().setGlobalAuthenticated(false); } // test division infos int[] divisionIds = config.getDivisionIds(); int ctr = 0; for (DivisionData data : config.getDivisions()) { assertTrue(ArrayUtils.contains(divisionIds, data.getId()), "Division ID not returned by getDivisionIds()."); assertTrue(StringUtils.isNotBlank(data.getDataSource()), "Division data source not returned"); assertTrue(StringUtils.isNotBlank(data.getDomainRegEx()), "Domain regexp missing"); if (data.isAvailable()) { assertTrue(StringUtils.isNotBlank(data.getDbVersion()), "DB version missing"); assertTrue(!data.getDbVendor().equals("Unknown"), "DB vendor missing"); } config.clearDivisionCache(); assertTrue(config.getDivisionData(data.getId()).equals(data)); ctr++; } assertTrue(ctr == divisionIds.length, "getDivisions() and getDivisionIds() array length don't match"); // test division table update final DivisionData[] orig = config.getDivisions(); FxContext.get().setGlobalAuthenticated(true); try { final DivisionData newDivision = new DivisionData(1, false, "test", "xxx", "Unknown", "1.2", "Unknown"); config.saveDivisions(Arrays.asList(newDivision)); assertTrue(config.getDivisions().length == 1, "Division table not updated"); assertTrue(config.getDivisions()[0].equals(newDivision), "New division not written properly"); } finally { config.saveDivisions(Arrays.asList(orig)); assertTrue(Arrays.equals(config.getDivisions(), orig)); FxContext.get().setGlobalAuthenticated(false); } }