List of usage examples for com.google.common.collect Multisets difference
@Beta public static <E> Multiset<E> difference(final Multiset<E> multiset1, final Multiset<?> multiset2)
From source file:com.google.caliper.worker.AllocationStats.java
/** * Computes and returns the difference between this measurement and the given * {@code baseline} measurement. The {@code baseline} measurement must have a lower weight * (fewer reps) than this measurement.// w ww. j a v a 2s . com */ AllocationStats minus(AllocationStats baseline) { for (Entry<Allocation> entry : baseline.allocations.entrySet()) { int superCount = allocations.count(entry.getElement()); if (superCount < entry.getCount()) { throw new IllegalStateException( String.format("Your benchmark appears to have non-deterministic allocation behavior. " + "Observed %d instance(s) of %s in the baseline but only %d in the actual " + "measurement", entry.getCount(), entry.getElement(), superCount)); } } try { return new AllocationStats(allocationCount - baseline.allocationCount, allocationSize - baseline.allocationSize, reps - baseline.reps, Multisets.difference(allocations, baseline.allocations)); } catch (IllegalArgumentException e) { throw new IllegalStateException(String.format( "Your benchmark appears to have non-deterministic allocation behavior. The difference " + "between the baseline %s and the measurement %s is invalid. Consider enabling " + "instrument.allocation.options.trackAllocations to get a more specific error message.", baseline, this), e); } }
From source file:google.registry.util.CollectionUtils.java
/** Returns any duplicates in an iterable. */ public static <T> Set<T> findDuplicates(Iterable<T> iterable) { return Multisets .difference(HashMultiset.create(iterable), HashMultiset.create(ImmutableSet.copyOf(iterable))) .elementSet();/* w w w .j a v a2s. co m*/ }
From source file:io.prestosql.tests.QueryAssertions.java
public static void assertEqualsIgnoreOrder(Iterable<?> actual, Iterable<?> expected, String message) { assertNotNull(actual, "actual is null"); assertNotNull(expected, "expected is null"); ImmutableMultiset<?> actualSet = ImmutableMultiset.copyOf(actual); ImmutableMultiset<?> expectedSet = ImmutableMultiset.copyOf(expected); if (!actualSet.equals(expectedSet)) { Multiset<?> unexpectedRows = Multisets.difference(actualSet, expectedSet); Multiset<?> missingRows = Multisets.difference(expectedSet, actualSet); int limit = 100; fail(format(/* w ww.j a v a 2s . co m*/ "%snot equal\n" + "Actual rows (up to %s of %s extra rows shown, %s rows in total):\n %s\n" + "Expected rows (up to %s of %s missing rows shown, %s rows in total):\n %s\n", message == null ? "" : (message + "\n"), limit, unexpectedRows.size(), actualSet.size(), Joiner.on("\n ").join(Iterables.limit(unexpectedRows, limit)), limit, missingRows.size(), expectedSet.size(), Joiner.on("\n ").join(Iterables.limit(missingRows, limit)))); } }
From source file:org.bin01.db.verifier.Validator.java
public String getResultsComparison() { List<List<Object>> controlResults = controlResult.getResults(); List<List<Object>> testResults = testResult.getResults(); if (valid() || (controlResults == null) || (testResults == null)) { return ""; }//from ww w . ja v a 2 s. co m Multiset<List<Object>> control = ImmutableSortedMultiset.copyOf(rowComparator(), controlResults); Multiset<List<Object>> test = ImmutableSortedMultiset.copyOf(rowComparator(), testResults); try { Iterable<ChangedRow> diff = ImmutableSortedMultiset.<ChangedRow>naturalOrder() .addAll(Iterables.transform(Multisets.difference(control, test), ChangedRow.changedRows(Changed.REMOVED))) .addAll(Iterables.transform(Multisets.difference(test, control), ChangedRow.changedRows(Changed.ADDED))) .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(); } }
From source file:io.prestosql.verifier.Validator.java
public String getResultsComparison(int precision) { List<List<Object>> controlResults = controlResult.getResults(); List<List<Object>> testResults = testResult.getResults(); if (valid() || (controlResults == null) || (testResults == null)) { return ""; }/*from w w w . ja va 2s. c o m*/ 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(); } }