当前位置: 首页>>代码示例>>Java>>正文


Java IntConsumer类代码示例

本文整理汇总了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;
    }
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:21,代码来源:WhileOps.java

示例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();
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:18,代码来源:Node.java

示例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");
}
 
开发者ID:natanbc,项目名称:GabrielBot,代码行数:23,代码来源:DiscordUtils.java

示例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);
                }
            };
        }
    };
}
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:18,代码来源:IntPipeline.java

示例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));
}
 
开发者ID:lambdalab-mirror,项目名称:jdk8u-jdk,代码行数:17,代码来源:PrimitiveIteratorDefaults.java

示例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);
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:46,代码来源:IntStream.java

示例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;
}
 
开发者ID:lambdalab-mirror,项目名称:jdk8u-jdk,代码行数:18,代码来源:Streams.java

示例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);
    }
}
 
开发者ID:lambdalab-mirror,项目名称:jdk8u-jdk,代码行数:18,代码来源:Streams.java

示例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;
    }
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:14,代码来源:Streams.java

示例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;
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:11,代码来源:CharBufferSpliterator.java

示例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;
}
 
开发者ID:lambdalab-mirror,项目名称:jdk8u-jdk,代码行数:11,代码来源:ThreadLocalRandom.java

示例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;
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:13,代码来源:StringUTF16.java

示例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;
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:11,代码来源:StringLatin1.java

示例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);
        }
    });
}
 
开发者ID:zhangboqing,项目名称:multithread,代码行数:10,代码来源:Arrays_Stream_Lambda.java

示例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));
}
 
开发者ID:zhangboqing,项目名称:multithread,代码行数:15,代码来源:Arrays_Stream_Lambda.java


注:本文中的java.util.function.IntConsumer类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。