コード例 #1
0
 @Before
 public void setUp() {
   Interval interval = Interval.oneTo(20000);
   this.iterables =
       Lists.immutable.of(
           interval.toList(),
           interval.toList().asUnmodifiable(),
           interval.toList().asSynchronized(),
           interval.toList().toImmutable(),
           interval.toSet(),
           interval.toSet().asUnmodifiable(),
           interval.toSet().asSynchronized(),
           interval.toSet().toImmutable(),
           interval.toBag(),
           interval.toBag().asUnmodifiable(),
           interval.toBag().asSynchronized(),
           interval.toBag().toImmutable(),
           interval.toSortedSet(),
           interval.toSortedSet().asUnmodifiable(),
           interval.toSortedSet().asSynchronized(),
           interval.toSortedSet().toImmutable(),
           interval.toMap(Functions.<Integer>getPassThru(), Functions.<Integer>getPassThru()),
           interval
               .toMap(Functions.<Integer>getPassThru(), Functions.<Integer>getPassThru())
               .asUnmodifiable(),
           interval
               .toMap(Functions.<Integer>getPassThru(), Functions.<Integer>getPassThru())
               .asSynchronized(),
           interval
               .toMap(Functions.<Integer>getPassThru(), Functions.<Integer>getPassThru())
               .toImmutable(),
           ArrayListAdapter.<Integer>newList().withAll(interval),
           ArrayListAdapter.<Integer>newList().withAll(interval).asUnmodifiable(),
           ArrayListAdapter.<Integer>newList().withAll(interval).asSynchronized(),
           new CompositeFastList<Integer>().withAll(interval.toList()),
           new CompositeFastList<Integer>().withAll(interval.toList()).asUnmodifiable(),
           new CompositeFastList<Integer>().withAll(interval.toList()).asSynchronized(),
           new CompositeFastList<Integer>().withAll(interval.toList()).toImmutable(),
           ListAdapter.adapt(new LinkedList<Integer>()).withAll(interval),
           ListAdapter.adapt(new LinkedList<Integer>()).withAll(interval).asUnmodifiable(),
           ListAdapter.adapt(new LinkedList<Integer>()).withAll(interval).asSynchronized(),
           UnifiedSetWithHashingStrategy.<Integer>newSet(HashingStrategies.defaultStrategy())
               .withAll(interval),
           UnifiedSetWithHashingStrategy.<Integer>newSet(HashingStrategies.defaultStrategy())
               .withAll(interval)
               .asUnmodifiable(),
           UnifiedSetWithHashingStrategy.<Integer>newSet(HashingStrategies.defaultStrategy())
               .withAll(interval)
               .asSynchronized(),
           UnifiedSetWithHashingStrategy.<Integer>newSet(HashingStrategies.defaultStrategy())
               .withAll(interval)
               .toImmutable());
 }
コード例 #2
0
  @Test
  public void testForEachUsingSet() {
    // Tests the default batch size calculations
    IntegerSum sum = new IntegerSum(0);
    MutableSet<Integer> set = Interval.toSet(1, 10000);
    ParallelIterate.forEach(set, new SumProcedure(sum), new SumCombiner(sum));
    Assert.assertEquals(50005000, sum.getSum());

    // Testing batch size 1
    IntegerSum sum2 = new IntegerSum(0);
    UnifiedSet<Integer> set2 = UnifiedSet.newSet(Interval.oneTo(100));
    ParallelIterate.forEach(
        set2, new SumProcedure(sum2), new SumCombiner(sum2), 1, set2.getBatchCount(set2.size()));
    Assert.assertEquals(5050, sum2.getSum());

    // Testing an uneven batch size
    IntegerSum sum3 = new IntegerSum(0);
    UnifiedSet<Integer> set3 = UnifiedSet.newSet(Interval.oneTo(100));
    ParallelIterate.forEach(
        set3, new SumProcedure(sum3), new SumCombiner(sum3), 1, set3.getBatchCount(13));
    Assert.assertEquals(5050, sum3.getSum());

    // Testing divideByZero exception by passing 1 as batchSize
    IntegerSum sum4 = new IntegerSum(0);
    UnifiedSet<Integer> set4 = UnifiedSet.newSet(Interval.oneTo(100));
    ParallelIterate.forEach(set4, new SumProcedure(sum4), new SumCombiner(sum4), 1);
    Assert.assertEquals(5050, sum4.getSum());
  }