Example usage for org.apache.commons.collections CollectionUtils disjunction

List of usage examples for org.apache.commons.collections CollectionUtils disjunction

Introduction

In this page you can find the example usage for org.apache.commons.collections CollectionUtils disjunction.

Prototype

public static Collection disjunction(final Collection a, final Collection b) 

Source Link

Document

Returns a Collection containing the exclusive disjunction (symmetric difference) of the given Collection s.

Usage

From source file:com.ebay.xcelite.utils.diff.XceliteDiff.java

/**
 * Returns the difference between two sheets. Note that T must implement
 * hashCode() and equals() if you wish to have meaningful symmetric difference
 * results./*www  . j av  a 2 s  .c  om*/
 * 
 * @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));
}

From source file:net.sourceforge.atunes.kernel.modules.search.NotLogicalSearchOperator.java

@SuppressWarnings("unchecked")
@Override/*from  w ww. j a v  a2  s  .  c  o  m*/
public Collection<IAudioObject> evaluate(List<ISearchNode> operands) {
    // This operand has only one operand
    if (operands.size() > 1) {
        throw new IllegalStateException("NOT has more than one operand");
    }
    Collection<IAudioObject> intersection = null;
    Collection<IAudioObject> operandResult = operands.get(0).evaluate();
    if (operandResult != null) {
        return CollectionUtils.disjunction(repositoryHandler.getAudioFilesList(), operandResult);
    } else {
        repositoryHandler.getAudioFilesList();
    }
    return intersection;
}

From source file:net.sourceforge.fenixedu.domain.candidacyProcess.DegreeOfficePublicCandidacyHashCode.java

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();//from w  w  w.  jav  a2 s  .com

    } else {
        return false;
    }
}

From source file:gr.abiss.calipso.wicket.components.validators.NonDuplicateInputValidator.java

protected void onValidate(IValidatable validatable) {

    String s = (String) validatable.getValue();
    // the original list of the text area
    // split by win/unix new lines just in case and remove empty new lines.
    List<String> _originalOptions = Arrays.asList(s.split("[\\r\\n]+"));
    // the above cannot be modified...
    List<String> originalOptions = new ArrayList<String>(_originalOptions);
    Set<String> uniqueOptions = new HashSet<String>(originalOptions);
    Map<String, String> errorVars = new HashMap<String, String>();
    boolean valid = true;
    // check for entering dupes within the textarea

    if (originalOptions.size() != uniqueOptions.size()) {
        valid = false;//  w  w  w.  j  a va 2  s.  c  om
        // remove the rest to add a message for the duplicates
        originalOptions.removeAll(uniqueOptions);

        errorVars.put("duplicateEntry",
                (String) CollectionUtils.disjunction(originalOptions, uniqueOptions).iterator().next());
    } else {
        // check for entering an existing option
        for (String originalOption : originalOptions) {
            if (field.hasOption(originalOption)) {
                valid = false;
                errorVars.put("duplicateEntry", originalOption);
            }
        }
    }
    if (!valid) {
        error(validatable, errorVars);
    }
}

From source file:de.tudarmstadt.ukp.dkpro.tc.fstore.simple.DenseFeatureStore.java

@Override
public void addInstance(Instance instance) throws TextClassificationException {
    if (featureNames == null) {
        featureNames = new TreeSet<String>();
        for (Feature feature : instance.getFeatures()) {
            String name = feature.getName();
            if (featureNames.contains(name)) {
                throw new TextClassificationException(
                        "Feature with name '" + name + "' is defined multiple times.");
            }/*from  w  ww  . j  a v  a 2  s  .  co  m*/
            featureNames.add(name);
        }
    }

    HashSet<String> instanceFeatureNames = new HashSet<String>();
    for (Feature f : instance.getFeatures()) {
        instanceFeatureNames.add(f.getName());
    }
    @SuppressWarnings("unchecked")
    String[] symDiff = new ArrayList<String>(CollectionUtils.disjunction(instanceFeatureNames, featureNames))
            .toArray(new String[] {});
    if (symDiff.length > 0) {
        throw new TextClassificationException(
                "One or more, but not all of your instances return the following feature(s): "
                        + StringUtils.join(symDiff, " and "));
    }

    // create map of feature names and offset in set
    Map<String, Integer> sortedFeatureNameMap = new HashMap<String, Integer>();
    int offset = 0;
    Iterator<String> iterator = featureNames.iterator();
    while (iterator.hasNext()) {
        sortedFeatureNameMap.put(iterator.next(), offset);
        offset++;
    }

    Object[] values = new Object[featureNames.size()];
    for (Feature feature : instance.getFeatures()) {
        values[sortedFeatureNameMap.get(feature.getName())] = feature.getValue();
    }
    this.instanceList.add(Arrays.asList(values));
    this.outcomeList.add(instance.getOutcomes());
    this.weightList.add(instance.getWeight());
    this.sequenceIds.add(instance.getSequenceId());
    this.sequencePositions.add(instance.getSequencePosition());
}

From source file:net.sourceforge.fenixedu.applicationTier.Servico.coordinator.degreeCurricularPlanManagement.ReadCurriculumHistoryByCurricularCourseCodeAndExecutionYearName.java

@Atomic
public static InfoCurriculum run(Integer executionDegreeCode, String curricularCourseCode,
        String stringExecutionYear) throws FenixServiceException {
    check(RolePredicates.COORDINATOR_PREDICATE);
    InfoCurriculum infoCurriculum = null;

    if (curricularCourseCode == null) {
        throw new FenixServiceException("nullCurricularCourse");
    }/*from  w  w  w .ja v a 2 s  . c  o m*/
    if (stringExecutionYear == null || stringExecutionYear.length() == 0) {
        throw new FenixServiceException("nullExecutionYearName");
    }
    CurricularCourse curricularCourse = (CurricularCourse) FenixFramework.getDomainObject(curricularCourseCode);
    if (curricularCourse == null) {
        throw new NonExistingServiceException("noCurricularCourse");
    }

    final ExecutionYear executionYear = ExecutionYear.readExecutionYearByName(stringExecutionYear);
    if (executionYear == null) {
        throw new NonExistingServiceException("noExecutionYear");
    }

    Curriculum curriculumExecutionYear = curricularCourse
            .findLatestCurriculumModifiedBefore(executionYear.getEndDate());
    if (curriculumExecutionYear != null) {
        List allCurricularCourseScopes = new ArrayList();
        List allExecutionCourses = new ArrayList();
        Collection executionPeriods = executionYear.getExecutionPeriodsSet();
        Iterator iterExecutionPeriods = executionPeriods.iterator();
        while (iterExecutionPeriods.hasNext()) {
            ExecutionSemester executionSemester = (ExecutionSemester) iterExecutionPeriods.next();
            Set<CurricularCourseScope> curricularCourseScopes = curricularCourse
                    .findCurricularCourseScopesIntersectingPeriod(executionSemester.getBeginDate(),
                            executionSemester.getEndDate());
            if (curricularCourseScopes != null) {
                List disjunctionCurricularCourseScopes = (List) CollectionUtils
                        .disjunction(allCurricularCourseScopes, curricularCourseScopes);
                List intersectionCurricularCourseScopes = (List) CollectionUtils
                        .intersection(allCurricularCourseScopes, curricularCourseScopes);

                allCurricularCourseScopes = (List) CollectionUtils.union(disjunctionCurricularCourseScopes,
                        intersectionCurricularCourseScopes);
            }
            List associatedExecutionCourses = new ArrayList();
            Collection<ExecutionCourse> executionCourses = curricularCourse.getAssociatedExecutionCoursesSet();
            for (ExecutionCourse executionCourse : executionCourses) {
                if (executionCourse.getExecutionPeriod().equals(executionSemester)) {
                    associatedExecutionCourses.add(executionCourse);
                }
            }

            if (associatedExecutionCourses != null) {
                allExecutionCourses.addAll(associatedExecutionCourses);
            }

        }

        infoCurriculum = createInfoCurriculum(curriculumExecutionYear, allCurricularCourseScopes,
                allExecutionCourses);
    }
    return infoCurriculum;
}

From source file:com.sworddance.util.TestPredicatedTransformingIterator.java

public void testSetFlattening() {
    PredicatedTransformingIterator<Double> transformingIterator = new PredicatedTransformingIterator<Double>(
            ints);/*  w w  w  .java  2 s.  c  o m*/
    Transformer transformer = new Transformer() {

        public Object transform(Object input) {
            Integer i = (Integer) input;
            HashSet<Double> d = new HashSet<Double>();
            for (int k = 0; k < i; k++) {
                d.add(Double.valueOf(i * 10 + k));
            }
            return d;
        }

    };
    transformingIterator.setTransformer(transformer);
    transformingIterator.setPredicate(predicate);
    HashSet<Double> expected = new HashSet<Double>();
    for (Integer i : ints) {
        if (i % 2 == 0) {
            for (int k = 0; k < i; k++) {
                expected.add(Double.valueOf(i * 10 + k));
            }
        }
    }
    HashSet<Double> actual = new HashSet<Double>();
    CollectionUtils.addAll(actual, transformingIterator);

    assertTrue(CollectionUtils.disjunction(actual, expected).isEmpty());
}

From source file:net.sf.firemox.token.CardPropertiesOperation.java

/**
 * Return the result operation result applied on the given properties.
 * //  ww w .j  av  a 2  s.  c  o m
 * @param properties
 *          first properties set.
 * @param properties2
 *          second properties set.
 * @param lower
 *          The minimal property value included used by the operation.
 * @param higher
 *          The maximal property value included used by the operation.
 * @return the result operation result applied on the given properties.
 */
@SuppressWarnings("unchecked")
public int getValue(Set<Integer> properties, Set<Integer> properties2, int lower, int higher) {
    final Collection<Integer> workingSet;
    switch (this) {
    case INTERSECTION_SIZE:
        workingSet = CollectionUtils.intersection(properties, properties2);
        break;
    case UNION_SIZE:
        workingSet = CollectionUtils.union(properties, properties2);
        break;
    case DISJONCTION_SIZE:
        workingSet = CollectionUtils.disjunction(properties, properties2);
        break;
    default:
        Log.fatal("Unhandled CardPropertiesOperation +" + this);
        workingSet = new ArrayList<Integer>();
    }
    int count = workingSet.size();
    for (Integer value : workingSet) {
        if (value < lower || higher > value) {
            count--;
        }
    }
    return count;
}

From source file:com.day.cq.wcm.foundation.forms.FormResourceEdit.java

/**
 * Calculates the set of common values and the set of partially present
 * values for a multi-value property on a list of resources. The
 * {@link #common} values will be the ones that are present in the property
 * in all resources, whereas the {@link #partial} values will be the set of
 * all values that are present at least in one resource, but not all of
 * them. The multi-value property is seen as set, so the order and multiple
 * occurences of the same value in a single property do not make any
 * difference.//  w  ww.  ja  va  2 s  .c  om
 * 
 * @param resources
 *            a list of resources
 * @param name
 *            the name of the multi-value property to inspect
 * @return a struct object with the {@link #common} and {@link #partial}
 *         sets of values
 */
@SuppressWarnings("unchecked")
public static CommonAndPartial getCommonAndPartialMultiValues(List<Resource> resources, String name) {
    CommonAndPartial r = new CommonAndPartial();

    boolean firstResource = true;
    for (Resource resource : resources) {
        ValueMap map = resource.adaptTo(ValueMap.class);
        if (map != null) {
            String[] values = map.get(name, new String[0]);
            if (firstResource) {
                for (String v : values) {
                    r.common.add(v);
                }
                firstResource = false;
            } else {
                List<String> newValues = Arrays.asList(values);
                // partial: add all that are not in common
                r.partial.addAll(CollectionUtils.disjunction(r.common, newValues));
                // common: reset to only what actually overlaps, all the time
                r.common = new HashSet<String>(CollectionUtils.intersection(r.common, newValues));
            }
        }
    }
    return r;
}

From source file:de.hybris.platform.core.RestartSlaveTenantTest.java

@Test
public void testTenantsAfterRestart() {

    final Map<String, Properties> decoratedProperties = new HashMap<String, Properties>();
    final Properties commonProps = new Properties();
    commonProps.setProperty("cluster.id", "0");
    decoratedProperties.put("foo", commonProps);
    decoratedProperties.put("bar", commonProps);

    try {/*w  w  w  .ja v a  2s  .  c  o m*/

        final MasterTenant before = Registry.getMasterTenant();
        final Map<String, SlaveTenant> beforeMap = Registry.getSlaveTenants();

        destroyAndForceStartupCurrentTenant();

        Assert.assertSame(before, Registry.getMasterTenant());
        Assert.assertEquals(beforeMap.size(), Registry.getSlaveTenants().size());

        final Map<String, SlaveTenant> afterMap = Registry.getSlaveTenants();

        Assert.assertTrue(CollectionUtils.disjunction(beforeMap.keySet(), afterMap.keySet()).isEmpty());
        Assert.assertTrue(CollectionUtils.disjunction(afterMap.keySet(), beforeMap.keySet()).isEmpty());
        for (final Map.Entry<String, SlaveTenant> afterMapEntries : afterMap.entrySet()) {
            final SlaveTenant slaveAfter = afterMapEntries.getValue();
            final SlaveTenant slaveBefore = beforeMap.get(afterMapEntries.getKey());

            Assert.assertSame(slaveAfter, slaveBefore);// compare values
        }
    } finally {
        //
    }
}