@Override public List<FieldGroup> getFieldGroups() { Collection<FieldGroup> transformed = CollectionUtils.collect(fieldGroupXrefs, new Transformer<StructuredContentFieldGroupXref, FieldGroup>() { @Override public FieldGroup transform(StructuredContentFieldGroupXref input) { return input.getFieldGroup(); } }); return Collections.unmodifiableList(new ArrayList<FieldGroup>(transformed)); }
/** * Transforms all elements from the input iterator with the given transformer * and adds them to the output collection. * <p> * If the input iterator or transformer is null, the result is an empty list. * * @param <I> the type of object in the input collection * @param <O> the type of object in the output collection * @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(final Iterator<I> inputIterator, final Transformer<? super I, ? extends O> transformer) { return collect(inputIterator, transformer, new ArrayList<O>()); }
/** * Transforms all elements from input collection with the given transformer * and adds them to the output collection. * <p> * If the input collection or transformer is null, there is no change to the * output collection. * * @param <I> the type of object in the input collection * @param <O> the type of object in the output collection * @param <R> the type of 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 if inputCollection * and transformer are not null * @return the output collection with the transformed input added * @throws NullPointerException if the outputCollection is null and both, inputCollection and * transformer are not null */ public static <I, O, R extends Collection<? super O>> R collect(final Iterable<? extends I> inputCollection, final Transformer<? super I, ? extends O> transformer, final R outputCollection) { if (inputCollection != null) { return collect(inputCollection.iterator(), transformer, outputCollection); } return outputCollection; }
/** * Returns a new Collection containing all elements of the input collection * transformed by the given transformer. * <p> * If the input collection or transformer is null, the result is an empty list. * * @param <I> the type of object in the input collection * @param <O> the type of object in the output collection * @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 <I, O> Collection<O> collect(final Iterable<I> inputCollection, final Transformer<? super I, ? extends O> transformer) { final Collection<O> answer = inputCollection instanceof Collection<?> ? new ArrayList<O>(((Collection<?>) inputCollection).size()) : new ArrayList<O>(); return collect(inputCollection, transformer, answer); }
final Collection<C> resultCollection = collect(collection, transformer); collection.clear(); collection.addAll(resultCollection);
collect(retain, transformer, new HashSet<EquatorWrapper<E>>());
collect(remove, transformer, new HashSet<EquatorWrapper<E>>());
private void assertAllDirectDependenciesArePresentInInput(MaterialRevisions actualRevisions, CaseInsensitiveString pipelineName) { Collection<String> actualRevFingerprints = CollectionUtils.collect(actualRevisions.iterator(), actualRevision -> actualRevision.getMaterial().getFingerprint()); for (FanInNode child : root.children) { //The dependency material that is not in 'passed' state will not be found in actual revisions if (!actualRevFingerprints.contains(child.materialConfig.getFingerprint())) { throw NoCompatibleUpstreamRevisionsException.doesNotHaveValidRevisions(pipelineName, child.materialConfig); } } }
@Test public void shouldRegisterAllGoConfigValidators() { List<String> list = (List<String>) CollectionUtils.collect(MagicalGoConfigXmlLoader.VALIDATORS, o -> o.getClass().getCanonicalName()); assertThat(list, hasItem(ArtifactDirValidator.class.getCanonicalName())); assertThat(list, hasItem(EnvironmentAgentValidator.class.getCanonicalName())); assertThat(list, hasItem(ServerIdImmutabilityValidator.class.getCanonicalName())); assertThat(list, hasItem(CommandRepositoryLocationValidator.class.getCanonicalName())); assertThat(list, hasItem(TokenGenerationKeyImmutabilityValidator.class.getCanonicalName())); }
assertThat(configuration.listOfConfigKeys().size(), is(3)); assertThat(configuration.listOfConfigKeys(), is(asList("url", "username", "password"))); Collection<String> values = CollectionUtils.collect(configuration.listOfConfigKeys(), o -> { ConfigurationProperty property = configuration.getProperty(o); return property.getConfigurationValue().getValue();
public Collection getServletMappings(String servletName) { final String servletMappingXPathExpr = "/webxml:web-app/webxml:servlet-mapping[webxml:servlet-name='" + servletName + "']/webxml:url-pattern"; final List servletMappings = getElementsFromXPath(servletMappingXPathExpr); return CollectionUtils.collect(servletMappings, new Transformer() { @Override public Object transform(Object input) { final Element servletMapping = (Element) input; return servletMapping.getText(); } }); }
@NonNull private List<WiFiDetail> getWiFiDetails(@NonNull Predicate<WiFiDetail> predicate) { Collection<WiFiDetail> selected = CollectionUtils.select(wiFiDetails, predicate); Collection<WiFiDetail> collected = CollectionUtils.collect(selected, new Transform()); return new ArrayList<>(collected); }
@NonNull public static <T extends Enum> Set<T> find(@NonNull Class<T> enumType, @NonNull Set<String> ordinals, @NonNull T defaultValue) { Set<T> results = new HashSet<>(CollectionUtils.collect(ordinals, new ToEnum<>(enumType, defaultValue))); return results.isEmpty() ? values(enumType) : results; }
@NonNull public static <T extends Enum, U> Predicate<U> predicate(@NonNull Class<T> enumType, @NonNull Collection<T> input, @NonNull Transformer<T, Predicate<U>> transformer) { if (input.size() >= values(enumType).size()) { return PredicateUtils.truePredicate(); } return PredicateUtils.anyPredicate(CollectionUtils.collect(input, transformer)); }
@Override public Collection<String> getResourceCodesByAuthorizeTargetAndType(Long target, String type){ List<SysResource> sysResources = this.getResourcesByAuthorizeTargetAndType(target,type); return CollectionUtils.collect(sysResources.iterator(),(input) -> input.getCode()); }
@NonNull private static List<Data> getData() { List<Data> results = new ArrayList<>(CollectionUtils.collect(LocaleUtils.getSupportedLanguages(), new ToData())); Collections.sort(results); return results; }
@NonNull private static List<Data> getData() { List<Data> results = new ArrayList<>(CollectionUtils.collect(WiFiChannelCountry.getAll(), new ToData())); Collections.sort(results); return results; }
@NonNull private Predicate<WiFiDetail> makeSSIDPredicate(Set<String> ssids) { if (ssids.isEmpty()) { return PredicateUtils.truePredicate(); } return PredicateUtils.anyPredicate(CollectionUtils.collect(ssids, new SSIDTransformer())); }
@NonNull public List<ChannelAPCount> getBestChannels(@NonNull final List<WiFiChannel> wiFiChannels) { List<ChannelAPCount> results = new ArrayList<>( CollectionUtils.collect( CollectionUtils.select(wiFiChannels, new BestChannelPredicate()) , new ToChannelAPCount())); Collections.sort(results, new ChannelAPCountSort()); return results; }