Example usage for java.util ArrayList removeAll

List of usage examples for java.util ArrayList removeAll

Introduction

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

Prototype

public boolean removeAll(Collection<?> c) 

Source Link

Document

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

Usage

From source file:Debug.java

public static boolean compare(String prefix, Map a, Map b, ArrayList ignore, StringBuffer buffer) {
    if ((a == null) && (b == null)) {
        log(buffer, prefix + " both maps null");
        return true;
    }//from   w w  w .j a  v a 2  s  .co m
    if (a == null) {
        log(buffer, prefix + " map a: null, map b: map");
        return false;
    }
    if (b == null) {
        log(buffer, prefix + " map a: map, map b: null");
        return false;
    }

    ArrayList keys_a = new ArrayList(a.keySet());
    ArrayList keys_b = new ArrayList(b.keySet());

    if (ignore != null) {
        keys_a.removeAll(ignore);
        keys_b.removeAll(ignore);
    }

    boolean result = true;

    for (int i = 0; i < keys_a.size(); i++) {
        Object key = keys_a.get(i);
        if (!keys_b.contains(key)) {
            log(buffer, prefix + "b is missing key '" + key + "' from a");
            result = false;
        } else {
            keys_b.remove(key);
            Object value_a = a.get(key);
            Object value_b = b.get(key);
            if (!value_a.equals(value_b)) {
                log(buffer, prefix + "key(" + key + ") value a: " + value_a + ") !=  b: " + value_b + ")");
                result = false;
            }
        }
    }
    for (int i = 0; i < keys_b.size(); i++) {
        Object key = keys_b.get(i);

        log(buffer, prefix + "a is missing key '" + key + "' from b");
        result = false;
    }

    if (result)
        log(buffer, prefix + "a is the same as  b");

    return result;
}

From source file:org.tros.utils.Random.java

/**
 * Gets a random item from a collection that is NOT equal to the specified
 * collection//from  w w w . ja v  a 2 s . c  o  m
 *
 * @param <T> the type
 * @param list the collection to select from
 * @param not the collection from which we do not want a duplicate selection
 * of
 * @return a new randomly selected object which is not equal to the
 * specified value
 */
public static <T> T getRandomNotInList(final Collection<T> list, final Collection<T> not) {
    if (LEGACY) {
        ArrayList<T> l = new ArrayList<>(list);
        l.removeAll(not);
        return getRandom(l);
    } else {
        return getRandom(org.apache.commons.collections4.CollectionUtils.subtract(list, not));
    }
}

From source file:org.tros.utils.Random.java

/**
 * Gets a random item from a collection that is NOT equal to the specified
 * collection/*ww  w  .j a v  a 2  s .c  o m*/
 *
 * @param <T> the type
 * @param random
 * @param list the collection to select from
 * @param not the collection from which we do not want a duplicate selection
 * of
 * @return a new randomly selected object which is not equal to the
 * specified value
 */
public static <T> T getRandomNotInList(java.util.Random random, final Collection<T> list,
        final Collection<T> not) {
    if (LEGACY) {
        ArrayList<T> l = new ArrayList<>(list);
        l.removeAll(not);
        return getRandom(random, l);
    } else {
        return getRandom(random, org.apache.commons.collections4.CollectionUtils.subtract(list, not));
    }
}

From source file:com.parse.ParseRemoveOperation.java

@Override
public Object apply(Object oldValue, String key) {
    if (oldValue == null) {
        return new ArrayList<>();
    } else if (oldValue instanceof JSONArray) {
        ArrayList<Object> old = ParseFieldOperations.jsonArrayAsArrayList((JSONArray) oldValue);
        @SuppressWarnings("unchecked")
        ArrayList<Object> newValue = (ArrayList<Object>) this.apply(old, key);
        return new JSONArray(newValue);
    } else if (oldValue instanceof List) {
        ArrayList<Object> result = new ArrayList<>((List<?>) oldValue);
        result.removeAll(objects);

        // Remove the removed objects from "objects" -- the items remaining
        // should be ones that weren't removed by object equality.
        ArrayList<Object> objectsToBeRemoved = new ArrayList<>(objects);
        objectsToBeRemoved.removeAll(result);

        // Build up set of object IDs for any ParseObjects in the remaining objects-to-be-removed
        HashSet<String> objectIds = new HashSet<>();
        for (Object obj : objectsToBeRemoved) {
            if (obj instanceof ParseObject) {
                objectIds.add(((ParseObject) obj).getObjectId());
            }/*from w w  w. j  a  v  a2  s  .  c  o  m*/
        }

        // And iterate over "result" to see if any other ParseObjects need to be removed
        Iterator<Object> resultIterator = result.iterator();
        while (resultIterator.hasNext()) {
            Object obj = resultIterator.next();
            if (obj instanceof ParseObject && objectIds.contains(((ParseObject) obj).getObjectId())) {
                resultIterator.remove();
            }
        }
        return result;
    } else {
        throw new IllegalArgumentException("Operation is invalid after previous operation.");
    }
}

From source file:stack49410929.SubtractCollection.java

@Test
public void subtract3() {
    ArrayList<Integer> a = new ArrayList<Integer>();
    a.addAll(Arrays.asList(1, 2, 2, 3, 3));
    List<Integer> b = Arrays.asList(1, 2, 4, 6, 5);
    a.removeAll(b);
    System.out.println(a);//from   w  w  w.j  av  a 2  s .c  o m
}

From source file:org.apache.hadoop.hbase.regionserver.DefaultStoreFileManager.java

@Override
public void addCompactionResults(Collection<StoreFile> compactedFiles, Collection<StoreFile> results) {
    ArrayList<StoreFile> newStoreFiles = Lists.newArrayList(storefiles);
    newStoreFiles.removeAll(compactedFiles);
    if (!results.isEmpty()) {
        newStoreFiles.addAll(results);/*ww  w  .  j  a v a  2 s .  c  om*/
    }
    sortAndSetStoreFiles(newStoreFiles);
}

From source file:com.moki.touch.util.management.ContentManager.java

/**
 * remove content from the content store that do not exist in the settings
 */// w  ww . j  av  a 2s.c om
public void deleteInvalidCache() {
    ArrayList<String> contentList = getAllContentUrls();
    if (contentList.removeAll(getAllSettingsUrls())) {
        for (int i = 0; i < contentList.size(); i++) {
            deleteContentFile(contentList.get(i));
        }
    }
}

From source file:eu.itesla_project.online.tools.ListForecastErrorsAnalysisTool.java

@Override
public void run(CommandLine line) throws Exception {
    ForecastErrorsAnalysisConfig config = ForecastErrorsAnalysisConfig.load();
    ForecastErrorsDataStorage feDataStorage = config.getForecastErrorsDataStorageFactoryClass().newInstance()
            .create();//w  w w  . j a  va2 s  .  c  o m
    List<ForecastErrorsAnalysisDetails> analysisList = feDataStorage.listAnalysis();
    DateTimeFormatter formatter = DateTimeFormat.forPattern("yyyy-MM-dd HH:mm:ss");
    Table table = new Table(5, BorderStyle.CLASSIC_WIDE);
    table.addCell("ID", new CellStyle(CellStyle.HorizontalAlign.center));
    table.addCell("Date", new CellStyle(CellStyle.HorizontalAlign.center));
    table.addCell("Errors Models", new CellStyle(CellStyle.HorizontalAlign.center));
    table.addCell("Statistics", new CellStyle(CellStyle.HorizontalAlign.center));
    table.addCell("Parameters", new CellStyle(CellStyle.HorizontalAlign.center));
    for (ForecastErrorsAnalysisDetails analysis : analysisList) {
        ArrayList<TimeHorizon> mergedList = new ArrayList<TimeHorizon>(analysis.getForecastErrorsDataList());
        mergedList.removeAll(analysis.getForecastErrorsStatisticsList());
        mergedList.addAll(analysis.getForecastErrorsStatisticsList());
        for (TimeHorizon timeHorizon : mergedList) {
            table.addCell(analysis.getAnalysisId());
            table.addCell(formatter.print(analysis.getAnalysisDate()));
            if (analysis.getForecastErrorsDataList().contains(timeHorizon))
                table.addCell(timeHorizon.getName());
            else
                table.addCell("-");
            if (analysis.getForecastErrorsStatisticsList().contains(timeHorizon))
                table.addCell(timeHorizon.getName());
            else
                table.addCell("-");
            ForecastErrorsAnalyzerParameters parameters = feDataStorage.getParameters(analysis.getAnalysisId(),
                    timeHorizon);
            if (parameters != null) {
                //table.addCell(parameters.toString().substring(32));
                String value = parameters.toString().substring(32);
                while (value.length() > COLUMN_LENGTH) {
                    table.addCell(value.substring(0, COLUMN_LENGTH),
                            new CellStyle(CellStyle.HorizontalAlign.left));
                    table.addCell(" ", new CellStyle(CellStyle.HorizontalAlign.left));
                    table.addCell(" ", new CellStyle(CellStyle.HorizontalAlign.left));
                    table.addCell(" ", new CellStyle(CellStyle.HorizontalAlign.left));
                    table.addCell(" ", new CellStyle(CellStyle.HorizontalAlign.left));
                    value = value.substring(COLUMN_LENGTH);
                }
                table.addCell(value, new CellStyle(CellStyle.HorizontalAlign.left));
            } else
                table.addCell("-");
        }
    }
    System.out.println(table.render());
}

From source file:org.apache.hadoop.hbase.regionserver.compactions.SortedCompactionPolicy.java

/**
 * @param candidates pre-filtrate/*from  w w  w .ja v  a 2 s  . c  om*/
 * @return filtered subset exclude all bulk load files if configured
 */
protected ArrayList<StoreFile> filterBulk(ArrayList<StoreFile> candidates) {
    candidates.removeAll(Collections2.filter(candidates, new Predicate<StoreFile>() {
        @Override
        public boolean apply(StoreFile input) {
            return input.excludeFromMinorCompaction();
        }
    }));
    return candidates;
}

From source file:simplealbum.mvc.picture.impl.SenderFTP.java

public List<String> listPending() throws IOException {
    //Manejar en memoria el log, manejar string[] en listnames
    List<String> listDir = Arrays.asList(ftpClient.listNames());
    ArrayList listPending = new ArrayList();
    for (String listName : listDir) {
        if (!listName.contains(":") && !listName.contains("~") && listName.endsWith(".jpg")) {
            listPending.add(listName);//from   www. j  av a2s .co  m
        }
    }
    listPending.removeAll(listConveyed);
    System.out.println("lis " + listPending.size());
    Collections.sort(listPending);
    return listPending;
}