org.apache.commons.collections.CollectionUtils.intersection()方法的使用及代码示例

x33g5p2x  于2022-01-17 转载在 其他  
字(10.3k)|赞(0)|评价(0)|浏览(378)

本文整理了Java中org.apache.commons.collections.CollectionUtils.intersection()方法的一些代码示例,展示了CollectionUtils.intersection()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。CollectionUtils.intersection()方法的具体详情如下:
包路径:org.apache.commons.collections.CollectionUtils
类名称:CollectionUtils
方法名:intersection

CollectionUtils.intersection介绍

[英]Returns a Collection containing the intersection of the given Collections.

The cardinality of each element in the returned Collectionwill be equal to the minimum of the cardinality of that element in the two given Collections.
[中]返回包含给定集合交集的集合。
返回集合中每个元素的基数将等于两个给定集合中该元素的最小基数。

代码示例

代码示例来源:origin: commons-collections/commons-collections

/**
 * Add an additional Map to the composite.
 *
 * @param map  the Map to be added to the composite
 * @throws IllegalArgumentException if there is a key collision and there is no
 *         MapMutator set to handle it.
 */
public synchronized void addComposited(Map map) throws IllegalArgumentException {
  for (int i = composite.length - 1; i >= 0; --i) {
    Collection intersect = CollectionUtils.intersection(this.composite[i].keySet(), map.keySet());
    if (intersect.size() != 0) {
      if (this.mutator == null) {
        throw new IllegalArgumentException("Key collision adding Map to CompositeMap");
      }
      else {
        this.mutator.resolveCollision(this, this.composite[i], map, intersect);
      }
    }
  }
  Map[] temp = new Map[this.composite.length + 1];
  System.arraycopy(this.composite, 0, temp, 0, this.composite.length);
  temp[temp.length - 1] = map;
  this.composite = temp;
}

代码示例来源:origin: apache/kylin

private Pair<Boolean, Set<String>> hasOverlap(ArrayList<Set<String>> dimsList, Set<String> Dims) {
  Set<String> existing = new HashSet<>();
  Set<String> overlap = new HashSet<>();
  for (Set<String> dims : dimsList) {
    if (CollectionUtils.containsAny(existing, dims)) {
      overlap.addAll(ensureOrder(CollectionUtils.intersection(existing, dims)));
    }
    existing.addAll(dims);
  }
  return new Pair<>(overlap.size() > 0, overlap);
}

代码示例来源:origin: wildfly/wildfly

/**
 * Add an additional Map to the composite.
 *
 * @param map  the Map to be added to the composite
 * @throws IllegalArgumentException if there is a key collision and there is no
 *         MapMutator set to handle it.
 */
public synchronized void addComposited(Map map) throws IllegalArgumentException {
  for (int i = composite.length - 1; i >= 0; --i) {
    Collection intersect = CollectionUtils.intersection(this.composite[i].keySet(), map.keySet());
    if (intersect.size() != 0) {
      if (this.mutator == null) {
        throw new IllegalArgumentException("Key collision adding Map to CompositeMap");
      }
      else {
        this.mutator.resolveCollision(this, this.composite[i], map, intersect);
      }
    }
  }
  Map[] temp = new Map[this.composite.length + 1];
  System.arraycopy(this.composite, 0, temp, 0, this.composite.length);
  temp[temp.length - 1] = map;
  this.composite = temp;
}

代码示例来源:origin: commons-collections/commons-collections

Collection intersects = CollectionUtils.intersection(set, c);
if (intersects.size() > 0) {
  if (this.mutator == null) {
  if (CollectionUtils.intersection(set, c).size() > 0) {
    throw new IllegalArgumentException(
      "Attempt to add illegal entry unresolved by SetMutator.resolveCollision()");

代码示例来源:origin: wildfly/wildfly

Collection intersects = CollectionUtils.intersection(set, c);
if (intersects.size() > 0) {
  if (this.mutator == null) {
  if (CollectionUtils.intersection(set, c).size() > 0) {
    throw new IllegalArgumentException(
      "Attempt to add illegal entry unresolved by SetMutator.resolveCollision()");

代码示例来源:origin: alibaba/nacos

public List<IpAddress> updatedIPs(Collection<IpAddress> a, Collection<IpAddress> b) {
  List<IpAddress> intersects = (List<IpAddress>) CollectionUtils.intersection(a, b);
  Map<String, IpAddress> stringIPAddressMap = new ConcurrentHashMap<>(intersects.size());

代码示例来源:origin: commons-collections/commons-collections

public void testIntersection() {
  Collection col = CollectionUtils.intersection(collectionA,collectionB);
  Map freq = CollectionUtils.getCardinalityMap(col);
  assertNull(freq.get("a"));
  assertEquals(new Integer(2),freq.get("b"));
  assertEquals(new Integer(3),freq.get("c"));
  assertEquals(new Integer(2),freq.get("d"));
  assertNull(freq.get("e"));
  Collection col2 = CollectionUtils.intersection(collectionB,collectionA);
  Map freq2 = CollectionUtils.getCardinalityMap(col2);
  assertNull(freq2.get("a"));
  assertEquals(new Integer(2),freq2.get("b"));
  assertEquals(new Integer(3),freq2.get("c"));
  assertEquals(new Integer(2),freq2.get("d"));
  assertNull(freq2.get("e"));      
}

代码示例来源:origin: apache/kylin

+ ensureOrder(CollectionUtils.intersection(mandatoryDims, hierarchyDims)));
    + ensureOrder(CollectionUtils.intersection(mandatoryDims, jointDims)));
throw new IllegalStateException(
    "Aggregation group " + index + " hierarchy dimensions overlap with joint dimensions: "
        + ensureOrder(CollectionUtils.intersection(hierarchyDims, jointDims)));

代码示例来源:origin: apache/kylin

for (String[] oneHierarchy : agg.getSelectRule().hierarchyDims) {
  Set<String> share = new TreeSet<>(String.CASE_INSENSITIVE_ORDER);
  share.addAll(CollectionUtils.intersection(oneJoint, Arrays.asList(oneHierarchy)));
  overlap.addAll(CollectionUtils.intersection(existing, oneJoint));

代码示例来源:origin: commons-collections/commons-collections

Collection intersection = CollectionUtils.intersection(cola,colb);
assertEquals(1,intersection.size());

代码示例来源:origin: commons-collections/commons-collections

public void testDisjunctionAsUnionMinusIntersection() {
  Collection dis = CollectionUtils.disjunction(collectionA,collectionB);
  Collection un = CollectionUtils.union(collectionA,collectionB);
  Collection inter = CollectionUtils.intersection(collectionA,collectionB);
  assertTrue(CollectionUtils.isEqualCollection(dis,CollectionUtils.subtract(un,inter)));
}

代码示例来源:origin: commons-collections/commons-collections

public void testIsProperSubCollection() {
  Collection a = new ArrayList();
  Collection b = new ArrayList();
  assertTrue(!CollectionUtils.isProperSubCollection(a,b));
  b.add("1");
  assertTrue(CollectionUtils.isProperSubCollection(a,b));
  assertTrue(!CollectionUtils.isProperSubCollection(b,a));
  assertTrue(!CollectionUtils.isProperSubCollection(b,b));
  assertTrue(!CollectionUtils.isProperSubCollection(a,a));
  a.add("1");
  a.add("2");
  b.add("2");
  assertTrue(!CollectionUtils.isProperSubCollection(b,a));
  assertTrue(!CollectionUtils.isProperSubCollection(a,b));
  a.add("1");
  assertTrue(CollectionUtils.isProperSubCollection(b,a));
  assertTrue(CollectionUtils.isProperSubCollection(
    CollectionUtils.intersection(collectionA, collectionB), collectionA));
  assertTrue(CollectionUtils.isProperSubCollection(
    CollectionUtils.subtract(a, b), a));
  assertTrue(!CollectionUtils.isProperSubCollection(
    a, CollectionUtils.subtract(a, b)));
}

代码示例来源:origin: apache/tinkerpop

final Collection<String> edgeKeySet = getEdgeKeysAndNormalizeIfRequired(identifiedEdgeKeyTypes);
intersection = CollectionUtils.intersection(vertexKeySet, edgeKeySet);

代码示例来源:origin: mulesoft/mule

@Override
public T build(ValueResolvingContext context) throws MuleException {
 if (!lazyInitEnabled) {
  Collection<String> definedExclusiveParameters =
    intersection(exclusiveOptionalsTypeAnnotation.getExclusiveParameterNames(),
           resolvers.keySet().stream().map(fs -> getAlias(fs.getField())).collect(toSet()));
  if (definedExclusiveParameters.isEmpty() && exclusiveOptionalsTypeAnnotation.isOneRequired()) {
   throw new ConfigurationException((createStaticMessage(format(
                                  "Parameter group of type '%s' requires that one of its optional parameters should be set but all of them are missing. "
                                    + "One of the following should be set: [%s]",
                                  prototypeClass.getName(),
                                  on(", ").join(exclusiveOptionalsTypeAnnotation
                                    .getExclusiveParameterNames())))));
  } else if (definedExclusiveParameters.size() > 1) {
   throw new ConfigurationException(
                    createStaticMessage(format("In Parameter group of type '%s', the following parameters cannot be set at the same time: [%s]",
                                 prototypeClass.getName(),
                                 on(", ").join(definedExclusiveParameters))));
  }
 }
 return super.build(context);
}

代码示例来源:origin: mulesoft/mule

for (ParameterGroupModel group : groups) {
 for (ExclusiveParametersModel exclusiveModel : group.getExclusiveParametersModels()) {
  Collection<String> definedExclusiveParameters = intersection(exclusiveModel.getExclusiveParameterNames(), resolverKeys);
  if (definedExclusiveParameters.isEmpty() && exclusiveModel.isOneRequired()) {
   throw new ConfigurationException((createStaticMessage(format(

代码示例来源:origin: com.atlassian.jira/jira-core

public boolean equals(final Object o)
{
  if (this == o)
  {
    return true;
  }
  if ((o == null) || (getClass() != o.getClass()))
  {
    return false;
  }
  final EnterpriseWorkflowTaskContext that = (EnterpriseWorkflowTaskContext) o;
  return isNotEmpty(intersection(projectIds, that.projectIds));
}

代码示例来源:origin: org.jbpm/jbpm-form-modeler-common

/**
 * Check if tow collections contains exactly the same elements.
 * The order of elements within each collection is not relevant.
 */
public static boolean equals(Collection o1, Collection o2) {
  if (o1 == null && o2 != null) return false;
  else if (o1 != null && o2 == null) return false;
  else if (o1 == null && o2 == null) return false;
  else if (o1.size() != o2.size()) return false;
  else if (o1.isEmpty() && o2.isEmpty()) return false;
  else return CollectionUtils.intersection(o1, o2).size() == o1.size();
}

代码示例来源:origin: uk.ac.ebi.intact.dataexchange.imex/imex-id-update

@Transactional(value = "jamiTransactionManager", propagation = Propagation.REQUIRED, readOnly = true)
public Collection<String> getPublicationsHavingIMExCurationLevelAndUniprotDrExportNo() {
  if (!isInitialised){
    initialise();
  }
  Collection<String> publicationsWithoutImexButImexCurationLevel = CollectionUtils.subtract(publicationsHavingImexCurationLevel, publicationsHavingImexId);
  return CollectionUtils.intersection(publicationsWithoutImexButImexCurationLevel, publicationsHavingUniprotDRExportNo);
}

代码示例来源:origin: spinnaker/fiat

private Predicate<ServiceAccount> getServiceAccountPredicate(boolean isAdmin, List<String> roleNames) {
 if (isAdmin) {
  return svcAcct -> true;
 }
 if (fiatRoleConfig.isOrMode()) {
  return svcAcct -> CollectionUtils.intersection(roleNames, svcAcct.getMemberOf()).size() > 0;
 } else {
  return svcAcct -> roleNames.containsAll(svcAcct.getMemberOf());
 }
}

代码示例来源:origin: FenixEdu/fenixedu-academic

@Override
  public boolean test(PhdIndividualProgramProcess toEval) {
    if (toEval.getPhdProgram() != null) {
      return getValue().equals(toEval.getPhdProgram());
    } else if (toEval.getPhdProgramFocusArea() != null) {
      return !CollectionUtils.intersection(Collections.singleton(getValue()),
          toEval.getPhdProgramFocusArea().getPhdProgramsSet()).isEmpty();
    } else {
      return false;
    }
  }
});

相关文章