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:Set1.java

public static void test(Set s) {
    // Strip qualifiers from class name:
    System.out.println(s.getClass().getName().replaceAll("\\w+\\.", ""));
    fill(s);//  w ww . j a  va  2s  .  c o  m
    fill(s);
    fill(s);
    System.out.println(s); // No duplicates!
    // Add another set to this one:
    s.addAll(s);
    s.add("one");
    s.add("one");
    s.add("one");
    System.out.println(s);
    // Look something up:
    System.out.println("s.contains(\"one\"): " + s.contains("one"));
}

From source file:de.xwic.appkit.core.transport.xml.EtoSerializer.java

/**
 * @param proxy/*from w ww . j  av  a  2 s . c  o m*/
 * @param to
 * @param type
 * @return
 * @throws IntrospectionException
 * @throws InvocationTargetException
 * @throws IllegalAccessException
 * @throws IllegalArgumentException
 */
private static IEntity transferData(final IEntity proxy, final Class<? extends IEntity> type)
        throws IntrospectionException, IllegalArgumentException, IllegalAccessException,
        InvocationTargetException {

    final IEntity result = EntityUtil.createEntity(type);
    Map<String, PropertyDescriptor> objectProp = getMap(result);
    Map<String, PropertyDescriptor> proxyProp = getMap(proxy);
    Set<String> allSet = new HashSet<String>(objectProp.keySet());
    allSet.addAll(proxyProp.keySet());
    allSet.removeAll(IGNORE_PROPERTIES);
    for (String prop : allSet) {
        if (proxyProp.containsKey(prop) && objectProp.containsKey(prop)) {
            Method readMethod = proxyProp.get(prop).getReadMethod();
            Method writeMethod = objectProp.get(prop).getWriteMethod();
            if (readMethod == null || writeMethod == null) {
                System.out.println("Illegal " + prop);
                continue;
            }
            writeMethod.invoke(result, readMethod.invoke(proxy));
        }
    }

    return result;
}

From source file:de.tudarmstadt.ukp.similarity.experiments.coling2012.util.CharacterNGramIdfValuesGenerator.java

@SuppressWarnings("unchecked")
public static void computeIdfScores(Dataset dataset, int n) throws Exception {
    File outputFile = new File(UTILS_DIR + "/character-ngrams-idf/" + n + "/" + dataset.toString() + ".txt");

    System.out.println("Computing character " + n + "-grams");

    if (outputFile.exists()) {
        System.out.println(" - skipping, already exists");
    } else {//  ww  w.  ja va  2  s.co m
        System.out.println(" - this may take a while...");

        CollectionReader reader = ColingUtils.getCollectionReader(dataset);

        // Tokenization
        AnalysisEngineDescription seg = createPrimitiveDescription(BreakIteratorSegmenter.class);
        AggregateBuilder builder = new AggregateBuilder();
        builder.add(seg, CombinationReader.INITIAL_VIEW, CombinationReader.VIEW_1);
        builder.add(seg, CombinationReader.INITIAL_VIEW, CombinationReader.VIEW_2);
        AnalysisEngine aggr_seg = builder.createAggregate();

        // Output Writer
        AnalysisEngine writer = createPrimitive(CharacterNGramIdfValuesGeneratorWriter.class,
                CharacterNGramIdfValuesGeneratorWriter.PARAM_OUTPUT_FILE, outputFile.getAbsolutePath());

        SimplePipeline.runPipeline(reader, aggr_seg, writer);

        // We now have plain text format
        List<String> lines = FileUtils.readLines(outputFile);

        Map<String, Double> idfValues = new HashMap<String, Double>();

        CharacterNGramMeasure measure = new CharacterNGramMeasure(n, new HashMap<String, Double>());

        // Get n-gram representations of texts
        List<Set<String>> docs = new ArrayList<Set<String>>();

        for (String line : lines) {
            Set<String> ngrams = measure.getNGrams(line);

            docs.add(ngrams);
        }

        // Get all ngrams
        Set<String> allNGrams = new HashSet<String>();
        for (Set<String> doc : docs)
            allNGrams.addAll(doc);

        // Compute idf values         
        for (String ngram : allNGrams) {
            double count = 0;
            for (Set<String> doc : docs) {
                if (doc.contains(ngram))
                    count++;
            }
            idfValues.put(ngram, count);
        }

        // Compute the idf
        for (String lemma : idfValues.keySet()) {
            double idf = Math.log10(lines.size() / idfValues.get(lemma));
            idfValues.put(lemma, idf);
        }

        // Store persistently
        StringBuilder sb = new StringBuilder();
        for (String key : idfValues.keySet()) {
            sb.append(key + "\t" + idfValues.get(key) + LF);
        }
        FileUtils.writeStringToFile(outputFile, sb.toString());

        System.out.println(" - done");
    }
}

From source file:dk.netarkivet.viewerproxy.webinterface.Reporting.java

/**
 * Submit a batch job to list all files for a job, and report result in a sorted list.
 *
 * @param jobid The job to get files for.
 * @param harvestprefix The harvestprefix for the files produced by heritrix
 * @return A sorted list of files./*from  ww w .j  a  va  2  s.co  m*/
 * @throws ArgumentNotValid If jobid is 0 or negative.
 * @throws IOFailure On trouble generating the file list
 */
public static List<String> getFilesForJob(int jobid, String harvestprefix) {
    ArgumentNotValid.checkPositive(jobid, "jobid");
    FileBatchJob fileListJob = new FileListJob();
    List<String> acceptedPatterns = new ArrayList<String>();
    acceptedPatterns.add(jobid + metadatafile_suffix);
    acceptedPatterns.add(harvestprefix + archivefile_suffix);
    fileListJob.processOnlyFilesMatching(acceptedPatterns);

    File f;
    try {
        f = File.createTempFile(jobid + "-files", ".txt", FileUtils.getTempDir());
    } catch (IOException e) {
        throw new IOFailure("Could not create temorary file", e);
    }
    BatchStatus status = ArcRepositoryClientFactory.getViewerInstance().batch(fileListJob,
            Settings.get(CommonSettings.USE_REPLICA_ID));
    status.getResultFile().copyTo(f);
    List<String> lines = new ArrayList<String>(FileUtils.readListFromFile(f));
    FileUtils.remove(f);
    Set<String> linesAsSet = new HashSet<String>();
    linesAsSet.addAll(lines);
    lines = new ArrayList<String>();
    lines.addAll(linesAsSet);
    Collections.sort(lines);
    return lines;
}

From source file:com.googlecode.idea.red5.Red5Utils.java

public static Collection<String> getConfiguredContextPaths(Red5Model configuration)
        throws RuntimeConfigurationException {
    Set<String> result = new HashSet<String>();
    try {/*w w w.j  a  v  a2 s  . c o m*/
        result.addAll(getContextPathsFromServerXML(configuration));
    } catch (ExecutionException e) {
        // Do nothing...
    }
    result.addAll(getContextPathsFromDirectory(configuration));
    return result;
}

From source file:io.github.lxgaming.teleportbow.managers.CommandManager.java

private static Optional<AbstractCommand> getCommand(AbstractCommand parentCommand, List<String> arguments) {
    Set<AbstractCommand> commands = Toolbox.newLinkedHashSet();
    if (parentCommand != null) {
        commands.addAll(parentCommand.getChildren());
    } else {//from   w  w  w .j  a v  a  2 s  . com
        commands.addAll(getCommands());
    }

    if (arguments.isEmpty() || commands.isEmpty()) {
        return Optional.ofNullable(parentCommand);
    }

    for (AbstractCommand command : commands) {
        if (Toolbox.containsIgnoreCase(command.getAliases(), arguments.get(0))) {
            arguments.remove(0);
            return getCommand(command, arguments);
        }
    }

    return Optional.ofNullable(parentCommand);
}

From source file:Main.java

public static <T> Set<T> merge(Set<T> c1, Set<T> c2) {
    if (c1 == null || c1.size() == 0) {
        return c2;
    }//w  w  w.  j  a  va 2 s  .c  om
    if (c2 == null || c2.size() == 0) {
        return c1;
    }
    Set<T> all = new HashSet<T>(c1.size() + c2.size());
    all.addAll(c1);
    all.addAll(c2);
    return all;
}

From source file:TwitterClustering.java

public static float jaccardDistance(Set<String> a, Set<String> b) {

    if (a.size() == 0 || b.size() == 0) {
        return 0;
    }/*from ww w .  j  a va 2s.  c  om*/

    Set<String> unionXY = new HashSet<String>(a);
    unionXY.addAll(b);

    Set<String> intersectionXY = new HashSet<String>(a);
    intersectionXY.retainAll(b);
    float retValue = (float) intersectionXY.size() / (float) unionXY.size();
    return retValue;

}

From source file:com.insightml.utils.Collections.java

public static <T> Set<T> sort(final Set<T> items) {
    final Set<T> set = new TreeSet<>();
    set.addAll(items);
    return set;//w  w w.j a  va2  s.  c  om
}

From source file:ch.ifocusit.plantuml.utils.ClassUtils.java

public static Set<Class> getConcernedTypes(Method method) {
    Set<Class> classes = new HashSet<>();
    // manage returned types
    classes.add(method.getReturnType());
    classes.addAll(getGenericTypes(method));
    // manage parameters types
    for (Parameter parameter : method.getParameters()) {
        classes.addAll(getConcernedTypes(parameter));
    }//from w  w w  .  j a v a  2 s.  c  o m
    return classes;
}