List of usage examples for com.google.common.collect Sets filter
@GwtIncompatible("NavigableSet") @SuppressWarnings("unchecked") @CheckReturnValue public static <E> NavigableSet<E> filter(NavigableSet<E> unfiltered, Predicate<? super E> predicate)
From source file:org.springframework.ide.eclipse.boot.dash.livexp.LiveSets.java
public static <S, T> ObservableSet<T> filter(final ObservableSet<S> source, final Class<T> retainType) { ObservableSet<T> filtered = new ObservableSet<T>() { @SuppressWarnings("unchecked") @Override//w w w . j a v a 2 s .co m protected ImmutableSet<T> compute() { return (ImmutableSet<T>) ImmutableSet.copyOf(Sets.filter(source.getValue(), new Predicate<S>() { @Override public boolean apply(S input) { return retainType.isAssignableFrom(input.getClass()); } })); } }; filtered.dependsOn(source); return filtered; }
From source file:org.apache.helix.controller.rebalancer.util.ConstraintBasedAssignment.java
/** * Get a set of disabled participants for a partition * @param participantMap map of all participants * @param partitionId the partition to check * @return a set of all participants that are disabled for the partition *///from w w w . j ava2s.c o m public static Set<ParticipantId> getDisabledParticipants(final Map<ParticipantId, Participant> participantMap, final PartitionId partitionId) { Set<ParticipantId> participantSet = new HashSet<ParticipantId>(participantMap.keySet()); Set<ParticipantId> disabledParticipantsForPartition = Sets.filter(participantSet, new Predicate<ParticipantId>() { @Override public boolean apply(ParticipantId participantId) { Participant participant = participantMap.get(participantId); return !participant.isEnabled() || participant.getDisabledPartitionIds().contains(partitionId); } }); return disabledParticipantsForPartition; }
From source file:prm4j.indexing.model.FindMaxArgs.java
public static List<Set<Parameter<?>>> getDisableSets(ParametricPropertyModel ppa, BaseEvent baseEvent, final Set<Parameter<?>> enableSet) { final Set<Parameter<?>> combination = Sets.union(baseEvent.getParameters(), enableSet); return toListOfParameterSetsAscending( Sets.filter(toParameterSets(ppa.getParametricProperty().getSpec().getBaseEvents()), new Predicate<Set<Parameter<?>>>() { @Override public boolean apply(Set<Parameter<?>> baseEventParameterSet) { return combination.containsAll(baseEventParameterSet) && !enableSet.containsAll(baseEventParameterSet); }//from ww w . jav a2 s.c om })); }
From source file:fr.keemto.scheduling.TaskScheduler.java
public boolean checkIfTaskHasAlreadyBeenScheduled(Object taskId) { return Sets.filter(scheduledTasks, new WithTaskId(taskId)).size() > 0; }
From source file:com.siemens.sw360.datahandler.common.SW360Constants.java
public static Collection<AttachmentType> allowedAttachmentTypes(String documentType) { Set<AttachmentType> types = newHashSet(AttachmentType.values()); if (TYPE_COMPONENT.equals(documentType)) { return Sets.filter(types, not(equalTo(AttachmentType.CLEARING_REPORT))); } else {//from www . j a v a 2 s .co m return types; } }
From source file:com.willowtreeapps.saguaro.plugin.SaguaroGenerate.java
private Set<LicenseDependency> collectDependencyLicences(SaguaroConfig config) throws PluginException { Set<LicenseDependency> licenseDependencies; if (config.includeDependencies()) { final Set<Dependency> ignore = config.getIgnore(); licenseDependencies = Sets.filter(licenseResolver.resolveLicenseDependencies(), new Predicate<LicenseDependency>() { @Override// ww w .j a va 2 s. co m public boolean apply(LicenseDependency licenseDependency) { return !ignore.contains(licenseDependency.getDependency()); } }); checkForMissingLicenses(licenseDependencies); } else { licenseDependencies = new LinkedHashSet<LicenseDependency>(); } return applyAliases(config.getAliases(), licenseDependencies); }
From source file:org.apache.drill.exec.compile.DrillJavaFileManager.java
@Override public Iterable<JavaFileObject> list(Location location, String packageName, Set<Kind> kinds, boolean recurse) throws IOException { return super.list(location, packageName, Sets.filter(kinds, NO_SOURCES_KIND), recurse); }
From source file:ezbake.thriftrunner.ThriftStarter.java
protected Class<? extends EzBakeBaseThriftService> getServiceClassUsingReflectionFromJar(URLClassLoader loader) throws Exception { final Reflections reflections = new Reflections( new ConfigurationBuilder().setUrls(ClasspathHelper.forClassLoader(loader)).addClassLoader(loader)); final Set<Class<? extends EzBakeBaseThriftService>> types = Sets .filter(reflections.getSubTypesOf(EzBakeBaseThriftService.class), new nonAbstractClassPredicate()); if (types.size() != 1) { Function<Class<? extends ezbake.base.thrift.EzBakeBaseThriftService>, String> nameGetter = new Function<Class<? extends ezbake.base.thrift.EzBakeBaseThriftService>, String>() { public String apply(Class<? extends ezbake.base.thrift.EzBakeBaseThriftService> c) { return c.getName(); }/*w w w. j av a 2s . c o m*/ }; String errorClasses = Joiner.on(", ").join(Iterables.transform(types, nameGetter)); throw new RuntimeException("Jar monst contain exactly one EzBakeBaseThriftService. " + types.size() + " classes found: " + errorClasses); } return types.iterator().next(); }
From source file:see.functions.functional.Filter.java
/** * Choose appropriate filter based on runtime type of collection * @param items collection to transform//from ww w. ja va 2s . c om * @param predicate predicate to match * @return lazy filtered collection */ private Iterable<?> filter(Iterable<?> items, Predicate<Object> predicate) { if (items instanceof Set<?>) { return Sets.filter((Set<?>) items, predicate); } else if (items instanceof Collection<?>) { return Collections2.filter((Collection<?>) items, predicate); } else { return Iterables.filter(items, predicate); } }
From source file:no.ssb.vtl.model.DatapointNormalizer.java
public DatapointNormalizer(DataStructure from, DataStructure to, Predicate<String> predicate) { checkNotNull(from);//from www .j a v a2 s . c o m checkArgument(!from.isEmpty()); checkNotNull(to); ImmutableList<String> fromList = ImmutableSet.copyOf(from.keySet()).asList(); ImmutableList<String> toList = ImmutableSet.copyOf(to.keySet()).asList(); // Make sure that both structures contains the columns we are mapping. Set<String> filteredFrom = Sets.filter(from.keySet(), predicate::test); Set<String> filteredTo = Sets.filter(to.keySet(), predicate::test); checkArgument(filteredFrom.containsAll(filteredTo)); // build indices ArrayList<Integer> fromIndices = Lists.newArrayList(); ArrayList<Integer> toIndices = Lists.newArrayList(); for (String fromName : filteredFrom) { int fromIndex = fromList.indexOf(fromName); int toIndex = toList.indexOf(fromName); if (fromIndex == toIndex) continue; fromIndices.add(fromIndex); toIndices.add(toIndex); } this.fromIndices = Ints.toArray(fromIndices); this.toIndices = Ints.toArray(toIndices); }