예제 #1
0
 public void testEveryMapShape() {
   assertCountSum(
       StreamSupport.stream(countTo(1000))
           .mapToInt(i -> i - 1)
           .mapToObj(i -> i + 1)
           .mapToLong(i -> i - 1)
           .mapToObj(i -> i + 1)
           .mapToDouble(i -> i - 1)
           .mapToObj(i -> i + 1)
           .mapToInt(i -> (int) (double) i)
           .mapToLong(i -> i)
           .mapToDouble(i -> i)
           .mapToLong(i -> (long) i)
           .mapToInt(i -> (int) i)
           .mapToObj(i -> i),
       1000,
       StreamSupport.stream(countTo(1000)).mapToInt(i -> i).sum());
 }
  private void testEntrySetSizeRemove2(String name, Set<Map.Entry<Integer, Integer>> c) {
    Map.Entry<Integer, Integer> first = c.iterator().next();
    assertTrue(c.remove(first));

    Stream<Map.Entry<Integer, Integer>> stream = StreamSupport.stream(c, 0, false);

    Map.Entry<Integer, Integer> second = c.iterator().next();
    assertTrue(c.remove(second));
    Object[] result = stream.toArray();
    assertEquals(result.length, c.size());
  }
  private void testEntrySetSizeRemove(String name, final Set<Map.Entry<Integer, Integer>> c) {
    Iterator<Map.Entry<Integer, Integer>> testIter = c.iterator();
    Map.Entry<Integer, Integer> first = testIter.next();
    assertTrue(c.remove(first));

    Supplier<Spliterator<Map.Entry<Integer, Integer>>> late =
        new Supplier<Spliterator<Map.Entry<Integer, Integer>>>() {
          @Override
          public Spliterator<Map.Entry<Integer, Integer>> get() {
            return Spliterators.spliterator(c, 0);
          }
        };

    Stream<Map.Entry<Integer, Integer>> stream = StreamSupport.stream(late, 0, false);

    Map.Entry<Integer, Integer> second = c.iterator().next();
    assertTrue(c.remove(second));
    Object[] result = stream.toArray();
    assertEquals(result.length, c.size());
  }
예제 #4
0
  public void testMap() {
    assertCountSum(StreamSupport.stream(countTo(0)).map(mId), 0, 0);
    assertCountSum(StreamSupport.stream(countTo(10)).map(mId), 10, 55);
    assertCountSum(StreamSupport.stream(countTo(10)).map(mZero), 10, 0);
    assertCountSum(StreamSupport.stream(countTo(0)).map(mDoubler), 0, 0);
    assertCountSum(StreamSupport.stream(countTo(10)).map(mDoubler), 10, 110);
    assertCountSum(StreamSupport.stream(countTo(10)).map(mDoubler).map(mDoubler), 10, 220);

    exerciseOps(countTo(0), s -> s.map(LambdaTestHelpers.identity()), countTo(0));
    exerciseOps(countTo(1000), s -> s.map(LambdaTestHelpers.identity()), countTo(1000));
    // @@@ Force cast to integer so output is Stream<Integer> rather an IntStream
    //     this just ensures that no warnings are logged about boxing
    //     when the result is compared with the output
    exerciseOps(countTo(1000), s -> s.map(e -> (Integer) (1000 + e)), range(1001, 2000));
  }
예제 #5
0
 @Override
 public Stream<PostponingReasons> streamAllPostponingReasons(boolean compat) {
   final HashMap<UtcDay, HashSet<CurrencyUnit>> accumulator =
       new HashMap<UtcDay, HashSet<CurrencyUnit>>(100);
   Schema.POSTPONED_CURRENCY_EXCHANGE_EVENTS
       .streamAll()
       .forEach(
           new Consumer<PostponedExchange>() {
             @Override
             public void accept(PostponedExchange postponedExchange) {
               final HashSet<CurrencyUnit> units =
                   getUnitsAcc(accumulator, new UtcDay(postponedExchange.timestamp));
               units.add(postponedExchange.toBuyAccount.getUnit());
               units.add(postponedExchange.sellAccount.getUnit());
             }
           });
   Schema.POSTPONED_FUNDS_MUTATION_EVENTS
       .streamAll()
       .forEach(
           new Consumer<PostponedMutationEvent>() {
             @Override
             public void accept(PostponedMutationEvent postponedMutationEvent) {
               final HashSet<CurrencyUnit> units =
                   getUnitsAcc(
                       accumulator, new UtcDay(postponedMutationEvent.mutationEvent.timestamp));
               units.add(postponedMutationEvent.mutationEvent.amount.getCurrencyUnit());
               units.add(postponedMutationEvent.conversionUnit);
             }
           });
   return StreamSupport.stream(accumulator.entrySet())
       .map(
           new Function<Map.Entry<UtcDay, HashSet<CurrencyUnit>>, PostponingReasons>() {
             @Override
             public PostponingReasons apply(Map.Entry<UtcDay, HashSet<CurrencyUnit>> entry) {
               return new PostponingReasons(entry.getKey(), ImmutableSet.copyOf(entry.getValue()));
             }
           });
 }