@Override public List<String> transform(final List<String> resource) { List<String> copy = new ArrayList<String>(resource); CollectionUtils.filter(copy, new Predicate<String>() { public boolean evaluate(String object) { return SCRIPTS_EXTRACT_PATTERN.matcher((String) object) .matches(); } }); CollectionUtils.transform(copy, new Transformer<String, String>() { public String transform(String input) { Matcher matcher = SCRIPTS_EXTRACT_PATTERN .matcher((String) input); if (matcher.matches()) { String transformed = StringUtils.isEmpty(getPrefix()) ? StringUtils.EMPTY : "/" + getPrefix(); return new StringBuilder(transformed).append("/") //$NON-NLS-1$ .append(matcher.group(2)).toString(); } return null; } }); return copy; }
/** * Selects all elements from input collection which match the given * predicate into an output collection. * <p/> * A <code>null</code> predicate matches no elements. * * @param inputCollection * the collection to get the input from, may not be null * @param predicate * the predicate to use, may be null * @return the elements matching the predicate (new list) * @throws NullPointerException * if the input collection is null */ public static <E> Collection<E> select(Collection<E> inputCollection, Predicate<? super E> predicate) { return select(inputCollection, predicate, new ArrayList<E>(inputCollection.size())); }
/** * 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 <I, O> Collection<O> collect(Iterator<I> inputIterator, Transformer<? super I, ? extends O> transformer) { ArrayList<O> answer = new ArrayList<O>(); collect(inputIterator, transformer, answer); return answer; }
/** * Returns <tt>true</tt> iff <i>a</i> is a sub-collection of <i>b</i>, that * is, iff the cardinality of <i>e</i> in <i>a</i> is less than or equal to * the cardinality of <i>e</i> in <i>b</i>, for each element <i>e</i> in * <i>a</i>. * * @param a * the first (sub?) collection, must not be null * @param b * the second (super?) collection, must not be null * @return <code>true</code> iff <i>a</i> is a sub-collection of <i>b</i> * @see #isProperSubCollection * @see Collection#containsAll */ public static <E> boolean isSubCollection(final Iterable<? extends E> a, final Iterable<? extends E> b) { Map mapa = getCardinalityMap(a); Map mapb = getCardinalityMap(b); for (E obj : a) { if (getFreq(obj, mapa) > getFreq(obj, mapb)) { return false; } } return true; }
@Override public boolean match(SimplePhysicalEntity a, SimplePhysicalEntity b) { return !a.equals(b) && a.getEntityReference() != null && !a.getName().isEmpty() && !b.getName().isEmpty() && !a.getEntityReference().isEquivalent(b.getEntityReference()) && CollectionUtils.containsAny(a.getName(), b.getName()); } };
@Override public List<String> transform(List<String> resource) { List<String> copy = new ArrayList<String>(resource); CollectionUtils.transform(copy, new Transformer<String, String>() { public String transform(String input) { return StringUtils.trim(input); } }); return copy; }
@Override public VertexPartition<V, E> transform(Graph<V, E> g) { Set<Pair<V>> vertex_pairs = getEquivalentPairs(g); Set<Set<V>> rv = new HashSet<Set<V>>(); Map<V, Set<V>> intermediate = new HashMap<V, Set<V>>(); for (Pair<V> p : vertex_pairs) { Set<V> res = intermediate.get(p.getFirst()); if (res == null) { res = intermediate.get(p.getSecond()); } if (res == null) { res = new HashSet<V>(); } res.add(p.getFirst()); res.add(p.getSecond()); intermediate.put(p.getFirst(), res); intermediate.put(p.getSecond(), res); } rv.addAll(intermediate.values()); // pick up the vertices which don't appear in intermediate; they are // singletons (equivalence classes of size 1) Collection<V> singletons = CollectionUtils.subtract(g.getVertices(), intermediate.keySet()); for (V v : singletons) { Set<V> v_set = Collections.singleton(v); intermediate.put(v, v_set); rv.add(v_set); } return new VertexPartition<V, E>(g, intermediate, rv); }
.union(g.getNeighbors(u), g.getNeighbors(v))); neighbors.remove(u); neighbors.remove(v);
public void find() { specs = new LinkedHashSet<SubstitutionSubtreeSpecification>(); Set<ExtendedNode> textTreeNodes = AbstractNodeUtils.treeToLinkedHashSet(textTree.getTree()); CollectionUtils.filter(textTreeNodes, textNodePredicate); if (textTreeNodes.isEmpty()) return; Set<ExtendedNode> hypothesisTreeNodes = AbstractNodeUtils.treeToLinkedHashSet(hypothesisTree.getTree()); CollectionUtils.filter(hypothesisTreeNodes, hypothesisNodePredicate); if (hypothesisTreeNodes.isEmpty()) return; for (ExtendedNode textNode: textTreeNodes) { for (ExtendedNode hypothesisNode: hypothesisTreeNodes) { specs.add(new SubstitutionSubtreeSpecification( description, textNode, hypothesisNode)); } } }
@SuppressWarnings("unchecked") private static <T extends Annotation> T findNestedAnnotation(Annotation[] parameterAnnotations, final Class<T> nestedAnnotationClass) { return (T) CollectionUtils.find(Arrays.asList(parameterAnnotations), new Predicate<Annotation>() { @Override public boolean evaluate(Annotation value) { return value.annotationType().isAnnotationPresent(nestedAnnotationClass); } }); }
@Test public void testOrderEntitiesByPrimaryKeys() { final List<Persistable> entities = new ArrayList<Persistable>(); final Persistable persistable1 = control.createMock(Persistable.class); final Persistable persistable2 = control.createMock(Persistable.class); final Persistable persistable3 = control.createMock(Persistable.class); CollectionUtils.addAll(entities, persistable1, persistable2, persistable3); final String pk1 = new String("pk1"); final String pk2 = new String("pk2"); final String pk3 = new String("pk3"); expect(persistable1.getPrimaryKey()).andReturn(pk1); expect(persistable2.getPrimaryKey()).andReturn(pk2); expect(persistable3.getPrimaryKey()).andReturn(pk3); final List<String> primaryKeys = new LinkedList<String>(); CollectionUtils.addAll(primaryKeys, pk1, pk3, pk2); control.replay(); final List<Persistable> orderedList = DaoUtils.orderEntitiesByPrimaryKeys(entities, primaryKeys); control.verify(); assertEquals(orderedList.get(0), persistable1); assertEquals(orderedList.get(1), persistable3); assertEquals(orderedList.get(2), persistable2); } }
final Collection<? extends E> b) { ArrayList<E> list = new ArrayList<E>(); Map mapa = getCardinalityMap(a); Map mapb = getCardinalityMap(b); Set<E> elts = new HashSet<E>(a); elts.addAll(b); while (it.hasNext()) { E obj = it.next(); for (int i = 0, m = Math.max(getFreq(obj, mapa), getFreq(obj, mapb)); i < m; i++) { list.add(obj);
&& CollectionUtils.containsAny(lefty.getName(), righty.getName());
@SuppressWarnings("unchecked") private void processStringCollection(final Map<String, String> prefixes, Collection valueObject) { CollectionUtils.transform(valueObject, input -> { if (input instanceof String) { return replaceAllMap("", prefixes, ":", (String) input); } return input; }); } }
Collection<V> singletons = CollectionUtils.subtract(g.getVertices(), intermediate.keySet()); for (V v : singletons)
if (id.indexOf(u) <= i_v) continue; Set<V> neighbors = new HashSet<V>(CollectionUtils.union(g.getNeighbors(u), g.getNeighbors(v))); neighbors.remove(u); neighbors.remove(v);
@SuppressWarnings("unchecked") private static <T extends Annotation> T findAnnotation(Annotation[] annotations, final Class<T> annotationClass) { return (T) CollectionUtils.find(Arrays.asList(annotations), new Predicate<Annotation>() { @Override public boolean evaluate(Annotation value) { return value.annotationType().equals(annotationClass); } }); }
final Collection<? extends E> a, final Collection<? extends E> b) { ArrayList<E> list = new ArrayList<E>(); Map mapa = getCardinalityMap(a); Map mapb = getCardinalityMap(b); Set<E> elts = new HashSet<E>(a); elts.addAll(b); while (it.hasNext()) { E obj = it.next(); for (int i = 0, m = Math.min(getFreq(obj, mapa), getFreq(obj, mapb)); i < m; i++) { list.add(obj);
public static <E, T extends Throwable> E getSingleRequired( List<E> list, Predicate<? super E> predicate, T throwable) throws T { Collection<E> found = CollectionUtils.select(list, predicate); if (found.size() != 1) { throw throwable; } return found.iterator().next(); }
/** * 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 not 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 <I, O, C extends Collection<O>> C collect( Iterable<I> inputCollection, final Transformer<? super I, ? extends O> transformer, final C outputCollection) { if (inputCollection != null) { return collect(inputCollection.iterator(), transformer, outputCollection); } return outputCollection; }