本文整理汇总了Java中java.util.Collection.retainAll方法的典型用法代码示例。如果您正苦于以下问题:Java Collection.retainAll方法的具体用法?Java Collection.retainAll怎么用?Java Collection.retainAll使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类java.util.Collection
的用法示例。
在下文中一共展示了Collection.retainAll方法的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: dataFlushed
import java.util.Collection; //导入方法依赖的package包/类
/**
* This method is eventually called from the middle of BinaryAnalyser work, after it flushes some data from memory. The method
* must check & store information that the data is NOT visible to IndexReaders yet
*/
private void dataFlushed(Index index) throws IOException, InterruptedException {
Collection<String> names = new LinkedList<String>();
// check using collected usages
index.query(
names,
DocumentUtil.binaryNameConvertor(),
DocumentUtil.declaredTypesFieldSelector(false, false),
null,
QueryUtil.createUsagesQuery("java.util.List", EnumSet.of(UsageType.TYPE_REFERENCE), Occur.SHOULD));
names.retainAll(
Arrays.asList(
"usages.ClassAnnotations",
"usages.ClassArrayAnnotations",
"usages.MethodAnnotations",
"usages.MethodArrayAnnotations",
"usages.FieldAnnotations",
"usages.FieldArrayAnnotations")
);
assertTrue(names.isEmpty());
flushCount++;
}
示例2: addBooleanGetGetters
import java.util.Collection; //导入方法依赖的package包/类
private void addBooleanGetGetters() {
Collection<String> accessibleBooleanFieldsWithoutGetGetters = new HashSet<String>();
accessibleBooleanFieldsWithoutGetGetters.addAll(booleanFields);
accessibleBooleanFieldsWithoutGetGetters.retainAll(booleanIsGetters);
accessibleBooleanFieldsWithoutGetGetters.removeAll(booleanGetGetters);
for (String booleanField : accessibleBooleanFieldsWithoutGetGetters) {
addBooleanGetGetter(booleanField);
}
}
示例3: visit
import java.util.Collection; //导入方法依赖的package包/类
public Object visit(RBDisjunction disjunction) {
Collection oldVars = getVars();
Collection intersection = null;
for (int i = 0; i < disjunction.getNumSubexps(); i++) {
Collection next = disjunction.getSubexp(i).getVariables();
if (intersection==null)
intersection = next;
else
intersection.retainAll(next);
}
if (intersection != null) {
oldVars.addAll(intersection);
}
return null;
}
示例4: retainAll
import java.util.Collection; //导入方法依赖的package包/类
public static <A,B> A[] retainAll(A[] a, B[] b) {
if (a.length == 0) {
return a;
}
if (b.length == 0) {
return makeArray(a, 0);
}
Collection<A> setA = new HashSet<A>(Arrays.asList(a));
Collection<B> setB = new HashSet<B>(Arrays.asList(b));
setA.retainAll(setB);
return setA.isEmpty() ? makeArray(a, 0)
: setA.toArray(makeArray(a, setA.size()));
}
示例5: ofRetainAll
import java.util.Collection; //导入方法依赖的package包/类
public static <T> Operator<T, Boolean> ofRetainAll() {
return new BooleanOperator<T>() {
@Override
protected Boolean executeOperator(Collection<T> src, OperateCondition<T, Boolean> condition) {
return src.retainAll(condition.getOtherCollectionr());
}
};
}
示例6: set
import java.util.Collection; //导入方法依赖的package包/类
public void set(CommandContext args, final CommandSender sender, final boolean value) throws CommandException {
final MutationMatchModule module = verify(sender);
final Match match = module.getMatch();
String action = args.getString(0);
// Mutations that *will* be added or removed
final Collection<Mutation> mutations = new HashSet<>();
// Mutations that *are allowed* to be added or removed
final Collection<Mutation> availableMutations = Sets.newHashSet(Mutation.values());
final Collection<Mutation> queue = mutationQueue.mutations();
if(value) availableMutations.removeAll(queue); else availableMutations.retainAll(queue);
// Check if all mutations have been enabled/disabled
if((queue.size() == Mutation.values().length && value) || (queue.isEmpty() && !value)) {
throw newCommandException(sender, new TranslatableComponent(value ? "command.mutation.error.enabled" : "command.mutation.error.disabled"));
}
// Get which action the user wants to preform
switch (action) {
case "*": mutations.addAll(availableMutations); break;
case "?": mutations.add(Iterables.get(availableMutations, RandomUtils.safeNextInt(match.getRandom(), availableMutations.size()))); break;
default:
Mutation query = StringUtils.bestFuzzyMatch(action, Sets.newHashSet(Mutation.values()), 0.9);
if (query == null) {
throw newCommandException(sender, new TranslatableComponent("command.mutation.error.find", action));
} else {
mutations.add(query);
}
}
// Send the queued changes off to the api
syncExecutor.callback(
value ? mutationQueue.mergeAll(mutations)
: mutationQueue.removeAll(mutations),
result -> {
audiences.get(sender).sendMessage(new Component(new TranslatableComponent(
message(false, value, mutations.size() == 1),
new ListComponent(Collections2.transform(mutations, Mutation.toComponent(ChatColor.AQUA)))
), ChatColor.WHITE));
}
);
}
示例7: mergeValues
import java.util.Collection; //导入方法依赖的package包/类
/**
* Merges previously collected values with a new collection of values,
* storing the result in oldValues.
*
* By default, the intersection of the two collections is retained.
*/
protected void mergeValues(
StyleSheetNode styleSheet,
Collection<E> oldValues,
Collection<E> newValues
)
{
oldValues.retainAll(newValues);
}
示例8: filterSearchCollections
import java.util.Collection; //导入方法依赖的package包/类
private void filterSearchCollections(DefaultSearch search, Collection<String> collectionUuids)
{
final Collection<String> existing = search.getCollectionUuids();
if( existing == null )
{
search.setCollectionUuids(collectionUuids);
}
else
{
existing.retainAll(collectionUuids);
}
}
示例9: getEntitiesWith
import java.util.Collection; //导入方法依赖的package包/类
@SafeVarargs
public final Collection<Entity> getEntitiesWith(Collection<Entity> dst, Class<? extends Component>... types)
{
boolean flag = false;
for(Class<? extends Component> componentType : this.components.keySet())
{
for(Class<? extends Component> type : types)
{
if (type.isAssignableFrom(componentType))
{
Map<Entity, Component> entityComponentMap = this.components.get(componentType);
if (!flag)
{
dst.addAll(entityComponentMap.keySet());
flag = true;
}
else
{
dst.retainAll(entityComponentMap.keySet());
if (dst.isEmpty())
{
return dst;
}
}
}
}
}
return dst;
}
示例10: retainAll
import java.util.Collection; //导入方法依赖的package包/类
@Override
public boolean retainAll(Collection<?> c) {
final Collection<V> coll = getMapping();
if (coll == null) {
return false;
}
boolean result = coll.retainAll(c);
if (coll.isEmpty()) {
AbstractMultiValuedMap.this.remove(key);
}
return result;
}
示例11: needsMerge
import java.util.Collection; //导入方法依赖的package包/类
private static Pair<Group,Group> needsMerge(AnnotationSet aset, Collection<String> inter) {
for (Group g1 : aset.getGroups())
for (Group g2 : aset.getGroups()) {
if (g1 == g2)
continue;
inter.clear();
inter.addAll(g1.getItemIds());
inter.retainAll(g2.getItemIds());
if (!inter.isEmpty())
return new Pair<Group,Group>(g1, g2);
}
return null;
}
示例12: intersection
import java.util.Collection; //导入方法依赖的package包/类
protected static <T> Collection<T> intersection(Collection<T> a, Collection<T> b) {
Collection<T> result = new ArrayList<T>(a);
result.retainAll(b);
return result;
}
示例13: retainAll
import java.util.Collection; //导入方法依赖的package包/类
/**
* Retains all the elements in the specified collection in this composite set,
* removing all others.
* <p>
* This implementation calls <code>retainAll()</code> on each collection.
*
* @param coll the collection to remove
* @return true if the composite was modified
* @throws UnsupportedOperationException if retainAll is unsupported
*/
public boolean retainAll(final Collection<?> coll) {
boolean changed = false;
for (final Collection<E> item : all) {
changed |= item.retainAll(coll);
}
return changed;
}
示例14: retainAll
import java.util.Collection; //导入方法依赖的package包/类
/**
* Retains all the elements in the specified collection in this composite collection,
* removing all others.
* <p>
* This implementation calls <code>retainAll()</code> on each collection.
*
* @param coll the collection to remove
* @return true if the collection was modified
* @throws UnsupportedOperationException if retainAll is unsupported
*/
@Override
public boolean retainAll(final Collection<?> coll) {
boolean changed = false;
for (final Collection<E> item : all) {
changed |= item.retainAll(coll);
}
return changed;
}