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

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

Introduction

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

Prototype

@Override
boolean removeAll(Collection<?> c);

Source Link

Document

Note: This method ignores how often any element might appear in c , and only cares whether or not an element appears at all.

Usage

From source file:org.jetbrains.jet.checkers.CheckerTestUtil.java

public static void diagnosticsDiff(List<DiagnosedRange> expected, Collection<Diagnostic> actual,
        DiagnosticDiffCallbacks callbacks) {
    Iterator<DiagnosedRange> expectedDiagnostics = expected.iterator();
    List<DiagnosticDescriptor> sortedDiagnosticDescriptors = getSortedDiagnosticDescriptors(actual);
    Iterator<DiagnosticDescriptor> actualDiagnostics = sortedDiagnosticDescriptors.iterator();

    DiagnosedRange currentExpected = safeAdvance(expectedDiagnostics);
    DiagnosticDescriptor currentActual = safeAdvance(actualDiagnostics);
    while (currentExpected != null || currentActual != null) {
        if (currentExpected != null) {
            if (currentActual == null) {
                missingDiagnostics(callbacks, currentExpected);
                currentExpected = safeAdvance(expectedDiagnostics);
            } else {
                int expectedStart = currentExpected.getStart();
                int actualStart = currentActual.getStart();
                int expectedEnd = currentExpected.getEnd();
                int actualEnd = currentActual.getEnd();
                if (expectedStart < actualStart) {
                    missingDiagnostics(callbacks, currentExpected);
                    currentExpected = safeAdvance(expectedDiagnostics);
                } else if (expectedStart > actualStart) {
                    unexpectedDiagnostics(currentActual.getDiagnostics(), callbacks);
                    currentActual = safeAdvance(actualDiagnostics);
                } else if (expectedEnd > actualEnd) {
                    assert expectedStart == actualStart;
                    missingDiagnostics(callbacks, currentExpected);
                    currentExpected = safeAdvance(expectedDiagnostics);
                } else if (expectedEnd < actualEnd) {
                    assert expectedStart == actualStart;
                    unexpectedDiagnostics(currentActual.getDiagnostics(), callbacks);
                    currentActual = safeAdvance(actualDiagnostics);
                } else {
                    assert expectedStart == actualStart && expectedEnd == actualEnd;
                    Multiset<String> actualDiagnosticTypes = currentActual.getDiagnosticTypeStrings();
                    Multiset<String> expectedDiagnosticTypes = currentExpected.getDiagnostics();
                    if (!actualDiagnosticTypes.equals(expectedDiagnosticTypes)) {
                        Multiset<String> expectedCopy = HashMultiset.create(expectedDiagnosticTypes);
                        expectedCopy.removeAll(actualDiagnosticTypes);
                        Multiset<String> actualCopy = HashMultiset.create(actualDiagnosticTypes);
                        actualCopy.removeAll(expectedDiagnosticTypes);

                        for (String type : expectedCopy) {
                            callbacks.missingDiagnostic(type, expectedStart, expectedEnd);
                        }//from   w w  w .  j  a  v  a  2s.  co  m
                        for (String type : actualCopy) {
                            callbacks.unexpectedDiagnostic(type, actualStart, actualEnd);
                        }
                    }
                    currentExpected = safeAdvance(expectedDiagnostics);
                    currentActual = safeAdvance(actualDiagnostics);
                }

            }
        } else {
            if (currentActual != null) {
                unexpectedDiagnostics(currentActual.getDiagnostics(), callbacks);
                currentActual = safeAdvance(actualDiagnostics);
            } else {
                break;
            }
        }

        //            assert expectedDiagnostics.hasNext() || actualDiagnostics.hasNext();
    }
}

From source file:org.napile.compiler.checkers.CheckerTestUtil.java

public static void diagnosticsDiff(List<DiagnosedRange> expected, Collection<Diagnostic> actual,
        DiagnosticDiffCallbacks callbacks) {
    Iterator<DiagnosedRange> expectedDiagnostics = expected.iterator();
    List<DiagnosticDescriptor> sortedDiagnosticDescriptors = getSortedDiagnosticDescriptors(actual);
    Iterator<DiagnosticDescriptor> actualDiagnostics = sortedDiagnosticDescriptors.iterator();

    DiagnosedRange currentExpected = safeAdvance(expectedDiagnostics);
    DiagnosticDescriptor currentActual = safeAdvance(actualDiagnostics);
    while (currentExpected != null || currentActual != null) {
        if (currentExpected != null) {
            if (currentActual == null) {
                missingDiagnostics(callbacks, currentExpected);
                currentExpected = safeAdvance(expectedDiagnostics);
            } else {
                int expectedStart = currentExpected.getStart();
                int actualStart = currentActual.getStart();
                int expectedEnd = currentExpected.getEnd();
                int actualEnd = currentActual.getEnd();
                if (expectedStart < actualStart) {
                    missingDiagnostics(callbacks, currentExpected);
                    currentExpected = safeAdvance(expectedDiagnostics);
                } else if (expectedStart > actualStart) {
                    unexpectedDiagnostics(currentActual.getDiagnostics(), callbacks);
                    currentActual = safeAdvance(actualDiagnostics);
                } else if (expectedEnd > actualEnd) {
                    assert expectedStart == actualStart;
                    missingDiagnostics(callbacks, currentExpected);
                    currentExpected = safeAdvance(expectedDiagnostics);
                } else if (expectedEnd < actualEnd) {
                    assert expectedStart == actualStart;
                    unexpectedDiagnostics(currentActual.getDiagnostics(), callbacks);
                    currentActual = safeAdvance(actualDiagnostics);
                } else {
                    assert expectedStart == actualStart && expectedEnd == actualEnd;
                    Multiset<String> actualDiagnosticTypes = currentActual.getDiagnosticTypeStrings();
                    Multiset<String> expectedDiagnosticTypes = currentExpected.getDiagnostics();
                    if (!actualDiagnosticTypes.equals(expectedDiagnosticTypes)) {
                        Multiset<String> expectedCopy = HashMultiset.create(expectedDiagnosticTypes);
                        expectedCopy.removeAll(actualDiagnosticTypes);
                        Multiset<String> actualCopy = HashMultiset.create(actualDiagnosticTypes);
                        actualCopy.removeAll(expectedDiagnosticTypes);

                        for (String type : expectedCopy) {
                            callbacks.missingDiagnostic(type, expectedStart, expectedEnd);
                        }// ww w . j  av  a2  s . c o m
                        for (String type : actualCopy) {
                            callbacks.unexpectedDiagnostic(type, actualStart, actualEnd);
                        }
                    }
                    currentExpected = safeAdvance(expectedDiagnostics);
                    currentActual = safeAdvance(actualDiagnostics);
                }
            }
        } else {
            if (currentActual != null) {
                unexpectedDiagnostics(currentActual.getDiagnostics(), callbacks);
                currentActual = safeAdvance(actualDiagnostics);
            } else {
                break;
            }
        }

        //            assert expectedDiagnostics.hasNext() || actualDiagnostics.hasNext();
    }
}

From source file:com.music.service.text.TimelineToMusicService.java

private Variation getVariation(List<Tweet> tweets, TimelineMusic meta) {
    Morphology morphology = new Morphology(new StringReader(""));
    Multiset<String> words = HashMultiset.create();
    for (Tweet tweet : tweets) {
        String tweetText = tweet.getText().toLowerCase();
        List<String> urls = TimelineToMusicService.extractUrls(tweetText);
        for (String url : urls) {
            tweetText = tweetText.replace(url, "");
        }//  ww  w .  j a v a 2s .  c om
        List<String> usernames = TimelineToMusicService.extractMentionedUsernames(tweetText);
        for (String username : usernames) {
            tweetText = tweetText.replace(username, "").replace("rt", "");
        }

        String[] wordsInTweet = tweetText.split("[^\\p{L}&&[^']]+");
        for (String word : wordsInTweet) {
            try {
                words.add(morphology.stem(word));
            } catch (Exception ex) {
                words.add(word);
            }
        }
    }
    words.removeAll(stopwords);

    // if a word is mentioned more times than is 4% of the tweets, it's considered a topic
    double topicThreshold = tweets.size() * 4 / 100;
    for (Iterator<String> it = words.iterator(); it.hasNext();) {
        String word = it.next();
        // remove stopwords not in the list (e.g. in a different language).
        // We consider all words less than 4 characters to be stop words
        if (word == null || word.length() < 4) {
            it.remove();
        } else if (words.count(word) < topicThreshold) {
            it.remove();
        }
    }

    meta.setTopKeywords(new HashSet<>(words.elementSet()));

    // the more topics you have, the more variative music
    if (meta.getTopKeywords().size() > 40) {
        return Variation.EXTREMELY_VARIATIVE;
    } else if (meta.getTopKeywords().size() > 30) {
        return Variation.VERY_VARIATIVE;
    } else if (meta.getTopKeywords().size() > 20) {
        return Variation.MOVING;
    } else if (meta.getTopKeywords().size() > 10) {
        return Variation.AVERAGE;
    } else {
        return Variation.MONOTONOUS;
    }
}