本文整理匯總了Java中com.google.common.base.Predicates.in方法的典型用法代碼示例。如果您正苦於以下問題:Java Predicates.in方法的具體用法?Java Predicates.in怎麽用?Java Predicates.in使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類com.google.common.base.Predicates
的用法示例。
在下文中一共展示了Predicates.in方法的5個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: collectProjectsWithDirectExternalDependencies
import com.google.common.base.Predicates; //導入方法依賴的package包/類
/**
* Sugar for collecting {@link IWorkspace Eclipse workspace} projects that have any direct dependency to any
* external projects. Same as {@link #collectProjectsWithDirectExternalDependencies()} but does not considers all
* the available projects but only those that are given as the argument.
*
* @param externalProjects
* the external projects that has to be considered as a possible dependency of an Eclipse workspace based
* project.
* @return an iterable of Eclipse workspace projects that has direct dependency to an external project given as the
* argument.
*/
public Iterable<IProject> collectProjectsWithDirectExternalDependencies(
final Iterable<? extends IProject> externalProjects) {
if (!Platform.isRunning()) {
return emptyList();
}
final Collection<String> externalIds = from(externalProjects).transform(p -> p.getName()).toSet();
final Predicate<String> externalIdsFilter = Predicates.in(externalIds);
return from(asList(getWorkspace().getRoot().getProjects()))
.filter(p -> Iterables.any(getDirectExternalDependencyIds(p), externalIdsFilter));
}
示例2: copyWithFilteredResponses
import com.google.common.base.Predicates; //導入方法依賴的package包/類
public ArgumentOutput copyWithFilteredResponses(Predicate<Scored<Response>> predicate) {
final Iterable<Scored<Response>> scoredResponses =
Iterables.filter(scoredResponses(), predicate);
final ImmutableSet<Response> responses = ImmutableSet.copyOf(
transform(scoredResponses, Scoreds.<Response>itemsOnly()));
final Predicate<Response> retainedResponse = Predicates.in(responses);
// retain only the responses and metadata that this predicate filters
return ArgumentOutput
.from(docId(), scoredResponses, Maps.filterKeys(metadata, retainedResponse));
}
示例3: storeUpdatedInternal
import com.google.common.base.Predicates; //導入方法依賴的package包/類
private void storeUpdatedInternal(final ExternalLibraryPreferenceStore store, final IProgressMonitor monitor) {
ensureInitialized();
final Set<java.net.URI> oldLocations = newLinkedHashSet(locations);
final Set<java.net.URI> newLocation = newLinkedHashSet(store.getLocations());
final Collection<java.net.URI> removedLocations = difference(oldLocations, newLocation);
final Collection<java.net.URI> addedLocations = difference(newLocation, oldLocations);
final SubMonitor subMonitor = convert(monitor, 3);
final Iterable<IProject> projectsToClean = getProjects(removedLocations);
// Clean projects.
if (!Iterables.isEmpty(projectsToClean)) {
builderHelper.clean(projectsToClean, subMonitor.newChild(1));
}
subMonitor.worked(1);
// Invalidate before collecting dependencies.
invalidateCache(store);
final Collection<IProject> workspaceProjectsToRebuild = newHashSet(
collector.collectProjectsWithDirectExternalDependencies(projectsToClean));
// Cache could be polluted with external projects while collecting associated workspace ones.
invalidateCache(store);
// Rebuild whole external workspace. Filter out projects that are present in the Eclipse workspace (if any).
final Collection<String> eclipseWorkspaceProjectNames = getAllEclipseWorkspaceProjectNames();
final Predicate<String> eclipseWorkspaceProjectNamesFilter = Predicates.in(eclipseWorkspaceProjectNames);
final Iterable<ExternalProject> projectsToBuild = from(
collector.hookUpReferencedBuildConfigs(getProjects(addedLocations)))
.filter(p -> !eclipseWorkspaceProjectNamesFilter.apply(p.getName()));
// Build recently added projects that do not exist in workspace.
// XXX akitta: consider filtering out external projects that exists in index already. (@ higher priority level)
if (!Iterables.isEmpty(projectsToBuild)) {
builderHelper.build(projectsToBuild, subMonitor.newChild(1));
}
subMonitor.worked(1);
addAll(workspaceProjectsToRebuild, collector.collectProjectsWithDirectExternalDependencies(projectsToBuild));
scheduler.scheduleBuildIfNecessary(workspaceProjectsToRebuild);
}
示例4: registerProjectsInternal
import com.google.common.base.Predicates; //導入方法依賴的package包/類
private void registerProjectsInternal(NpmProjectAdaptionResult result, IProgressMonitor monitor,
boolean triggerCleanbuild) {
checkState(result.isOK(), "Expected OK result: " + result);
ensureInitialized();
if (!ExternalLibrariesActivator.requiresInfrastructureForLibraryManager()) {
LOGGER.warn("Built-in libraries and NPM support are disabled.");
}
final SubMonitor subMonitor = convert(monitor, 3);
final Iterable<IProject> projectsToClean = from(result.getToBeBuilt().getToBeDeleted())
.transform(uri -> getProject(new File(uri).getName())).filter(notNull());
final Set<IProject> workspaceProjectsToRebuild = newHashSet(
collector.collectProjectsWithDirectExternalDependencies(projectsToClean));
// Clean projects.
if (!Iterables.isEmpty(projectsToClean)) {
builderHelper.clean(projectsToClean, subMonitor.newChild(1));
}
subMonitor.worked(1);
// Update internal state.
updateState();
// Rebuild whole external workspace. Filter out projects that are present in the Eclipse workspace (if any).
final Collection<String> eclipseWorkspaceProjectNames = getAllEclipseWorkspaceProjectNames();
final Predicate<String> eclipseWorkspaceProjectNamesFilter = Predicates.in(eclipseWorkspaceProjectNames);
final Iterable<IProject> projectsToBuild = from(result.getToBeBuilt().getToBeUpdated())
.transform(uri -> getProject(new File(uri).getName())).filter(notNull())
.filter(p -> !eclipseWorkspaceProjectNamesFilter.apply(p.getName()));
// Build recently added projects that do not exist in workspace.
// Also includes projects that exist already in the index, but are shadowed.
if (!Iterables.isEmpty(projectsToBuild)) {
builderHelper.build(projectsToBuild, subMonitor.newChild(1));
}
subMonitor.worked(1);
if (triggerCleanbuild) {
Iterable<IProject> depPjs = collector.collectProjectsWithDirectExternalDependencies(projectsToBuild);
addAll(workspaceProjectsToRebuild, depPjs);
scheduler.scheduleBuildIfNecessary(workspaceProjectsToRebuild);
}
}
示例5: intersection
import com.google.common.base.Predicates; //導入方法依賴的package包/類
/**
* Returns an unmodifiable <b>view</b> of the intersection of two sets. The
* returned set contains all elements that are contained by both backing sets.
* The iteration order of the returned set matches that of {@code set1}.
*
* <p>Results are undefined if {@code set1} and {@code set2} are sets based
* on different equivalence relations (as {@code HashSet}, {@code TreeSet},
* and the keySet of an {@code IdentityHashMap} all are).
*
* <p><b>Note:</b> The returned view performs slightly better when {@code
* set1} is the smaller of the two sets. If you have reason to believe one of
* your sets will generally be smaller than the other, pass it first.
* Unfortunately, since this method sets the generic type of the returned set
* based on the type of the first set passed, this could in rare cases force
* you to make a cast, for example: <pre> {@code
*
* Set<Object> aFewBadObjects = ...
* Set<String> manyBadStrings = ...
*
* // impossible for a non-String to be in the intersection
* SuppressWarnings("unchecked")
* Set<String> badStrings = (Set) Sets.intersection(
* aFewBadObjects, manyBadStrings);}</pre>
*
* <p>This is unfortunate, but should come up only very rarely.
*/
public static <E> SetView<E> intersection(final Set<E> set1, final Set<?> set2) {
checkNotNull(set1, "set1");
checkNotNull(set2, "set2");
final Predicate<Object> inSet2 = Predicates.in(set2);
return new SetView<E>() {
@Override
public UnmodifiableIterator<E> iterator() {
return Iterators.filter(set1.iterator(), inSet2);
}
@Override
public Stream<E> stream() {
return set1.stream().filter(inSet2);
}
@Override
public Stream<E> parallelStream() {
return set1.parallelStream().filter(inSet2);
}
@Override
public int size() {
return Iterators.size(iterator());
}
@Override
public boolean isEmpty() {
return !iterator().hasNext();
}
@Override
public boolean contains(Object object) {
return set1.contains(object) && set2.contains(object);
}
@Override
public boolean containsAll(Collection<?> collection) {
return set1.containsAll(collection) && set2.containsAll(collection);
}
};
}