Example usage for java.util Collection remove

List of usage examples for java.util Collection remove

Introduction

In this page you can find the example usage for java.util Collection remove.

Prototype

boolean remove(Object o);

Source Link

Document

Removes a single instance of the specified element from this collection, if it is present (optional operation).

Usage

From source file:ubic.gemma.core.analysis.expression.diff.DifferentialExpressionAnalysisUtil.java

/**
 * Returns biomaterials with 'filtered' factor values. That is, each biomaterial will only contain those factor
 * values equivalent to a factor value from one of the input experimental factors.
 *
 * @return Collection<BioMaterial>
 *//*from w w  w  .  ja v a2  s.co m*/
private static Collection<BioMaterial> filterFactorValuesFromBiomaterials(
        Collection<ExperimentalFactor> factors, Collection<BioMaterial> biomaterials) {

    assert !biomaterials.isEmpty();
    assert !factors.isEmpty();

    Collection<FactorValue> allFactorValuesFromGivenFactors = new HashSet<>();
    for (ExperimentalFactor ef : factors) {
        allFactorValuesFromGivenFactors.addAll(ef.getFactorValues());
    }

    Collection<BioMaterial> biomaterialsWithGivenFactorValues = new HashSet<>();
    int numHaveAny = 0;
    for (BioMaterial b : biomaterials) {
        Collection<FactorValue> biomaterialFactorValues = b.getFactorValues();
        Collection<FactorValue> factorValuesToConsider = new HashSet<>(biomaterialFactorValues);
        for (FactorValue biomaterialFactorValue : biomaterialFactorValues) {
            numHaveAny++;
            if (!allFactorValuesFromGivenFactors.contains(biomaterialFactorValue)) {
                factorValuesToConsider.remove(biomaterialFactorValue);
            }
        }
        b.setFactorValues(factorValuesToConsider);
        biomaterialsWithGivenFactorValues.add(b);
    }

    if (numHaveAny == 0) {
        throw new IllegalStateException("No biomaterials had any factor values");
    }

    return biomaterialsWithGivenFactorValues;
}

From source file:org.goko.core.rs274ngcv3.RS274.java

public static GCodeToken removeUniqueTokenByLetter(String letter, Collection<GCodeToken> lstTokens)
        throws GkException {
    GCodeToken uniqueToken = null;/*from www  . j  a va2s .  co m*/
    for (GCodeToken token : lstTokens) {
        if (StringUtils.equalsIgnoreCase(letter, getTokenLetter(token))) {
            if (uniqueToken != null) {
                throw new GkTechnicalException(
                        "Multiple GCode word with letter " + letter + " found in token list.");
            }
            uniqueToken = token;
        }
    }
    if (uniqueToken != null) {
        lstTokens.remove(uniqueToken);
    }
    return uniqueToken;
}

From source file:com.cloudera.oryx.app.batch.mllib.als.ALSUpdate.java

private static JavaPairRDD<String, Collection<String>> knownsRDD(JavaRDD<String[]> allData,
        final boolean knownItems) {
    JavaRDD<String[]> sorted = allData.sortBy(new Function<String[], Long>() {
        @Override//from   w  w w  .ja va  2s .  c o m
        public Long call(String[] datum) {
            return Long.valueOf(datum[3]);
        }
    }, true, allData.partitions().size());

    JavaPairRDD<String, Tuple2<String, Boolean>> tuples = sorted
            .mapToPair(new PairFunction<String[], String, Tuple2<String, Boolean>>() {
                @Override
                public Tuple2<String, Tuple2<String, Boolean>> call(String[] datum) {
                    String user = datum[0];
                    String item = datum[1];
                    Boolean delete = datum[2].isEmpty();
                    return knownItems ? new Tuple2<>(user, new Tuple2<>(item, delete))
                            : new Tuple2<>(item, new Tuple2<>(user, delete));
                }
            });

    // TODO likely need to figure out a way to avoid groupByKey but collectByKey
    // won't work here -- doesn't guarantee enough about ordering
    return tuples.groupByKey().mapValues(new Function<Iterable<Tuple2<String, Boolean>>, Collection<String>>() {
        @Override
        public Collection<String> call(Iterable<Tuple2<String, Boolean>> idDeletes) {
            Collection<String> ids = new HashSet<>();
            for (Tuple2<String, Boolean> idDelete : idDeletes) {
                if (idDelete._2()) {
                    ids.remove(idDelete._1());
                } else {
                    ids.add(idDelete._1());
                }
            }
            return ids;
        }
    });
}

From source file:org.beangle.model.persist.hibernate.CriterionUtils.java

/**
 * ?. ??.// w w  w.  ja  v a2 s .  com
 * 
 * @param entity
 * @param excludePropertes
 * @param mode
 * @return
 */
@SuppressWarnings("rawtypes")
public static List<Criterion> getEntityCriterions(String nestedName, Object entity, String[] excludePropertes,
        MatchMode mode, boolean ignoreZero) {
    if (null == entity) {
        return Collections.emptyList();
    }
    List<Criterion> criterions = CollectUtils.newArrayList();
    BeanMap map = new BeanMap(entity);
    Set keySet = map.keySet();
    Collection properties = null;
    if (null == excludePropertes) {
        List proList = CollectUtils.newArrayList();
        proList.addAll(keySet);
        properties = proList;
    } else {
        properties = CollectionUtils.subtract(keySet, Arrays.asList(excludePropertes));
    }
    properties.remove("class");

    for (Iterator iter = properties.iterator(); iter.hasNext();) {
        String propertyName = (String) iter.next();
        if (!PropertyUtils.isWriteable(entity, propertyName)) {
            continue;
        }
        Object value = map.get(propertyName);
        addCriterion(nestedName, entity, excludePropertes, propertyName, value, criterions, mode, ignoreZero);
    }
    return criterions;
}

From source file:org.alex73.osm.monitors.export.ExportOutput.java

/**
 *  ExportOutput' ? ?   border+type.//from  w  ww .jav a2s .c om
 */
public static List<ExportOutput> list(List<CheckType> types, Borders borders, Set<String> unusedFiles)
        throws Exception {
    Collection<File> files = FileUtils.listFiles(new File(Env.readProperty("monitoring.gitdir")),
            new String[] { "txt" }, true);

    List<ExportOutput> result = new ArrayList<>();
    for (CheckType t : types) {
        for (Borders.Border b : borders.kraina) {
            ExportOutput o = new ExportOutput(t.getType().getFile(), b.name);
            if (o.file1.exists() || o.file2.exists()) {
                result.add(o);
                files.remove(o.file1);
                files.remove(o.file2);
            }
        }
        for (Borders.Border b : borders.voblasci) {
            ExportOutput o = new ExportOutput(t.getType().getFile(), b.name);
            if (o.file1.exists() || o.file2.exists()) {
                result.add(o);
                files.remove(o.file1);
                files.remove(o.file2);
            }
        }
        for (Borders.Border b : borders.rajony) {
            ExportOutput o = new ExportOutput(t.getType().getFile(), b.name);
            if (o.file1.exists() || o.file2.exists()) {
                result.add(o);
                files.remove(o.file1);
                files.remove(o.file2);
            }
        }
        for (Borders.Border b : borders.miesty) {
            ExportOutput o = new ExportOutput(t.getType().getFile(), b.name);
            if (o.file1.exists() || o.file2.exists()) {
                result.add(o);
                files.remove(o.file1);
                files.remove(o.file2);
            }
        }
    }
    String prefix = new File(Env.readProperty("monitoring.gitdir")).getAbsolutePath().replace('\\', '/') + '/';
    for (File f : files) {
        String fn = f.getAbsolutePath().replace('\\', '/');
        if (!fn.startsWith(prefix)) {
            throw new RuntimeException("Wrong file: " + f);
        }
        unusedFiles.add(fn.substring(prefix.length()));
    }

    return result;
}

From source file:gov.nih.nci.cananolab.util.StringUtils.java

public static String join(Collection<String> stringList, String delimiter) {
    String joinedStr = "";
    if (stringList == null || stringList.isEmpty()) {
        return joinedStr;
    }/*  ww  w  .  j  a  v a 2  s  .c  om*/
    // remove empty items
    Collection<String> modList = new ArrayList<String>(stringList);
    for (String str : modList) {
        if (isEmpty(str)) {
            stringList.remove(str);
        }
    }

    StringBuilder sb = new StringBuilder();
    int i = 0;
    for (String str : stringList) {
        if (i < stringList.size() - 1) {
            sb.append(str);
            sb.append(delimiter);
        } else {
            sb.append(str);
        }
        i++;
    }
    joinedStr = sb.toString();
    return joinedStr;
}

From source file:mitm.application.djigzo.impl.NamedCertificateUtils.java

/**
 * Replaces all the named certificates with the given name in the target set with the new certificates. The replacement is
 * done in-place (ie. target is modified)
 *//*from w ww.  j av a2s  .c om*/
public static void replaceNamedCertificates(Collection<NamedCertificate> target, String name,
        Collection<X509Certificate> certificates) {
    Check.notNull(name, "name");

    if (target != null) {
        /*
         * We need to store the items we need to remove. We cannot change target
         * while looping.
         */
        List<NamedCertificate> toRemove = new LinkedList<NamedCertificate>();

        for (NamedCertificate namedCertificate : target) {
            if (namedCertificate != null && StringUtils.equals(name, namedCertificate.getName())) {
                toRemove.add(namedCertificate);
            }
        }

        for (NamedCertificate namedCertificate : toRemove) {
            target.remove(namedCertificate);
        }

        if (certificates != null) {
            for (X509Certificate certificate : certificates) {
                target.add(new NamedCertificateImpl(name, certificate));
            }
        }
    }
}

From source file:ubic.basecode.bio.geneset.GeneSetMapTools.java

/**
 * Identify classes which are absoluely identical to others. This isn't superfast, because it doesn't know which
 * classes are actually relevant in the data.
 *//*from   w  w w.j  a  va  2 s.co m*/
public static void collapseGeneSets(GeneAnnotations geneData, StatusViewer messenger) {
    Collection<String> geneSets = geneData.getGeneSets();
    Map<String, Collection<String>> classesToRedundantMap = geneData.geneSetToRedundantMap();
    Map<String, String> seenClasses = new LinkedHashMap<String, String>();
    Map<String, String> sigs = new LinkedHashMap<String, String>();

    Map<String, Boolean> seenit = new HashMap<String, Boolean>();

    if (messenger != null) {
        messenger.showStatus("There are " + geneData.numGeneSets()
                + " classes represented on the chip (of any size). Redundant classes are being removed...");
    }

    // sort each arraylist in for each go and create a string that is a signature for this class.
    int ignored = 0;
    for (Iterator<String> iter = geneSets.iterator(); iter.hasNext();) {
        String classId = iter.next();
        Collection<String> classMembers = geneData.getActiveGeneSetGenes(classId);
        if (classMembers.size() == 0)
            continue;
        if (classMembers.contains(null)) {
            classMembers.remove(null); // FIXME why do we need to do this?
            // throw new IllegalStateException(classId + " contains null.");
        }

        // This is a bit of a hack : Skip classes that are huge. It's too slow
        // otherwise. This is a total heuristic. Note that this
        // doesn't mean the class won't get analyzed, it just
        // means we don't bother looking for redundancies. Big
        // classes are less likely to be identical to others,
        // anyway. In tests, the range shown below has no effect
        // on the results, but it _could_ matter.
        if (classMembers.size() > 250 || classMembers.size() < 2) {
            continue;
        }

        List<String> cls = new Vector<String>(classMembers);

        Collections.sort(cls);
        String signature = "";
        seenit.clear();
        Iterator<String> classit = cls.iterator();
        while (classit.hasNext()) {
            String probeid = classit.next();
            if (!seenit.containsKey(probeid)) {
                signature = signature + "__" + probeid;
                seenit.put(probeid, new Boolean(true));
            }
        }
        sigs.put(classId, signature);
    }

    // look at the signatures for repeats.
    for (Iterator<String> iter = sigs.keySet().iterator(); iter.hasNext();) {
        String classId = iter.next();
        String signature = sigs.get(classId);

        // if the signature has already been seen, add it to the redundant
        // list, and remove this class from the classToProbeMap.
        if (seenClasses.containsKey(signature)) {
            if (!classesToRedundantMap.containsKey(seenClasses.get(signature))) {
                classesToRedundantMap.put(seenClasses.get(signature), new ArrayList<String>());

            }
            classesToRedundantMap.get(seenClasses.get(signature)).add(classId);
            ignored++;
            geneData.removeClassFromMaps(classId);
            // System.err.println(classId + " is the same as an existing class, " + seenClasses.get(signature));
        } else {
            // add string to hash
            seenClasses.put(signature, classId);
        }
    }

    geneData.resetSelectedSets();
    geneData.sortGeneSets();

    if (messenger != null) {
        messenger.showStatus("There are now " + geneData.numGeneSets() + " classes represented on the chip ("
                + ignored + " were removed)");
    }
}

From source file:org.apache.openejb.util.classloader.URLClassLoaderFirst.java

public static Enumeration<URL> filterResources(final String name, final Enumeration<URL> result) {
    if (isFilterableResource(name)) {
        final Collection<URL> values = Collections.list(result);
        if (values.size() > 1) {
            // remove openejb one
            final URL url = URLClassLoaderFirst.class.getResource("/" + name);
            if (url != null) {
                values.remove(url);
            }//from  ww  w  .j  a  va  2  s  .co m
        }
        return Collections.enumeration(values);
    }
    return result;
}

From source file:ubic.gemma.analysis.expression.diff.DifferentialExpressionAnalysisUtil.java

/**
 * Returns biomaterials with 'filtered' factor values. That is, each biomaterial will only contain those factor
 * values equivalent to a factor value from one of the input experimental factors.
 * <p>/*from   w  ww.j  av  a2s. com*/
 * FIXME I don't like the way this code modifies the factorvalues associated with the biomaterial.
 * 
 * @param factors
 * @param biomaterials
 * @return Collection<BioMaterial>
 */
private static Collection<BioMaterial> filterFactorValuesFromBiomaterials(
        Collection<ExperimentalFactor> factors, Collection<BioMaterial> biomaterials) {

    assert !biomaterials.isEmpty();
    assert !factors.isEmpty();

    Collection<FactorValue> allFactorValuesFromGivenFactors = new HashSet<FactorValue>();
    for (ExperimentalFactor ef : factors) {
        allFactorValuesFromGivenFactors.addAll(ef.getFactorValues());
    }

    Collection<BioMaterial> biomaterialsWithGivenFactorValues = new HashSet<BioMaterial>();
    int numHaveAny = 0;
    for (BioMaterial b : biomaterials) {
        Collection<FactorValue> biomaterialFactorValues = b.getFactorValues();
        Collection<FactorValue> factorValuesToConsider = new HashSet<FactorValue>();
        factorValuesToConsider.addAll(biomaterialFactorValues);
        for (FactorValue biomaterialFactorValue : biomaterialFactorValues) {
            numHaveAny++;
            if (!allFactorValuesFromGivenFactors.contains(biomaterialFactorValue)) {
                factorValuesToConsider.remove(biomaterialFactorValue);
            }
        }
        b.setFactorValues(factorValuesToConsider);
        biomaterialsWithGivenFactorValues.add(b);
    }

    if (numHaveAny == 0) {
        throw new IllegalStateException("No biomaterials had any factor values");
    }

    return biomaterialsWithGivenFactorValues;
}