Example usage for com.google.common.collect Multiset addAll

List of usage examples for com.google.common.collect Multiset addAll

Introduction

In this page you can find the example usage for com.google.common.collect Multiset addAll.

Prototype

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

Source Link

Document

Adds all of the elements in the specified collection to this collection (optional operation).

Usage

From source file:org.carcv.impl.core.util.CollectionUtils.java

public static <T> T highestCountElement(final List<T> list) throws NoSuchElementException {
    final Multiset<T> plateSet = HashMultiset.create();
    plateSet.addAll(list);
    return Multisets.copyHighestCountFirst(plateSet).iterator().next();
}

From source file:com.flaptor.indextank.index.scorer.FacetingManager.java

public static Map<String, Multiset<String>> mergeFacets(Map<String, Multiset<String>> facets1,
        Map<String, Multiset<String>> facets2) {
    Map<String, Multiset<String>> result = Maps.newHashMap();

    Set<String> facets1Cats = facets1.keySet();

    for (String category : facets1Cats) {
        Multiset<String> facet1 = HashMultiset.create(facets1.get(category));
        Multiset<String> facet2 = facets2.get(category);

        if (facet2 != null) {
            facet1.addAll(facet2);
        }/*from  ww w  . j a  v  a 2s.  co m*/
        result.put(category, facet1);
    }

    Set<String> facets2Cats = facets2.keySet();

    for (String category : facets2Cats) {
        if (!result.containsKey(category)) {
            result.put(category, HashMultiset.create(facets2.get(category)));
        }
    }

    return result;
}

From source file:org.javafunk.funk.Multisets.java

public static <T> Multiset<T> concatenate(Iterable<? extends Iterable<? extends T>> iterables) {
    Multiset<T> concatenatedMultiset = multisetFrom(first(iterables).get());
    for (Iterable<? extends T> iterable : rest(iterables)) {
        concatenatedMultiset.addAll(collectionFrom(iterable));
    }/*from ww w  . j a v  a2s . co m*/
    return concatenatedMultiset;
}

From source file:org.apache.mahout.classifier.NewsgroupHelper.java

public static void countWords(Analyzer analyzer, Collection<String> words, Reader in,
        Multiset<String> overallCounts) throws IOException {
    TokenStream ts = analyzer.tokenStream("text", in);
    ts.addAttribute(CharTermAttribute.class);
    ts.reset();/*from ww w  .ja v  a  2 s.c om*/
    while (ts.incrementToken()) {
        String s = ts.getAttribute(CharTermAttribute.class).toString();
        words.add(s);
    }
    overallCounts.addAll(words);
    ts.end();
    Closeables.close(ts, true);
}

From source file:com.memonews.mahout.sentiment.SentimentModelHelper.java

private static void countWords(final Analyzer analyzer, final Collection<String> words, final Reader in,
        final Multiset<String> overallCounts) throws IOException {
    final TokenStream ts = analyzer.reusableTokenStream("text", in);
    ts.addAttribute(CharTermAttribute.class);
    ts.reset();/*w  ww  . j  av a2s .c  o m*/
    while (ts.incrementToken()) {
        final String s = ts.getAttribute(CharTermAttribute.class).toString();
        words.add(s);
    }
    overallCounts.addAll(words);
}

From source file:org.apache.mahout.classifier.sgd.NewsgroupHelper.java

private static void countWords(Analyzer analyzer, Collection<String> words, Reader in,
        Multiset<String> overallCounts) throws IOException {
    TokenStream ts = analyzer.reusableTokenStream("text", in);
    ts.addAttribute(CharTermAttribute.class);
    ts.reset();/*  w w  w  .j a  v  a 2s  . c  o m*/
    while (ts.incrementToken()) {
        String s = ts.getAttribute(CharTermAttribute.class).toString();
        words.add(s);
    }
    overallCounts.addAll(words);
}

From source file:org.sonar.java.se.JavaCheckVerifier.java

private static void validateSecondaryLocations(List<AnalyzerMessage> actual, List<Integer> expected) {
    Multiset<Integer> actualLines = HashMultiset.create();
    actualLines.addAll(
            actual.stream().map(secondaryLocation -> secondaryLocation.getLine()).collect(Collectors.toList()));
    List<Integer> unexpected = new ArrayList<>();
    for (Integer actualLine : actualLines) {
        if (expected.contains(actualLine)) {
            expected.remove(actualLine);
        } else {/*from  w w w . j  a  va 2 s  . co  m*/
            unexpected.add(actualLine);
        }
    }
    if (!expected.isEmpty() || !unexpected.isEmpty()) {
        fail("Secondary locations: expected: " + expected + " unexpected:" + unexpected);
    }
}

From source file:org.apache.mahout.knn.tools.Vectorize20NewsGroups.java

private static void recursivelyCount(Set<String> documents, Multiset<String> wordFrequency, File f)
        throws IOException {
    if (f.isDirectory()) {
        for (File file : f.listFiles()) {
            recursivelyCount(documents, wordFrequency, file);
        }//from  ww w  . j a v  a2  s . c o m
    } else {
        // count each word once per document regardless of actual count
        documents.add(f.getCanonicalPath());
        wordFrequency.addAll(parse(f).elementSet());
    }
}

From source file:edu.washington.cs.cupid.standard.MostFrequent.java

@Override
public LinearJob<List<V>, V> getJob(final List<V> input) {
    return new LinearJob<List<V>, V>(this, input) {
        @Override/*from  w w w. j  a  va2  s  . c  o  m*/
        protected LinearStatus<V> run(final IProgressMonitor monitor) {
            try {
                monitor.beginTask(getName(), 100);

                Multiset<V> set = HashMultiset.create();
                set.addAll(input);
                for (V val : Multisets.copyHighestCountFirst(set)) {
                    return LinearStatus.makeOk(getCapability(), val);
                }

                return LinearStatus.<V>makeError(
                        new IllegalArgumentException("Cannot get most frequent element of empty collection"));
            } catch (Exception ex) {
                return LinearStatus.<V>makeError(ex);
            } finally {
                monitor.done();
            }
        }
    };
}

From source file:org.javafunk.funk.builders.MultisetBuilder.java

@Override
public Multiset<E> build(Class<? extends Multiset> implementationClass)
        throws IllegalAccessException, InstantiationException {
    @SuppressWarnings("unchecked")
    Multiset<E> multiset = (Multiset<E>) implementationClass.newInstance();
    multiset.addAll(elements);
    return multiset;
}