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:com.github.cereda.sucuri.Sucuri.java

/**
 * Main method./*www. j a  v a 2 s . com*/
 * 
 * @param args The command line arguments.
 */
public static void main(String[] args) {
    try {

        // draw header
        SucuriUtils.drawHeader();

        // provide the command line arguments
        CommandLineAnalyzer cmd = new CommandLineAnalyzer(args);

        // try to parse them
        if (cmd.parse()) {

            // get the template
            LanguageFile template = new LanguageFile();
            template.load(cmd.getTemplate());

            // get the input
            LanguageFile input = new LanguageFile();
            input.load(cmd.getInput(), cmd.getEncoding());

            // set the output
            LanguageFile output = new LanguageFile();

            // get the differences
            List<String> newKeysOnTemplate = (List<String>) CollectionUtils.subtract(template.getKeys(),
                    input.getKeys());
            List<String> oldKeysOnInput = (List<String>) CollectionUtils.subtract(input.getKeys(),
                    template.getKeys());

            // check for report
            if (cmd.hasReport()) {

                // add new info
                Report report = new Report(cmd.getOutput().getName().concat(".txt"));
                report.generate(cmd.getTemplate().getName(), cmd.getInput().getName(),
                        cmd.getOutput().getName(), newKeysOnTemplate, oldKeysOnInput);
            }

            // set header
            String header = "Converted from '" + cmd.getTemplate().getName() + "' and '" + cmd.getInput()
                    + "'\n";
            header = header.concat("by sucuri ").concat(SucuriConstants.VERSION).concat(" on ")
                    .concat(SucuriUtils.getDate());
            output.setHeader(header);

            // sets
            Set<String> keysTemplate = template.getKeys();
            Set<String> keysInput = input.getKeys();

            // iterate
            for (String key : keysTemplate) {

                // if it's a new key
                if (!keysInput.contains(key)) {

                    // set from template
                    output.setProperty(key, template.getProperty(key));
                } else {

                    // set from input
                    output.setProperty(key, input.getProperty(key));
                }
            }

            // save new output
            output.save(cmd.getOutput());

            // print message
            System.out.println("File converted successfully.");

        }
    } catch (SucuriException sucuriException) {

        // an error ocurred, print it
        System.out.println("\n".concat(sucuriException.getMessage()));
    }
}

From source file:com.hiperium.dao.common.list.impl.ListOperationDAOImpl.java

/**
 * {@inheritDoc}/* w ww  . jav a  2s . c om*/
 */
@SuppressWarnings("unchecked")
public void process(@NotNull List<T> actualList, @NotNull List<T> newList, @NotNull String sessionId) {
    Collection<T> toUpdateOriginal = CollectionUtils.intersection(actualList, newList);
    Collection<T> toUpdateNew = CollectionUtils.intersection(newList, actualList);
    Collection<T> delete = CollectionUtils.subtract(actualList, newList);
    for (T entity : delete) {
        this.entityManager.remove(entity);
    }
    Collection<T> insert = CollectionUtils.subtract(newList, actualList);
    for (T entity : insert) {
        this.entityManager.persist(entity);
    }
    T[] updatedOriginalList = (T[]) toUpdateOriginal.toArray();
    T[] updatedNewList = (T[]) toUpdateNew.toArray();
    for (int i = 0; i < updatedOriginalList.length; i++) {
        boolean update = false;
        try {
            Map<String, String> originalProperties = BeanUtils.describe(updatedOriginalList[i]);
            Map<String, String> newProperties = BeanUtils.describe(updatedNewList[i]);
            Set<String> properties = originalProperties.keySet();
            for (String string : properties) {
                if (!(originalProperties.get(string) == null && newProperties.get(string) == null)
                        && !originalProperties.get(string).equals(newProperties.get(string))) {
                    update = true;
                    break;
                }
            }
        } catch (Exception e) {
            update = true;
        }
        if (update) {
            this.entityManager.merge(updatedNewList[i]);
        }
    }
}

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

@Test
public void testLoadCustomExtensionListAddsCoreIfNeeded() {
    final Properties fooProps = new Properties();
    fooProps.put("cluster.id", "0");
    fooProps.put("cronjob.timertask.loadonstartup", "false");
    fooProps.put("allowed.extensions", "deliveryzone;commons;validation;europe1;catalog;");

    final SlaveTenant slaveTenant = new SlaveTenant("foo", fooProps);

    final Collection given = slaveTenant.getTenantSpecificExtensionNames();
    final Collection expected = Arrays.asList("core", "deliveryzone", "commons", "validation", "europe1",
            "catalog");
    Assert.assertTrue(CollectionUtils.subtract(expected, given).isEmpty());
    Assert.assertTrue(CollectionUtils.subtract(given, expected).isEmpty());

}

From source file:net.sourceforge.fenixedu.domain.ExternalApplication.java

public void setScopeList(List<AuthScope> newScopes) {
    Set<AuthScope> oldScopes = getScopesSet();
    if (CollectionUtils.subtract(newScopes, oldScopes).size() > 0) {
        deleteAuthorizations();/*from   w w w  .j a  v  a 2s  . c  o m*/
    }
    oldScopes.clear();
    oldScopes.addAll(newScopes);
}

From source file:net.sourceforge.fenixedu.domain.AuthScope.java

public void changeJerseyEndpoints(Collection<String> endpoints) {
    Collection<String> currentEndpoints = getJerseyEndpoints();
    Collection<String> removedEndpoints = CollectionUtils.subtract(currentEndpoints, endpoints);
    Collection<String> newEndpoints = CollectionUtils.subtract(endpoints, currentEndpoints);
    if (!removedEndpoints.isEmpty() || !newEndpoints.isEmpty()) {
        notifyAllAppsScopeHasChanged();//from  w ww  .  j a  v a 2s  . co  m
    }
    setJerseyEndpoints(endpoints);
}

From source file:net.sourceforge.fenixedu.webServices.jersey.api.FenixJerseyAPIConfig.java

@Atomic
private static void removeUnusedAuthScopes() {
    final Set<AuthScope> authScopes = Bennu.getInstance().getAuthScopesSet();
    ImmutableSet<String> authScopesNames = FluentIterable.from(authScopes)
            .transform(new Function<AuthScope, String>() {

                @Override/*  w  w w.ja va 2 s .c  o m*/
                public String apply(AuthScope scope) {
                    return scope.getName();
                }
            }).toSet();

    Collection<String> unusedScopes = CollectionUtils.subtract(authScopesNames, scopePathsMap.keySet());
    for (String unusedScope : unusedScopes) {
        AuthScope authScope = AuthScope.getAuthScope(unusedScope);
        if (authScope != null) {
            LOGGER.debug("delete unused scope {}", unusedScope);
            authScope.delete();
        }
    }
}

From source file:lab.examples.zookeeper.demo.RouteMutationProcessor.java

@SuppressWarnings({ "unchecked", "deprecation" })
@Override//w  w  w .j  a  v  a 2  s.  co  m
public void process(Exchange exchange) throws Exception {
    ZooKeeperMessage message = (ZooKeeperMessage) exchange.getIn();
    List<String> childNodes = (List<String>) message.getBody();

    ZooKeeper zookeeper = zookeeperConnector.getZooKeeper();
    Stat stat = new Stat();

    if (!routeIdList.isEmpty()) {
        if (childNodes.size() < routeIdList.size()) {
            for (String routeId : (List<String>) CollectionUtils.subtract(routeIdList, childNodes)) {
                //camelContext.stopRoute(routeId,5,TimeUnit.MILLISECONDS,true);
                //camelContext.removeRoute(routeId);
                camelContext.shutdownRoute(routeId, 5, TimeUnit.MILLISECONDS);
                routeIdList.remove(routeId);
            }
        }
    }

    for (String routeId : childNodes) {
        // Add notification received
        if (camelContext.getRoute(routeId) == null) { // Route does not already exist
            String[] destinations = new String(zookeeper.getData("/DEMO/" + routeId, null, stat))
                    .split(DELIMITER);
            camelContext.addRoutes(new MyDynamicRouteBuilder(camelContext, routeId, destinations[0].trim(),
                    destinations[1].trim()));
            routeIdList.add(routeId);
        }
    }
}

From source file:mondrian.rolap.RolapAggregationManager.java

/**
 * Creates a request for the fact-table rows underlying the cell identified
 * by <code>members</code>.//from w ww . j av a 2 s  . c o  m
 *
 * <p>If any of the members is the null member, returns null, since there
 * is no cell. If the measure is calculated, returns null.
 *
 * @param members           Set of members which constrain the cell
 *
 * @param extendedContext   If true, add non-constraining columns to the
 *                          query for levels below each current member.
 *                          This additional context makes the drill-through
 *                          queries easier for humans to understand.
 *
 * @param cube              Cube
 * @return Cell request, or null if the requst is unsatisfiable
 */
public static DrillThroughCellRequest makeDrillThroughRequest(final Member[] members,
        final boolean extendedContext, RolapCube cube, List<OlapElement> returnClauseMembers) {
    assert cube != null;

    List<OlapElement> applicableMembers = getApplicableReturnClauseMembers(cube, members, returnClauseMembers,
            extendedContext);
    List<OlapElement> nonApplicableMembers = new ArrayList<OlapElement>(
            (List<OlapElement>) CollectionUtils.subtract(returnClauseMembers, applicableMembers));

    return (DrillThroughCellRequest) makeCellRequest(members, true, extendedContext, cube, null,
            applicableMembers, nonApplicableMembers);
}

From source file:gov.nih.nci.ncicb.tcga.dcc.qclive.common.action.DroppedBarcodeFinder.java

private Collection<BCRID> filterBarcodes(final Collection<BCRID> currentBarcodeList,
        final Collection<BCRID> previousBarcodeList) {
    // put them into a Set to make sure there are no duplicates
    final Set<BCRID> currentBarcodeSet = new HashSet<BCRID>();
    currentBarcodeSet.addAll(currentBarcodeList);
    final Set<BCRID> previousBarcodeSet = new HashSet<BCRID>();
    previousBarcodeSet.addAll(previousBarcodeList);
    final Collection<BCRID> droppedBarcodes = CollectionUtils.subtract(previousBarcodeSet, currentBarcodeSet);
    if (droppedBarcodes.size() != 0) {
        for (Iterator<BCRID> it = droppedBarcodes.iterator(); it.hasNext();) {
            if (it.next().getViewable() != 1) {
                it.remove();//from www  .j a v  a  2  s . c  om
            }
        }
    }
    return droppedBarcodes;
}

From source file:net.sourceforge.fenixedu.applicationTier.Servico.masterDegree.commons.candidate.WriteCandidateEnrolments.java

protected void run(Set<String> selectedCurricularCoursesIDs, String candidateID, Double credits,
        String givenCreditsRemarks) throws FenixServiceException {

    MasterDegreeCandidate masterDegreeCandidate = FenixFramework.getDomainObject(candidateID);
    if (masterDegreeCandidate == null) {
        throw new NonExistingServiceException();
    }/*from   www  .  j  a v a2s . c  o m*/

    masterDegreeCandidate.setGivenCredits(credits);

    if (credits.floatValue() != 0) {
        masterDegreeCandidate.setGivenCreditsRemarks(givenCreditsRemarks);
    }

    Collection<CandidateEnrolment> candidateEnrolments = masterDegreeCandidate.getCandidateEnrolmentsSet();
    List<String> candidateEnrolmentsCurricularCoursesIDs = (List<String>) CollectionUtils
            .collect(candidateEnrolments, new Transformer() {
                @Override
                public Object transform(Object arg0) {
                    CandidateEnrolment candidateEnrolment = (CandidateEnrolment) arg0;
                    return candidateEnrolment.getCurricularCourse().getExternalId();
                }
            });

    Collection<String> curricularCoursesToEnroll = CollectionUtils.subtract(selectedCurricularCoursesIDs,
            candidateEnrolmentsCurricularCoursesIDs);

    final Collection<Integer> curricularCoursesToDelete = CollectionUtils
            .subtract(candidateEnrolmentsCurricularCoursesIDs, selectedCurricularCoursesIDs);

    Collection<CandidateEnrolment> candidateEnrollmentsToDelete = CollectionUtils.select(candidateEnrolments,
            new Predicate() {
                @Override
                public boolean evaluate(Object arg0) {
                    CandidateEnrolment candidateEnrolment = (CandidateEnrolment) arg0;
                    return (curricularCoursesToDelete
                            .contains(candidateEnrolment.getCurricularCourse().getExternalId()));
                }
            });

    writeFilteredEnrollments(masterDegreeCandidate, curricularCoursesToEnroll);

    for (CandidateEnrolment candidateEnrolmentToDelete : candidateEnrollmentsToDelete) {
        candidateEnrolmentToDelete.delete();
    }
}