java.util.function.ObjIntConsumer Java Examples

The following examples show how to use java.util.function.ObjIntConsumer. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: IntStreamEx.java    From streamex with Apache License 2.0 6 votes vote down vote up
private <A> A collectSized(Supplier<A> supplier, ObjIntConsumer<A> accumulator, BiConsumer<A, A> combiner,
                           IntFunction<A> sizedSupplier, ObjIntConsumer<A> sizedAccumulator) {
    if (isParallel())
        return collect(supplier, accumulator, combiner);
    java.util.Spliterator.OfInt spliterator = spliterator();
    int size = intSize(spliterator);
    A intermediate;
    if (size != -1) {
        intermediate = sizedSupplier.apply(size);
        spliterator.forEachRemaining((IntConsumer) i -> sizedAccumulator.accept(intermediate, i));
    } else {
        intermediate = supplier.get();
        spliterator.forEachRemaining((IntConsumer) i -> accumulator.accept(intermediate, i));
    }
    return intermediate;
}
 
Example #2
Source File: Paginator.java    From adventure with MIT License 6 votes vote down vote up
@SuppressWarnings("unchecked")
static <T> void forEachPageEntry(final @NonNull Collection<? extends T> content, final int pageSize, final int page, final @NonNull ObjIntConsumer<? super T> consumer) {
  final int size = content.size();
  final int start = pageSize * (page - 1);
  final int end = pageSize * page;
  if(content instanceof List<?> && content instanceof RandomAccess) {
    final List<? extends T> list = (List<? extends T>) content;
    for(int i = start; i < end && i < size; i++) {
      consumer.accept(list.get(i), i);
    }
  } else {
    final Iterator<? extends T> it = content.iterator();

    // skip entries on previous pages
    for(int i = 0; i < start; i++) {
      it.next();
    }

    for(int i = start; i < end && i < size; i++) {
      consumer.accept(it.next(), i);
    }
  }
}
 
Example #3
Source File: ReduceOps.java    From jdk1.8-source-analysis with Apache License 2.0 5 votes vote down vote up
/**
 * Constructs a {@code TerminalOp} that implements a mutable reduce on
 * {@code int} values.
 *
 * @param <R> The type of the result
 * @param supplier a factory to produce a new accumulator of the result type
 * @param accumulator a function to incorporate an int into an
 *        accumulator
 * @param combiner a function to combine an accumulator into another
 * @return A {@code ReduceOp} implementing the reduction
 */
public static <R> TerminalOp<Integer, R>
makeInt(Supplier<R> supplier,
        ObjIntConsumer<R> accumulator,
        BinaryOperator<R> combiner) {
    Objects.requireNonNull(supplier);
    Objects.requireNonNull(accumulator);
    Objects.requireNonNull(combiner);
    class ReducingSink extends Box<R>
            implements AccumulatingSink<Integer, R, ReducingSink>, Sink.OfInt {
        @Override
        public void begin(long size) {
            state = supplier.get();
        }

        @Override
        public void accept(int t) {
            accumulator.accept(state, t);
        }

        @Override
        public void combine(ReducingSink other) {
            state = combiner.apply(state, other.state);
        }
    }
    return new ReduceOp<Integer, R, ReducingSink>(StreamShape.INT_VALUE) {
        @Override
        public ReducingSink makeSink() {
            return new ReducingSink();
        }
    };
}
 
Example #4
Source File: ReduceOps.java    From TencentKona-8 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Constructs a {@code TerminalOp} that implements a mutable reduce on
 * {@code int} values.
 *
 * @param <R> The type of the result
 * @param supplier a factory to produce a new accumulator of the result type
 * @param accumulator a function to incorporate an int into an
 *        accumulator
 * @param combiner a function to combine an accumulator into another
 * @return A {@code ReduceOp} implementing the reduction
 */
public static <R> TerminalOp<Integer, R>
makeInt(Supplier<R> supplier,
        ObjIntConsumer<R> accumulator,
        BinaryOperator<R> combiner) {
    Objects.requireNonNull(supplier);
    Objects.requireNonNull(accumulator);
    Objects.requireNonNull(combiner);
    class ReducingSink extends Box<R>
            implements AccumulatingSink<Integer, R, ReducingSink>, Sink.OfInt {
        @Override
        public void begin(long size) {
            state = supplier.get();
        }

        @Override
        public void accept(int t) {
            accumulator.accept(state, t);
        }

        @Override
        public void combine(ReducingSink other) {
            state = combiner.apply(state, other.state);
        }
    }
    return new ReduceOp<Integer, R, ReducingSink>(StreamShape.INT_VALUE) {
        @Override
        public ReducingSink makeSink() {
            return new ReducingSink();
        }
    };
}
 
Example #5
Source File: IntPipeline.java    From JDKSourceCode1.8 with MIT License 5 votes vote down vote up
@Override
public final <R> R collect(Supplier<R> supplier,
                           ObjIntConsumer<R> accumulator,
                           BiConsumer<R, R> combiner) {
    BinaryOperator<R> operator = (left, right) -> {
        combiner.accept(left, right);
        return left;
    };
    return evaluate(ReduceOps.makeInt(supplier, accumulator, operator));
}
 
Example #6
Source File: FunctionalMaps.java    From Kettle with GNU General Public License v3.0 5 votes vote down vote up
public static <V> void forEachPrimitive(Int2ObjectMap<V> map, ObjIntConsumer<V> action) {
    if (map instanceof ArrayMap) {
        ((ArrayMap<V>) checkNotNull(map, "Null map")).forEachPrimitive(action);
    } else {
        defaultForEachPrimitive(map, action);
    }
}
 
Example #7
Source File: ArrayMap.java    From Kettle with GNU General Public License v3.0 5 votes vote down vote up
public void forEachPrimitive(ObjIntConsumer<V> action) {
    AtomicReferenceArray<V> values = this.values;
    for (int index = 0; index < values.length(); index++) {
        V value = values.get(index);
        if (value != null) {
            action.accept(value, index);
        }
    }
}
 
Example #8
Source File: IntPipeline.java    From TencentKona-8 with GNU General Public License v2.0 5 votes vote down vote up
@Override
public final <R> R collect(Supplier<R> supplier,
                           ObjIntConsumer<R> accumulator,
                           BiConsumer<R, R> combiner) {
    Objects.requireNonNull(combiner);
    BinaryOperator<R> operator = (left, right) -> {
        combiner.accept(left, right);
        return left;
    };
    return evaluate(ReduceOps.makeInt(supplier, accumulator, operator));
}
 
Example #9
Source File: ReduceOps.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Constructs a {@code TerminalOp} that implements a mutable reduce on
 * {@code int} values.
 *
 * @param <R> The type of the result
 * @param supplier a factory to produce a new accumulator of the result type
 * @param accumulator a function to incorporate an int into an
 *        accumulator
 * @param combiner a function to combine an accumulator into another
 * @return A {@code ReduceOp} implementing the reduction
 */
public static <R> TerminalOp<Integer, R>
makeInt(Supplier<R> supplier,
        ObjIntConsumer<R> accumulator,
        BinaryOperator<R> combiner) {
    Objects.requireNonNull(supplier);
    Objects.requireNonNull(accumulator);
    Objects.requireNonNull(combiner);
    class ReducingSink extends Box<R>
            implements AccumulatingSink<Integer, R, ReducingSink>, Sink.OfInt {
        @Override
        public void begin(long size) {
            state = supplier.get();
        }

        @Override
        public void accept(int t) {
            accumulator.accept(state, t);
        }

        @Override
        public void combine(ReducingSink other) {
            state = combiner.apply(state, other.state);
        }
    }
    return new ReduceOp<Integer, R, ReducingSink>(StreamShape.INT_VALUE) {
        @Override
        public ReducingSink makeSink() {
            return new ReducingSink();
        }
    };
}
 
Example #10
Source File: ReduceOps.java    From jdk8u-jdk with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Constructs a {@code TerminalOp} that implements a mutable reduce on
 * {@code int} values.
 *
 * @param <R> The type of the result
 * @param supplier a factory to produce a new accumulator of the result type
 * @param accumulator a function to incorporate an int into an
 *        accumulator
 * @param combiner a function to combine an accumulator into another
 * @return A {@code ReduceOp} implementing the reduction
 */
public static <R> TerminalOp<Integer, R>
makeInt(Supplier<R> supplier,
        ObjIntConsumer<R> accumulator,
        BinaryOperator<R> combiner) {
    Objects.requireNonNull(supplier);
    Objects.requireNonNull(accumulator);
    Objects.requireNonNull(combiner);
    class ReducingSink extends Box<R>
            implements AccumulatingSink<Integer, R, ReducingSink>, Sink.OfInt {
        @Override
        public void begin(long size) {
            state = supplier.get();
        }

        @Override
        public void accept(int t) {
            accumulator.accept(state, t);
        }

        @Override
        public void combine(ReducingSink other) {
            state = combiner.apply(state, other.state);
        }
    }
    return new ReduceOp<Integer, R, ReducingSink>(StreamShape.INT_VALUE) {
        @Override
        public ReducingSink makeSink() {
            return new ReducingSink();
        }
    };
}
 
Example #11
Source File: IntPipeline.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 5 votes vote down vote up
@Override
public final <R> R collect(Supplier<R> supplier,
                           ObjIntConsumer<R> accumulator,
                           BiConsumer<R, R> combiner) {
    BinaryOperator<R> operator = (left, right) -> {
        combiner.accept(left, right);
        return left;
    };
    return evaluate(ReduceOps.makeInt(supplier, accumulator, operator));
}
 
Example #12
Source File: ReduceOps.java    From Bytecoder with Apache License 2.0 5 votes vote down vote up
/**
 * Constructs a {@code TerminalOp} that implements a mutable reduce on
 * {@code int} values.
 *
 * @param <R> The type of the result
 * @param supplier a factory to produce a new accumulator of the result type
 * @param accumulator a function to incorporate an int into an
 *        accumulator
 * @param combiner a function to combine an accumulator into another
 * @return A {@code ReduceOp} implementing the reduction
 */
public static <R> TerminalOp<Integer, R>
makeInt(Supplier<R> supplier,
        ObjIntConsumer<R> accumulator,
        BinaryOperator<R> combiner) {
    Objects.requireNonNull(supplier);
    Objects.requireNonNull(accumulator);
    Objects.requireNonNull(combiner);
    class ReducingSink extends Box<R>
            implements AccumulatingSink<Integer, R, ReducingSink>, Sink.OfInt {
        @Override
        public void begin(long size) {
            state = supplier.get();
        }

        @Override
        public void accept(int t) {
            accumulator.accept(state, t);
        }

        @Override
        public void combine(ReducingSink other) {
            state = combiner.apply(state, other.state);
        }
    }
    return new ReduceOp<Integer, R, ReducingSink>(StreamShape.INT_VALUE) {
        @Override
        public ReducingSink makeSink() {
            return new ReducingSink();
        }
    };
}
 
Example #13
Source File: IntPipeline.java    From Bytecoder with Apache License 2.0 5 votes vote down vote up
@Override
public final <R> R collect(Supplier<R> supplier,
                           ObjIntConsumer<R> accumulator,
                           BiConsumer<R, R> combiner) {
    Objects.requireNonNull(combiner);
    BinaryOperator<R> operator = (left, right) -> {
        combiner.accept(left, right);
        return left;
    };
    return evaluate(ReduceOps.makeInt(supplier, accumulator, operator));
}
 
Example #14
Source File: ReduceOps.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Constructs a {@code TerminalOp} that implements a mutable reduce on
 * {@code int} values.
 *
 * @param <R> The type of the result
 * @param supplier a factory to produce a new accumulator of the result type
 * @param accumulator a function to incorporate an int into an
 *        accumulator
 * @param combiner a function to combine an accumulator into another
 * @return A {@code ReduceOp} implementing the reduction
 */
public static <R> TerminalOp<Integer, R>
makeInt(Supplier<R> supplier,
        ObjIntConsumer<R> accumulator,
        BinaryOperator<R> combiner) {
    Objects.requireNonNull(supplier);
    Objects.requireNonNull(accumulator);
    Objects.requireNonNull(combiner);
    class ReducingSink extends Box<R>
            implements AccumulatingSink<Integer, R, ReducingSink>, Sink.OfInt {
        @Override
        public void begin(long size) {
            state = supplier.get();
        }

        @Override
        public void accept(int t) {
            accumulator.accept(state, t);
        }

        @Override
        public void combine(ReducingSink other) {
            state = combiner.apply(state, other.state);
        }
    }
    return new ReduceOp<Integer, R, ReducingSink>(StreamShape.INT_VALUE) {
        @Override
        public ReducingSink makeSink() {
            return new ReducingSink();
        }
    };
}
 
Example #15
Source File: IntPipeline.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
@Override
public final <R> R collect(Supplier<R> supplier,
                           ObjIntConsumer<R> accumulator,
                           BiConsumer<R, R> combiner) {
    Objects.requireNonNull(combiner);
    BinaryOperator<R> operator = (left, right) -> {
        combiner.accept(left, right);
        return left;
    };
    return evaluate(ReduceOps.makeInt(supplier, accumulator, operator));
}
 
Example #16
Source File: ReduceOps.java    From jdk8u-jdk with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Constructs a {@code TerminalOp} that implements a mutable reduce on
 * {@code int} values.
 *
 * @param <R> The type of the result
 * @param supplier a factory to produce a new accumulator of the result type
 * @param accumulator a function to incorporate an int into an
 *        accumulator
 * @param combiner a function to combine an accumulator into another
 * @return A {@code ReduceOp} implementing the reduction
 */
public static <R> TerminalOp<Integer, R>
makeInt(Supplier<R> supplier,
        ObjIntConsumer<R> accumulator,
        BinaryOperator<R> combiner) {
    Objects.requireNonNull(supplier);
    Objects.requireNonNull(accumulator);
    Objects.requireNonNull(combiner);
    class ReducingSink extends Box<R>
            implements AccumulatingSink<Integer, R, ReducingSink>, Sink.OfInt {
        @Override
        public void begin(long size) {
            state = supplier.get();
        }

        @Override
        public void accept(int t) {
            accumulator.accept(state, t);
        }

        @Override
        public void combine(ReducingSink other) {
            state = combiner.apply(state, other.state);
        }
    }
    return new ReduceOp<Integer, R, ReducingSink>(StreamShape.INT_VALUE) {
        @Override
        public ReducingSink makeSink() {
            return new ReducingSink();
        }
    };
}
 
Example #17
Source File: PodUpload.java    From kubernetes-client with Apache License 2.0 5 votes vote down vote up
static void copy(InputStream inputStream, ObjIntConsumer<byte[]> consumer) throws IOException {
  final byte[] buffer = new byte[DEFAULT_BUFFER_SIZE];
  int n;
  while (-1 != (n = inputStream.read(buffer))) {
    consumer.accept(buffer, n);
  }
}
 
Example #18
Source File: IntPipeline.java    From jdk8u-jdk with GNU General Public License v2.0 5 votes vote down vote up
@Override
public final <R> R collect(Supplier<R> supplier,
                           ObjIntConsumer<R> accumulator,
                           BiConsumer<R, R> combiner) {
    BinaryOperator<R> operator = (left, right) -> {
        combiner.accept(left, right);
        return left;
    };
    return evaluate(ReduceOps.makeInt(supplier, accumulator, operator));
}
 
Example #19
Source File: ReduceOps.java    From Java8CN with Apache License 2.0 5 votes vote down vote up
/**
 * Constructs a {@code TerminalOp} that implements a mutable reduce on
 * {@code int} values.
 *
 * @param <R> The type of the result
 * @param supplier a factory to produce a new accumulator of the result type
 * @param accumulator a function to incorporate an int into an
 *        accumulator
 * @param combiner a function to combine an accumulator into another
 * @return A {@code ReduceOp} implementing the reduction
 */
public static <R> TerminalOp<Integer, R>
makeInt(Supplier<R> supplier,
        ObjIntConsumer<R> accumulator,
        BinaryOperator<R> combiner) {
    Objects.requireNonNull(supplier);
    Objects.requireNonNull(accumulator);
    Objects.requireNonNull(combiner);
    class ReducingSink extends Box<R>
            implements AccumulatingSink<Integer, R, ReducingSink>, Sink.OfInt {
        @Override
        public void begin(long size) {
            state = supplier.get();
        }

        @Override
        public void accept(int t) {
            accumulator.accept(state, t);
        }

        @Override
        public void combine(ReducingSink other) {
            state = combiner.apply(state, other.state);
        }
    }
    return new ReduceOp<Integer, R, ReducingSink>(StreamShape.INT_VALUE) {
        @Override
        public ReducingSink makeSink() {
            return new ReducingSink();
        }
    };
}
 
Example #20
Source File: IntPipeline.java    From Java8CN with Apache License 2.0 5 votes vote down vote up
@Override
public final <R> R collect(Supplier<R> supplier,
                           ObjIntConsumer<R> accumulator,
                           BiConsumer<R, R> combiner) {
    BinaryOperator<R> operator = (left, right) -> {
        combiner.accept(left, right);
        return left;
    };
    return evaluate(ReduceOps.makeInt(supplier, accumulator, operator));
}
 
Example #21
Source File: ReduceOps.java    From hottub with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Constructs a {@code TerminalOp} that implements a mutable reduce on
 * {@code int} values.
 *
 * @param <R> The type of the result
 * @param supplier a factory to produce a new accumulator of the result type
 * @param accumulator a function to incorporate an int into an
 *        accumulator
 * @param combiner a function to combine an accumulator into another
 * @return A {@code ReduceOp} implementing the reduction
 */
public static <R> TerminalOp<Integer, R>
makeInt(Supplier<R> supplier,
        ObjIntConsumer<R> accumulator,
        BinaryOperator<R> combiner) {
    Objects.requireNonNull(supplier);
    Objects.requireNonNull(accumulator);
    Objects.requireNonNull(combiner);
    class ReducingSink extends Box<R>
            implements AccumulatingSink<Integer, R, ReducingSink>, Sink.OfInt {
        @Override
        public void begin(long size) {
            state = supplier.get();
        }

        @Override
        public void accept(int t) {
            accumulator.accept(state, t);
        }

        @Override
        public void combine(ReducingSink other) {
            state = combiner.apply(state, other.state);
        }
    }
    return new ReduceOp<Integer, R, ReducingSink>(StreamShape.INT_VALUE) {
        @Override
        public ReducingSink makeSink() {
            return new ReducingSink();
        }
    };
}
 
Example #22
Source File: PodUploadTest.java    From kubernetes-client with Apache License 2.0 5 votes vote down vote up
@Test
void testCopy() throws Exception {
  final ByteArrayInputStream input = new ByteArrayInputStream("I'LL BE COPIED".getBytes(Charset.defaultCharset()));
  final ObjIntConsumer<byte[]> consumer = (bytes, length) -> {
    assertThat(length, equalTo(14));
    assertThat(new String(Arrays.copyOf(bytes, 14), Charset.defaultCharset()),
      equalTo("I'LL BE COPIED"));
  };

  PodUpload.copy(input, consumer);
}
 
Example #23
Source File: ReduceOps.java    From openjdk-8-source with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Constructs a {@code TerminalOp} that implements a mutable reduce on
 * {@code int} values.
 *
 * @param <R> The type of the result
 * @param supplier a factory to produce a new accumulator of the result type
 * @param accumulator a function to incorporate an int into an
 *        accumulator
 * @param combiner a function to combine an accumulator into another
 * @return A {@code ReduceOp} implementing the reduction
 */
public static <R> TerminalOp<Integer, R>
makeInt(Supplier<R> supplier,
        ObjIntConsumer<R> accumulator,
        BinaryOperator<R> combiner) {
    Objects.requireNonNull(supplier);
    Objects.requireNonNull(accumulator);
    Objects.requireNonNull(combiner);
    class ReducingSink extends Box<R>
            implements AccumulatingSink<Integer, R, ReducingSink>, Sink.OfInt {
        @Override
        public void begin(long size) {
            state = supplier.get();
        }

        @Override
        public void accept(int t) {
            accumulator.accept(state, t);
        }

        @Override
        public void combine(ReducingSink other) {
            state = combiner.apply(state, other.state);
        }
    }
    return new ReduceOp<Integer, R, ReducingSink>(StreamShape.INT_VALUE) {
        @Override
        public ReducingSink makeSink() {
            return new ReducingSink();
        }
    };
}
 
Example #24
Source File: IntPipeline.java    From openjdk-8-source with GNU General Public License v2.0 5 votes vote down vote up
@Override
public final <R> R collect(Supplier<R> supplier,
                           ObjIntConsumer<R> accumulator,
                           BiConsumer<R, R> combiner) {
    BinaryOperator<R> operator = (left, right) -> {
        combiner.accept(left, right);
        return left;
    };
    return evaluate(ReduceOps.makeInt(supplier, accumulator, operator));
}
 
Example #25
Source File: ReduceOps.java    From openjdk-8 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Constructs a {@code TerminalOp} that implements a mutable reduce on
 * {@code int} values.
 *
 * @param <R> The type of the result
 * @param supplier a factory to produce a new accumulator of the result type
 * @param accumulator a function to incorporate an int into an
 *        accumulator
 * @param combiner a function to combine an accumulator into another
 * @return A {@code ReduceOp} implementing the reduction
 */
public static <R> TerminalOp<Integer, R>
makeInt(Supplier<R> supplier,
        ObjIntConsumer<R> accumulator,
        BinaryOperator<R> combiner) {
    Objects.requireNonNull(supplier);
    Objects.requireNonNull(accumulator);
    Objects.requireNonNull(combiner);
    class ReducingSink extends Box<R>
            implements AccumulatingSink<Integer, R, ReducingSink>, Sink.OfInt {
        @Override
        public void begin(long size) {
            state = supplier.get();
        }

        @Override
        public void accept(int t) {
            accumulator.accept(state, t);
        }

        @Override
        public void combine(ReducingSink other) {
            state = combiner.apply(state, other.state);
        }
    }
    return new ReduceOp<Integer, R, ReducingSink>(StreamShape.INT_VALUE) {
        @Override
        public ReducingSink makeSink() {
            return new ReducingSink();
        }
    };
}
 
Example #26
Source File: IntPipeline.java    From openjdk-8 with GNU General Public License v2.0 5 votes vote down vote up
@Override
public final <R> R collect(Supplier<R> supplier,
                           ObjIntConsumer<R> accumulator,
                           BiConsumer<R, R> combiner) {
    BinaryOperator<R> operator = (left, right) -> {
        combiner.accept(left, right);
        return left;
    };
    return evaluate(ReduceOps.makeInt(supplier, accumulator, operator));
}
 
Example #27
Source File: ReduceOps.java    From jdk8u_jdk with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Constructs a {@code TerminalOp} that implements a mutable reduce on
 * {@code int} values.
 *
 * @param <R> The type of the result
 * @param supplier a factory to produce a new accumulator of the result type
 * @param accumulator a function to incorporate an int into an
 *        accumulator
 * @param combiner a function to combine an accumulator into another
 * @return A {@code ReduceOp} implementing the reduction
 */
public static <R> TerminalOp<Integer, R>
makeInt(Supplier<R> supplier,
        ObjIntConsumer<R> accumulator,
        BinaryOperator<R> combiner) {
    Objects.requireNonNull(supplier);
    Objects.requireNonNull(accumulator);
    Objects.requireNonNull(combiner);
    class ReducingSink extends Box<R>
            implements AccumulatingSink<Integer, R, ReducingSink>, Sink.OfInt {
        @Override
        public void begin(long size) {
            state = supplier.get();
        }

        @Override
        public void accept(int t) {
            accumulator.accept(state, t);
        }

        @Override
        public void combine(ReducingSink other) {
            state = combiner.apply(state, other.state);
        }
    }
    return new ReduceOp<Integer, R, ReducingSink>(StreamShape.INT_VALUE) {
        @Override
        public ReducingSink makeSink() {
            return new ReducingSink();
        }
    };
}
 
Example #28
Source File: IntPipeline.java    From jdk8u_jdk with GNU General Public License v2.0 5 votes vote down vote up
@Override
public final <R> R collect(Supplier<R> supplier,
                           ObjIntConsumer<R> accumulator,
                           BiConsumer<R, R> combiner) {
    Objects.requireNonNull(combiner);
    BinaryOperator<R> operator = (left, right) -> {
        combiner.accept(left, right);
        return left;
    };
    return evaluate(ReduceOps.makeInt(supplier, accumulator, operator));
}
 
Example #29
Source File: OpenTracingPluginRetryTest.java    From riptide with MIT License 5 votes vote down vote up
private static <T> void forEachWithIndex(
        final Iterable<T> collection,
        final ObjIntConsumer<T> consumer) {

    int index = 0;
    for (final T element : collection) {
        consumer.accept(element, index++);
    }
}
 
Example #30
Source File: IntStreamEx.java    From streamex with Apache License 2.0 5 votes vote down vote up
/**
 * {@inheritDoc}
 * 
 * @see #collect(IntCollector)
 */
@Override
public <R> R collect(Supplier<R> supplier, ObjIntConsumer<R> accumulator, BiConsumer<R, R> combiner) {
    if (context.fjp != null)
        return context.terminate(() -> stream().collect(supplier, accumulator, combiner));
    return stream().collect(supplier, accumulator, combiner);
}