@Generates private static <K extends Comparable<? super K>, V> ImmutableSortedMap<K, V> generateImmutableSortedMap(K key, V value) { return ImmutableSortedMap.of(key, value); }
static <K, V> ImmutableSortedMap<K, V> emptyMap(Comparator<? super K> comparator) { if (Ordering.natural().equals(comparator)) { return of(); } else { return new ImmutableSortedMap<>( ImmutableSortedSet.emptySet(comparator), ImmutableList.<V>of()); } }
private NavigableMap<Cut<C>, Range<C>> subMap(Range<Cut<C>> window) { if (!window.isConnected(lowerBoundWindow)) { return ImmutableSortedMap.of(); } else { return new SubRangeSetRangesByLowerBound<C>( lowerBoundWindow.intersection(window), restriction, rangesByLowerBound); } }
public void testOfWithDuplicateKey() { try { ImmutableSortedMap.of("one", 1, "one", 1); fail(); } catch (IllegalArgumentException expected) { } }
private NavigableMap<Cut<C>, Range<C>> subMap(Range<Cut<C>> subWindow) { if (!complementLowerBoundWindow.isConnected(subWindow)) { return ImmutableSortedMap.of(); } else { subWindow = subWindow.intersection(complementLowerBoundWindow); return new ComplementRangesByLowerBound<C>(positiveRangesByLowerBound, subWindow); } }
@SuppressWarnings("unchecked") // varargs public void testHeadMapExclusive() { Map<String, Integer> map = ImmutableSortedMap.of("one", 1, "two", 2, "three", 3).headMap("three", false); assertThat(map.entrySet()).containsExactly(Maps.immutableEntry("one", 1)); }
@SuppressWarnings("unchecked") // varargs public void testTailMapExclusive() { Map<String, Integer> map = ImmutableSortedMap.of("one", 1, "two", 2, "three", 3).tailMap("three", false); assertThat(map.entrySet()).containsExactly(Maps.immutableEntry("two", 2)); }
@SuppressWarnings("unchecked") // varargs public void testSubMapExclusiveExclusive() { Map<String, Integer> map = ImmutableSortedMap.of("one", 1, "two", 2, "three", 3).subMap("one", false, "two", false); assertThat(map.entrySet()).containsExactly(Maps.immutableEntry("three", 3)); }
@SuppressWarnings("unchecked") // varargs public void testSubMapInclusiveInclusive() { Map<String, Integer> map = ImmutableSortedMap.of("one", 1, "two", 2, "three", 3).subMap("one", true, "two", true); assertThat(map.entrySet()) .containsExactly( Maps.immutableEntry("one", 1), Maps.immutableEntry("three", 3), Maps.immutableEntry("two", 2)) .inOrder(); }
@SuppressWarnings("unchecked") // varargs public void testHeadMapInclusive() { Map<String, Integer> map = ImmutableSortedMap.of("one", 1, "two", 2, "three", 3).headMap("three", true); assertThat(map.entrySet()) .containsExactly(Maps.immutableEntry("one", 1), Maps.immutableEntry("three", 3)) .inOrder(); }
@SuppressWarnings("unchecked") // varargs public void testTailMapInclusive() { Map<String, Integer> map = ImmutableSortedMap.of("one", 1, "two", 2, "three", 3).tailMap("three", true); assertThat(map.entrySet()) .containsExactly(Maps.immutableEntry("three", 3), Maps.immutableEntry("two", 2)) .inOrder(); }
@SuppressWarnings("unchecked") // varargs public void testSubMapExclusiveInclusive() { Map<String, Integer> map = ImmutableSortedMap.of("one", 1, "two", 2, "three", 3).subMap("one", false, "two", true); assertThat(map.entrySet()) .containsExactly(Maps.immutableEntry("three", 3), Maps.immutableEntry("two", 2)) .inOrder(); }
public void testMutableValues() { IntHolder holderA = new IntHolder(1); IntHolder holderB = new IntHolder(2); Map<String, IntHolder> map = ImmutableSortedMap.of("a", holderA, "b", holderB); holderA.value = 3; assertTrue(map.entrySet().contains(Maps.immutableEntry("a", new IntHolder(3)))); Map<String, Integer> intMap = ImmutableSortedMap.of("a", 3, "b", 2); assertEquals(intMap.hashCode(), map.entrySet().hashCode()); assertEquals(intMap.hashCode(), map.hashCode()); }
@SuppressWarnings("unchecked") // varargs public void testSubMapInclusiveExclusive() { Map<String, Integer> map = ImmutableSortedMap.of("one", 1, "two", 2, "three", 3).subMap("one", true, "two", false); assertThat(map.entrySet()) .containsExactly(Maps.immutableEntry("one", 1), Maps.immutableEntry("three", 3)) .inOrder(); }
@GwtIncompatible // SerializableTester public void testViewSerialization() { Map<String, Integer> map = ImmutableSortedMap.of("one", 1, "two", 2, "three", 3); SerializableTester.reserializeAndAssert(map.entrySet()); SerializableTester.reserializeAndAssert(map.keySet()); assertEquals( Lists.newArrayList(map.values()), Lists.newArrayList(SerializableTester.reserialize(map.values()))); }
@GwtIncompatible // NavigableMap public void testSubMap_unboundedRange() { ImmutableSortedMap<Integer, Integer> map = ImmutableSortedMap.of(2, 0, 4, 0, 6, 0, 8, 0, 10, 0); assertEquals(map, Maps.subMap(map, Range.<Integer>all())); }
public void testCopyOfImmutableSortedSetDifferentComparator() { Comparator<String> comparator = Ordering.natural().reverse(); Map<String, Integer> original = ImmutableSortedMap.of("one", 1, "two", 2, "three", 3); ImmutableSortedMap<String, Integer> copy = ImmutableSortedMap.copyOf(original, comparator); assertMapEquals(copy, "two", 2, "three", 3, "one", 1); assertSame(copy, ImmutableSortedMap.copyOf(copy, comparator)); assertSame(comparator, copy.comparator()); }