List of usage examples for com.google.common.collect HashMultiset create
public static <E> HashMultiset<E> create(Iterable<? extends E> elements)
From source file:io.airlift.airship.shared.ExtraAssertions.java
public static void assertEqualsNoOrder(Iterable<?> actual, Iterable<?> expected) { if (actual == expected) { return;/*from w w w. j a v a 2s.com*/ } if (actual == null || expected == null) { fail("Collections not equal: expected: " + expected + " and actual: " + actual); } if (!HashMultiset.create(actual).equals(HashMultiset.create(expected))) { fail("Collections differ:\n expected \n " + ERROR_JOINER.join(expected) + "\n actual:\n " + ERROR_JOINER.join(actual)); } }
From source file:org.javafunk.funk.Iterators.java
public static <T> Multiset<T> asMultiset(Iterator<? extends T> iterator) { return HashMultiset.create(asList(iterator)); }
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);/* w ww . ja v a 2s . c om*/ } 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:com.google.testing.util.MoreAsserts.java
/** * Asserts that {@code actual} contains precisely the elements * {@code expected}, in any order. Both collections may contain * duplicates, and this method will only pass if the quantities are * exactly the same./*from w ww .j av a 2s . co m*/ */ public static void assertContentsAnyOrder(String message, Iterable<?> actual, Object... expected) { assertEqualsImpl(message, HashMultiset.create(asList(expected)), HashMultiset.create(actual)); }
From source file:org.javafunk.funk.builders.MultisetBuilder.java
@Override public Multiset<E> build() { return HashMultiset.create(elements); }
From source file:org.javafunk.matchbox.implementations.HasOnlyItemsInAnyOrderMatcher.java
public HasOnlyItemsInAnyOrderMatcher(Iterable<E> expectedMultiset) { this.expectedMultiset = HashMultiset.create(expectedMultiset); }
From source file:com.googlecode.blaisemath.graph.modules.metrics.GraphMetrics.java
/** * Returns computeDistribution of the values of a particular metric * @param <N> metric result type// ww w .jav a 2 s . c o m * @param graph the graph * @param metric metric used to generate values * @return distribution of values */ public static <N> Multiset<N> computeDistribution(Graph graph, GraphNodeMetric<N> metric) { return HashMultiset.create(computeValues(graph, metric)); }
From source file:org.apache.sqoop.test.asserts.HdfsAsserts.java
/** * Verify that mapreduce output (across all files) is as expected. * * @param directory Mapreduce output directory * @param lines Expected lines//from w ww. j a va2 s.co m * @throws IOException */ public static void assertMapreduceOutput(FileSystem fs, String directory, String... lines) throws IOException { Multiset<String> setLines = HashMultiset.create(Arrays.asList(lines)); List<String> notFound = new LinkedList<String>(); Path[] files = HdfsUtils.getOutputMapreduceFiles(fs, directory); for (Path file : files) { BufferedReader br = new BufferedReader(new InputStreamReader(fs.open(file))); String line; while ((line = br.readLine()) != null) { if (!setLines.remove(line)) { notFound.add(line); } } br.close(); } if (!setLines.isEmpty() || !notFound.isEmpty()) { LOG.error("Output do not match expectations."); LOG.error("Expected lines that weren't present in the files:"); LOG.error("\t'" + StringUtils.join(setLines, "'\n\t'") + "'"); LOG.error("Extra lines in files that weren't expected:"); LOG.error("\t'" + StringUtils.join(notFound, "'\n\t'") + "'"); fail("Output do not match expectations."); } }
From source file:com.github.lstephen.ootp.ai.selection.SlotAssignments.java
private SlotAssignments(Iterable<Slot> slots) { this.remaining = HashMultiset.create(slots); }
From source file:com.arpnetworking.tsdaggregator.test.UnorderedRecordEquality.java
/** * Compare two <code>Record</code> instances ignoring the ordering of the * values in each metric.//from w w w .j a v a2s . c o m * * @param r1 First <code>Record</code> instance. * @param r2 Second <code>Record</code> instance. * @return True if and only if <code>Record</code> instances are equal * irregardless of the order of the values of each metric. */ public static boolean equals(final Record r1, final Record r2) { if (!r1.getTime().equals(r2.getTime()) || !r1.getAnnotations().equals(r2.getAnnotations())) { return false; } for (final Map.Entry<String, ? extends Metric> entry : r1.getMetrics().entrySet()) { if (!r2.getMetrics().containsKey(entry.getKey())) { return false; } final Metric m1 = entry.getValue(); final Metric m2 = r2.getMetrics().get(entry.getKey()); if (!m1.getType().equals(m2.getType())) { return false; } final Multiset<Quantity> v1 = HashMultiset.create(m1.getValues()); final Multiset<Quantity> v2 = HashMultiset.create(m2.getValues()); if (!v1.equals(v2)) { return false; } } return true; }