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

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

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

CollectionUtils.disjunction介绍

[英]Returns a Collection containing the exclusive disjunction (symmetric difference) of the given Collections.

The cardinality of each element e in the returned Collectionwill be equal to max(cardinality(e,a),cardinality(e,b)) - min(cardinality(e,a),cardinality(e,b)).

This is equivalent to #subtract( #union, #intersection) or #union( #subtract, #subtract).
[中]返回包含给定集合的独占析取(对称差)的集合。
返回集合中每个元素e的基数将等于max(基数(e,a),基数(e,b))-min(基数(e,a),基数(e,b))。
这相当于#减法(#并集,#交集)或#并集(#减法,#减法)。

代码示例

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

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

代码示例来源: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 testDisjunctionAsSymmetricDifference() {
  Collection dis = CollectionUtils.disjunction(collectionA,collectionB);
  Collection amb = CollectionUtils.subtract(collectionA,collectionB);
  Collection bma = CollectionUtils.subtract(collectionB,collectionA);
  assertTrue(CollectionUtils.isEqualCollection(dis,CollectionUtils.union(amb,bma)));
}

代码示例来源:origin: jamesagnew/hapi-fhir

public static void main(String[] aaa) {
  String input = "[INFO] Running ca.uhn.fhir.rest.client.RestfulClientFactoryDstu2Test\n" +
    "[INFO] Tests run: 9, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 2.982 s - in ca.uhn.fhir.validation.ResourceValidatorDstu2Test";
  Set<String> started = new HashSet<>();
  Set<String> finished = new HashSet<>();
  for (String next : input.split("\n")) {
    if (next.startsWith("[INFO] ")) {
      next = next.substring("[INFO] ".length());
    }
    if (next.startsWith("[WARNING] ")) {
      next = next.substring("[WARNING] ".length());
    }
    if (next.startsWith("Running ")) {
      started.add(next.substring("Running ".length()));
    } else if (next.startsWith("Tests run: ")) {
      finished.add(next.substring(next.indexOf(" - in ") + " - in ".length()));
    } else if (isBlank(next)) {
      continue;
    } else {
      throw new IllegalStateException("Unknown line: " + next);
    }
  }
  ourLog.info("Started {}", started.size());
  ourLog.info("Finished {}", finished.size());
  ourLog.info(CollectionUtils.disjunction(started, finished).toString());
}

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

private void validateErrorMappings() {
 executeOnEveryComponentTree(componentModel -> {
  List<ComponentModel> errorMappings = componentModel.getInnerComponents().stream()
    .filter(c -> c.getIdentifier().equals(ERROR_MAPPING_IDENTIFIER)).collect(toList());
  if (!errorMappings.isEmpty()) {
   List<ComponentModel> anyMappings = errorMappings.stream().filter(this::isErrorMappingWithSourceAny).collect(toList());
   if (anyMappings.size() > 1) {
    throw new MuleRuntimeException(createStaticMessage("Only one mapping for 'ANY' or an empty source type is allowed."));
   } else if (anyMappings.size() == 1 && !isErrorMappingWithSourceAny(errorMappings.get(errorMappings.size() - 1))) {
    throw new MuleRuntimeException(createStaticMessage("Only the last error mapping can have 'ANY' or an empty source type."));
   }
   List<String> sources = errorMappings.stream().map(model -> model.getParameters().get(SOURCE_TYPE)).collect(toList());
   List<String> distinctSources = sources.stream().distinct().collect(toList());
   if (sources.size() != distinctSources.size()) {
    throw new MuleRuntimeException(createStaticMessage(format("Repeated source types are not allowed. Offending types are '%s'.",
                                 on("', '").join(disjunction(sources, distinctSources)))));
   }
  }
 });
}

代码示例来源:origin: org.andromda.translationlibraries/andromda-ocl-validation-library

/**
 * Returns those element that are contained in only one of both collections.
 * @param first
 * @param second
 * @return CollectionUtils.disjunction(first, second)
 */
public static Collection symmetricDifference(
    final Collection first,
    final Collection second)
{
  return CollectionUtils.disjunction(first, second);
}

代码示例来源:origin: com.googlecode.jannocessor/jannocessor-collections

@SuppressWarnings("unchecked")
@Override
public PowerList<E> getDisjunction(Collection<E> list) {
  return powerList(CollectionUtils.disjunction(this, list));
}

代码示例来源:origin: com.googlecode.jannocessor/jannocessor-collections

@SuppressWarnings("unchecked")
public PowerSet<E> getDisjunction(Collection<E> Set) {
  return powerSet(CollectionUtils.disjunction(this, Set));
}

代码示例来源:origin: org.apache.maven.plugins/maven-dependency-plugin

@SuppressWarnings( "unchecked" )
  private Set<String> findDuplicateDependencies( List<Dependency> modelDependencies )
  {
    List<String> modelDependencies2 = new ArrayList<String>();
    for ( Dependency dep : modelDependencies )
    {
      modelDependencies2.add( dep.getManagementKey() );
    }

    //@formatter:off
    return new LinkedHashSet<String>( 
     CollectionUtils.disjunction( modelDependencies2, new LinkedHashSet<String>( modelDependencies2 ) ) 
    );
    //@formatter:on
  }
}

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

private List<PhdIndividualProgramProcess> getStudentOtherProcesses(final PhdIndividualProgramProcess process) {
  List<PhdIndividualProgramProcess> result = new ArrayList<PhdIndividualProgramProcess>();
  result.addAll(CollectionUtils.disjunction(process.getPerson().getPhdIndividualProgramProcessesSet(),
      Collections.singletonList(process)));
  return result;
}

代码示例来源:origin: openmrs/openmrs-core

@Test
public void shouldAllowEditingADiscontinuationOrder() {
  Order originalDCOrder = orderService.getOrder(22);
  assertEquals(Order.Action.DISCONTINUE, originalDCOrder.getAction());
  List<Order> originalPatientOrders = orderService.getAllOrdersByPatient(originalDCOrder.getPatient());
  final Order previousOrder = originalDCOrder.getPreviousOrder();
  assertNotNull(previousOrder);
  final Date newStartDate = originalDCOrder.getEncounter().getEncounterDatetime();
  
  Order newDcOrder = originalDCOrder.cloneForRevision();
  newDcOrder.setEncounter(originalDCOrder.getEncounter());
  newDcOrder.setOrderer(originalDCOrder.getOrderer());
  newDcOrder.setDateActivated(newStartDate);
  orderService.voidOrder(originalDCOrder, "To be replace with a new one");
  assertNull(originalDCOrder.getDateStopped());
  orderService.saveOrder(newDcOrder, null);
  
  //We need to flush so that we ensure the interceptor is okay with all this
  Context.flushSession();
  assertTrue(originalDCOrder.getVoided());
  List<Order> newPatientOrders = orderService.getAllOrdersByPatient(originalDCOrder.getPatient());
  assertEquals(originalPatientOrders.size() + 1, newPatientOrders.size());
  Collection<Order> newOrders = CollectionUtils.disjunction(originalPatientOrders, newPatientOrders);
  assertEquals(1, newOrders.size());
  assertEquals(newOrders.iterator().next().getPreviousOrder(), previousOrder);
}

代码示例来源:origin: org.opensingular/form-wicket

protected static Set<? extends SInstance> collectLowerBoundInstances(FeedbackFence feedbackFence) {
  // coleta os componentes descendentes que possuem um handler, e as instancias correspondentes
  final Set<Component> mainComponents     = collectLowerBoundInstances(feedbackFence.getMainContainer());
  final Set<Component> externalComponents = collectLowerBoundInstances(feedbackFence.getExternalContainer());
  return ((Collection<Component>) CollectionUtils.disjunction(mainComponents, externalComponents)).stream()
      .flatMap(it -> resolveRootInstances(it).stream())
      .collect(toSet());
}

代码示例来源:origin: org.mule.runtime/mule-module-spring-config

private void validateErrorMappings() {
 executeOnEveryComponentTree(componentModel -> {
  List<ComponentModel> errorMappings = componentModel.getInnerComponents().stream()
    .filter(c -> c.getIdentifier().equals(ERROR_MAPPING_IDENTIFIER)).collect(toList());
  if (!errorMappings.isEmpty()) {
   List<ComponentModel> anyMappings = errorMappings.stream().filter(this::isErrorMappingWithSourceAny).collect(toList());
   if (anyMappings.size() > 1) {
    throw new MuleRuntimeException(createStaticMessage("Only one mapping for 'ANY' or an empty source type is allowed."));
   } else if (anyMappings.size() == 1 && !isErrorMappingWithSourceAny(errorMappings.get(errorMappings.size() - 1))) {
    throw new MuleRuntimeException(createStaticMessage("Only the last error mapping can have 'ANY' or an empty source type."));
   }
   List<String> sources = errorMappings.stream().map(model -> model.getParameters().get(SOURCE_TYPE)).collect(toList());
   List<String> distinctSources = sources.stream().distinct().collect(toList());
   if (sources.size() != distinctSources.size()) {
    throw new MuleRuntimeException(createStaticMessage(format("Repeated source types are not allowed. Offending types are '%s'.",
                                 on("', '").join(disjunction(sources, distinctSources)))));
   }
  }
 });
}

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

private Collection<Long> getChangedProjectIds()
  {
    List<Project> previousProjects = getConfigScheme().getAssociatedProjectObjects();
    List<Long> previousProjectIds;
    if (previousProjects != null && !previousProjects.isEmpty())
    {
      previousProjectIds = Lists.newArrayList(Iterables.transform(previousProjects, WithFunctions.getId()));
    }
    else
    {
      previousProjectIds = Collections.emptyList();
    }

    List<Long> newProjectIds;
    if (getProjects() != null && getProjects().length > 0)
    {
      newProjectIds = Arrays.asList(getProjects());
    }
    else
    {
      newProjectIds = Collections.emptyList();
    }

    Collection<Long> affectedProjectIds =  CollectionUtils.disjunction(previousProjectIds, newProjectIds);
    return affectedProjectIds;
  }
}

代码示例来源:origin: com.atlassian.plugins/atlassian-plugins-webresource-rest

Collection<String> invalidRootPageNames = CollectionUtils.<String>disjunction(rootPageNames, validRootPageNames);
return new ValidatedRootPages(invalidRootPageNames, validRootPageNames, includedRootPages);

代码示例来源:origin: org.dkpro.tc/dkpro-tc-fstore-simple

String[] symDiff = new ArrayList<String>(CollectionUtils.disjunction(
    instanceFeatureNames,
    featureNames)).toArray(new String[] {});

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

public boolean isAssociatedWithEmailAndCandidacyProcess(String email, Class<? extends IndividualCandidacyProcess> type,
    CandidacyProcess process, List<Degree> degreeList) {
  if (email.equals(this.getEmail()) && this.getIndividualCandidacyProcess() != null
      && !getIndividualCandidacyProcess().isCandidacyCancelled()
      && this.getIndividualCandidacyProcess().getClass() == type
      && this.getIndividualCandidacyProcess().getCandidacyProcess() == process) {
    return CollectionUtils.disjunction(this.getIndividualCandidacyProcess().getCandidacy().getAllDegrees(), degreeList)
        .isEmpty();
  } else {
    return false;
  }
}

代码示例来源:origin: oVirt/ovirt-engine

private void assertGetAllForConnectionResult(List<StorageServerConnections> expected, StorageServerConnections forQuery) {
  assertTrue(CollectionUtils.disjunction(expected, dao.getAllForConnection(forQuery)).isEmpty());
}

代码示例来源:origin: oVirt/ovirt-engine

@Test
public void testGetAllForStoragePoolAndStatuses() {
  prepareHostWithDifferentStatus();
  List<VDS> result = dao.getAllForStoragePoolAndStatuses(existingVds.getStoragePoolId(), EnumSet.of(existingVds.getStatus(), existingVds2.getStatus()));
  assertTrue(CollectionUtils.disjunction(result, Arrays.asList(existingVds, existingVds2)).isEmpty());
  assertCorrectGetAllResult(result);
}

代码示例来源:origin: eBay/xcelite

/**
 * Returns the difference between two sheets. Note that T must implement
 * hashCode() and equals() if you wish to have meaningful symmetric difference
 * results.
 * 
 * @param a the first sheet
 * @param b the second sheet
 * @param reportGenerator a custom reporter implementation
 * @return DiffResult object which holds the diff result
 */
@SuppressWarnings("unchecked")
public static <T> DiffResult<T> diff(@Nonnull SheetReader<T> a, @Nonnull SheetReader<T> b,
  ReportGenerator reportGenerator) {
 Collection<T> ca = a.read();
 Collection<T> cb = b.read();
 Collection<T> disjunction = CollectionUtils.disjunction(ca, cb);
 Info<T> info = new ReportInfo<T>(new Files(a.getSheet().getFile().getAbsolutePath(), b.getSheet().getFile()
   .getAbsolutePath()), new Sheets(a.getSheet().getNativeSheet().getSheetName(), b.getSheet().getNativeSheet()
   .getSheetName()), new Collections<T>(ca, cb, disjunction));
 ReportGenerator reporter;
 if (reportGenerator != null) {
  reporter = reportGenerator;
 } else {
  reporter = new SimpleReportGenerator();
 }
 return new DiffResultImpl<T>(disjunction, reporter.generateReport(info));
}

相关文章