List of usage examples for org.apache.commons.collections CollectionUtils addAll
public static void addAll(Collection collection, Object[] elements)
From source file:org.kuali.rice.core.api.criteria.PredicateFactory.java
/** * Creates an or predicate that is used to "or" predicate together. * * <p>An "or" predicate will evaluate the truth value of of it's * internal predicates and, if any one of them evaluate to true, then * the or predicate itself should evaluate to true. If all predicates * contained within the "or" evaluate to false, then the or iself will * evaluate to false. The implementation of an or predicate may * short-circuit./*from ww w . java2 s .c o m*/ * * <p> * This factory method does automatic reductions. * </p> * @param predicates to "or" together * * @return a predicate */ public static Predicate or(Predicate... predicates) { //reduce single item compound if (predicates != null && predicates.length == 1 && predicates[0] != null) { return predicates[0]; } final Set<Predicate> predicateSet = new HashSet<Predicate>(); CollectionUtils.addAll(predicateSet, predicates); return new OrPredicate(predicateSet); }
From source file:org.mule.modules.handshake.client.impl.GenericHandshakeClientImpl.java
@Override public Collection<T> getAll(final Map<String, String> filters, final boolean fetchAllResults) { final GenericHandshakeClientImpl<T> client = this; final Collection<T> pagedResult = new PaginatedCollection<T, HandshakeAPIResponse<T>>() { private HandshakeAPIResponse<T> first; @Override/*from w w w . j av a 2 s . c o m*/ protected synchronized HandshakeAPIResponse<T> firstPage() { if (first == null) { first = client.paginate(filters, null, null); } return first; } @Override protected boolean hasNextPage(final HandshakeAPIResponse<T> currentPage) { return currentPage.getMeta().getNextOffset() != null; } @Override protected HandshakeAPIResponse<T> nextPage(final HandshakeAPIResponse<T> currentPage) { return client.paginate(filters, currentPage.getMeta().getLimit(), currentPage.getMeta().getNextOffset()); } @Override protected Iterator<T> pageIterator(final HandshakeAPIResponse<T> currentPage) { return currentPage.getObjects().iterator(); } @Override public boolean isEmpty() { return (this.size() == 0); } @Override public int size() { return this.firstPage().getMeta().getTotalCount(); } }; if (fetchAllResults) { final Collection<T> result = new ArrayList<T>(pagedResult.size()); CollectionUtils.addAll(result, pagedResult.iterator()); return result; } else { return pagedResult; } }
From source file:org.nuxeo.connect.packages.PackageManagerImpl.java
/** * Sort the given orderedList list of package ids by dependencies and optional dependencies. If a package A has a * dependency on a package B, B will be ordered before A. If B is missing, a {@link DependencyException} will be * thrown. If a package C has an optional dependency on a package D, D will be ordered before C. If D is missing, a * message will be logged to inform that D will be ignored. * * @param allPackagesByID all available packages sorted by id * @param listToOrder the package ids list to order * @param orderedRemoveList the package ids list which are going to be removed * @param isRemoveList if true, no message will be logged for missing optional dependencies * @throws DependencyException if one ore more dependency (non optional) is missing *///w ww . java 2s .co m private void orderByDependencies(Map<String, DownloadablePackage> allPackagesByID, List<String> listToOrder, List<String> orderedRemoveList, boolean isRemoveList) throws DependencyException { Map<String, Package> orderedMap = Collections.synchronizedMap(new LinkedHashMap<String, Package>()); boolean hasChanged = true; Set<String> missingDeps = new HashSet<>(); Map<String, Set<String>> optionalMissingDeps = new HashMap<>(); while (!listToOrder.isEmpty() && hasChanged) { hasChanged = false; for (String id : listToOrder) { DownloadablePackage pkg = allPackagesByID.get(id); if (pkg.getDependencies().length == 0 && pkg.getOptionalDependencies().length == 0) { // Add pkg to orderedMap if it has no dependencies nor optional dependencies orderedMap.put(id, pkg); hasChanged = true; } else { // Add to orderedMap if all its dependencies and optional dependencies are satisfied boolean allSatisfied = true; List<PackageDependency> allDependencies = new ArrayList<>(); CollectionUtils.addAll(allDependencies, pkg.getDependencies()); List<PackageDependency> optionalDependencies = Arrays.asList(pkg.getOptionalDependencies()); allDependencies.addAll(optionalDependencies); for (PackageDependency pkgDep : allDependencies) { // is pkDep optional? boolean isOptionalPkgDep = optionalDependencies.contains(pkgDep); // is pkgDep satisfied in orderedMap? boolean satisfied = false; for (Package orderedPkg : orderedMap.values()) { if (matchDependency(pkgDep, orderedPkg)) { satisfied = true; if (isOptionalPkgDep) { if (optionalMissingDeps.get(id) != null) { optionalMissingDeps.get(id).remove(pkgDep.toString()); } } else { missingDeps.remove(pkgDep.toString()); } break; } } // else, is pkgDep satisfied in already installed pkgs and is not going to be removed or // upgraded ? if (!satisfied && !hasMatchInIdList(pkgDep, listToOrder)) { for (Version version : findLocalPackageInstalledVersions(pkgDep.getName())) { if ((isRemoveList || !hasMatchInIdList(pkgDep.getName(), version, orderedRemoveList)) && pkgDep.getVersionRange().matchVersion(version)) { satisfied = true; if (isOptionalPkgDep) { if (optionalMissingDeps.get(id) != null) { optionalMissingDeps.get(id).remove(pkgDep.toString()); } } else { missingDeps.remove(pkgDep.toString()); } break; } } // if it's an optional dependency that will not be installed if (!satisfied && isOptionalPkgDep) { // consider the pkDep as satisfied, but add it in optional missing dependencies for // logging if it is not going to be removed satisfied = true; if (!hasMatchInIdList(pkgDep, orderedRemoveList)) { optionalMissingDeps.computeIfAbsent(id, k -> new HashSet<>()) .add(pkgDep.toString()); } } } if (!satisfied) { // couldn't satisfy pkgDep allSatisfied = false; if (isOptionalPkgDep) { optionalMissingDeps.computeIfAbsent(id, k -> new HashSet<>()) .add(pkgDep.toString()); } else { missingDeps.add(pkgDep.toString()); } break; } } if (allSatisfied) { orderedMap.put(id, pkg); orderedRemoveList.remove(pkg.getName()); hasChanged = true; } } } listToOrder.removeAll(orderedMap.keySet()); } if (!optionalMissingDeps.isEmpty() && !isRemoveList) { for (Entry<String, Set<String>> entry : optionalMissingDeps.entrySet()) { if (entry.getValue() != null && !entry.getValue().isEmpty()) { log.info(String.format("Optional dependencies %s will be ignored for '%s'.", entry.getValue(), entry.getKey())); } } } if (!listToOrder.isEmpty()) { if (missingDeps.isEmpty()) { for (String id : listToOrder) { DownloadablePackage pkg = allPackagesByID.get(id); orderedMap.put(id, pkg); } listToOrder.clear(); } else { throw new DependencyException( String.format("Couldn't order %s missing %s.", listToOrder, missingDeps)); } } listToOrder.addAll(orderedMap.keySet()); }
From source file:org.omnaest.utils.structure.container.ByteArrayContainer.java
/** * Returns the content as a list of strings, separated by an arbitrary regular expression. * /*from w ww .ja v a2 s. c o m*/ * @param encoding * : for example = "utf-8" * @see #ENCODING_UTF8 * @return */ public List<String> toStringList(String encoding, String regExDelimiter) { // List<String> retlist = new ArrayList<String>(); // String content = this.toString(encoding); // final String tokenDelimiter = "}>|<{"; content = content.replaceAll(regExDelimiter, tokenDelimiter); String[] lines = StringUtils.splitByWholeSeparatorPreserveAllTokens(content, tokenDelimiter); CollectionUtils.addAll(retlist, lines); // return retlist; }
From source file:org.openanzo.glitter.syntax.abstrakt.TreeNode.java
/** * * @return A set of all filters {@link Expression}s that are in scope (act on the bindings) for this tree node. *//*from ww w. j av a 2s . co m*/ @SuppressWarnings("unchecked") final public Set<Expression> getInScopeFilterSet() { Object o = this.cache.get(inScopeFilterSetKey); if (o != null) return (Set<Expression>) o; HashSet<Expression> filters = new HashSet<Expression>(); CollectionUtils.addAll(filters, this.getFilters().iterator()); if (this.getParent() != null) filters.addAll(this.getParent().getInScopeFilterSet()); this.cache.put(inScopeFilterSetKey, filters); return filters; }
From source file:org.openengsb.core.common.internal.VirtualConnectorManager.java
protected static <T> Collection<T> getServicesFromTracker(ServiceTracker tracker, Class<T> serviceClass) { Collection<T> result = new ArrayList<T>(); if (tracker == null) { return result; }// w ww . j a v a 2 s .c o m Object[] services = tracker.getServices(); if (services != null) { CollectionUtils.addAll(result, services); } return result; }
From source file:org.openengsb.core.common.SecurityAttributeProviderImpl.java
public void putAttribute(Object key, SecurityAttributeEntry... values) { if (!data.containsKey(key)) { data.put(key, new HashSet<SecurityAttributeEntry>()); }/*from w w w. ja va 2 s . co m*/ CollectionUtils.addAll(data.get(key), values); }
From source file:org.openengsb.core.util.DefaultOsgiUtilsService.java
private <T> List<T> getListFromTracker(ServiceTracker tracker) { tracker.open();//w ww. j a va 2 s. c om Object[] services = tracker.getServices(); List<T> result = new ArrayList<T>(); if (services != null) { CollectionUtils.addAll(result, services); } tracker.close(); return result; }
From source file:org.opens.tgol.controller.AuditResultController.java
private Collection<String> getTestResultSortSelection(AuditResultSortCommand asuc) { Collection<String> selectedValues = new HashSet<String>(); if ((asuc.getSortOptionMap().get(testResultSortKey)) instanceof Object[]) { CollectionUtils.addAll(selectedValues, ((Object[]) asuc.getSortOptionMap().get(testResultSortKey))); } else if ((asuc.getSortOptionMap().get(testResultSortKey)) instanceof String) { selectedValues.add((String) asuc.getSortOptionMap().get(testResultSortKey)); }/*from www . j ava2 s .c o m*/ return selectedValues; }
From source file:org.openvpms.web.component.im.query.LocalSortResultSet.java
/** * Sorts the set. This resets the iterator. * * @param sort the sort criteria. May be <tt>null</tt> */// w w w . j av a 2s.c o m public void sort(SortConstraint[] sort) { ResultSet<T> set; if (!sortLocally(sort)) { // revert to the original set, using its sorting mechanism set = original; local = null; } else { if (local == null) { // load all of the objects List<T> objects = new ArrayList<T>(); original.reset(); CollectionUtils.addAll(objects, new ResultSetIterator<T>(original)); local = new IMObjectListResultSet<T>(objects, getPageSize()); } set = local; } set.sort(sort); setResultSet(set); }