List of usage examples for com.google.common.collect Collections2 filter
@CheckReturnValue public static <E> Collection<E> filter(Collection<E> unfiltered, Predicate<? super E> predicate)
From source file:org.openengsb.core.util.CollectionUtilsExtended.java
/** * provides a view to the given collection, that only contains objects that are instances of the given clazz. It * uses the guava-methods {@link Collections2#filter(Collection, Predicate)} and * {@link Collections2#transform(Collection, Function)}. * * The returned collection is immutable. *//*from w w w .j av a 2s .c o m*/ public static <TargetType> Collection<TargetType> filterCollectionByClass(Collection<?> source, final Class<TargetType> clazz) { Collection<?> filtered = Collections2.filter(source, new Predicate<Object>() { @Override public boolean apply(Object input) { return clazz.isInstance(input); } }); return Collections2.transform(filtered, new Function<Object, TargetType>() { @SuppressWarnings("unchecked") @Override public TargetType apply(Object input) { return (TargetType) input; } }); }
From source file:pl.coffeepower.blog.examples.NumberUtils.java
public static Collection<? extends Number> getEvenNumbers(Collection<? extends Number> numbers) { return Collections2.filter(numbers, number -> isEvenNumber(number)); }
From source file:com.siemens.pl.it.rest.services.QuoteService.java
public Quote quote(final String quoteId, final String revision) { Collection<Quote> quotesFound = Collections2.filter(getAllQuotes(), new Predicate<Quote>() { @Override/*from w w w .j a va 2 s . c o m*/ public boolean apply(Quote quote) { return quote.getQuoteId().equals(quoteId) && quote.getRevision().equals(revision); } }); if (!quotesFound.isEmpty()) { return quotesFound.iterator().next(); } else { // Use 400 if it is the user's fault, 500 if it is yours. throw new WebApplicationException(Response.status(Response.Status.NOT_FOUND) .entity("Quote id/rev not found").type(MediaType.APPLICATION_JSON_TYPE).build()); } }
From source file:com.stackframe.sarariman.DirectRateAudit.java
@Override public Collection<AuditResult> getResults() { Collection<AuditResult> c = new ArrayList<>(); Collection<Employee> activeEmployees = Collections2.filter(directory.getByUserName().values(), Utilities.active);// w w w. j av a2s . c om for (Employee e : activeEmployees) { BigDecimal directRate = e.getDirectRate(); if (directRate == null) { c.add(new AuditResult(AuditResultType.error, String.format("%s (%d) has no current direct rate", e.getDisplayName(), e.getNumber()), e.getURL())); } } return c; }
From source file:org.pentaho.di.trans.dataservice.validation.ValidationUtil.java
public static Collection<ParameterGeneration> getParameterGenerationsForStep( final DataServiceMeta dataServiceMeta, final String stepName) { return Collections2.transform(Collections2.filter(dataServiceMeta.getPushDownOptimizationMeta(), new Predicate<PushDownOptimizationMeta>() { @Override/*from w ww.j a va 2 s . c om*/ public boolean apply(PushDownOptimizationMeta pushDownOptimizationMeta) { return pushDownOptimizationMeta.getType() instanceof ParameterGeneration && stepName.equals(pushDownOptimizationMeta.getStepName()); } }), new Function<PushDownOptimizationMeta, ParameterGeneration>() { @Override public ParameterGeneration apply(PushDownOptimizationMeta pushDownOptimizationMeta) { return (ParameterGeneration) pushDownOptimizationMeta.getType(); } }); }
From source file:com.madvay.tools.android.perf.common.TraceTransformers.java
public static TT keep(final Predicate<StackTraceElement> spec) { return new TT() { @Override//ww w . j av a 2s . c o m public List<StackTraceElement> apply(List<StackTraceElement> input) { return Lists.newArrayList(Collections2.filter(input, spec)); } }; }
From source file:com.android.tools.idea.editors.theme.ThemeEditorTestUtils.java
/** * Returns the attributes that were defined in the theme itself and not its parents. *//*from w ww.j a va 2 s.co m*/ public static Collection<EditedStyleItem> getStyleLocalValues(@NotNull final ConfiguredThemeEditorStyle style) { final Set<String> localAttributes = Sets.newHashSet(); for (ConfiguredElement<ItemResourceValue> value : style.getConfiguredValues()) { localAttributes.add(ResolutionUtils.getQualifiedItemName(value.getElement())); } return Collections2.filter( ThemeAttributeResolver.resolveAll(style, style.getConfiguration().getConfigurationManager()), new Predicate<EditedStyleItem>() { @Override public boolean apply(@Nullable EditedStyleItem input) { assert input != null; return localAttributes.contains(input.getQualifiedName()); } }); }
From source file:org.asoem.greyfish.utils.space.SpatialData.java
/** * Filter all elements out of the given collection that are in the range distance range of given origin. if origin * is an element of collection, it will be excluded in the result. * * @param collection the collection to filter * @param origin the origin//from w w w .j a v a2 s.co m * @param range the range * @param distanceMeasure the distance measure to use * @param <O> the type of the objects * @return a live view of the given collection */ public static <O> Collection<O> filterNeighbors(final Collection<O> collection, final O origin, final double range, final DistanceMeasure<? super O> distanceMeasure) { return Collections2.filter(collection, new Predicate<O>() { @Override public boolean apply(@Nullable final O input) { checkNotNull(input); if (input == origin) { return false; } final double distance = distanceMeasure.apply(origin, input); checkState(distance >= 0, "the distance must be positive"); return distance <= range; } }); }
From source file:org.zanata.ui.FilterUtil.java
/** * Return filtered list of HPerson from personList which are NOT in * allPersonList//from ww w .j a v a 2 s . co m * * @param allPersonList * @param personList * @return */ public static List<HPerson> filterOutPersonList(final List<HPerson> allPersonList, List<HPerson> personList) { Collection<HPerson> filtered = Collections2.filter(personList, new Predicate<HPerson>() { @Override public boolean apply(HPerson input) { return !allPersonList.contains(input); } }); return Lists.newArrayList(filtered); }
From source file:vars.LinkUtilities.java
/** * Return all links in a collection that match a given {@link ILink}. This compares the linkName, * toConcept, and linkValue fields//from w ww. j av a2s . com * * @param links * @param templateLink * @return */ public static Collection<ILink> findMatchingLinksIn(Collection<ILink> links, final ILink templateLink) { return Collections2.filter(links, new Predicate<ILink>() { public boolean apply(ILink input) { return COMPARATOR.compare(input, templateLink) == 0; } }); }