Java Code Examples for java.util.SortedMap#toString()

The following examples show how to use java.util.SortedMap#toString() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ImmutableBitSetTest.java    From calcite with Apache License 2.0 5 votes vote down vote up
/** Tests the method
 * {@link org.apache.calcite.util.BitSets#closure(java.util.SortedMap)}. */
@Test void testClosure() {
  final SortedMap<Integer, ImmutableBitSet> empty = new TreeMap<>();
  assertThat(ImmutableBitSet.closure(empty), equalTo(empty));

  // Currently you need an entry for each position, otherwise you get an NPE.
  // We should fix that.
  final SortedMap<Integer, ImmutableBitSet> map = new TreeMap<>();
  map.put(0, ImmutableBitSet.of(3));
  map.put(1, ImmutableBitSet.of());
  map.put(2, ImmutableBitSet.of(7));
  map.put(3, ImmutableBitSet.of(4, 12));
  map.put(4, ImmutableBitSet.of());
  map.put(5, ImmutableBitSet.of());
  map.put(6, ImmutableBitSet.of());
  map.put(7, ImmutableBitSet.of());
  map.put(8, ImmutableBitSet.of());
  map.put(9, ImmutableBitSet.of());
  map.put(10, ImmutableBitSet.of());
  map.put(11, ImmutableBitSet.of());
  map.put(12, ImmutableBitSet.of());
  final String original = map.toString();
  final String expected =
      "{0={3, 4, 12}, 1={}, 2={7}, 3={3, 4, 12}, 4={4, 12}, 5={}, 6={}, 7={7}, 8={}, 9={}, 10={}, 11={}, 12={4, 12}}";
  assertThat(ImmutableBitSet.closure(map).toString(), equalTo(expected));
  assertThat("argument modified", map.toString(), equalTo(original));

  // Now a similar map with missing entries. Same result.
  final SortedMap<Integer, ImmutableBitSet> map2 = new TreeMap<>();
  map2.put(0, ImmutableBitSet.of(3));
  map2.put(2, ImmutableBitSet.of(7));
  map2.put(3, ImmutableBitSet.of(4, 12));
  map2.put(9, ImmutableBitSet.of());
  final String original2 = map2.toString();
  assertThat(ImmutableBitSet.closure(map2).toString(), equalTo(expected));
  assertThat("argument modified", map2.toString(), equalTo(original2));
}
 
Example 2
Source File: BitSetsTest.java    From calcite with Apache License 2.0 5 votes vote down vote up
/**
 * Tests the method {@link BitSets#closure(java.util.SortedMap)}
 */
@Test void testClosure() {
  final SortedMap<Integer, BitSet> empty = new TreeMap<>();
  assertThat(BitSets.closure(empty), equalTo(empty));

  // Map with an an entry for each position.
  final SortedMap<Integer, BitSet> map = new TreeMap<>();
  map.put(0, BitSets.of(3));
  map.put(1, BitSets.of());
  map.put(2, BitSets.of(7));
  map.put(3, BitSets.of(4, 12));
  map.put(4, BitSets.of());
  map.put(5, BitSets.of());
  map.put(6, BitSets.of());
  map.put(7, BitSets.of());
  map.put(8, BitSets.of());
  map.put(9, BitSets.of());
  map.put(10, BitSets.of());
  map.put(11, BitSets.of());
  map.put(12, BitSets.of());
  final String original = map.toString();
  final String expected =
      "{0={3, 4, 12}, 1={}, 2={7}, 3={3, 4, 12}, 4={4, 12}, 5={}, 6={}, 7={7}, 8={}, 9={}, 10={}, 11={}, 12={4, 12}}";
  assertThat(BitSets.closure(map).toString(), equalTo(expected));
  assertThat("argument modified", map.toString(), equalTo(original));

  // Now a similar map with missing entries. Same result.
  final SortedMap<Integer, BitSet> map2 = new TreeMap<>();
  map2.put(0, BitSets.of(3));
  map2.put(2, BitSets.of(7));
  map2.put(3, BitSets.of(4, 12));
  map2.put(9, BitSets.of());
  final String original2 = map2.toString();
  assertThat(BitSets.closure(map2).toString(), equalTo(expected));
  assertThat("argument modified", map2.toString(), equalTo(original2));
}