本文整理汇总了Java中java.util.function.ObjIntConsumer.accept方法的典型用法代码示例。如果您正苦于以下问题:Java ObjIntConsumer.accept方法的具体用法?Java ObjIntConsumer.accept怎么用?Java ObjIntConsumer.accept使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类java.util.function.ObjIntConsumer
的用法示例。
在下文中一共展示了ObjIntConsumer.accept方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: eachWithIndex
import java.util.function.ObjIntConsumer; //导入方法依赖的package包/类
/**
* Iterates through an iterable type, passing each item and the item's index
* (a counter starting at zero) to the given consumer.
*/
public static <T> Object eachWithIndex(Iterable<T> receiver, ObjIntConsumer<T> consumer) {
int count = 0;
for (T t : receiver) {
consumer.accept(t, count++);
}
return receiver;
}
示例2: forEachEntry
import java.util.function.ObjIntConsumer; //导入方法依赖的package包/类
@Override
public void forEachEntry(ObjIntConsumer<? super E> action) {
checkNotNull(action);
for (int i = 0; i < length; i++) {
action.accept(elementSet.asList().get(i), getCount(i));
}
}
示例3: makeInt
import java.util.function.ObjIntConsumer; //导入方法依赖的package包/类
/**
* 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();
}
};
}
示例4: forEachEntry
import java.util.function.ObjIntConsumer; //导入方法依赖的package包/类
@Override
public void forEachEntry(ObjIntConsumer<? super E> action) {
checkNotNull(action);
for (int i = 0; i < size(); i++) {
action.accept(elementSet.asList().get(i), getCount(i));
}
}
示例5: setIndexes
import java.util.function.ObjIntConsumer; //导入方法依赖的package包/类
@SuppressWarnings("ValueOfIncrementOrDecrementUsed")
private <T> void setIndexes(T[] standings, Comparator<T> c, ObjIntConsumer<T> consumer) {
Objects.requireNonNull(standings, "standings");
Objects.requireNonNull(c, "c");
Objects.requireNonNull(consumer, "consumer");
int i = 0, len = standings.length, lastIndex = 0;
for (T last = null, standing; i < len; last = standing) {
standing = standings[i++];
if (c.compare(standing, last) != 0) {
lastIndex = i;
}
consumer.accept(standing, lastIndex);
}
}
示例6: forEach
import java.util.function.ObjIntConsumer; //导入方法依赖的package包/类
public static <T> void forEach(PrintStream out, List<T> items, ObjIntConsumer<T> fn) {
int total = items.size();
Debouncer msg = new Debouncer();
for (int i = 0; i < total; i++) {
fn.accept(items.get(i), i);
if(msg.ready()) {
out.println("-> "+msg.estimate(i, total));
}
}
out.println("<> "+msg.estimate(total, total));
}
示例7: F
import java.util.function.ObjIntConsumer; //导入方法依赖的package包/类
F(ObjIntConsumer<T1> objIntConsumer) {
this((BiFunction<T1, T2, R>) new BiFunction<T1, Integer, R>() {
@Override
public R apply(T1 t, Integer u) {
objIntConsumer.accept(t, u);
return null;
}
});
}
示例8: collect
import java.util.function.ObjIntConsumer; //导入方法依赖的package包/类
@Override
public <R> R collect(Supplier<R> supplier, ObjIntConsumer<R> accumulator, BiConsumer<R, R> combiner) {
requireNonNull(supplier);
requireNonNull(accumulator);
final R value = supplier.get();
accumulator.accept(value, element);
// the combiner is never used in a non-parallell stream
return value;
}
示例9: forEach
import java.util.function.ObjIntConsumer; //导入方法依赖的package包/类
@Override
public synchronized void forEach(ObjIntConsumer<LogEntry> function, int start_index, int end_index) {
if(start_index < first_appended)
start_index=first_appended;
if(end_index > last_appended)
end_index=last_appended;
int start=Math.max(1, start_index)- first_appended, end=end_index- first_appended;
for(int i=start; i <= end; i++) {
LogEntry entry=entries[i];
function.accept(entry, start_index);
start_index++;
}
}
示例10: forEach
import java.util.function.ObjIntConsumer; //导入方法依赖的package包/类
@Override
public void forEach(ObjIntConsumer<LogEntry> function, int start_index, int end_index) {
start_index = Math.max(start_index, Math.max(firstAppended,1));
end_index = Math.min(end_index, lastAppended);
for (int i=start_index; i<=end_index; i++) {
LogEntry entry = getLogEntry(i);
function.accept(entry, i);
}
}
示例11: forEachEntry
import java.util.function.ObjIntConsumer; //导入方法依赖的package包/类
@Override
public void forEachEntry(ObjIntConsumer<? super E> action) {
checkNotNull(action);
for (AvlNode<E> node = firstNode();
node != header && node != null && !range.tooHigh(node.getElement());
node = node.succ) {
action.accept(node.getElement(), node.getCount());
}
}
示例12: forEachEntry
import java.util.function.ObjIntConsumer; //导入方法依赖的package包/类
@Override
public void forEachEntry(ObjIntConsumer<? super E> action) {
checkNotNull(action);
for (int i = 0; i < enumConstants.length; i++) {
if (counts[i] > 0) {
action.accept(enumConstants[i], counts[i]);
}
}
}
示例13: forEachByIndex
import java.util.function.ObjIntConsumer; //导入方法依赖的package包/类
/**
* Special forEach that takes an {@link ObjIntConsumer} which is provided the
* value AND the index.
*
* @param aConsumer
* The consumer to use. May not be <code>null</code>.
*/
default void forEachByIndex (@Nonnull final ObjIntConsumer <? super ELEMENTTYPE> aConsumer)
{
int nIndex = 0;
for (final ELEMENTTYPE aItem : this)
{
aConsumer.accept (aItem, nIndex);
++nIndex;
}
}
示例14: _readUntilEOF
import java.util.function.ObjIntConsumer; //导入方法依赖的package包/类
private static void _readUntilEOF (@Nonnull @WillNotClose final InputStream aIS,
@Nonnull final byte [] aBuffer,
@Nonnull final ObjIntConsumer <? super byte []> aConsumer) throws IOException
{
ValueEnforcer.notNull (aIS, "InputStream");
ValueEnforcer.notNull (aBuffer, "Buffer");
ValueEnforcer.notNull (aConsumer, "Consumer");
int nBytesRead;
// Potentially blocking read
while ((nBytesRead = aIS.read (aBuffer, 0, aBuffer.length)) > -1)
aConsumer.accept (aBuffer, nBytesRead);
}
示例15: assertObjIntConsumer
import java.util.function.ObjIntConsumer; //导入方法依赖的package包/类
private <E extends Exception> void assertObjIntConsumer(ObjIntConsumer<Object> test, Class<E> type) {
assertNotNull(test);
try {
test.accept(null, 0);
fail();
}
catch (Exception e) {
assertException(type, e, "null:0");
}
}