if (multimap instanceof SortedSetMultimap) { unmodifiable = Multimaps.unmodifiableSortedSetMultimap((SortedSetMultimap<String, Integer>) multimap); } else if (multimap instanceof SetMultimap) { unmodifiable = Multimaps.unmodifiableSetMultimap((SetMultimap<String, Integer>) multimap);
/** Test that creating one TreeMultimap from a SortedSetMultimap uses natural ordering. */ public void testCreateFromSortedSetMultimap() { SortedSetMultimap<Double, Double> tree = TreeMultimap.create(KEY_COMPARATOR, VALUE_COMPARATOR); tree.put(1.0, 2.0); tree.put(2.0, 3.0); tree.put(3.0, 4.0); tree.put(4.0, 5.0); SortedSetMultimap<Double, Double> sorted = Multimaps.unmodifiableSortedSetMultimap(tree); TreeMultimap<Double, Double> copyFromSorted = TreeMultimap.create(sorted); assertEquals(tree, copyFromSorted); assertSame(Ordering.natural(), copyFromSorted.keyComparator()); assertSame(Ordering.natural(), copyFromSorted.valueComparator()); assertSame(Ordering.natural(), copyFromSorted.get(1.0).comparator()); }
/** * Creates with the given assignment. * * @param name Name of the resource. * @param assignments Set of assignments carries by this object. */ public ResourceAssignment(String name, Multimap<Discoverable, PartitionReplica> assignments) { this.name = name; TreeMultimap<Discoverable, PartitionReplica> multimap = TreeMultimap.create(DiscoverableComparator.COMPARATOR, PartitionReplica.COMPARATOR); multimap.putAll(assignments); this.assignments = Multimaps.unmodifiableSortedSetMultimap(multimap); }
/** * Creates with the given assignment. * * @param name Name of the resource. * @param assignments Set of assignments carries by this object. */ public ResourceAssignment(String name, Multimap<Discoverable, PartitionReplica> assignments) { this.name = name; TreeMultimap<Discoverable, PartitionReplica> multimap = TreeMultimap.create(DiscoverableComparator.COMPARATOR, PartitionReplica.COMPARATOR); multimap.putAll(assignments); this.assignments = Multimaps.unmodifiableSortedSetMultimap(multimap); }
unmodifiable = Multimaps.unmodifiableSortedSetMultimap( (SortedSetMultimap<String, Integer>) multimap); } else if (multimap instanceof SetMultimap) {
/** * Test that creating one TreeMultimap from a SortedSetMultimap uses natural * ordering. */ public void testCreateFromSortedSetMultimap() { SortedSetMultimap<Double, Double> tree = TreeMultimap.create(KEY_COMPARATOR, VALUE_COMPARATOR); tree.put(1.0, 2.0); tree.put(2.0, 3.0); tree.put(3.0, 4.0); tree.put(4.0, 5.0); SortedSetMultimap<Double, Double> sorted = Multimaps.unmodifiableSortedSetMultimap(tree); TreeMultimap<Double, Double> copyFromSorted = TreeMultimap.create(sorted); assertEquals(tree, copyFromSorted); assertSame(Ordering.natural(), copyFromSorted.keyComparator()); assertSame(Ordering.natural(), copyFromSorted.valueComparator()); assertSame(Ordering.natural(), copyFromSorted.get(1.0).comparator()); }