@Override public ImmutableMap<Range<K>, V> asDescendingMapOfRanges() { if (ranges.isEmpty()) { return ImmutableMap.of(); } RegularImmutableSortedSet<Range<K>> rangeSet = new RegularImmutableSortedSet<>(ranges.reverse(), Range.<K>rangeLexOrdering().reverse()); return new ImmutableSortedMap<>(rangeSet, values.reverse()); }
public void testBuilderPutAllVarargs() { ImmutableSetMultimap.Builder<String, Integer> builder = ImmutableSetMultimap.builder(); builder.putAll("foo", 1, 2, 3); builder.putAll("bar", 4, 5); builder.putAll("foo", 6, 7); Multimap<String, Integer> multimap = builder.build(); assertEquals(ImmutableSet.of(1, 2, 3, 6, 7), multimap.get("foo")); assertEquals(ImmutableSet.of(4, 5), multimap.get("bar")); assertEquals(7, multimap.size()); }
public void testNewMultimapValueCollectionMatchesNavigableSet() { Supplier<TreeSet<Integer>> factory = new SortedSetSupplier(); Map<Color, Collection<Integer>> map = Maps.newEnumMap(Color.class); Multimap<Color, Integer> multimap = Multimaps.newMultimap(map, factory); assertTrue(multimap.get(Color.BLUE) instanceof NavigableSet); }
public void testSubRangeMapClear() { RangeMap<Integer, Integer> rangeMap = TreeRangeMap.create(); rangeMap.put(Range.open(3, 7), 1); rangeMap.put(Range.closed(9, 10), 2); rangeMap.put(Range.closed(12, 16), 3); RangeMap<Integer, Integer> sub = rangeMap.subRangeMap(Range.closed(5, 11)); sub.clear(); assertEquals( ImmutableMap.of(Range.open(3, 5), 1, Range.closed(12, 16), 3), rangeMap.asMapOfRanges()); }
public void testCopyOfDuplicateInconsistentWithEquals() { IntegerDiv10 three = new IntegerDiv10(3); IntegerDiv10 eleven = new IntegerDiv10(11); IntegerDiv10 twelve = new IntegerDiv10(12); IntegerDiv10 twenty = new IntegerDiv10(20); List<IntegerDiv10> original = ImmutableList.of(three, eleven, twelve, twenty); Multiset<IntegerDiv10> copy = ImmutableSortedMultiset.copyOf(original); assertTrue(copy.contains(eleven)); assertTrue(copy.contains(twelve)); } }
/** See {@link SynchronizedBiMapTest} for more tests. */ public void testSynchronizedBiMap() { BiMap<String, Integer> bimap = HashBiMap.create(); bimap.put("one", 1); BiMap<String, Integer> sync = Maps.synchronizedBiMap(bimap); bimap.put("two", 2); sync.put("three", 3); assertEquals(ImmutableSet.of(1, 2, 3), bimap.inverse().keySet()); assertEquals(ImmutableSet.of(1, 2, 3), sync.inverse().keySet()); }
public void testContainsAll() { ImmutableSortedSet<Integer> set = ContiguousSet.create(Range.closed(1, 3), integers()); for (Set<Integer> subset : Sets.powerSet(ImmutableSet.of(1, 2, 3))) { assertTrue(set.containsAll(subset)); } for (Set<Integer> subset : Sets.powerSet(ImmutableSet.of(1, 2, 3))) { assertFalse(set.containsAll(Sets.union(subset, ImmutableSet.of(9)))); } assertFalse(set.containsAll((Collection<?>) ImmutableSet.of("blah"))); }
public void testPutCoalescingEmpty() { RangeMap<Integer, Integer> rangeMap = TreeRangeMap.create(); rangeMap.put(Range.closedOpen(0, 1), 1); rangeMap.put(Range.closedOpen(1, 2), 1); assertEquals( ImmutableMap.of(Range.closedOpen(0, 1), 1, Range.closedOpen(1, 2), 1), rangeMap.asMapOfRanges()); rangeMap.putCoalescing(Range.closedOpen(1, 1), 1); // empty range coalesces connected ranges assertEquals(ImmutableMap.of(Range.closedOpen(0, 2), 1), rangeMap.asMapOfRanges()); }
public void testIntersection_empty() { ContiguousSet<Integer> set = ContiguousSet.closed(1, 3); ContiguousSet<Integer> emptySet = ContiguousSet.closedOpen(2, 2); assertEquals(ImmutableSet.of(), set.intersection(emptySet)); assertEquals(ImmutableSet.of(), emptySet.intersection(set)); assertEquals( ImmutableSet.of(), ContiguousSet.create(Range.closed(-5, -1), integers()) .intersection(ContiguousSet.create(Range.open(3, 64), integers()))); }
public void testIntersection() { ContiguousSet<Integer> set = ContiguousSet.create(Range.closed(1, 3), integers()); assertEquals( ImmutableSet.of(1, 2, 3), ContiguousSet.create(Range.open(-1, 4), integers()).intersection(set)); assertEquals( ImmutableSet.of(1, 2, 3), set.intersection(ContiguousSet.create(Range.open(-1, 4), integers()))); assertEquals( ImmutableSet.of(3), set.intersection(ContiguousSet.create(Range.closed(3, 5), integers()))); }
public void testCreate_empty() { assertEquals(ImmutableSet.of(), ContiguousSet.create(Range.closedOpen(1, 1), integers())); assertEquals(ImmutableSet.of(), ContiguousSet.closedOpen(1, 1)); assertEquals(ImmutableSet.of(), ContiguousSet.create(Range.openClosed(5, 5), integers())); assertEquals( ImmutableSet.of(), ContiguousSet.create(Range.lessThan(Integer.MIN_VALUE), integers())); assertEquals( ImmutableSet.of(), ContiguousSet.create(Range.greaterThan(Integer.MAX_VALUE), integers())); }
public void testBuilderPutAllMultimapWithDuplicates() { Multimap<String, Integer> toPut = LinkedListMultimap.create(); toPut.put("foo", 1); toPut.put("bar", 4); toPut.put("foo", 2); toPut.put("foo", 1); toPut.put("bar", 5); ImmutableSetMultimap.Builder<String, Integer> builder = ImmutableSetMultimap.builder(); builder.putAll(toPut); ImmutableSetMultimap<String, Integer> multimap = builder.build(); assertEquals(4, multimap.size()); }
public void testNewMultimapValueCollectionMatchesList() { Supplier<LinkedList<Integer>> factory = new ListSupplier(); Map<Color, Collection<Integer>> map = Maps.newEnumMap(Color.class); Multimap<Color, Integer> multimap = Multimaps.newMultimap(map, factory); assertTrue(multimap.get(Color.BLUE) instanceof List); }
public void testFromRangeOneEnd() { for (BoundType endpointType : BoundType.values()) { assertEquals( GeneralRange.upTo(Ordering.natural(), 3, endpointType), GeneralRange.from(Range.upTo(3, endpointType))); assertEquals( GeneralRange.downTo(Ordering.natural(), 3, endpointType), GeneralRange.from(Range.downTo(3, endpointType))); } }
@SuppressWarnings("unchecked") // varargs! public void testCartesianProductTooBig() { Set<Integer> set = ContiguousSet.create(Range.closed(0, 10000), DiscreteDomain.integers()); try { Sets.cartesianProduct(set, set, set, set, set); fail("Expected IAE"); } catch (IllegalArgumentException expected) { } }
public void testGenerics_gwtCompatible() { ListMultimap<String, Integer> a = MultimapBuilder.hashKeys().arrayListValues().<String, Integer>build(); SortedSetMultimap<String, Integer> b = MultimapBuilder.linkedHashKeys().treeSetValues().<String, Integer>build(); SetMultimap<String, Integer> c = MultimapBuilder.treeKeys(String.CASE_INSENSITIVE_ORDER) .hashSetValues() .<String, Integer>build(); }
public void testSpanTwoRanges() { for (Range<Integer> range1 : RANGES) { for (Range<Integer> range2 : RANGES) { if (!range1.isConnected(range2) || range1.intersection(range2).isEmpty()) { RangeMap<Integer, Integer> rangemap = ImmutableRangeMap.<Integer, Integer>builder().put(range1, 1).put(range2, 2).build(); assertEquals(range1.span(range2), rangemap.span()); } } } }
public void testSubSubRangeMap() { RangeMap<Integer, Integer> rangeMap = TreeRangeMap.create(); rangeMap.put(Range.open(3, 7), 1); rangeMap.put(Range.closed(9, 10), 2); rangeMap.put(Range.closed(12, 16), 3); RangeMap<Integer, Integer> sub1 = rangeMap.subRangeMap(Range.closed(5, 11)); assertEquals( ImmutableMap.of(Range.closedOpen(5, 7), 1, Range.closed(9, 10), 2), sub1.asMapOfRanges()); RangeMap<Integer, Integer> sub2 = sub1.subRangeMap(Range.open(6, 15)); assertEquals( ImmutableMap.of(Range.open(6, 7), 1, Range.closed(9, 10), 2), sub2.asMapOfRanges()); }