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

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

Introduction

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

Prototype

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

Source Link

Document

Returns a new Collection containing a - b.

Usage

From source file:org.drools.planner.examples.machinereassignment.solver.score.MachineReassignmentIncrementalScoreCalculator.java

@Override
public String buildScoreCorruptionAnalysis(IncrementalScoreCalculator uncorruptedIncrementalScoreCalculator) {
    MachineReassignmentIncrementalScoreCalculator other = (MachineReassignmentIncrementalScoreCalculator) uncorruptedIncrementalScoreCalculator;
    StringBuilder analysis = new StringBuilder();
    if (!serviceScorePartMap.keySet().equals(other.serviceScorePartMap.keySet())) {
        Collection excess = CollectionUtils.subtract(serviceScorePartMap.keySet(),
                other.serviceScorePartMap.keySet());
        Collection lacking = CollectionUtils.subtract(other.serviceScorePartMap.keySet(),
                serviceScorePartMap.keySet());
        analysis.append("  The serviceScorePartMap has in excess (").append(excess).append(") and is lacking (")
                .append(lacking).append(").\n");
    } else {//from  w  ww  . j a v a 2s  . co m
        for (Map.Entry<MrService, MrServiceScorePart> entry : serviceScorePartMap.entrySet()) {
            MrService service = entry.getKey();
            MrServiceScorePart part = entry.getValue();
            MrServiceScorePart otherPart = other.serviceScorePartMap.get(service);
            if (!part.locationBag.equals(otherPart.locationBag)) {
                Collection excess = CollectionUtils.subtract(part.locationBag.values(),
                        otherPart.locationBag.values());
                Collection lacking = CollectionUtils.subtract(otherPart.locationBag.values(),
                        part.locationBag.values());
                analysis.append("  On service (").append(service).append(") the locationBag has in excess (")
                        .append(excess).append(") and is lacking (").append(lacking).append(").\n");
            }
            if (!part.neighborhoodBag.equals(otherPart.neighborhoodBag)) {
                Collection excess = CollectionUtils.subtract(part.neighborhoodBag.values(),
                        otherPart.neighborhoodBag.values());
                Collection lacking = CollectionUtils.subtract(otherPart.neighborhoodBag.values(),
                        part.neighborhoodBag.values());
                analysis.append("  On service (").append(service)
                        .append(") the neighborhoodBag has in excess (").append(excess)
                        .append(") and is lacking (").append(lacking).append(").\n");
            }
            if (part.movedProcessCount != otherPart.movedProcessCount) {
                analysis.append("  On service (").append(service).append(") the movedProcessCount (")
                        .append(part.movedProcessCount).append(") is not correct (")
                        .append(otherPart.movedProcessCount).append(").\n");
            }
        }
    }
    // TODO implement analysis for other parts too

    return analysis.toString();
}

From source file:org.dspace.discovery.configuration.DiscoveryConfiguration.java

/**
 * After all the properties are set check that the sidebar facets are a subset of our search filters
 *
 * @throws Exception throws an exception if this isn't the case
 *///www  .  j  av a 2  s . c  o m
@Override
public void afterPropertiesSet() throws Exception {
    Collection missingSearchFilters = CollectionUtils.subtract(getSidebarFacets(), getSearchFilters());
    if (CollectionUtils.isNotEmpty(missingSearchFilters)) {
        StringBuilder error = new StringBuilder();
        error.append("The following sidebar facet configurations are not present in the search filters list: ");
        for (Object missingSearchFilter : missingSearchFilters) {
            DiscoverySearchFilter searchFilter = (DiscoverySearchFilter) missingSearchFilter;
            error.append(searchFilter.getIndexFieldName()).append(" ");

        }
        error.append("all the sidebar facets MUST be a part of the search filters list.");

        throw new DiscoveryConfigurationException(error.toString());
    }

}

From source file:org.eclipse.wb.internal.core.gef.policy.snapping.PlacementsSupport.java

/**
 * @return the list of the components which should not be affected by operation.
 *//*from ww  w  . jav  a 2s.c  om*/
@SuppressWarnings("unchecked")
private List<IAbstractComponentInfo> getRemainingWidgets() {
    return (List<IAbstractComponentInfo>) CollectionUtils.subtract(m_allWidgets, m_operatingWidgets);
}

From source file:org.ensembl.healthcheck.testcase.generic.ProductionMeta.java

/**
 * Run the test.//from www.  j  a  v a2  s.  c o  m
 * 
 * @param dbre
 *          The database to use.
 * @return true if the test passed.
 * 
 */
@SuppressWarnings("unchecked")
public boolean run(DatabaseRegistryEntry dbre) {

    boolean result = true;

    Connection con = dbre.getConnection();
    DatabaseRegistryEntry prodDbre = getProductionDatabase();

    // we'll use a different query depending on the database type; also some keys are only for certain species
    String databaseType = dbre.getType().getName(); // will be core, otherfeatures etc
    String species = dbre.getSpecies().toString(); // will be homo_sapiens etc

    List<String> dbMetaKeys = DBUtils.getColumnValuesList(con, "SELECT DISTINCT(meta_key) FROM meta");

    // First check that keys present in database are all valid and current
    List<String> productionMetaKeys = DBUtils.getColumnValuesList(prodDbre.getConnection(),
            "SELECT mk.name " + "FROM meta_key mk LEFT JOIN (" + "meta_key_species JOIN "
                    + "species s USING (species_id) ) USING (meta_key_id) " + "WHERE FIND_IN_SET('"
                    + databaseType + "', mk.db_type) > 0 AND " + "(s.db_name = '" + species
                    + "' OR s.db_name IS NULL) AND " + "mk.is_current = 1");

    // remove the list of valid keys from the list of keys in the database, the remainder (if any) are invalid
    Collection<String> dbOnly = (Collection<String>) CollectionUtils.subtract(dbMetaKeys, productionMetaKeys);

    if (!dbOnly.isEmpty()) {
        for (String key : dbOnly) {
            String msg = String.format("Meta key '%s' is not in the allowed meta key list from production",
                    key);
            ReportManager.problem(this, con, msg);
        }
        result = false;

    } else {

        ReportManager.correct(this, con,
                "Set of meta keys matches the current valid list in the production database.");

    }

    // now check that all non-optional keys in production database appear here
    dbMetaKeys = DBUtils.getColumnValuesList(con, "SELECT DISTINCT(meta_key) FROM meta");

    productionMetaKeys = DBUtils.getColumnValuesList(prodDbre.getConnection(),
            "SELECT mk.name " + "FROM meta_key mk LEFT JOIN (" + "meta_key_species JOIN "
                    + "species s USING (species_id) ) USING (meta_key_id) " + "WHERE FIND_IN_SET('"
                    + databaseType + "', mk.db_type) > 0 AND " + "(s.db_name = '" + species
                    + "' OR s.db_name IS NULL) AND " + "mk.is_current = 1 AND " + "mk.is_optional = 0");

    // remove the keys in the database from the non-optional list, any remaining in the non-optional list are missing from the
    // database
    Collection<String> productionOnly = (Collection<String>) CollectionUtils.subtract(productionMetaKeys,
            dbMetaKeys);

    if (!productionOnly.isEmpty()) {
        for (String key : productionOnly) {
            String msg = String.format("Missing required meta key: %s", key);
            ReportManager.problem(this, con, msg);
        }
        result = false;

    } else {

        ReportManager.correct(this, con, "All current required meta keys are present.");

    }
    return result;

}

From source file:org.ensembl.healthcheck.testcase.generic.ProductionSpeciesAlias.java

private <T extends CharSequence> boolean checkHasAlias(DatabaseRegistryEntry dbre, Collection<T> core,
        Collection<T> toRemove, String type) {
    Collection<String> dbOnly = (Collection<String>) CollectionUtils.subtract(core, toRemove);
    if (dbOnly.isEmpty()) {
        return true;
    } else {/*  w w w. j  ava  2s. co m*/
        for (String key : dbOnly) {
            String msg = String.format("Species alias '%s' is not in the %s database", key, type);
            ReportManager.problem(this, dbre.getConnection(), msg);
        }
        return false;
    }
}

From source file:org.fenixedu.ulisboa.specifications.domain.student.access.importation.DgesStudentImportationProcess.java

public static List<DgesStudentImportationProcess> readUndoneJobs(ExecutionYear executionYear) {
    return new ArrayList(CollectionUtils.subtract(readAllJobs(executionYear), readDoneJobs(executionYear)));
}

From source file:org.gradle.integtests.fixtures.executer.OutputScrapingExecutionResult.java

private Collection<String> getNotSkippedTasks() {
    List all = getExecutedTasks();
    Set skipped = getSkippedTasks();
    return CollectionUtils.subtract(all, skipped);
}

From source file:org.intermine.bio.dataconversion.ProteinAtlasConverter.java

private void processTissueToOrgan(Reader reader) throws ObjectStoreException, IOException {
    // file has two colums:
    // Tissue name <\t> Tissue group

    Iterator<?> lineIter = FormattedTextParser.parseTabDelimitedReader(reader);

    Map<String, Item> tissueGroups = new HashMap<String, Item>();

    // Read all lines into gene records
    while (lineIter.hasNext()) {
        String[] line = (String[]) lineIter.next();
        String tissueName = line[0];
        String tissueGroupName = line[1];

        Item tissue = getTissue(tissueName);
        Item tissueGroup = tissueGroups.get(tissueGroupName);
        if (tissueGroup == null) {
            tissueGroup = createItem("TissueGroup");
            tissueGroup.setAttribute("name", tissueGroupName);
            store(tissueGroup);//from  w w w  .  j a v  a 2 s  .c om
            tissueGroups.put(tissueGroupName, tissueGroup);
        }
        tissue.setAttribute("name", tissueName);
        tissue.setReference("tissueGroup", tissueGroup);
        store(tissue);
        storedTissues.add(tissueName);
    }

    // Tissue data is homebrew, it has been out of data after protein-atlas v10, a hacky
    // way for the new tissue types
    @SuppressWarnings("unchecked")
    Collection<String> unstoredTissues = CollectionUtils.subtract(tissues.keySet(), storedTissues);
    for (String tissueName : unstoredTissues) {
        Item tissue = getTissue(tissueName);
        tissue.setAttribute("name", tissueName);
        store(tissue);
    }
}

From source file:org.kuali.kfs.sys.batch.service.impl.FiscalYearMakerServiceImpl.java

/**
 * Returns List of <code>FiscalYearMaker</code> objects in the order they should be copied. Ordered by Parent classes first then
 * children. This is necessary to ensure referential integrity is satisfied when the new record is inserted.
 * //from w  w w .ja va2  s.  co m
 * @return List<FiscalYearMaker> in copy order
 */
protected List<FiscalYearMaker> getFiscalYearMakerHelpersInCopyOrder() {
    List<Class<? extends FiscalYearBasedBusinessObject>> classCopyOrder = new ArrayList<Class<? extends FiscalYearBasedBusinessObject>>();

    // build map of parents and their children
    Map<Class<? extends FiscalYearBasedBusinessObject>, Set<Class<? extends FiscalYearBasedBusinessObject>>> parentChildren = getParentChildrenMap();

    // figure out correct order among parents by picking off levels of hierarchy
    while (!parentChildren.isEmpty()) {
        Set<Class<? extends FiscalYearBasedBusinessObject>> parents = parentChildren.keySet();
        Set<Class<? extends FiscalYearBasedBusinessObject>> children = getChildren(parentChildren);

        Set<Class<? extends FiscalYearBasedBusinessObject>> rootParents = new HashSet<Class<? extends FiscalYearBasedBusinessObject>>(
                CollectionUtils.subtract(parents, children));

        // if there are no root parents, then we must have a circular reference
        if (rootParents.isEmpty()) {
            findCircularReferenceAndThrowException(parentChildren);
        }

        for (Class<? extends FiscalYearBasedBusinessObject> rootParent : rootParents) {
            classCopyOrder.add(rootParent);
            parentChildren.remove(rootParent);
        }
    }

    // now add remaining objects (those that are not parents)
    for (FiscalYearMaker fiscalYearMakerHelper : this.fiscalYearMakers) {
        if (!classCopyOrder.contains(fiscalYearMakerHelper.getBusinessObjectClass())) {
            classCopyOrder.add(fiscalYearMakerHelper.getBusinessObjectClass());
        }
    }

    // finally build list of FiscalYearMaker objects by the correct class order
    List<FiscalYearMaker> fiscalYearMakerHelpersCopyOrder = new ArrayList<FiscalYearMaker>();

    Map<Class<? extends FiscalYearBasedBusinessObject>, FiscalYearMaker> copyMap = getFiscalYearMakerMap();
    for (Class<? extends FiscalYearBasedBusinessObject> copyClass : classCopyOrder) {
        fiscalYearMakerHelpersCopyOrder.add(copyMap.get(copyClass));
    }

    return fiscalYearMakerHelpersCopyOrder;
}

From source file:org.kuali.kfs.sys.batch.service.impl.FiscalYearMakerServiceImpl.java

/**
 * Validates each configured fiscal year maker implementation
 *///from  w  w w . j  ava2  s.  co m
protected void validateFiscalYearMakerConfiguration() {
    Set<Class<? extends FiscalYearBasedBusinessObject>> businessObjectClasses = new HashSet<Class<? extends FiscalYearBasedBusinessObject>>();

    for (FiscalYearMaker fiscalYearMaker : fiscalYearMakers) {
        Class<? extends FiscalYearBasedBusinessObject> businessObjectClass = fiscalYearMaker
                .getBusinessObjectClass();
        if (businessObjectClass == null) {
            String error = "Business object class is null for fiscal year maker";
            LOG.error(error);
            throw new RuntimeException(error);
        }

        if (!FiscalYearBasedBusinessObject.class.isAssignableFrom(businessObjectClass)) {
            String error = String.format("Business object class %s does not implement %s",
                    businessObjectClass.getName(), FiscalYearBasedBusinessObject.class.getName());
            LOG.error(error);
            throw new RuntimeException(error);
        }

        if (businessObjectClasses.contains(businessObjectClass)) {
            String error = String.format(
                    "Business object class %s has two fiscal year maker implementations defined",
                    businessObjectClass.getName());
            LOG.error(error);
            throw new RuntimeException(error);
        }

        businessObjectClasses.add(businessObjectClass);
    }

    // validate parents are in copy list
    Set<Class<? extends PersistableBusinessObject>> parentsNotInCopyList = new HashSet<Class<? extends PersistableBusinessObject>>();
    for (FiscalYearMaker fiscalYearMaker : fiscalYearMakers) {
        parentsNotInCopyList
                .addAll(CollectionUtils.subtract(fiscalYearMaker.getParentClasses(), businessObjectClasses));
    }

    if (!parentsNotInCopyList.isEmpty()) {
        String error = "Parent classes not in copy list: " + StringUtils.join(parentsNotInCopyList, ",");
        LOG.error(error);
        throw new RuntimeException(error);
    }
}