예제 #1
0
 @Test
 public void collectCharWithTarget() {
   CharHashBag target = new CharHashBag();
   CharHashBag result =
       this.newBag().collectChar((CharFunction<String>) string -> string.charAt(0), target);
   Assert.assertSame("Target sent as parameter not returned", target, result);
   Assert.assertEquals(this.numKeys(), result.sizeDistinct());
   for (int i = 1; i <= this.numKeys(); i++) {
     Assert.assertEquals(i, result.occurrencesOf((char) ((int) '0' + i)));
   }
 }
 @Override
 @Test
 public void collectChar() {
   MutableBag<Integer> integers = UnmodifiableBag.of(HashBag.newBagWith(1, 2, 2, 3, 3, 3));
   Assert.assertEquals(
       CharHashBag.newBagWith('A', 'B', 'B', 'C', 'C', 'C'),
       integers.collectChar(
           new CharFunction<Integer>() {
             public char charValueOf(Integer integer) {
               return (char) (integer.intValue() + 64);
             }
           }));
 }