List of usage examples for org.apache.commons.collections CollectionUtils intersection
public static Collection intersection(final Collection a, final Collection b)
From source file:org.jahia.services.render.filter.cache.LegacyAclCacheKeyPartGenerator.java
@SuppressWarnings("unchecked") private Map<String, Set<String>> getPrincipalAcl(final String aclKey, final String siteKey) throws RepositoryException { final String cacheKey = siteKey != null ? aclKey + ":" + siteKey : aclKey; Element element = cache.get(cacheKey); if (element == null) { Semaphore semaphore = processings.get(cacheKey); if (semaphore == null) { semaphore = new Semaphore(1); processings.putIfAbsent(cacheKey, semaphore); }//from w ww.ja v a 2 s .com try { semaphore.tryAcquire(500, TimeUnit.MILLISECONDS); element = cache.get(cacheKey); if (element != null) { return (Map<String, Set<String>>) element.getObjectValue(); } logger.debug("Getting ACL for {}", cacheKey); long l = System.currentTimeMillis(); Map<String, Set<String>> map = template.doExecuteWithSystemSessionAsUser(null, Constants.LIVE_WORKSPACE, null, new JCRCallback<Map<String, Set<String>>>() { @Override public Map<String, Set<String>> doInJCR(JCRSessionWrapper session) throws RepositoryException { Query query = session.getWorkspace().getQueryManager() .createQuery("select * from [jnt:ace] as ace where ace.[j:principal] = '" + JCRContentUtils.sqlEncode(aclKey) + "'", Query.JCR_SQL2); QueryResult queryResult = query.execute(); NodeIterator rowIterator = queryResult.getNodes(); Map<String, Set<String>> mapGranted = new ConcurrentHashMap<String, Set<String>>(); Map<String, Set<String>> mapDenied = new LinkedHashMap<String, Set<String>>(); while (rowIterator.hasNext()) { JCRNodeWrapper node = (JCRNodeWrapper) rowIterator.next(); if (siteKey != null && !node.getResolveSite().getName().equals(siteKey)) { continue; } String path = node.getParent().getParent().getPath(); Set<String> foundRoles = new HashSet<String>(); boolean granted = node.getProperty("j:aceType").getString().equals("GRANT"); Value[] roles = node.getProperty(Constants.J_ROLES).getValues(); for (Value r : roles) { String role = r.getString(); if (!foundRoles.contains(role)) { foundRoles.add(role); } } if (path.equals("/")) { path = ""; } if (granted) { mapGranted.put(path, foundRoles); } else { mapDenied.put(path, foundRoles); } } for (String deniedPath : mapDenied.keySet()) { String grantedPath = deniedPath; while (grantedPath.length() > 0) { grantedPath = StringUtils.substringBeforeLast(grantedPath, "/"); if (mapGranted.containsKey(grantedPath)) { Collection<String> intersection = CollectionUtils.intersection( mapGranted.get(grantedPath), mapDenied.get(deniedPath)); for (String s : intersection) { mapGranted.get(grantedPath).add(s + " -> " + deniedPath); } } } } return mapGranted; } }); element = new Element(cacheKey, map); element.setEternal(true); cache.put(element); logger.debug("Getting ACL for {} took {} ms", cacheKey, System.currentTimeMillis() - l); } catch (InterruptedException e) { logger.debug(e.getMessage(), e); } finally { semaphore.release(); } } return (Map<String, Set<String>>) element.getObjectValue(); }
From source file:org.jahia.services.render.filter.cache.PrincipalAcl.java
public PrincipalAcl(Map<String, Set<String>> mapGranted, Map<String, Set<String>> mapDenied) { for (Map.Entry<String, Set<String>> entry : mapGranted.entrySet()) { grantAceByPath.put(entry.getKey(), new HashMap<String, SortedSet<String>>()); for (String role : entry.getValue()) { grantAceByPath.get(entry.getKey()).put(role, null); }/*from w w w .j av a 2s . co m*/ } for (Map.Entry<String, Set<String>> entry : mapDenied.entrySet()) { String path = entry.getKey(); String grantedPath = path; while (grantedPath.length() > 0) { grantedPath = StringUtils.substringBeforeLast(grantedPath, "/"); if (grantAceByPath.containsKey(grantedPath)) { Map<String, SortedSet<String>> rolesMap = grantAceByPath.get(grantedPath); Collection<String> intersection = CollectionUtils.intersection(rolesMap.keySet(), entry.getValue()); for (String s : intersection) { if (rolesMap.get(s) == null) { rolesMap.put(s, new TreeSet<String>()); } rolesMap.get(s).add(path); } } } } allPaths.addAll(mapGranted.keySet()); allPaths.addAll(mapDenied.keySet()); }
From source file:org.jannocessor.collection.impl.PowerArrayList.java
@SuppressWarnings("unchecked") @Override//www . j a v a2 s . co m public PowerList<E> getIntersection(Collection<E> list) { return powerList(CollectionUtils.intersection(this, list)); }
From source file:org.jannocessor.collection.impl.PowerLinkedHashSet.java
@SuppressWarnings("unchecked") public PowerSet<E> getIntersection(Collection<E> Set) { return powerSet(CollectionUtils.intersection(this, Set)); }
From source file:org.jboss.dashboard.commons.comparator.ComparatorUtils.java
/** * Check if tow collections contains exactly the same elements. * The order of elements within each collection is not relevant. *///from w w w. j a va 2 s . c o m public static boolean equals(Collection o1, Collection o2) { if (o1 == null && o2 != null) return false; else if (o1 != null && o2 == null) return false; else if (o1 == null && o2 == null) return false; else if (o1.size() != o2.size()) return false; else if (o1.isEmpty() && o2.isEmpty()) return false; else return CollectionUtils.intersection(o1, o2).size() == o1.size(); }
From source file:org.jboss.dashboard.commons.filter.AbstractFilter.java
public boolean equals(Object obj) { try {/*from w ww.ja v a2 s .c o m*/ AbstractFilter other = (AbstractFilter) obj; if (filterProperties.size() != other.filterProperties.size()) return false; for (int i = 0; i < filterProperties.size(); i++) { Object[] tprop = (Object[]) filterProperties.get(i); String propId = (String) tprop[0]; Object[] oprop = other.getProperty(propId); for (int j = 0; j < tprop.length; j++) { if (ComparatorUtils.compare(tprop[j], oprop[j], 1) != 0) { return false; } } // Allowed values must be strictly equals. Collection thisAllowed = getPropertyAllowedValues(propId); Collection otherAllowed = other.getPropertyAllowedValues(propId); if (CollectionUtils.intersection(thisAllowed, otherAllowed).size() != thisAllowed.size()) { return false; } } return true; } catch (ClassCastException e) { return false; } }
From source file:org.jenkinsci.plugins.drupal.beans.DrushInvocation.java
/** * Run a code review.//from w w w . ja va 2s .c o m */ public boolean coderReview(File outputDir, Collection<String> reviews, final Collection<String> projectNames, boolean ignoresPass) throws IOException, InterruptedException { // Make sure Coder is enabled. DrupalExtension coder = getProjects(true, true).get("coder"); if (coder == null) { listener.getLogger().println("[DRUPAL] Coder does not exist: aborting code review"); return false; } // Build command depending on Coder's version. ArgumentListBuilder args = getArgumentListBuilder(); args.add("coder-review"); if (coder.getVersion().startsWith("7.x-2")) { args.add("--minor"); args.add("--checkstyle"); args.add("--reviews=" + StringUtils.join(reviews, ",")); } else if (coder.getVersion().startsWith("7.x-1")) { args.add("minor"); args.add("checkstyle"); for (String review : reviews) { args.add(review); } } else { listener.getLogger().println("[DRUPAL] Unsupported Coder version " + coder.getVersion()); return false; } // Ignores pass if needed. // This option works only with coder-7.x-2.4+. if (ignoresPass) { if (coder.getVersion().startsWith("7.x-2") && (Integer.parseInt(coder.getVersion().replaceFirst("7\\.x-2\\.", "")) >= 4)) { args.add("--ignores-pass"); } else { listener.getLogger().println( "[DRUPAL]'Ignores pass' option is available only with Coder-7.x-2.4+, ignoring option"); } } // In coder-7.x-2.x, 'drush coder-review comment' fails with error "use --reviews or --comment". Same for i18n. // Ignore projects involved in conflicts. Collection<String> conflicts = CollectionUtils.intersection(projectNames, reviews); if (!conflicts.isEmpty()) { listener.getLogger().println("[DRUPAL] Ignoring project(s) conflicting with Coder options: " + StringUtils.join(conflicts, ", ")); } for (String projectName : projectNames) { if (!conflicts.contains(projectName)) { args.add(projectName); } } // Run command. File outputFile = new File(outputDir, "coder_review.xml"); return execute(args, new StreamTaskListener(outputFile)); }
From source file:org.jimcat.util.SetUtils.java
/** * This methode is creating an intersection set for the given sets. * // ww w . j av a 2s . c o m * @param <T> - * generic type of the sets * @param a - * set a * @param b - * set b * @return returns a set containing the intersection of set a and b */ @SuppressWarnings("unchecked") public static <T> Set<T> intersection(Set<T> a, Set<T> b) { return new HashSet<T>(CollectionUtils.intersection(a, b)); }
From source file:org.jumpmind.symmetric.service.impl.RouterService.java
@SuppressWarnings("unchecked") protected int routeData(ProcessInfo processInfo, Data data, ChannelRouterContext context) { int numberOfDataEventsInserted = 0; List<TriggerRouter> triggerRouters = getTriggerRoutersForData(data); Table table = symmetricDialect.getTable(data.getTriggerHistory(), true); if (triggerRouters != null && triggerRouters.size() > 0) { for (TriggerRouter triggerRouter : triggerRouters) { DataMetaData dataMetaData = new DataMetaData(data, table, triggerRouter.getRouter(), context.getChannel()); Collection<String> nodeIds = null; if (!context.getChannel().isIgnoreEnabled() && triggerRouter.isRouted(data.getDataEventType())) { String targetNodeIds = data.getNodeList(); if (StringUtils.isNotBlank(targetNodeIds)) { List<String> targetNodeIdsList = Arrays.asList(targetNodeIds.split(",")); nodeIds = CollectionUtils.intersection(targetNodeIdsList, toNodeIds(findAvailableNodes(triggerRouter, context))); if (nodeIds.size() == 0) { log.info(//w w w. ja v a2 s . c om "None of the target nodes specified in the data.node_list field ({}) were qualified nodes. {} will not be routed using the {} router", new Object[] { targetNodeIds, data.getDataId(), triggerRouter.getRouter().getRouterId() }); } } else { try { IDataRouter dataRouter = getDataRouter(triggerRouter.getRouter()); context.addUsedDataRouter(dataRouter); long ts = System.currentTimeMillis(); nodeIds = dataRouter.routeToNodes(context, dataMetaData, findAvailableNodes(triggerRouter, context), false, false, triggerRouter); context.incrementStat(System.currentTimeMillis() - ts, ChannelRouterContext.STAT_DATA_ROUTER_MS); } catch (RuntimeException ex) { StringBuilder failureMessage = new StringBuilder("Failed to route data: "); failureMessage.append(data.getDataId()); failureMessage.append(" for table: "); failureMessage.append(data.getTableName()); failureMessage.append(".\n"); data.writeCsvDataDetails(failureMessage); log.error(failureMessage.toString()); throw ex; } } if (nodeIds != null) { if (!triggerRouter.isPingBackEnabled() && data.getSourceNodeId() != null) { nodeIds.remove(data.getSourceNodeId()); } // should never route to self nodeIds.remove(engine.getNodeService().findIdentityNodeId()); } } numberOfDataEventsInserted += insertDataEvents(processInfo, context, dataMetaData, nodeIds); } } else { log.warn( "Could not find trigger routers for trigger history id of {}. There is a good chance that data was captured and the trigger router link was removed before the data could be routed", data.getTriggerHistory().getTriggerHistoryId()); log.info("Data with the id of {} will be assigned to an unrouted batch", data.getDataId()); numberOfDataEventsInserted += insertDataEvents(processInfo, context, new DataMetaData(data, table, null, context.getChannel()), new HashSet<String>(0)); } context.incrementStat(numberOfDataEventsInserted, ChannelRouterContext.STAT_DATA_EVENTS_INSERTED); return numberOfDataEventsInserted; }
From source file:org.jwebsocket.plugins.system.SystemPlugIn.java
/** * Gets the client headers and put them into connector variables * * @param aConnector// w ww .jav a 2 s .com * @param aToken */ private void getHeaders(WebSocketConnector aConnector, Token aToken) { aConnector.setVar("clientType", aToken.getString("clientType")); aConnector.setVar("clientName", aToken.getString("clientName")); aConnector.setVar("clientVersion", aToken.getString("clientVersion")); aConnector.setVar("clientInfo", aToken.getString("clientInfo")); aConnector.setVar("jwsType", aToken.getString("jwsType")); aConnector.setVar("jwsVersion", aToken.getString("jwsVersion")); aConnector.setVar("jwsInfo", aToken.getString("jwsInfo")); List lUserFormats = aToken.getList(JWebSocketCommonConstants.ENCODING_FORMATS_VAR_KEY); List lEncodingFormats = new FastList(); if (null != lUserFormats && !lUserFormats.isEmpty()) { lEncodingFormats.addAll(lUserFormats); } // getting the string format of the user supported encodings String lEncFormats = StringUtils .join(CollectionUtils.intersection(lEncodingFormats, SystemFilter.getSupportedEncodings()), ","); aConnector.setVar(JWebSocketCommonConstants.ENCODING_FORMATS_VAR_KEY, lEncFormats); if (mLog.isDebugEnabled()) { mLog.debug("Processing 'getHeaders' from connector '" + aConnector.getId() + "'..."); } }