List of usage examples for java.util List retainAll
boolean retainAll(Collection<?> c);
From source file:org.axe.util.CollectionUtil.java
@SuppressWarnings({ "unchecked", "rawtypes" }) public static <T> List<T> intersect(List ls, List ls2) { List<T> list = new ArrayList(Arrays.asList(new Object[ls.size()])); Collections.copy(list, ls);//from www.j av a2s. com list.retainAll(ls2); return list; }
From source file:Main.java
public static <T> T[] intersection(@NonNull final T[] array1, @NonNull final T[] array2) { final List<T> list1 = new ArrayList<>(); Collections.addAll(list1, array1); final List<T> list2 = new ArrayList<>(); Collections.addAll(list2, array2); list1.retainAll(list2); //noinspection unchecked return list1.toArray((T[]) Array.newInstance(array1.getClass().getComponentType(), list1.size())); }
From source file:Main.java
public static long[] intersection(final long[] array1, final long[] array2) { if (array1 == null || array2 == null) return new long[0]; final List<Long> list1 = new ArrayList<Long>(); for (final long item : array1) { list1.add(item);/*from w w w . ja v a2 s .c om*/ } final List<Long> list2 = new ArrayList<Long>(); for (final long item : array2) { list2.add(item); } list1.retainAll(list2); return fromList(list1); }
From source file:Main.java
public static long[] intersection(final long[] array1, final long[] array2) { if (array1 == null || array2 == null) return new long[0]; final List<Long> list1 = new ArrayList<>(); for (final long item : array1) { list1.add(item);/* www .java2 s . com*/ } final List<Long> list2 = new ArrayList<>(); for (final long item : array2) { list2.add(item); } list1.retainAll(list2); return fromList(list1); }
From source file:org.apache.asterix.optimizer.rules.util.EquivalenceClassUtils.java
/** * Find the header variables that can imply all subplan-local live variables at <code>operator</code>. * * @param operator/*from w ww .ja v a2 s .c o m*/ * the operator of interest. * @param usedForCorrelationJoin * whether the generated primary key will be used for a join that recovers the correlation. * @param context * the optimization context. * @return Pair<ILogicalOperator, Set<LogicalVariable>>, an operator (which is either the original parameter * <code>operator</code> or a newly created operator) and * a set of primary key variables at the operator. * @throws AlgebricksException */ public static Pair<ILogicalOperator, Set<LogicalVariable>> findOrCreatePrimaryKeyOpAndVariables( ILogicalOperator operator, boolean usedForCorrelationJoin, IOptimizationContext context) throws AlgebricksException { computePrimaryKeys(operator, context); Set<LogicalVariable> liveVars = new HashSet<>(); VariableUtilities.getSubplanLocalLiveVariables(operator, liveVars); Set<LogicalVariable> primaryKeyVars = new HashSet<>(); Set<LogicalVariable> noKeyVars = new HashSet<>(); for (LogicalVariable liveVar : liveVars) { List<LogicalVariable> keyVars = context.findPrimaryKey(liveVar); if (keyVars != null) { keyVars.retainAll(liveVars); } if ((keyVars == null || keyVars.isEmpty())) { noKeyVars.add(liveVar); } else { primaryKeyVars.addAll(keyVars); } } primaryKeyVars.retainAll(liveVars); if (primaryKeyVars.containsAll(noKeyVars)) { return new Pair<ILogicalOperator, Set<LogicalVariable>>(operator, primaryKeyVars); } else { LogicalVariable assignVar = context.newVar(); ILogicalOperator assignOp = new AssignOperator(assignVar, new MutableObject<ILogicalExpression>(new StatefulFunctionCallExpression( FunctionUtil.getFunctionInfo(AsterixBuiltinFunctions.CREATE_QUERY_UID), null))); OperatorPropertiesUtil.markMovable(assignOp, !usedForCorrelationJoin); assignOp.getInputs().add(new MutableObject<ILogicalOperator>(operator)); context.addPrimaryKey(new FunctionalDependency(Collections.singletonList(assignVar), new ArrayList<LogicalVariable>(liveVars))); context.computeAndSetTypeEnvironmentForOperator(assignOp); return new Pair<ILogicalOperator, Set<LogicalVariable>>(assignOp, Collections.singleton(assignVar)); } }
From source file:org.carrot2.workbench.editors.factory.EditorFactory.java
/** * Sort attribute editors based on various criteria (type proximity, number * of matching and available constraints). *///from www . j av a2 s. c o m private static List<TypeEditorWrapper> sortTypeEditors(List<TypeEditorWrapper> editors, final AttributeDescriptor attribute) { final List<String> annotationNames = Lists.newArrayList(); for (Annotation ann : attribute.constraints) { annotationNames.add(ann.annotationType().getName()); } final HashMap<TypeEditorWrapper, Integer> matchingConstraints = Maps.newHashMap(); for (TypeEditorWrapper t : editors) { List<String> matches = Lists.newArrayList(annotationNames); matches.retainAll(t.constraints); matchingConstraints.put(t, matches.size()); } final Comparator<TypeEditorWrapper> comparator = new Comparator<TypeEditorWrapper>() { public int compare(TypeEditorWrapper o1, TypeEditorWrapper o2) { int result = distance(attribute.type, o1.attributeClass) - distance(attribute.type, o2.attributeClass); /* * Consult the number of matching constraints and pick the more specific * editor (with more available constraints). */ if (result == 0) { result = -(matchingConstraints.get(o1) - matchingConstraints.get(o2)); } /* * Consult again in case of a draw and pick the editor that has more optional * constraints (even if they are not present). */ if (result == 0) { result = -(o1.constraints.size() - o2.constraints.size()); } return result; } }; return Ordering.from(comparator).sortedCopy(editors); }
From source file:org.opencms.workplace.comparison.CmsResourceComparison.java
/** * Helper method that finds out, which of the properties were added, removed, modified or remain unchanged.<p> * //from w ww . j a v a 2 s .co m * @param cms the CmsObject to use * @param resource1 the first resource to read the properties from * @param version1 the version of the first resource * @param resource2 the second resource to read the properties from * @param version2 the version of the second resource * * @return a list of the compared attributes * * @throws CmsException if something goes wrong */ public static List compareProperties(CmsObject cms, CmsResource resource1, String version1, CmsResource resource2, String version2) throws CmsException { List properties1; if (resource1 instanceof I_CmsHistoryResource) { properties1 = cms.readHistoryPropertyObjects((I_CmsHistoryResource) resource1); } else { if (Integer.parseInt(version1) < 0) { // switch to the online project CmsProject prj = cms.getRequestContext().getCurrentProject(); try { cms.getRequestContext().setCurrentProject(cms.readProject(CmsProject.ONLINE_PROJECT_ID)); properties1 = cms.readPropertyObjects(resource1, false); } finally { cms.getRequestContext().setCurrentProject(prj); } } else { properties1 = cms.readPropertyObjects(resource1, false); } } List properties2; if (resource2 instanceof I_CmsHistoryResource) { properties2 = cms.readHistoryPropertyObjects((I_CmsHistoryResource) resource2); } else { if (Integer.parseInt(version2) < 0) { // switch to the online project CmsProject prj = cms.getRequestContext().getCurrentProject(); try { cms.getRequestContext().setCurrentProject(cms.readProject(CmsProject.ONLINE_PROJECT_ID)); properties2 = cms.readPropertyObjects(resource2, false); } finally { cms.getRequestContext().setCurrentProject(prj); } } else { properties2 = cms.readPropertyObjects(resource2, false); } } List comparedProperties = new ArrayList(); List removedProperties = new ArrayList(properties1); removedProperties.removeAll(properties2); List addedProperties = new ArrayList(properties2); addedProperties.removeAll(properties1); List retainedProperties = new ArrayList(properties2); retainedProperties.retainAll(properties1); CmsProperty prop; Iterator i = addedProperties.iterator(); while (i.hasNext()) { prop = (CmsProperty) i.next(); comparedProperties.add(new CmsAttributeComparison(prop.getName(), "", prop.getValue(), CmsResourceComparison.TYPE_ADDED)); } i = removedProperties.iterator(); while (i.hasNext()) { prop = (CmsProperty) i.next(); comparedProperties.add(new CmsAttributeComparison(prop.getName(), prop.getValue(), "", CmsResourceComparison.TYPE_REMOVED)); } i = retainedProperties.iterator(); while (i.hasNext()) { prop = (CmsProperty) i.next(); String value1 = ((CmsProperty) properties1.get(properties1.indexOf(prop))).getValue(); String value2 = ((CmsProperty) properties2.get(properties2.indexOf(prop))).getValue(); if (value1.equals(value2)) { comparedProperties.add(new CmsAttributeComparison(prop.getName(), value1, value2, CmsResourceComparison.TYPE_UNCHANGED)); } else { comparedProperties.add(new CmsAttributeComparison(prop.getName(), value1, value2, CmsResourceComparison.TYPE_CHANGED)); } } return comparedProperties; }
From source file:org.codehaus.groovy.grails.web.binding.ListOrderedSet.java
/** * Factory method to create an ordered set using the supplied list to retain order. * * A HashSet is used for the set behaviour. * * @param list the list to decorate, must not be null * @throws IllegalArgumentException if list is null *//*from www. j a va 2 s . c om*/ public static ListOrderedSet decorate(List list) { Assert.notNull(list, "List must not be null"); Set set = new HashSet(list); list.retainAll(set); return new ListOrderedSet(set, list); }
From source file:Main.java
public static <T> List<T> intersection(Collection<? extends Collection<T>> availableValuesByDescriptor) { List<T> result = new ArrayList<T>(); Iterator<? extends Collection<T>> iterator = availableValuesByDescriptor.iterator(); if (iterator.hasNext()) { Collection<T> firstSet = iterator.next(); result.addAll(firstSet);//from w w w . j ava 2 s. c om while (iterator.hasNext()) { Collection<T> next = iterator.next(); result.retainAll(next); } } return result; }
From source file:YexTool.java
private static boolean isValidAttrs(OpenRtb.BidResponse.SeatBid.Bid bid, Map<String, List<Integer>> impId2Battributes) { List<Integer> battris = impId2Battributes.get(bid.getImpid()); List<Integer> attris = new ArrayList<Integer>(bid.getExtension(OpenRtbYDExtForDsp.attri)); boolean attrisIsEmpty = attris.isEmpty(); attris.retainAll(battris); boolean attrisNotBlocked = attris.isEmpty(); boolean valid = !attrisIsEmpty && attrisNotBlocked; if (attrisIsEmpty) { logger.warn("Attri is empty! Bid: \n" + bid); } else if (!attrisNotBlocked) { logger.warn("Attri is blocked! Bid: \n" + bid); }// w w w . ja v a2 s .c o m return valid; }