コード例 #1
0
 @Test
 public void toSortedMap() {
   LazyIterable<Integer> integers = this.newWith(1, 2, 3);
   MutableSortedMap<Integer, String> map =
       integers.toSortedMap(Functions.getIntegerPassThru(), Functions.getToString());
   Verify.assertMapsEqual(TreeSortedMap.newMapWith(1, "1", 2, "2", 3, "3"), map);
   Verify.assertListsEqual(FastList.newListWith(1, 2, 3), map.keySet().toList());
 }
コード例 #2
0
  @Test
  public void toSortedMap() {
    MutableSortedMap<Integer, String> map =
        this.newBag().toSortedMap(Integer::valueOf, Functions.<String>getPassThru());

    Verify.assertMapsEqual(
        this.newBag().toMap(Integer::valueOf, Functions.<String>getPassThru()), map);
    Verify.assertListsEqual(Interval.oneTo(this.numKeys()), map.keySet().toList());
  }
コード例 #3
0
 @Override
 @Test
 public void toSortedMap_with_comparator() {
   MutableSortedMap<String, String> map =
       this.newBag()
           .toSortedMap(
               Comparators.<String>reverseNaturalOrder(),
               Functions.getStringPassThru(),
               Functions.getStringPassThru());
   Verify.assertEmpty(map);
   Verify.assertInstanceOf(TreeSortedMap.class, map);
   Assert.assertEquals(Comparators.<String>reverseNaturalOrder(), map.comparator());
 }
コード例 #4
0
  @Test
  public void toSortedMap_with_comparator() {
    MutableSortedMap<Integer, String> map =
        this.newBag()
            .toSortedMap(
                Comparators.<Integer>reverseNaturalOrder(),
                Integer::valueOf,
                Functions.<String>getPassThru());

    Verify.assertMapsEqual(
        this.newBag().toMap(Integer::valueOf, Functions.<String>getPassThru()), map);
    Verify.assertListsEqual(Interval.fromTo(this.numKeys(), 1), map.keySet().toList());
  }
コード例 #5
0
 @Test
 public void toSortedMap_with_comparator() {
   LazyIterable<Integer> integers = this.newWith(1, 2, 3);
   MutableSortedMap<Integer, String> map =
       integers.toSortedMap(
           Comparators.<Integer>reverseNaturalOrder(),
           Functions.getIntegerPassThru(),
           Functions.getToString());
   Verify.assertMapsEqual(
       TreeSortedMap.newMapWith(
           Comparators.<Integer>reverseNaturalOrder(), 1, "1", 2, "2", 3, "3"),
       map);
   Verify.assertListsEqual(FastList.newListWith(3, 2, 1), map.keySet().toList());
 }