本文整理匯總了Java中java.util.function.IntConsumer類的典型用法代碼示例。如果您正苦於以下問題:Java IntConsumer類的具體用法?Java IntConsumer怎麽用?Java IntConsumer使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
IntConsumer類屬於java.util.function包,在下文中一共展示了IntConsumer類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: tryAdvance
import java.util.function.IntConsumer; //導入依賴的package包/類
@Override
public boolean tryAdvance(IntConsumer action) {
boolean test = true;
if (takeOrDrop && // If can take
checkCancelOnCount() && // and if not cancelled
s.tryAdvance(this) && // and if advanced one element
(test = p.test(t))) { // and test on element passes
action.accept(t); // then accept element
return true;
}
else {
// Taking is finished
takeOrDrop = false;
// Cancel all further traversal and splitting operations
// only if test of element failed (short-circuited)
if (!test)
cancel.set(true);
return false;
}
}
示例2: truncate
import java.util.function.IntConsumer; //導入依賴的package包/類
@Override
default Node.OfInt truncate(long from, long to, IntFunction<Integer[]> generator) {
if (from == 0 && to == count())
return this;
long size = to - from;
Spliterator.OfInt spliterator = spliterator();
Node.Builder.OfInt nodeBuilder = Nodes.intBuilder(size);
nodeBuilder.begin(size);
for (int i = 0; i < from && spliterator.tryAdvance((IntConsumer) e -> { }); i++) { }
if (to == count()) {
spliterator.forEachRemaining((IntConsumer) nodeBuilder);
} else {
for (int i = 0; i < size && spliterator.tryAdvance((IntConsumer) nodeBuilder); i++) { }
}
nodeBuilder.end();
return nodeBuilder.build();
}
示例3: list
import java.util.function.IntConsumer; //導入依賴的package包/類
public static Future<Void> list(GuildMessageReceivedEvent event, int timeoutSeconds, boolean canEveryoneUse, List<MessageEmbed> embeds, IntConsumer beforePageSent) {
if(embeds.size() == 0) return null;
AtomicInteger index = new AtomicInteger();
Message m = event.getChannel().sendMessage(embeds.get(0)).complete();
return ReactionOperations.create(m, timeoutSeconds, (e)->{
if(!canEveryoneUse && e.getUser().getIdLong() != event.getAuthor().getIdLong()) return Operation.IGNORED;
switch(e.getReactionEmote().getName()) {
case "\u2b05": //left arrow
if(index.get() == 0) break;
m.editMessage(embeds.get(index.decrementAndGet())).queue();
break;
case "\u27a1": //right arrow
if(index.get() + 1 >= embeds.size()) break;
m.editMessage(embeds.get(index.incrementAndGet())).queue();
break;
}
if(event.getGuild().getSelfMember().hasPermission(e.getTextChannel(), Permission.MESSAGE_MANAGE)) {
e.getReaction().removeReaction(e.getUser()).queue();
}
return Operation.RESET_TIMEOUT;
}, "\u2b05", "\u27a1");
}
示例4: peek
import java.util.function.IntConsumer; //導入依賴的package包/類
@Override
public final IntStream peek(IntConsumer action) {
Objects.requireNonNull(action);
return new StatelessOp<Integer>(this, StreamShape.INT_VALUE,
0) {
@Override
Sink<Integer> opWrapSink(int flags, Sink<Integer> sink) {
return new Sink.ChainedInt<Integer>(sink) {
@Override
public void accept(int t) {
action.accept(t);
downstream.accept(t);
}
};
}
};
}
示例5: testIntForEachRemainingWithNull
import java.util.function.IntConsumer; //導入依賴的package包/類
public void testIntForEachRemainingWithNull() {
PrimitiveIterator.OfInt i = new PrimitiveIterator.OfInt() {
@Override
public int nextInt() {
return 0;
}
@Override
public boolean hasNext() {
return false;
}
};
executeAndCatch(() -> i.forEachRemaining((IntConsumer) null));
executeAndCatch(() -> i.forEachRemaining((Consumer<Integer>) null));
}
示例6: iterate
import java.util.function.IntConsumer; //導入依賴的package包/類
/**
* Returns an infinite sequential ordered {@code IntStream} produced by iterative
* application of a function {@code f} to an initial element {@code seed},
* producing a {@code Stream} consisting of {@code seed}, {@code f(seed)},
* {@code f(f(seed))}, etc.
*
* <p>The first element (position {@code 0}) in the {@code IntStream} will be
* the provided {@code seed}. For {@code n > 0}, the element at position
* {@code n}, will be the result of applying the function {@code f} to the
* element at position {@code n - 1}.
*
* <p>The action of applying {@code f} for one element
* <a href="../concurrent/package-summary.html#MemoryVisibility"><i>happens-before</i></a>
* the action of applying {@code f} for subsequent elements. For any given
* element the action may be performed in whatever thread the library
* chooses.
*
* @param seed the initial element
* @param f a function to be applied to the previous element to produce
* a new element
* @return a new sequential {@code IntStream}
*/
public static IntStream iterate(final int seed, final IntUnaryOperator f) {
Objects.requireNonNull(f);
Spliterator.OfInt spliterator = new Spliterators.AbstractIntSpliterator(Long.MAX_VALUE,
Spliterator.ORDERED | Spliterator.IMMUTABLE | Spliterator.NONNULL) {
int prev;
boolean started;
@Override
public boolean tryAdvance(IntConsumer action) {
Objects.requireNonNull(action);
int t;
if (started)
t = f.applyAsInt(prev);
else {
t = seed;
started = true;
}
action.accept(prev = t);
return true;
}
};
return StreamSupport.intStream(spliterator, false);
}
示例7: tryAdvance
import java.util.function.IntConsumer; //導入依賴的package包/類
@Override
public boolean tryAdvance(IntConsumer consumer) {
Objects.requireNonNull(consumer);
final int i = from;
if (i < upTo) {
from++;
consumer.accept(i);
return true;
}
else if (last > 0) {
last = 0;
consumer.accept(i);
return true;
}
return false;
}
示例8: forEachRemaining
import java.util.function.IntConsumer; //導入依賴的package包/類
@Override
public void forEachRemaining(IntConsumer consumer) {
Objects.requireNonNull(consumer);
int i = from;
final int hUpTo = upTo;
int hLast = last;
from = upTo;
last = 0;
while (i < hUpTo) {
consumer.accept(i++);
}
if (hLast > 0) {
// Last element of closed range
consumer.accept(i);
}
}
示例9: tryAdvance
import java.util.function.IntConsumer; //導入依賴的package包/類
@Override
public boolean tryAdvance(IntConsumer action) {
Objects.requireNonNull(action);
if (count == -2) {
action.accept(first);
count = -1;
return true;
}
else {
return false;
}
}
示例10: tryAdvance
import java.util.function.IntConsumer; //導入依賴的package包/類
@Override
public boolean tryAdvance(IntConsumer action) {
if (action == null)
throw new NullPointerException();
if (index >= 0 && index < limit) {
action.accept(buffer.getUnchecked(index++));
return true;
}
return false;
}
示例11: tryAdvance
import java.util.function.IntConsumer; //導入依賴的package包/類
public boolean tryAdvance(IntConsumer consumer) {
if (consumer == null) throw new NullPointerException();
long i = index, f = fence;
if (i < f) {
consumer.accept(ThreadLocalRandom.current().internalNextInt(origin, bound));
index = i + 1;
return true;
}
return false;
}
示例12: tryAdvance
import java.util.function.IntConsumer; //導入依賴的package包/類
@Override
public boolean tryAdvance(IntConsumer action) {
if (action == null)
throw new NullPointerException();
int i = index;
if (i >= 0 && i < fence) {
action.accept(charAt(array, i));
index++;
return true;
}
return false;
}
示例13: tryAdvance
import java.util.function.IntConsumer; //導入依賴的package包/類
@Override
public boolean tryAdvance(IntConsumer action) {
if (action == null)
throw new NullPointerException();
if (index >= 0 && index < fence) {
action.accept(array[index++] & 0xff);
return true;
}
return false;
}
示例14: run
import java.util.function.IntConsumer; //導入依賴的package包/類
@Test
public void run() {
Arrays.stream(arr).forEach(new IntConsumer() {
@Override
public void accept(int value) {
System.out.println(value);
}
});
}
示例15: run3
import java.util.function.IntConsumer; //導入依賴的package包/類
/**
* 這裏首先使用函數引用,直接定義了兩個Int-Consumer接口實例,一個指向標準輸出,另一個指向標準錯誤。
* 使用接口默認函數IntConsumer.addThen(),將兩個IntConsumer進行組合,得到一個新的IntConsumer,
* 這個新的Int-Consumer會依次調用outprintln和errprintln,完成對數組中元素的處理。
*
* 這個新的IntConsumer會先調用第1個IntConsumer進行處理,接著調用第2個Int-Consumer處理,從而實現多個處理器的整合
*/
@Test
public void run3() {
IntConsumer outprintln = System.out::println;
IntConsumer errprintln = System.err::println;
Arrays.stream(arr).forEach(outprintln.andThen(errprintln));
}