Beispiel #1
0
 @Override
 @Test
 public void ifPresentApply() {
   MutableMap<Integer, String> map = new SingletonMap<Integer, String>(1, "1");
   Assert.assertNull(map.ifPresentApply(4, Functions.<String>getPassThru()));
   Assert.assertEquals("1", map.ifPresentApply(1, Functions.<String>getPassThru()));
 }
Beispiel #2
0
 @Override
 @Test
 public void getIfAbsentWith() {
   MutableMap<Integer, String> map = new SingletonMap<Integer, String>(1, "1");
   Assert.assertNull(map.get(4));
   Assert.assertEquals("4", map.getIfAbsentWith(4, Functions.getToString(), 4));
   Assert.assertEquals("1", map.getIfAbsentWith(1, Functions.getToString(), 1));
   Assert.assertEquals(UnifiedMap.newWithKeysValues(1, "1"), map);
 }
 public ImmutableSortedSet<Pair<T, Integer>> zipWithIndex() {
   Comparator<? super T> comparator = this.comparator();
   if (comparator == null) {
     TreeSortedSet<Pair<T, Integer>> pairs =
         TreeSortedSet.newSet(
             Comparators.<Pair<T, Integer>, T>byFunction(
                 Functions.<T>firstOfPair(), Comparators.<T>naturalOrder()));
     return Iterate.zipWithIndex(this, pairs).toImmutable();
   }
   return Iterate.zipWithIndex(
           this, TreeSortedSet.<Pair<T, Integer>>newSet(Comparators.<T>byFirstOfPair(comparator)))
       .toImmutable();
 }
 public <S> ImmutableSortedSet<Pair<T, S>> zip(Iterable<S> that) {
   Comparator<? super T> comparator = this.comparator();
   if (comparator == null) {
     TreeSortedSet<Pair<T, S>> pairs =
         TreeSortedSet.newSet(
             Comparators.<Pair<T, S>, T>byFunction(
                 Functions.<T>firstOfPair(), Comparators.<T>naturalOrder()));
     return Iterate.zip(this, that, pairs).toImmutable();
   }
   return Iterate.zip(
           this, that, TreeSortedSet.<Pair<T, S>>newSet(Comparators.<T>byFirstOfPair(comparator)))
       .toImmutable();
 }
Beispiel #5
0
 @Override
 @Test
 public void getIfAbsentPutWith() {
   final MutableMap<Integer, String> map = new SingletonMap<Integer, String>(1, "1");
   Verify.assertThrows(
       UnsupportedOperationException.class,
       new Runnable() {
         public void run() {
           map.getIfAbsentPutWith(4, Functions.getToString(), 4);
         }
       });
   Assert.assertEquals("1", map.getIfAbsentPutWith(1, Functions.getToString(), 1));
 }