コード例 #1
0
 @Test
 public void rejectWith() {
   ImmutableCollection<Integer> integers = this.classUnderTest();
   Assert.assertEquals(
       this.<Integer>newMutable().withAll(integers).reject(IntegerPredicates.isOdd()),
       integers.rejectWith(Predicates2.in(), iList(1, 3, 5, 7, 9)));
 }
コード例 #2
0
 @Test
 public void partition() {
   ImmutableCollection<Integer> integers = this.classUnderTest();
   PartitionImmutableCollection<Integer> partition = integers.partition(IntegerPredicates.isOdd());
   Assert.assertEquals(integers.select(IntegerPredicates.isOdd()), partition.getSelected());
   Assert.assertEquals(integers.select(IntegerPredicates.isEven()), partition.getRejected());
 }
コード例 #3
0
 @Test
 public void collectIf() {
   ImmutableCollection<Integer> integers = this.classUnderTest();
   Assert.assertEquals(
       integers,
       integers.collectIf(Predicates.instanceOf(Integer.class), Functions.getIntegerPassThru()));
 }
コード例 #4
0
 @Test
 public void collectBoolean() {
   ImmutableCollection<Integer> integers = this.classUnderTest();
   ImmutableBooleanCollection immutableCollection =
       integers.collectBoolean(PrimitiveFunctions.integerIsPositive());
   Verify.assertSize(1, immutableCollection);
 }
コード例 #5
0
 @Test
 public void injectInto() {
   ImmutableCollection<Integer> integers = this.classUnderTest();
   Integer result = integers.injectInto(0, AddFunction.INTEGER);
   Assert.assertEquals(
       FastList.newList(integers).injectInto(0, AddFunction.INTEGER_TO_INT), result.intValue());
 }
コード例 #6
0
 @Test
 public void countWith() {
   ImmutableCollection<Integer> integers = this.classUnderTest();
   Assert.assertEquals(
       integers.size(), integers.countWith(Predicates2.instanceOf(), Integer.class));
   Assert.assertEquals(0, integers.countWith(Predicates2.instanceOf(), String.class));
 }
コード例 #7
0
 @Test
 public void detectWith() {
   ImmutableCollection<Integer> integers = this.classUnderTest();
   Assert.assertEquals(
       Integer.valueOf(1), integers.detectWith(Predicates2.equal(), Integer.valueOf(1)));
   Assert.assertNull(
       integers.detectWith(Predicates2.equal(), Integer.valueOf(integers.size() + 1)));
 }
コード例 #8
0
 @Test
 public void collectShort() {
   ImmutableCollection<Integer> integers = this.classUnderTest();
   ImmutableShortCollection immutableCollection =
       integers.collectShort(PrimitiveFunctions.unboxIntegerToShort());
   Verify.assertSize(integers.size(), immutableCollection);
   Assert.assertEquals(integers, immutableCollection.collect(Integer::valueOf));
 }
コード例 #9
0
 @Test
 public void toArray() {
   ImmutableCollection<Integer> integers = this.classUnderTest();
   MutableList<Integer> copy = FastList.newList(integers);
   Assert.assertArrayEquals(integers.toArray(), copy.toArray());
   Assert.assertArrayEquals(
       integers.toArray(new Integer[integers.size()]), copy.toArray(new Integer[integers.size()]));
 }
コード例 #10
0
 @Test
 public void toSortedList() {
   ImmutableCollection<Integer> integers = this.classUnderTest();
   MutableList<Integer> copy = FastList.newList(integers);
   MutableList<Integer> list = integers.toSortedList(Collections.<Integer>reverseOrder());
   Assert.assertEquals(copy.sortThis(Collections.<Integer>reverseOrder()), list);
   MutableList<Integer> list2 = integers.toSortedList();
   Assert.assertEquals(copy.sortThis(), list2);
 }
コード例 #11
0
 @Test
 public void toSortedSetWithComparator() {
   ImmutableCollection<Integer> integers = this.classUnderTest();
   MutableSortedSet<Integer> set =
       integers.toSortedSet(Comparators.<Integer>reverseNaturalOrder());
   Assert.assertEquals(integers.toSet(), set);
   Assert.assertEquals(
       integers.toSortedList(Comparators.<Integer>reverseNaturalOrder()), set.toList());
 }
コード例 #12
0
 @Test
 public void detectWithIfNone() {
   ImmutableCollection<Integer> integers = this.classUnderTest();
   Integer sum = Integer.valueOf(integers.size() + 1);
   Function0<Integer> function = new PassThruFunction0<Integer>(sum);
   Assert.assertEquals(
       Integer.valueOf(1),
       integers.detectWithIfNone(Predicates2.equal(), Integer.valueOf(1), function));
   Assert.assertEquals(sum, integers.detectWithIfNone(Predicates2.equal(), sum, function));
 }
コード例 #13
0
 @Test
 public void collectLong() {
   ImmutableCollection<Integer> integers = this.classUnderTest();
   ImmutableLongCollection immutableCollection =
       integers.collectLong(PrimitiveFunctions.unboxIntegerToLong());
   Verify.assertSize(integers.size(), immutableCollection);
   Assert.assertEquals(
       integers,
       immutableCollection.collect(longParameter -> Integer.valueOf((int) longParameter)));
 }
コード例 #14
0
  @Test
  public void collectWith() {
    ImmutableCollection<Integer> integers = this.classUnderTest();
    ImmutableCollection<String> expected =
        integers.collect(Functions.chain(Functions.getToString(), StringFunctions.append("!")));
    ImmutableCollection<String> actual =
        integers.collectWith((argument1, argument2) -> argument1 + argument2, "!");

    Assert.assertEquals(expected, actual);
  }
コード例 #15
0
 @Test
 public void collect_target() {
   ImmutableCollection<Integer> integers = this.classUnderTest();
   MutableCollection<String> strings = this.<String>newMutable();
   integers.forEach(
       (Procedure<Integer>)
           each -> {
             strings.add(each.toString());
           });
   MutableCollection<String> target = this.<String>newMutable();
   MutableCollection<String> actual = integers.collect(Functions.getToString(), target);
   Assert.assertEquals(strings, actual);
   Assert.assertSame(target, actual);
 }
コード例 #16
0
 @Test
 public void iterator() {
   ImmutableCollection<Integer> integers = this.classUnderTest();
   Iterator<Integer> iterator = integers.iterator();
   for (int i = 0; iterator.hasNext(); i++) {
     Integer integer = iterator.next();
     Assert.assertEquals(i + 1, integer.intValue());
   }
   Verify.assertThrows(
       NoSuchElementException.class,
       (Runnable)
           () -> {
             iterator.next();
           });
 }
コード例 #17
0
  @Test
  public void collectWith_target() {
    ImmutableCollection<Integer> integers = this.classUnderTest();
    MutableCollection<String> expected =
        this.<String>newMutable()
            .with("?")
            .withAll(
                integers.collect(
                    Functions.chain(Functions.getToString(), StringFunctions.append("!"))));
    MutableCollection<String> targetCollection = this.<String>newMutable().with("?");
    MutableCollection<String> actual =
        integers.collectWith(
            (argument1, argument2) -> argument1 + argument2, "!", targetCollection);

    Assert.assertEquals(expected, actual);
    Assert.assertSame(targetCollection, actual);
  }
コード例 #18
0
 @Test
 public void toSortedSet() {
   ImmutableCollection<Integer> integers = this.classUnderTest();
   MutableSortedSet<Integer> set = integers.toSortedSet();
   Verify.assertListsEqual(integers.toSortedList(), set.toList());
 }
コード例 #19
0
 @Test
 public void selectInstancesOf() {
   ImmutableCollection<Integer> integers = this.classUnderTest();
   ImmutableCollection<Integer> result = integers.selectInstancesOf(Integer.class);
   Assert.assertEquals(integers, result);
 }
コード例 #20
0
 @Test
 public void reject() {
   ImmutableCollection<Integer> integers = this.classUnderTest();
   Verify.assertIterableEmpty(integers.reject(Predicates.lessThan(integers.size() + 1)));
   Assert.assertEquals(integers, integers.reject(Predicates.greaterThan(integers.size())));
 }
コード例 #21
0
 @Test
 public void isEmpty() {
   ImmutableCollection<Integer> immutableCollection = this.classUnderTest();
   Assert.assertFalse(immutableCollection.isEmpty());
   Assert.assertTrue(immutableCollection.notEmpty());
 }
コード例 #22
0
 @Test
 public void getLast() {
   ImmutableCollection<Integer> integers = this.classUnderTest();
   Assert.assertEquals(Integer.valueOf(integers.size()), integers.getLast());
 }
コード例 #23
0
 @Test
 public void collect() {
   ImmutableCollection<Integer> integers = this.classUnderTest();
   Assert.assertEquals(integers, integers.collect(Functions.getIntegerPassThru()));
 }
コード例 #24
0
 @Test
 public void toSortedSetBy() {
   ImmutableCollection<Integer> integers = this.classUnderTest();
   MutableSortedSet<Integer> set = integers.toSortedSetBy(Functions.getToString());
   Verify.assertSortedSetsEqual(TreeSortedSet.newSet(integers), set);
 }
コード例 #25
0
 @Test
 public void anySatisfyWith() {
   ImmutableCollection<Integer> integers = this.classUnderTest();
   Assert.assertFalse(integers.anySatisfyWith(Predicates2.instanceOf(), String.class));
   Assert.assertTrue(integers.anySatisfyWith(Predicates2.instanceOf(), Integer.class));
 }
コード例 #26
0
 @Test
 public void allSatisfy() {
   ImmutableCollection<Integer> integers = this.classUnderTest();
   Assert.assertTrue(integers.allSatisfy(Predicates.instanceOf(Integer.class)));
   Assert.assertFalse(integers.allSatisfy(Predicates.equal(0)));
 }
コード例 #27
0
 @Test
 public void noneSatisfy() {
   ImmutableCollection<Integer> integers = this.classUnderTest();
   Assert.assertTrue(integers.noneSatisfy(Predicates.instanceOf(String.class)));
   Assert.assertFalse(integers.noneSatisfy(Predicates.equal(1)));
 }