Example usage for java.util List removeAll

List of usage examples for java.util List removeAll

Introduction

In this page you can find the example usage for java.util List removeAll.

Prototype

boolean removeAll(Collection<?> c);

Source Link

Document

Removes from this list all of its elements that are contained in the specified collection (optional operation).

Usage

From source file:com.liferay.blade.samples.integration.test.utils.BladeCLIUtil.java

public static String execute(File workingDir, String... bladeArgs) throws Exception {

    String bladeCLIJarPath = getLatestBladeCLIJar();

    List<String> command = new ArrayList<>();

    command.add("java");
    command.add("-jar");
    command.add(bladeCLIJarPath);//from   ww  w  . j av a2  s .  c o m

    for (String arg : bladeArgs) {
        command.add(arg);
    }

    Process process = new ProcessBuilder(command.toArray(new String[0])).directory(workingDir).start();

    process.waitFor();

    InputStream stream = process.getInputStream();

    String output = new String(IO.read(stream));

    InputStream errorStream = process.getErrorStream();

    List<String> errorList = new ArrayList<>();

    String stringStream = null;

    if (errorStream != null) {
        stringStream = new String(IO.read(errorStream));

        errorList.add(stringStream);
    }

    List<String> filteredErrorList = new ArrayList<>();

    for (String string : errorList) {
        String exclusion = "(.*setlocale.*)";

        Pattern p = Pattern.compile(exclusion, Pattern.DOTALL);

        Matcher m = p.matcher(string);

        while (m.find()) {
            filteredErrorList.add(string);
        }

        if (string.contains("Picked up JAVA_TOOL_OPTIONS:")) {
            filteredErrorList.add(string);
        }
    }

    errorList.removeAll(filteredErrorList);

    Assert.assertTrue(errorList.toString(), errorList.size() <= 1);

    if (errorList.size() == 1) {
        Assert.assertTrue(errorList.get(0), errorList.get(0).isEmpty());
    }

    return output;
}

From source file:net.sourceforge.fenixedu.domain.accounting.report.events.EventReportQueueJob.java

public static List<EventReportQueueJob> retrievePendingOrCancelledGeneratedReports() {
    List<EventReportQueueJob> all = retrieveAllGeneratedReports();
    List<EventReportQueueJob> done = retrieveDoneGeneratedReports();

    all.removeAll(done);

    return all;/*from w  w w  . jav  a2 s .  c o m*/
}

From source file:org.opentides.util.CrudUtil.java

/**
 * Creates the logging message for update audit logs 
 * @param obj/*from   w w  w .  ja v  a  2 s.com*/
 * @return
 */
@SuppressWarnings({ "rawtypes", "unchecked" })
public static String buildUpdateMessage(BaseEntity oldObject, BaseEntity newObject) {

    StringBuilder message = new StringBuilder("<p class='change-message'>Changed ");
    AuditableField pf = CacheUtil.getPrimaryField(oldObject);
    message.append(buildPrimaryField(pf, oldObject)).append(" with the following: ");
    // loop through the fields list
    List<AuditableField> auditableFields = CacheUtil.getAuditable(oldObject);
    int count = 0;

    // scenarios
    // 1 - collection vs null -> Enter collection
    // 2 - collection vs collection -> Enter collection
    // 3 - object vs null -> Enter object
    // 4 - object vs object -> Enter object
    // 5 - collection vs object -> Invalid or convert collection to object. 

    for (AuditableField property : auditableFields) {
        _log.debug("Building update message for field " + property.getFieldName());
        Object oldValue = retrieveNullableObjectValue(oldObject, property.getFieldName());
        Object newValue = retrieveNullableObjectValue(newObject, property.getFieldName());
        oldValue = normalizeValue(oldValue);
        newValue = normalizeValue(newValue);

        if (oldValue.getClass() != newValue.getClass()) {
            _log.debug("Old object: " + oldValue);
            _log.warn("Unable to compare [" + property.getFieldName()
                    + "] for audit logging due to difference in datatype. " + "oldValue is ["
                    + oldValue.getClass() + "] and newValue is [" + newValue.getClass() + "]");
            continue;
        }

        if (Collection.class.isAssignableFrom(oldValue.getClass())
                && Collection.class.isAssignableFrom(newValue.getClass())) {
            if (((Collection) oldValue).isEmpty() && ((Collection) newValue).isEmpty()) {
                _log.debug("Old and New values are empty");
                continue;
            }
            _log.debug("Old and New values are not empty");
            List addedList = new ArrayList((Collection) newValue);
            //Collection addedCollection = (Collection)newValue;
            //addedCollection.removeAll((Collection)oldValue);
            //addedList.addAll(new ArrayList((Collection)newValue));
            addedList.removeAll(new ArrayList((Collection) oldValue));

            List removedList = new ArrayList((Collection) oldValue);
            //removedList.addAll((List) oldValue);
            removedList.removeAll(new ArrayList((Collection) newValue));
            //Collection removedCollection = (Collection)oldValue;
            //removedCollection.remove((Collection)newValue);
            if (!addedList.isEmpty() || !removedList.isEmpty()) {
                if (count > 0)
                    message.append("and ");
            }
            if (!addedList.isEmpty()) {
                message.append("added ").append(property.getTitle())
                        .append(" <span class='field-values-added'>").append(addedList).append("</span> ");
            }
            if (!removedList.isEmpty()) {
                if (!addedList.isEmpty())
                    message.append("and ");
                message.append("removed ").append(property.getTitle())
                        .append(" <span class='field-values-removed'>").append(removedList).append("</span> ");
                count++;
            }
        } else {
            if (!oldValue.equals(newValue)) {
                if (count > 0)
                    message.append("and ");
                if (StringUtil.isEmpty(newValue.toString())) {
                    message.append(property.getTitle()).append(" <span class='field-value-removed'>")
                            .append(oldValue.toString()).append("</span> is removed ");
                } else {
                    message.append(property.getTitle());
                    if (!StringUtil.isEmpty(oldValue.toString()))
                        message.append(" from <span class='field-value-from'>").append(oldValue.toString())
                                .append("</span> ");
                    else
                        message.append(" is set ");
                    message.append("to <span class='field-value-to'>").append(newValue.toString())
                            .append("</span> ");
                }
                count++;
            }
        }
    }
    message.append("</p>");
    if (count == 0)
        return "";
    else
        return message.toString();
}

From source file:immf.SendMailBridge.java

private static List<InternetAddress> getBccRecipients(List<String> allRecipients, List<InternetAddress> to,
        List<InternetAddress> cc) throws AddressException {
    List<String> addrList = new ArrayList<String>();
    List<String> toccAddrList = new ArrayList<String>();
    for (String addr : allRecipients) {
        addrList.add(addr);/*w w  w  .j a  v  a 2  s  .  c  o m*/
    }
    for (InternetAddress ia : to) {
        toccAddrList.add(ia.getAddress());
    }
    for (InternetAddress ia : cc) {
        toccAddrList.add(ia.getAddress());
    }
    addrList.removeAll(toccAddrList);
    List<InternetAddress> r = new ArrayList<InternetAddress>();
    for (String addr : addrList) {
        r.add(new InternetAddress(addr));
    }
    return r;
}

From source file:forge.game.staticability.StaticAbilityContinuous.java

private static List<Player> getAffectedPlayers(final StaticAbility stAb) {
    final Map<String, String> params = stAb.getMapParams();
    final Card hostCard = stAb.getHostCard();
    final Player controller = hostCard.getController();

    final List<Player> players = new ArrayList<Player>();

    if (!params.containsKey("Affected")) {
        return players;
    }/*  w  w w  . j a v a  2  s.  co m*/

    final String[] strngs = params.get("Affected").split(",");

    for (Player p : controller.getGame().getPlayersInTurnOrder()) {
        if (p.isValid(strngs, controller, hostCard)) {
            players.add(p);
        }
    }
    players.removeAll(stAb.getIgnoreEffectPlayers());

    return players;
}

From source file:net.sf.jabref.model.entry.CustomEntryType.java

@Override
public List<String> getSecondaryOptionalFields() {
    List<String> result = new ArrayList<>(optional);
    result.removeAll(primaryOptional);
    return Collections.unmodifiableList(result);
}

From source file:com.romeikat.datamessie.core.base.util.fullText.FullTextMatch.java

public void addNewMatchingTerms(final List<String> matchingTerms) {
    final List<String> newMatchingTerms = new ArrayList<String>(matchingTerms);
    newMatchingTerms.removeAll(this.matchingTerms);
    this.matchingTerms.addAll(newMatchingTerms);
}

From source file:com.kibana.multitenancy.plugin.kibana.KibanaSeed.java

public static void setDashboards(String user, Set<String> projects, Set<String> roles, Client esClient,
        String kibanaIndex, String kibanaVersion) {

    //GET .../.kibana/index-pattern/_search?pretty=true&fields=
    //  compare results to projects; handle any deltas (create, delete?)
    //check projects for default and remove
    for (String project : BLACKLIST_PROJECTS)
        if (projects.contains(project)) {
            logger.debug("Black-listed project '{}' found.  Not adding as an index pattern", project);
            projects.remove(project);/*from ww w.  j  av  a  2  s . co  m*/
        }

    Set<String> indexPatterns = getIndexPatterns(user, esClient, kibanaIndex);
    logger.debug("Found '{}' Index patterns for user", indexPatterns.size());

    // Check roles here, if user is a cluster-admin we should add .operations to their project? -- correct way to do this?
    logger.debug("Checking for '{}' in users roles '{}'", OPERATIONS_ROLES, roles);
    /*for ( String role : OPERATIONS_ROLES )
       if ( roles.contains(role) ) {
    logger.debug("{} is an admin user", user);
    projects.add(OPERATIONS_PROJECT);
    break;
       }*/

    List<String> sortedProjects = new ArrayList<String>(projects);
    Collections.sort(sortedProjects);

    if (sortedProjects.isEmpty())
        sortedProjects.add(BLANK_PROJECT);

    logger.debug("Setting dashboards given user '{}' and projects '{}'", user, projects);

    // If none have been set yet
    if (indexPatterns.isEmpty()) {
        create(user, sortedProjects, true, esClient, kibanaIndex, kibanaVersion);
        //TODO : Currently it is generating wrong search properties when integrated with ES 2.1
        //createSearchProperties(user, esClient, kibanaIndex);
    } else {
        List<String> common = new ArrayList<String>(indexPatterns);

        // Get a list of all projects that are common
        common.retainAll(sortedProjects);

        sortedProjects.removeAll(common);
        indexPatterns.removeAll(common);

        // for any to create (remaining in projects) call createIndices, createSearchmapping?, create dashboard
        create(user, sortedProjects, false, esClient, kibanaIndex, kibanaVersion);

        // cull any that are in ES but not in OS (remaining in indexPatterns)
        remove(user, indexPatterns, esClient, kibanaIndex);

        common.addAll(sortedProjects);
        Collections.sort(common);
        // Set default index to first index in common if we removed the default
        String defaultIndex = getDefaultIndex(user, esClient, kibanaIndex, kibanaVersion);

        logger.debug("Checking if '{}' contains '{}'", indexPatterns, defaultIndex);

        if (indexPatterns.contains(defaultIndex) || StringUtils.isEmpty(defaultIndex)) {
            logger.debug("'{}' does contain '{}' and common size is {}", indexPatterns, defaultIndex,
                    common.size());
            if (common.size() > 0)
                setDefaultIndex(user, common.get(0), esClient, kibanaIndex, kibanaVersion);
        }

    }
}

From source file:com.gemalto.split.additionalservices.ViveService_RemoveRecordsFromCsvFile.java

public void removeExceptionRecords() {
    Set<HeaderKey> headers = recordsMap.keySet();
    for (HeaderKey headerKey : headers) { //lets remove the exceptions records
        logger.info("Removing records from header:" + headerKey.getHeaderKey());
        List<Record> recordsByHeader = recordsMap.get(headerKey);
        boolean wasRemoved = recordsByHeader.removeAll(exceptionRecords);
        logger.info("Records were removed? " + wasRemoved + " Quantity now:" + recordsByHeader.size());
        headerKey.setQuantity(recordsByHeader.size());
    }/*from w ww.  ja  v a 2 s  . c o  m*/

}

From source file:com.boxedfolder.carrot.service.impl.EventServiceImpl.java

@Override
public Event save(Event object) {
    Event oldObject = null;/*w w w.java  2  s  .c om*/
    if (object.getId() != null) {
        oldObject = repository.findOne(object.getId());
    }

    if (oldObject != null) {
        // Check if there are event-app relationship changes
        List<App> difference = new ArrayList<>(oldObject.getApps());
        difference.removeAll(object.getApps());

        for (App app : difference) {
            RemovedRelationshipLog log = logRepository.findOne(oldObject.getId(), app.getId());
            if (log == null) {
                log = new RemovedRelationshipLog();
                log.setAppId(app.getId());
                log.setEventId(oldObject.getId());
            }
            log.setDateTime(new DateTime());
            logRepository.save(log);
        }

        // Remove all obsolete logs
        difference = new ArrayList<>(object.getApps());
        difference.removeAll(oldObject.getApps());

        for (App app : difference) {
            RemovedRelationshipLog log = logRepository.findOne(object.getId(), app.getId());
            if (log != null) {
                logRepository.delete(log);
            }
        }
    }

    return super.save(object);
}