/** * Delegates to {@link CollectionUtils#collect(Collection, Transformer)}, but performs the necessary type coercion * to allow the returned collection to be correctly casted based on the TypedTransformer. * * @param inputCollection * @param transformer * @return the typed, collected Collection */ @SuppressWarnings({ "unchecked", "rawtypes" }) public static <T> Collection<T> collect(Collection inputCollection, TypedTransformer<T> transformer) { return CollectionUtils.collect(inputCollection, transformer); }
/** * Transforms all elements from the inputIterator with the given transformer * and adds them to the outputCollection. * <p> * If the input iterator or transformer is null, the result is an empty list. * * @param inputIterator the iterator to get the input from, may be null * @param transformer the transformer to use, may be null * @return the transformed result (new list) */ public static Collection collect(Iterator inputIterator, Transformer transformer) { ArrayList answer = new ArrayList(); collect(inputIterator, transformer, answer); return answer; }
/** * Transforms all elements from the inputIterator with the given transformer * and adds them to the outputCollection. * <p> * If the input iterator or transformer is null, the result is an empty list. * * @param inputIterator the iterator to get the input from, may be null * @param transformer the transformer to use, may be null * @return the transformed result (new list) */ public static Collection collect(Iterator inputIterator, Transformer transformer) { ArrayList answer = new ArrayList(); collect(inputIterator, transformer, answer); return answer; }
/** * Transforms all elements from inputCollection with the given transformer * and adds them to the outputCollection. * <p> * If the input collection or transformer is null, there is no change to the * output collection. * * @param inputCollection the collection to get the input from, may be null * @param transformer the transformer to use, may be null * @param outputCollection the collection to output into, may not be null * @return the outputCollection with the transformed input added * @throws NullPointerException if the output collection is null */ public static Collection collect(Collection inputCollection, final Transformer transformer, final Collection outputCollection) { if (inputCollection != null) { return collect(inputCollection.iterator(), transformer, outputCollection); } return outputCollection; }
/** * Returns a new Collection consisting of the elements of inputCollection transformed * by the given transformer. * <p> * If the input transformer is null, the result is an empty list. * * @param inputCollection the collection to get the input from, may not be null * @param transformer the transformer to use, may be null * @return the transformed result (new list) * @throws NullPointerException if the input collection is null */ public static Collection collect(Collection inputCollection, Transformer transformer) { ArrayList answer = new ArrayList(inputCollection.size()); collect(inputCollection, transformer, answer); return answer; }
/** * Transforms all elements from inputCollection with the given transformer * and adds them to the outputCollection. * <p> * If the input collection or transformer is null, there is no change to the * output collection. * * @param inputCollection the collection to get the input from, may be null * @param transformer the transformer to use, may be null * @param outputCollection the collection to output into, may not be null * @return the outputCollection with the transformed input added * @throws NullPointerException if the output collection is null */ public static Collection collect(Collection inputCollection, final Transformer transformer, final Collection outputCollection) { if (inputCollection != null) { return collect(inputCollection.iterator(), transformer, outputCollection); } return outputCollection; }
/** * Returns a new Collection consisting of the elements of inputCollection transformed * by the given transformer. * <p> * If the input transformer is null, the result is an empty list. * * @param inputCollection the collection to get the input from, may not be null * @param transformer the transformer to use, may be null * @return the transformed result (new list) * @throws NullPointerException if the input collection is null */ public static Collection collect(Collection inputCollection, Transformer transformer) { ArrayList answer = new ArrayList(inputCollection.size()); collect(inputCollection, transformer, answer); return answer; }
/** * Transform the collection by applying a Transformer to each element. * <p> * If the input collection or transformer is null, there is no change made. * <p> * This routine is best for Lists, for which set() is used to do the * transformations "in place." For other Collections, clear() and addAll() * are used to replace elements. * <p> * If the input collection controls its input, such as a Set, and the * Transformer creates duplicates (or are otherwise invalid), the * collection may reduce in size due to calling this method. * * @param collection the collection to get the input from, may be null * @param transformer the transformer to perform, may be null */ public static void transform(Collection collection, Transformer transformer) { if (collection != null && transformer != null) { if (collection instanceof List) { List list = (List) collection; for (ListIterator it = list.listIterator(); it.hasNext();) { it.set(transformer.transform(it.next())); } } else { Collection resultCollection = collect(collection, transformer); collection.clear(); collection.addAll(resultCollection); } } }
/** * Transform the collection by applying a Transformer to each element. * <p> * If the input collection or transformer is null, there is no change made. * <p> * This routine is best for Lists, for which set() is used to do the * transformations "in place." For other Collections, clear() and addAll() * are used to replace elements. * <p> * If the input collection controls its input, such as a Set, and the * Transformer creates duplicates (or are otherwise invalid), the * collection may reduce in size due to calling this method. * * @param collection the collection to get the input from, may be null * @param transformer the transformer to perform, may be null */ public static void transform(Collection collection, Transformer transformer) { if (collection != null && transformer != null) { if (collection instanceof List) { List list = (List) collection; for (ListIterator it = list.listIterator(); it.hasNext();) { it.set(transformer.transform(it.next())); } } else { Collection resultCollection = collect(collection, transformer); collection.clear(); collection.addAll(resultCollection); } } }
@SuppressWarnings("unchecked") @Override protected int calculatePrecedence(WorkQueue wq) { // FIXME: it's ridiculously inefficient to do this every time, // and optimizing will probably require inserting stateful policy // helper object into WorkQueue -- expected when URI-precedence is // also supported int precedence = getBasePrecedence() - 1; Collection<Integer> increments = CollectionUtils.collect( Arrays.asList(getIncrementCounts().split(",")), new Transformer() { public Object transform(final Object string) { return Integer.parseInt((String)string); }}); Iterator<Integer> iter = increments.iterator(); int increment = iter.next(); long successes = wq.getSubstats().getFetchSuccesses(); while(successes>=0) { successes -= increment; precedence++; increment = iter.hasNext() ? iter.next() : increment; } return precedence; } }
Collections.sort(returnCategoryFacets, facetPositionComparator); final Collection<SearchFacet> facets = CollectionUtils.collect(returnCategoryFacets, new Transformer() { @Override public Object transform(Object input) {
result.addAll(CollectionUtils.collect(order.getOrderAdjustments(), adjustmentToOfferTransformer)); result.addAll(CollectionUtils.collect(item.getOrderItemAdjustments(), adjustmentToOfferTransformer)); result.addAll(CollectionUtils.collect(detail.getOrderItemPriceDetailAdjustments(), adjustmentToOfferTransformer)); result.addAll(CollectionUtils.collect(fg.getFulfillmentGroupAdjustments(), adjustmentToOfferTransformer));
CollectionUtils.collect(values, new Transformer() {
message.append("The final ordering of activities for the " + getBeanName() + " workflow is: \n"); ArrayList<String> activityNames = new ArrayList<>(); CollectionUtils.collect(activities, new Transformer() {
public void testCollect() { Transformer transformer = TransformerUtils.constantTransformer("z"); Collection collection = CollectionUtils.collect(collectionA, transformer); assertTrue(collection.size() == collectionA.size()); assertTrue(collectionA.contains("a") && ! collectionA.contains("z")); CollectionUtils.collect(collectionA, transformer, collection); assertTrue(collection.size() == collectionA.size()); assertTrue(collectionA.contains("a") && ! collectionA.contains("z")); CollectionUtils.collect(iterator, transformer, collection); CollectionUtils.collect(iterator, transformer, collection); assertTrue(collection.size() == collectionA.size()); assertTrue(collectionA.contains("a") && ! collectionA.contains("z")); collection = CollectionUtils.collect(iterator, transformer); assertTrue(collection.size() == collectionA.size()); assertTrue(collection.contains("z") && !collection.contains("a")); collection = CollectionUtils.collect((Iterator) null, (Transformer) null); assertTrue(collection.size() == 0); CollectionUtils.collect((Collection) null, transformer, collectionA); assertTrue(collectionA.size() == size && collectionA.contains("a")); CollectionUtils.collect(collectionB, null, collectionA); assertTrue(collectionA.size() == size && collectionA.contains("a"));
/** * Returns a collection of strings corresponding to the name * or uniqueName of each OlapElement in olapElements, based on the * flag uniqueName. */ private Collection<String> getOlapElementNames( OlapElement[] olapElements, final boolean uniqueName) { return CollectionUtils.collect( Arrays.asList(olapElements), new Transformer() { public Object transform(Object o) { return uniqueName ? ((OlapElement)o).getUniqueName() : ((OlapElement)o).getName(); } }); }
@Override public boolean isUpdatedZombieArtifact(String artifactName) { @SuppressWarnings("rawtypes") Collection<String> deployedAppNames = collect(artifacts, new BeanToPropertyValueTransformer(ARTIFACT_NAME_PROPERTY)); if (deployedAppNames.contains(artifactName) && (!artifactZombieMap.containsKey(artifactName))) { return false; } // First get saved zombieFile ZombieArtifact zombieArtifact = artifactZombieMap.get(artifactName); if ((zombieArtifact != null) && (!zombieArtifact.updatedZombieApp())) { return false; } return true; }
/** * Filters the children list to those that contain identifiers * we think we can batch resolve, then transforms the Id list * to the corresponding NameSegment. */ private List<Id.NameSegment> collectChildrenNameSegments( final Member parentMember, List<Id> children) { filter( children, new Predicate() { // remove children we can't support public boolean evaluate(Object theId) { Id id = (Id)theId; return !Util.matches(parentMember, id.getSegments()) && supportedIdentifier(id); } }); return new ArrayList( CollectionUtils.collect( children, new Transformer() { // convert the collection to a list of NameSegments public Object transform(Object theId) { Id id = (Id)theId; return getLastSegment(id); } })); }
@SuppressWarnings ( { "unchecked" }) public Collection<String> getOptionIds() { return CollectionUtils.collect(lazyConstants, new Transformer() { public Object transform(Object input) { return ((LazyIssueConstant) input).getId(); } }); }
@Override public long reIndexIssueObjects(final Collection<? extends Issue> issueObjects, final IssueIndexingParams issueIndexingParams) throws IndexException { // We would like to transform the Issue object to GenericValues before re-indexing to ensure that there // are no discrepancies between them. Once we move the entire system to Issue objects this will be unnecessary. // Until then, please do *not* change this behaviour. @SuppressWarnings ({ "unchecked" }) final Collection<GenericValue> genericValues = CollectionUtils.collect(issueObjects, IssueFactory.TO_GENERIC_VALUE); return reIndexIssues(genericValues, issueIndexingParams); }