private void basicReject(RichIterable<Integer> iterable) {
   Collection<Integer> actual1 = ParallelIterate.reject(iterable, Predicates.greaterThan(10000));
   Collection<Integer> actual2 =
       ParallelIterate.reject(
           iterable,
           Predicates.greaterThan(10000),
           HashBag.<Integer>newBag(),
           3,
           this.executor,
           true);
   Collection<Integer> actual3 =
       ParallelIterate.reject(iterable, Predicates.greaterThan(10000), true);
   RichIterable<Integer> expected = iterable.reject(Predicates.greaterThan(10000));
   Assert.assertEquals(
       expected.getClass().getSimpleName() + '/' + actual1.getClass().getSimpleName(),
       expected,
       actual1);
   Assert.assertEquals(
       expected.getClass().getSimpleName() + '/' + actual2.getClass().getSimpleName(),
       expected.toBag(),
       actual2);
   Assert.assertEquals(
       expected.getClass().getSimpleName() + '/' + actual3.getClass().getSimpleName(),
       expected.toBag(),
       HashBag.newBag(actual3));
 }
  @Test
  public void noneSatisfy() {
    ImmutableSortedMap<String, String> map = new ImmutableEmptySortedMap<String, String>();

    Assert.assertTrue(map.noneSatisfy(Predicates.instanceOf(Integer.class)));
    Assert.assertTrue(map.noneSatisfy(Predicates.equal("Monkey")));
  }
  @Test
  public void anySatisfy() {
    ImmutableSortedMap<String, String> map = new ImmutableEmptySortedMap<String, String>();

    Assert.assertFalse(map.anySatisfy(Predicates.instanceOf(String.class)));
    Assert.assertFalse(map.anySatisfy(Predicates.equal("Monkey")));
  }
 @Test
 public void detectIndexSmallList() {
   ArrayList<Integer> list = new ArrayList<Integer>(Interval.toReverseList(1, 5));
   Assert.assertEquals(4, ArrayListIterate.detectIndex(list, Predicates.equal(1)));
   Assert.assertEquals(0, Iterate.detectIndex(list, Predicates.equal(5)));
   Assert.assertEquals(-1, Iterate.detectIndex(list, Predicates.equal(10)));
 }
Exemplo n.º 5
0
 @Test
 public void reject() {
   ImmutableBag<String> strings = this.newBag();
   Verify.assertIterableEmpty(strings.reject(Predicates.greaterThan("0")));
   Assert.assertEquals(strings, strings.reject(Predicates.lessThan("0")));
   Verify.assertIterableSize(strings.size() - 1, strings.reject(Predicates.lessThan("2")));
 }
Exemplo n.º 6
0
 @Test
 public void rejectToTarget() {
   ImmutableBag<String> strings = this.newBag();
   Assert.assertEquals(
       strings, strings.reject(Predicates.lessThan("0"), FastList.<String>newList()).toBag());
   Verify.assertEmpty(strings.reject(Predicates.greaterThan("0"), FastList.<String>newList()));
 }
 @Test
 public void detectIndexOver100() {
   ArrayList<Integer> list = new ArrayList<Integer>(Interval.toReverseList(1, 101));
   Assert.assertEquals(100, ArrayListIterate.detectIndex(list, Predicates.equal(1)));
   Assert.assertEquals(0, Iterate.detectIndex(list, Predicates.equal(101)));
   Assert.assertEquals(-1, Iterate.detectIndex(list, Predicates.equal(200)));
 }
 private void basicCount(RichIterable<Integer> listIterable) {
   int actual1 = ParallelIterate.count(listIterable, Predicates.greaterThan(10000));
   int actual2 =
       ParallelIterate.count(listIterable, Predicates.greaterThan(10000), 11, this.executor);
   Assert.assertEquals(10000, actual1);
   Assert.assertEquals(10000, actual2);
 }
 @Test
 public void detectIfNone() {
   ArrayList<Integer> list = this.getIntegerList();
   Assert.assertEquals(
       Integer.valueOf(7), ArrayListIterate.detectIfNone(list, Predicates.equal(6), 7));
   Assert.assertEquals(
       Integer.valueOf(2), ArrayListIterate.detectIfNone(list, Predicates.equal(2), 7));
 }
Exemplo n.º 10
0
 @Test
 public void select() {
   ImmutableBag<String> strings = this.newBag();
   Verify.assertContainsAll(
       FastList.newList(strings.select(Predicates.greaterThan("0"))), strings.toArray());
   Verify.assertIterableEmpty(strings.select(Predicates.lessThan("0")));
   Verify.assertIterableSize(strings.size() - 1, strings.select(Predicates.greaterThan("1")));
 }
 @Test
 public void detectIfNoneWithBlock() {
   Function0<Integer> function = new PassThruFunction0<Integer>(9);
   Assert.assertEquals(
       Integer.valueOf(3), this.lazyIterable.detectIfNone(Predicates.equal(3), function));
   Assert.assertEquals(
       Integer.valueOf(9), this.lazyIterable.detectIfNone(Predicates.equal(8), function));
 }
 @Test
 public void testSelect() {
   Assert.assertEquals(
       ArrayStack.newStackFromTopToBottom(2, 3),
       this.unmodifiableStack.select(Predicates.greaterThan(1)));
   Verify.assertSize(
       3,
       this.unmodifiableStackString.select(Predicates.alwaysTrue(), FastList.<String>newList()));
 }
 @Test
 public void detectIfNone() {
   ImmutableCollection<Integer> integers = this.classUnderTest();
   Function0<Integer> function = new PassThruFunction0<Integer>(integers.size() + 1);
   Assert.assertEquals(Integer.valueOf(1), integers.detectIfNone(Predicates.equal(1), function));
   Assert.assertEquals(
       Integer.valueOf(integers.size() + 1),
       integers.detectIfNone(Predicates.equal(integers.size() + 1), function));
 }
 @Test
 public void detect() {
   ArrayList<Integer> list = this.getIntegerList();
   Assert.assertEquals(Integer.valueOf(1), ArrayListIterate.detect(list, Predicates.equal(1)));
   //noinspection CachedNumberConstructorCall,UnnecessaryBoxing
   ArrayList<Integer> list2 =
       this.newArrayList(1, new Integer(2), 2); // test relies on having a unique instance of "2"
   Assert.assertSame(list2.get(1), ArrayListIterate.detect(list2, Predicates.equal(2)));
 }
 @Test
 public void toArray() {
   Assert.assertArrayEquals(
       FastList.newListWith(1, 2).toArray(),
       this.lazyIterable.select(Predicates.lessThan(3)).toArray());
   Assert.assertArrayEquals(
       FastList.newListWith(1, 2).toArray(),
       this.lazyIterable.select(Predicates.lessThan(3)).toArray(new Object[2]));
 }
Exemplo n.º 16
0
  @Test
  public void partition() {
    ImmutableBag<String> strings = this.newBag();
    PartitionImmutableBag<String> partition = strings.partition(Predicates.greaterThan("0"));
    Assert.assertEquals(strings, partition.getSelected());
    Verify.assertIterableEmpty(partition.getRejected());

    Verify.assertIterableSize(
        strings.size() - 1, strings.partition(Predicates.greaterThan("1")).getSelected());
  }
 @Override
 @Test
 public void forEach() {
   super.forEach();
   MutableList<Integer> list = FastList.newList();
   CompositeFastList<Integer> iterables = new CompositeFastList<Integer>();
   iterables.addComposited(Interval.oneTo(5).toList());
   iterables.addComposited(Interval.fromTo(6, 10).toList());
   iterables.forEach(CollectionAddProcedure.on(list));
   Verify.assertSize(10, list);
   Verify.assertAllSatisfy(list, Predicates.greaterThan(0).and(Predicates.lessThan(11)));
 }
 @Override
 @Test
 public void forEachWith() {
   super.forEachWith();
   MutableList<Integer> list = FastList.newList();
   CompositeFastList<Integer> iterables = new CompositeFastList<Integer>();
   iterables.addComposited(Interval.fromTo(6, 10).toList());
   iterables.addComposited(Interval.oneTo(5).toList());
   iterables.forEachWith((each, parameter) -> list.add(parameter.intValue(), each), 0);
   Verify.assertSize(10, list);
   Verify.assertAllSatisfy(list, Predicates.greaterThan(0).and(Predicates.lessThan(11)));
   Verify.assertStartsWith(list, 5, 4, 3, 2, 1, 10, 9, 8, 7, 6);
 }
 @Override
 @Test
 public void forEachWithIndex() {
   super.forEachWithIndex();
   MutableList<Integer> list = FastList.newList();
   CompositeFastList<Integer> iterables = new CompositeFastList<Integer>();
   iterables.addComposited(Interval.fromTo(6, 10).toList());
   iterables.addComposited(Interval.oneTo(5).toList());
   iterables.forEachWithIndex((each, index) -> list.add(index, each));
   Verify.assertSize(10, list);
   Verify.assertAllSatisfy(list, Predicates.greaterThan(0).and(Predicates.lessThan(11)));
   Verify.assertStartsWith(list, 6, 7, 8, 9, 10, 1, 2, 3, 4, 5);
 }
 @Test
 public void select() {
   ArrayList<Integer> list = this.getIntegerList();
   ArrayList<Integer> results =
       ArrayListIterate.select(list, Predicates.instanceOf(Integer.class));
   Verify.assertSize(5, results);
 }
 @Test
 public void collectIf() {
   ImmutableCollection<Integer> integers = this.classUnderTest();
   Assert.assertEquals(
       integers,
       integers.collectIf(Predicates.instanceOf(Integer.class), Functions.getIntegerPassThru()));
 }
 @Test
 public void selectOver100() {
   ArrayList<Integer> list = new ArrayList<Integer>(Interval.oneTo(101));
   ArrayList<Integer> results =
       ArrayListIterate.select(list, Predicates.instanceOf(Integer.class));
   Verify.assertSize(101, results);
 }
 @Test
 public void reject() {
   ArrayList<Integer> list = this.getIntegerList();
   ArrayList<Integer> results =
       ArrayListIterate.reject(list, Predicates.instanceOf(Integer.class));
   Verify.assertEmpty(results);
 }
 @Test
 public void collectIfOver100() {
   ArrayList<Integer> list = new ArrayList<Integer>(Interval.oneTo(101));
   ArrayList<Class<?>> result =
       ArrayListIterate.collectIf(list, Predicates.equal(101), Functions.getToClass());
   Assert.assertEquals(FastList.newListWith(Integer.class), result);
 }
  @Test
  public void count() {
    ImmutableMap<String, String> map =
        this.newMapWithKeysValues("1", "One", "2", "Two", "3", "Three", "4", "Four");

    int actual = map.count(Predicates.or("One"::equals, "Three"::equals));

    switch (map.size()) {
      case 1:
        Assert.assertEquals(1, actual);
        break;
      case 2:
        Assert.assertEquals(1, actual);
        break;
      case 3:
        Assert.assertEquals(2, actual);
        break;
      case 4:
        Assert.assertEquals(2, actual);
        break;
      default:
        Assert.assertEquals(0, actual);
        break;
    }
  }
 @Test
 public void testForEachWithIndexToArrayUsingFixedArrayList() {
   Integer[] array = new Integer[10];
   List<Integer> list = Arrays.asList(1, 2, 3, 4, 5, 6, 7, 8, 9, 10);
   Assert.assertTrue(ArrayIterate.allSatisfy(array, Predicates.isNull()));
   ParallelIterate.forEachWithIndex(list, (each, index) -> array[index] = each, 1, 2);
   Assert.assertArrayEquals(array, list.toArray(new Integer[list.size()]));
 }
 @Test
 public void testForEachWithIndexToArrayUsingArrayList() {
   Integer[] array = new Integer[200];
   List<Integer> list = new ArrayList<>(Interval.oneTo(200));
   Assert.assertTrue(ArrayIterate.allSatisfy(array, Predicates.isNull()));
   ParallelIterate.forEachWithIndex(list, (each, index) -> array[index] = each, 10, 10);
   Assert.assertArrayEquals(array, list.toArray(new Integer[] {}));
 }
 @Test
 public void partitionOver100() {
   ArrayList<Integer> list = new ArrayList<Integer>(Interval.oneTo(101));
   PartitionMutableList<Integer> result =
       ArrayListIterate.partition(list, Predicates.in(Lists.immutable.of(1)));
   Verify.assertSize(1, result.getSelected());
   Verify.assertSize(100, result.getRejected());
 }
 @Test
 public void collectIf() {
   Assert.assertEquals(
       FastList.newListWith("1", "2", "3"),
       this.newWith(1, 2, 3)
           .collectIf(Predicates.instanceOf(Integer.class), Functions.getToString())
           .toList());
 }
 @Test
 public void selectSortedSet() {
   RichIterable<Integer> iterable = Interval.oneTo(20000).toSortedSet();
   Collection<Integer> actual1 = ParallelIterate.select(iterable, Predicates.greaterThan(10000));
   Collection<Integer> actual2 =
       ParallelIterate.select(iterable, Predicates.greaterThan(10000), true);
   RichIterable<Integer> expected = iterable.select(Predicates.greaterThan(10000));
   Assert.assertSame(expected.getClass(), actual1.getClass());
   Assert.assertSame(expected.getClass(), actual2.getClass());
   Assert.assertEquals(
       expected.getClass().getSimpleName() + '/' + actual1.getClass().getSimpleName(),
       expected,
       actual1);
   Assert.assertEquals(
       expected.getClass().getSimpleName() + '/' + actual2.getClass().getSimpleName(),
       expected,
       actual2);
 }