コード例 #1
0
 @Test
 public void selectByOccurrences() {
   MutableBag<Integer> integers =
       UnmodifiableBag.of(HashBag.newBagWith(1, 1, 1, 1, 2, 2, 2, 3, 3, 4));
   Assert.assertEquals(
       iBag(1, 1, 1, 1, 3, 3), integers.selectByOccurrences(IntPredicates.isEven()));
 }
コード例 #2
0
 @Override
 @Test
 public void collectShort() {
   MutableBag<Integer> integers = UnmodifiableBag.of(HashBag.newBagWith(1, 2, 2, 3, 3, 3));
   Assert.assertEquals(
       ShortHashBag.newBagWith((short) 1, (short) 2, (short) 2, (short) 3, (short) 3, (short) 3),
       integers.collectShort(PrimitiveFunctions.unboxIntegerToShort()));
 }
コード例 #3
0
 @Override
 @Test
 public void collectLong() {
   MutableBag<Integer> integers = UnmodifiableBag.of(HashBag.newBagWith(1, 2, 2, 3, 3, 3));
   Assert.assertEquals(
       LongHashBag.newBagWith(1L, 2L, 2L, 3L, 3L, 3L),
       integers.collectLong(PrimitiveFunctions.unboxIntegerToLong()));
 }
コード例 #4
0
 @Override
 @Test
 public void collectFloat() {
   MutableBag<Integer> integers = UnmodifiableBag.of(HashBag.newBagWith(1, 2, 2, 3, 3, 3));
   Assert.assertEquals(
       FloatHashBag.newBagWith(1.0f, 2.0f, 2.0f, 3.0f, 3.0f, 3.0f),
       integers.collectFloat(PrimitiveFunctions.unboxIntegerToFloat()));
 }
コード例 #5
0
 @Override
 @Test
 public void collectDouble() {
   MutableBag<Integer> integers = UnmodifiableBag.of(HashBag.newBagWith(1, 2, 2, 3, 3, 3));
   Assert.assertEquals(
       DoubleHashBag.newBagWith(1.0d, 2.0d, 2.0d, 3.0d, 3.0d, 3.0d),
       integers.collectDouble(PrimitiveFunctions.unboxIntegerToDouble()));
 }
コード例 #6
0
 @Override
 @Test
 public void collectByte() {
   MutableBag<Integer> integers = UnmodifiableBag.of(HashBag.newBagWith(1, 2, 2, 3, 3, 3));
   Assert.assertEquals(
       ByteHashBag.newBagWith((byte) 1, (byte) 2, (byte) 2, (byte) 3, (byte) 3, (byte) 3),
       integers.collectByte(PrimitiveFunctions.unboxIntegerToByte()));
 }
コード例 #7
0
 @Override
 @Test
 public void collectBoolean() {
   MutableBag<Integer> integers = UnmodifiableBag.of(HashBag.newBagWith(0, 1, 2, 2));
   Assert.assertEquals(
       BooleanHashBag.newBagWith(false, true, true, true),
       integers.collectBoolean(PrimitiveFunctions.integerIsPositive()));
 }
コード例 #8
0
 @Test
 public void forEachKeyValue() {
   MutableBag<String> collection = Bags.mutable.of();
   Multimap<Integer, String> multimap =
       this.newMultimapWithKeysValues(1, "One", 2, "Two", 3, "Three");
   multimap.forEachKeyValue((key, value) -> collection.add(key + value));
   Assert.assertEquals(HashBag.newBagWith("1One", "2Two", "3Three"), collection);
 }
コード例 #9
0
 @Test
 public void equalsAndHashCode() {
   ImmutableBag<String> immutable = this.newBag();
   MutableBag<String> mutable = HashBag.newBag(immutable);
   Verify.assertEqualsAndHashCode(immutable, mutable);
   Assert.assertNotEquals(immutable, FastList.newList(mutable));
   Assert.assertEquals(this.newBag().toMapOfItemToCount().hashCode(), this.newBag().hashCode());
   Assert.assertNotEquals(immutable, mutable.with("5").without("1"));
 }
コード例 #10
0
 @Test
 public void forEachWith() {
   MutableBag<String> result = Bags.mutable.of();
   ImmutableBag<String> bag = this.newBag();
   bag.forEachWith(
       (argument1, argument2) -> {
         result.add(argument1 + argument2);
       },
       "");
   Assert.assertEquals(bag, result);
 }
コード例 #11
0
  @Test
  public void iterator() {
    ImmutableBag<String> strings = this.newBag();
    MutableBag<String> result = Bags.mutable.of();
    Iterator<String> iterator = strings.iterator();
    for (int i = 0; iterator.hasNext(); i++) {
      String string = iterator.next();
      result.add(string);
    }
    Assert.assertEquals(strings, result);

    Verify.assertThrows(NoSuchElementException.class, iterator::next);
  }
コード例 #12
0
 @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);
             }
           }));
 }
コード例 #13
0
 @Test
 public void toImmutable() {
   MutableBag<?> bag = this.getCollection();
   Verify.assertInstanceOf(ImmutableBag.class, bag.toImmutable());
 }
コード例 #14
0
 @Test
 public void asSynchronized() {
   MutableBag<?> bag = this.getCollection();
   Verify.assertInstanceOf(SynchronizedBag.class, bag.asSynchronized());
 }
コード例 #15
0
 @Test
 public void asUnmodifiable() {
   MutableBag<?> bag = this.getCollection();
   Verify.assertInstanceOf(UnmodifiableBag.class, bag.asUnmodifiable());
 }
コード例 #16
0
 @Test
 public void selectInstancesOf() {
   MutableBag<Number> numbers = UnmodifiableBag.of(HashBag.<Number>newBagWith(1, 2.0, 3, 4.0, 5));
   Assert.assertEquals(iBag(1, 3, 5), numbers.selectInstancesOf(Integer.class));
   Assert.assertEquals(iBag(1, 2.0, 3, 4.0, 5), numbers.selectInstancesOf(Number.class));
 }