Java Code Examples for com.google.common.collect.ImmutableSortedMultiset#copyOf()

The following examples show how to use com.google.common.collect.ImmutableSortedMultiset#copyOf() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: Validator.java    From presto with Apache License 2.0 5 votes vote down vote up
private static boolean resultsMatch(QueryResult controlResult, QueryResult testResult, int precision)
{
    SortedMultiset<List<Object>> control = ImmutableSortedMultiset.copyOf(rowComparator(precision), controlResult.getResults());
    SortedMultiset<List<Object>> test = ImmutableSortedMultiset.copyOf(rowComparator(precision), testResult.getResults());
    try {
        return control.equals(test);
    }
    catch (TypesDoNotMatchException e) {
        return false;
    }
}
 
Example 2
Source File: Validator.java    From presto with Apache License 2.0 5 votes vote down vote up
public String getResultsComparison(int precision)
{
    List<List<Object>> controlResults = controlResult.getResults();
    List<List<Object>> testResults = testResult.getResults();

    if (valid() || (controlResults == null) || (testResults == null)) {
        return "";
    }

    Multiset<List<Object>> control = ImmutableSortedMultiset.copyOf(rowComparator(precision), controlResults);
    Multiset<List<Object>> test = ImmutableSortedMultiset.copyOf(rowComparator(precision), testResults);

    try {
        Iterable<ChangedRow> diff = ImmutableSortedMultiset.<ChangedRow>naturalOrder()
                .addAll(Iterables.transform(Multisets.difference(control, test), row -> new ChangedRow(Changed.REMOVED, row, precision)))
                .addAll(Iterables.transform(Multisets.difference(test, control), row -> new ChangedRow(Changed.ADDED, row, precision)))
                .build();
        diff = Iterables.limit(diff, 100);

        StringBuilder sb = new StringBuilder();

        sb.append(format("Control %s rows, Test %s rows%n", control.size(), test.size()));
        if (verboseResultsComparison) {
            Joiner.on("\n").appendTo(sb, diff);
        }
        else {
            sb.append("RESULTS DO NOT MATCH\n");
        }

        return sb.toString();
    }
    catch (TypesDoNotMatchException e) {
        return e.getMessage();
    }
}