本文整理汇总了Java中java.util.Set.retainAll方法的典型用法代码示例。如果您正苦于以下问题:Java Set.retainAll方法的具体用法?Java Set.retainAll怎么用?Java Set.retainAll使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类java.util.Set
的用法示例。
在下文中一共展示了Set.retainAll方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: assist
import java.util.Set; //导入方法依赖的package包/类
public List<Object> assist(String levelName, InvestigationLevel nextLevel, int drilldownLimit)
{
Twin<VerifiableTable> queryResults = execute(nextLevel);
VerifiableTable actualResults = new KeyedVerifiableTableAdapter(queryResults.getOne(), queryResults.getOne().getColumnCount() - 1);
VerifiableTable expectedResults = new KeyedVerifiableTableAdapter(queryResults.getTwo(), queryResults.getTwo().getColumnCount() - 1);
List<String> actualColumns = getColumns(actualResults);
List<String> expectedColumns = getColumns(expectedResults);
if (!Iterate.getLast(actualColumns).equals(Iterate.getLast(expectedColumns)))
{
throw new IllegalArgumentException(String.format("Key columns must match at each investigation level [actual: %s, expected: %s]", Iterate.getLast(actualColumns), Iterate.getLast(expectedColumns)));
}
Set<String> commonColumns = UnifiedSet.newSet(actualColumns);
commonColumns.retainAll(expectedColumns);
if (Math.min(actualColumns.size(), expectedColumns.size()) > 1 && commonColumns.size() < 2)
{
throw new IllegalArgumentException(String.format("There must be at least 2 matching columns at each investigation level [actual: %s, expected: %s]", Iterate.getLast(actualColumns), Iterate.getLast(expectedColumns)));
}
String levelDescription = nextLevel.getLevelDescription();
ResultTable results = this.findBreaks(levelDescription, actualResults, expectedResults);
HtmlFormatter htmlFormatter = new HtmlFormatter(outputFile, new HtmlOptions(false, HtmlFormatter.DEFAULT_ROW_LIMIT, false, true, false, Collections.<String>emptySet()));
htmlFormatter.appendResults(levelName, Maps.fixedSize.of(levelDescription, results), Metadata.newEmpty());
return getRowKeys(results, drilldownLimit);
}
示例2: getClusterForCurrentTopics
import java.util.Set; //导入方法依赖的package包/类
private Cluster getClusterForCurrentTopics(Cluster cluster) {
Set<String> unauthorizedTopics = new HashSet<>();
Collection<PartitionInfo> partitionInfos = new ArrayList<>();
List<Node> nodes = Collections.emptyList();
Set<String> internalTopics = Collections.emptySet();
Node controller = null;
String clusterId = null;
if (cluster != null) {
clusterId = cluster.clusterResource().clusterId();
internalTopics = cluster.internalTopics();
unauthorizedTopics.addAll(cluster.unauthorizedTopics());
unauthorizedTopics.retainAll(this.topics.keySet());
for (String topic : this.topics.keySet()) {
List<PartitionInfo> partitionInfoList = cluster.partitionsForTopic(topic);
if (!partitionInfoList.isEmpty()) {
partitionInfos.addAll(partitionInfoList);
}
}
nodes = cluster.nodes();
controller = cluster.controller();
}
return new Cluster(clusterId, nodes, partitionInfos, unauthorizedTopics, internalTopics, controller);
}
示例3: getStreamsMetadataForKey
import java.util.Set; //导入方法依赖的package包/类
private <K> StreamsMetadata getStreamsMetadataForKey(final String storeName,
final K key,
final StreamPartitioner<? super K, ?> partitioner,
final SourceTopicsInfo sourceTopicsInfo) {
final Integer partition = partitioner.partition(key, null, sourceTopicsInfo.maxPartitions);
final Set<TopicPartition> matchingPartitions = new HashSet<>();
for (String sourceTopic : sourceTopicsInfo.sourceTopics) {
matchingPartitions.add(new TopicPartition(sourceTopic, partition));
}
for (StreamsMetadata streamsMetadata : allMetadata) {
final Set<String> stateStoreNames = streamsMetadata.stateStoreNames();
final Set<TopicPartition> topicPartitions = new HashSet<>(streamsMetadata.topicPartitions());
topicPartitions.retainAll(matchingPartitions);
if (stateStoreNames.contains(storeName)
&& !topicPartitions.isEmpty()) {
return streamsMetadata;
}
}
return null;
}
示例4: guessLanguages
import java.util.Set; //导入方法依赖的package包/类
/**
* Guesses the languages of a word.
*
* @param input
* the word
* @return a Set of Strings of language names that are potential matches for the input word
*/
public Languages.LanguageSet guessLanguages(final String input) {
final String text = input.toLowerCase(Locale.ENGLISH);
final Set<String> langs = new HashSet<String>(this.languages.getLanguages());
for (final LangRule rule : this.rules) {
if (rule.matches(text)) {
if (rule.acceptOnMatch) {
langs.retainAll(rule.languages);
} else {
langs.removeAll(rule.languages);
}
}
}
final Languages.LanguageSet ls = Languages.LanguageSet.from(langs);
return ls.equals(Languages.NO_LANGUAGES) ? Languages.ANY_LANGUAGE : ls;
}
示例5: compute
import java.util.Set; //导入方法依赖的package包/类
/** Computes the minimum Jaccard distance on the set of API calls
* between the original and the predicted ASTs.
*/
@Override
public float compute(DSubTree originalAST, List<DSubTree> predictedASTs) {
List<Float> jaccard = new ArrayList<>();
jaccard.add((float) 1);
Set<DAPICall> A = originalAST.bagOfAPICalls();
for (DSubTree predictedAST : predictedASTs) {
Set<DAPICall> B = predictedAST.bagOfAPICalls();
// A union B
Set<DAPICall> AunionB = new HashSet<>();
AunionB.addAll(A);
AunionB.addAll(B);
// A intersect B
Set<DAPICall> AinterB = new HashSet<>();
AinterB.addAll(A);
AinterB.retainAll(B);
jaccard.add(1 - ((float) AinterB.size()) / AunionB.size());
}
return Metric.min(jaccard);
}
示例6: stabilise
import java.util.Set; //导入方法依赖的package包/类
/** Removes entries from the resolver map if they have an empty resolver. */
private void stabilise(Map<VariableNode,List<Set<VariableNode>>> resolverMap) {
boolean stable = false;
// repeat until no more changes
while (!stable) {
stable = true;
// iterate over all resolver lists
Iterator<List<Set<VariableNode>>> iter = resolverMap.values()
.iterator();
while (iter.hasNext()) {
// try each resolver in turn
for (Set<VariableNode> resolver : iter.next()) {
// restrict to the unresolved nodes
resolver.retainAll(resolverMap.keySet());
// if there are no unresolved nodes, the entry may be removed
if (resolver.isEmpty()) {
iter.remove();
stable = false;
break;
}
}
}
}
}
示例7: apply
import java.util.Set; //导入方法依赖的package包/类
@Override
public Set<NitriteId> apply(final NitriteMap<NitriteId, Document> documentMap) {
Set<NitriteId> result = new LinkedHashSet<>();
ExecutorService executorService = nitriteService.getNitriteContext().getWorkerPool();
try {
List<Callable<Set<NitriteId>>> tasks = createTasks(filters, documentMap);
boolean initialCount = true;
List<Future<Set<NitriteId>>> futures = executorService.invokeAll(tasks);
for (Future<Set<NitriteId>> future : futures) {
Set<NitriteId> nitriteIds = future.get();
if (initialCount && nitriteIds != null) {
result.addAll(nitriteIds);
initialCount = false;
} else if (nitriteIds != null) {
if (nitriteIds.isEmpty()) {
result.clear();
}
result.retainAll(nitriteIds);
}
}
} catch (FilterException fe) {
throw fe;
} catch (Throwable t) {
throw new FilterException(INVALID_AND_FILTER, t);
}
return result;
}
示例8: removeIntersectionFrom
import java.util.Set; //导入方法依赖的package包/类
public static boolean removeIntersectionFrom(Set<String> first, Set<String> second) {
// TODO: test: Set<String> intersection = Sets.intersection(first, second);
Set<String> intersection = new ObjectOpenHashSet<String>(first);
intersection.retainAll(second);
first.removeAll(intersection);
second.removeAll(intersection);
return !intersection.isEmpty();
}
示例9: getMostSpecificCommonTypeUnequalNonprimitives
import java.util.Set; //导入方法依赖的package包/类
private static Class<?> getMostSpecificCommonTypeUnequalNonprimitives(final Class<?> c1, final Class<?> c2) {
final Class<?> npc1 = c1.isPrimitive() ? getWrapperType(c1) : c1;
final Class<?> npc2 = c2.isPrimitive() ? getWrapperType(c2) : c2;
final Set<Class<?>> a1 = getAssignables(npc1, npc2);
final Set<Class<?>> a2 = getAssignables(npc2, npc1);
a1.retainAll(a2);
if(a1.isEmpty()) {
// Can happen when at least one of the arguments is an interface,
// as they don't have Object at the root of their hierarchy.
return Object.class;
}
// Gather maximally specific elements. Yes, there can be more than one
// thank to interfaces. I.e., if you call this method for String.class
// and Number.class, you'll have Comparable, Serializable, and Object
// as maximal elements.
final List<Class<?>> max = new ArrayList<>();
outer: for(final Class<?> clazz: a1) {
for(final Iterator<Class<?>> maxiter = max.iterator(); maxiter.hasNext();) {
final Class<?> maxClazz = maxiter.next();
if(isSubtype(maxClazz, clazz)) {
// It can't be maximal, if there's already a more specific
// maximal than it.
continue outer;
}
if(isSubtype(clazz, maxClazz)) {
// If it's more specific than a currently maximal element,
// that currently maximal is no longer a maximal.
maxiter.remove();
}
}
// If we get here, no current maximal is more specific than the
// current class, so it is considered maximal as well
max.add(clazz);
}
if(max.size() > 1) {
return Object.class;
}
return max.get(0);
}
示例10: getActiveNames
import java.util.Set; //导入方法依赖的package包/类
/**
* Returns the set of resource names of the active resources of a given kind.
* These are the names stored as active, but can be overridden locally in
* the grammar model.
* @see #setLocalActiveNames(ResourceKind, Collection)
*/
public Set<QualName> getActiveNames(ResourceKind kind) {
// first check for locally stored names
Set<QualName> result = this.localActiveNamesMap.get(kind);
if (result == null) {
// if there are none, check for active names in the store
result = this.storedActiveNamesMap.get(kind);
}
result.retainAll(getNames(kind));
return Collections.unmodifiableSet(result);
}
示例11: removeIntersectionFrom
import java.util.Set; //导入方法依赖的package包/类
public static boolean removeIntersectionFrom(Set<String> first, Set<String> second) {
// TODO: test: Set<String> intersection = Sets.intersection(first, second);
Set<String> intersection = new ObjectOpenHashSet<String>(first);
intersection.retainAll(second);
first.removeAll(intersection);
second.removeAll(intersection);
return !intersection.isEmpty();
}
示例12: computeICdiff
import java.util.Set; //导入方法依赖的package包/类
private List<InnerClass> computeICdiff() {
List<InnerClass> impliedICs = computeGloballyImpliedICs();
List<InnerClass> actualICs = getInnerClasses();
if (actualICs == null)
actualICs = Collections.emptyList();
// Symmetric difference is calculated from I, A like this:
// diff = (I+A) - (I*A)
// Note that the center C is unordered, but the result
// preserves the original ordering of I and A.
//
// Class file rules require that outers precede inners.
// So, add I before A, in case A$B$Z is local, but A$B
// is implicit. The reverse is never the case.
if (actualICs.isEmpty()) {
return impliedICs;
// Diff is I since A is empty.
}
if (impliedICs.isEmpty()) {
return actualICs;
// Diff is A since I is empty.
}
// (I*A) is non-trivial
Set<InnerClass> center = new HashSet<>(actualICs);
center.retainAll(new HashSet<>(impliedICs));
impliedICs.addAll(actualICs);
impliedICs.removeAll(center);
// Diff is now I^A = (I+A)-(I*A).
return impliedICs;
}
示例13: recall
import java.util.Set; //导入方法依赖的package包/类
public static <E> double recall(Set<E> gold, Set<E> result) {
if (gold.size() == 0) {
return 0;
}
Set<E> intersection = new HashSet<E>(result);
intersection.retainAll(gold);
return (double) intersection.size() / gold.size();
}
示例14: getSameNames
import java.util.Set; //导入方法依赖的package包/类
private synchronized Set<ObjectName> getSameNames(final Set<ObjectName> superSet) {
final Set<ObjectName> result = new HashSet<>(superSet);
result.retainAll(registeredObjectNames);
for (InternalJMXRegistrator child : children) {
result.addAll(child.getSameNames(superSet));
}
return result;
}
示例15: jaccard
import java.util.Set; //导入方法依赖的package包/类
/**
* Computes jaccard between sets of objects
* @param x
* @param y
* @return
*/
public static <T> double jaccard(Set<T> x, Set<T> y) {
Set<T> intersection = new HashSet<T>(x);
intersection.retainAll(y);
Set<T> union = new HashSet<T>(x);
union.addAll(y);
double res = union.size() == 0 ? 1.0 : (double) intersection.size() / union.size();
return res;
}