Example usage for java.util Set addAll

List of usage examples for java.util Set addAll

Introduction

In this page you can find the example usage for java.util Set addAll.

Prototype

boolean addAll(Collection<? extends E> c);

Source Link

Document

Adds all of the elements in the specified collection to this set if they're not already present (optional operation).

Usage

From source file:edu.uci.ics.hyracks.algebricks.core.algebra.operators.logical.visitors.VariableUtilities.java

public static <T> boolean varListEqualUnordered(List<T> var, List<T> varArg) {
    Set<T> varSet = new HashSet<T>();
    Set<T> varArgSet = new HashSet<T>();
    varSet.addAll(var);
    varArgSet.addAll(varArg);//from ww  w .j a  v  a 2 s . c om
    return varSet.equals(varArgSet);
}

From source file:Main.java

/**
 * Returns a {@link Collection} containing the exclusive disjunction
 * (symmetric difference) of the given {@link Collection}s.
 * <p>/*from  ww  w . j ava  2 s  .  c  om*/
 * The cardinality of each element <i>e</i> in the returned
 * {@link Collection} will be equal to
 * <tt>max(cardinality(<i>e</i>,<i>a</i>),cardinality(<i>e</i>,<i>b</i>)) - min(cardinality(<i>e</i>,<i>a</i>),cardinality(<i>e</i>,<i>b</i>))</tt>.
 * <p>
 * This is equivalent to
 * <tt>{@link #subtract subtract}({@link #union union(a,b)},{@link #intersection intersection(a,b)})</tt>
 * or
 * <tt>{@link #union union}({@link #subtract subtract(a,b)},{@link #subtract subtract(b,a)})</tt>.
 */
public static Collection disjunction(final Collection a, final Collection b) {
    ArrayList list = new ArrayList();
    Map mapa = getCardinalityMap(a);
    Map mapb = getCardinalityMap(b);
    Set elts = new HashSet(a);
    elts.addAll(b);
    Iterator it = elts.iterator();
    while (it.hasNext()) {
        Object obj = it.next();
        for (int i = 0, m = ((Math.max(getFreq(obj, mapa), getFreq(obj, mapb)))
                - (Math.min(getFreq(obj, mapa), getFreq(obj, mapb)))); i < m; i++) {
            list.add(obj);
        }
    }
    return list;
}

From source file:MainClass.java

public static void test(Set s) {
    System.out.println(s.getClass().getName().replaceAll("\\w+\\.", ""));
    fill(s);// w ww  .  ja  v a 2s  .  c  om
    fill(s);
    fill(s);
    System.out.println(s); // No duplicates!

    s.addAll(s);
    s.add("one");
    s.add("one");
    s.add("one");
    System.out.println(s);

    System.out.println("s.contains(\"one\"): " + s.contains("one"));
}

From source file:tr.edu.gsu.nerwip.recognition.internal.modelless.subee.SubeeTools.java

/**
 * Updates the file containing unknown types so that it contains
 * all types retrieved from Freebase not already present in the
 * existing type files./*from ww  w .j  a  va2s  . c  om*/
 * 
 * @throws RecognizerException 
 *       Problem while loading/retrieving the FB types.
 * @throws org.json.simple.parser.ParseException 
 *       Problem while loading/retrieving the FB types.
 * @throws IOException 
 *       Problem while loading/retrieving the FB types.
 * @throws ClientProtocolException 
 *       Problem while loading/retrieving the FB types.
 */
public static void updateUnknownTypes() throws RecognizerException, ClientProtocolException, IOException,
        org.json.simple.parser.ParseException {
    logger.setName("Updating-Subee-List");
    logger.log("Updating Subee unknown FB types list");

    // build Subee and loads the necessary files
    logger.log("Load the Subee files");
    Subee subee = new Subee(true, true, true, true, true);
    subee.prepareRecognizer();

    // retrieve the loaded lists
    logger.log("Get the existing type lists from these files");
    Set<String> knownTypes = new TreeSet<String>();
    knownTypes.addAll(Subee.TYPE_MAP.keySet());
    knownTypes.addAll(Subee.UNKNOWN_TYPES);

    // retrieve the last types from Freebase
    logger.log("Get the last type from Freebase");
    Set<String> fbTypes = FbTypeTools.retrieveDomainTypes();

    // retain only the unknown ones
    logger.log("Udpdate the 'unknown' file");
    fbTypes.removeAll(knownTypes);

    // append them to the 'unknown' file
    subee.updateUnknownTypes("-NOT A TYPE^^---------------------");
    for (String type : fbTypes)
        subee.updateUnknownTypes(type);
}

From source file:com.sap.prd.mobile.ios.mios.XCodeTest.java

private static void getPomFiles(File root, final Set<File> pomFiles) {
    if (root.isFile())
        return;/*from   w w w.  j  av a 2  s. c  om*/

    pomFiles.addAll(Arrays.asList(root.listFiles(new FileFilter() {

        @Override
        public boolean accept(File f) {
            // here we have the implicit assumtion that a pom file is named "pom.xml".
            // In case we introduce any test with a diffent name for a pom file we have
            // to revisit that.
            return f.isFile() && f.getName().equals("pom.xml");
        }

    })));

    for (File f : Arrays.asList(root.listFiles(new FileFilter() {

        @Override
        public boolean accept(File f) {
            return f.isDirectory();
        }
    })))
        getPomFiles(f, pomFiles);
}

From source file:ca.on.oicr.pde.tools.BEDFileUtils.java

/**
 * Gets the set (no duplicates) of chromosomes from a collection of bed files.
 *
 * @param bedFiles A collection of bed file paths
 *
 * @return The set of chromosomes (no duplicates)
 *
 * @throws FileNotFoundException, IOException
 */// w w w  .  j  a  v  a 2 s.c o m
public static Set<String> getChromosomes(Collection<String> bedFiles)
        throws FileNotFoundException, IOException {
    Set<String> chrs = new LinkedHashSet<>();
    for (String bedFile : bedFiles) {
        chrs.addAll(BEDFileUtils.getChromosomes(bedFile));
    }
    return chrs;
}

From source file:Main.java

/**
 * Internal function to realize the mathematical combination of given
 * values. This method creates the next sub-tree by iterating over values
 * given by parameter set./*w ww  . j  a v a 2 s  . c  om*/
 * 
 * @param <E>
 *            the type of the given and returned values
 * @param set
 *            the possible values for next iteration
 * @param combination
 *            the current path of the abstract combination tree
 * @param combinations
 *            overall combinations
 */
private static <E extends Object> void combination(Set<E> set, Set<E> combination, Set<Set<E>> combinations) {
    for (E value : set) {
        Set<E> combination_ = new HashSet<E>();
        combination_.addAll(combination);
        combination_.add(value);
        combinations.add(combination_);

        Set<E> set_ = new HashSet<E>();
        set_.addAll(set);
        long size = set_.size();
        set_.remove(value);
        if (set_.size() == size) {
            for (E v : set_) {
                if (v.equals(value)) {
                    set_.remove(v);
                    break;
                }
            }
        }
        if (!set_.isEmpty()) {
            combination(set_, combination_, combinations);
        }
    }
}

From source file:org.apache.aries.blueprint.plugin.FilteredClassFinder.java

public static Set<Class<?>> findClasses(ClassFinder finder, Collection<String> packageNames,
        Class<? extends Annotation>[] annotations) {
    Set<Class<?>> rawClasses = new HashSet<Class<?>>();
    for (Class<? extends Annotation> annotation : annotations) {
        rawClasses.addAll(finder.findAnnotatedClasses(annotation));
    }/*from  w  ww .ja v a 2 s.c o m*/
    return filterByBasePackages(rawClasses, packageNames);
}

From source file:com.enonic.cms.core.content.ContentKey.java

public static Set convertToSet(Collection<ContentKey> contentKeys) {
    Set<ContentKey> set = new HashSet<ContentKey>();
    set.addAll(contentKeys);
    return set;/*www. j a v a 2 s . c  o m*/
}

From source file:Inmemantlr.java

private static Set<File> getFilesForOption(CommandLine cmd, String opt) {
    Set<File> ret = new HashSet<>();
    if (cmd.hasOption(opt)) {
        Set<String> us = new HashSet<>();
        us.addAll(Arrays.asList(cmd.getOptionValues(opt)));
        ret.addAll(us.stream().map(File::new).collect(Collectors.toSet()));
    }//from   ww  w  .ja v  a 2  s.  c o m
    return ret;
}