• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Java Consumer类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Java中java8.util.function.Consumer的典型用法代码示例。如果您正苦于以下问题:Java Consumer类的具体用法?Java Consumer怎么用?Java Consumer使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



Consumer类属于java8.util.function包,在下文中一共展示了Consumer类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。

示例1: tryAdvance

import java8.util.function.Consumer; //导入依赖的package包/类
@Override
public boolean tryAdvance(Consumer<? super T> action) {
    Objects.requireNonNull(action);

    if (sliceOrigin >= fence)
        return false;

    while (sliceOrigin > index) {
        s.tryAdvance(e -> {});
        index++;
    }

    if (index >= fence)
        return false;

    index++;
    return s.tryAdvance(action);
}
 
开发者ID:streamsupport,项目名称:streamsupport,代码行数:19,代码来源:StreamSpliterators.java


示例2: forEachRemaining

import java8.util.function.Consumer; //导入依赖的package包/类
@Override
public void forEachRemaining(Consumer<? super T> action) {
    Objects.requireNonNull(action);

    if (sliceOrigin >= fence)
        return;

    if (index >= fence)
        return;

    if (index >= sliceOrigin && (index + s.estimateSize()) <= sliceFence) {
        // The spliterator is contained within the slice
        s.forEachRemaining(action);
        index = fence;
    } else {
        // The spliterator intersects with the slice
        while (sliceOrigin > index) {
            s.tryAdvance(e -> {});
            index++;
        }
        // Traverse elements up to the fence
        for (;index < fence; index++) {
            s.tryAdvance(action);
        }
    }
}
 
开发者ID:streamsupport,项目名称:streamsupport,代码行数:27,代码来源:StreamSpliterators.java


示例3: forEachRemaining

import java8.util.function.Consumer; //导入依赖的package包/类
public void forEachRemaining(Consumer<? super E> action) {
    Objects.requireNonNull(action);
    List<E> lst = list;
    int hi = getFence();
    int i = index;
    index = hi;
    try {
        for (; i < hi; ++i) {
            action.accept(lst.get(i));
        }
    } catch (IndexOutOfBoundsException e) {
        // action must have modified the list
        throw new ConcurrentModificationException();
    }
    checkAbsListModCount(alist, expectedModCount);
}
 
开发者ID:streamsupport,项目名称:streamsupport,代码行数:17,代码来源:RASpliterator.java


示例4: tryAdvance

import java8.util.function.Consumer; //导入依赖的package包/类
@Override
public boolean tryAdvance(Consumer<? super Element> action) {
    if (current < elements.size()) {
        action.accept(elements.get(current));
        current++;
        return true;
    } else {
        return false;
    }
}
 
开发者ID:joshschriever,项目名称:LiveNotes,代码行数:11,代码来源:MusicXmlRenderer.java


示例5: find

import java8.util.function.Consumer; //导入依赖的package包/类
public <T> CompletableFuture<T> find(final Class<T> entityType, String id) {
    final CompletableFuture<T> promise = new CompletableFuture<>();

    final EntityDefinition entityDef;
    try {
        entityDef = entityDefinitionManager.getDefinition(entityType);
    } catch (Exception e) {
        promise.completeExceptionally(e);
        return promise;
    }

    String path = StringUtils.path(entityDef.getReference(), id);
    connection.read(StringUtils.path(rootPath, path))
            .thenAccept(new Consumer<Data>() {
                @Override
                public void accept(Data entityData) {
                    promise.complete(entityParser.deserialize(entityType, entityData));
                }
            })
            .exceptionally(new Function<Throwable, Void>() {
                @Override
                public Void apply(Throwable throwable) {
                    promise.completeExceptionally(throwable);
                    return null;
                }
            });

    return promise;
}
 
开发者ID:akhahaha,项目名称:firebomb-java,代码行数:30,代码来源:Firebomb.java


示例6: query

import java8.util.function.Consumer; //导入依赖的package包/类
public <T> CompletableFuture<List<T>> query(final Criteria<T> criteria) {
    final CompletableFuture<List<T>> promise = new CompletableFuture<>();

    final Class<T> entityType = criteria.getEntityType();
    EntityDefinition entityDef;
    try {
        entityDef = entityDefinitionManager.getDefinition(entityType);
    } catch (DefinitionException e) {
        promise.completeExceptionally(e);
        return promise;
    }

    connection.query(StringUtils.path(rootPath, entityDef.getReference()), criteria)
            .thenAccept(new Consumer<Data>() {
                @Override
                public void accept(Data data) {
                    List<T> results = new ArrayList<T>();
                    for (Data entityData : data.getChildren()) {
                        T entity = entityParser.deserialize(entityType, entityData);
                        // Filter
                        if (criteria.match(entity)) {
                            results.add(entity);
                        }
                    }
                    promise.complete(results);
                }
            })
            .exceptionally(new Function<Throwable, Void>() {
                @Override
                public Void apply(Throwable throwable) {
                    promise.completeExceptionally(throwable);
                    return null;
                }
            });

    return promise;
}
 
开发者ID:akhahaha,项目名称:firebomb-java,代码行数:38,代码来源:Firebomb.java


示例7: refreshBalance

import java8.util.function.Consumer; //导入依赖的package包/类
private void refreshBalance() {
    if (walletService == null) {
        return;
    }
    //TODO: this may be called twice
    refreshConnectionIcons();
    final Coin coinBalance = walletService.getBalance();

    CompletableFuture<Coin> future = CompletableFuture.supplyAsync(new Supplier<Coin>() {
        @Override
        public Coin get() {
            try {
                Coin virtualBalance = walletService.virtualBalance();
                return coinBalance.add(virtualBalance);
            } catch (final Exception e) {
                Snackbar snackbar = Snackbar.make(getView(), e.getMessage(), Snackbar.LENGTH_LONG);
                snackbar.show();
                e.printStackTrace();
            }
            return Coin.ZERO;
        }
    });

    future.thenAccept(new Consumer<Coin>() {
        @Override
        public void accept(Coin coin) {
            Fiat fiatBalance = walletService.getExchangeRate().coinToFiat(coin);
            refreshBalance(coin, fiatBalance);
        }
    });







}
 
开发者ID:coinblesk,项目名称:coinblesk-client-gui,代码行数:39,代码来源:CurrentBalanceFragment.java


示例8: tryAdvance

import java8.util.function.Consumer; //导入依赖的package包/类
@Override
@SuppressWarnings("unchecked")
public boolean tryAdvance(Consumer<? super E> action) {
    Objects.requireNonNull(action);
    int i;
    if (getFence() > (i = index)) {
        index = i + 1;
        action.accept((E) array[i]);
        if (expectedModCount != getModCount(list)) {
            throw new ConcurrentModificationException();
        }
        return true;
    }
    return false;
}
 
开发者ID:streamsupport,项目名称:streamsupport,代码行数:16,代码来源:VectorSpliterator.java


示例9: forEachRemaining

import java8.util.function.Consumer; //导入依赖的package包/类
@Override
public void forEachRemaining(Consumer<? super T> action) {
    Objects.requireNonNull(action);
    Iterator<? extends T> i;
    if ((i = it) == null) {
        i = it = collection.iterator();
        est = collection.size();
    }
    Iterators.forEachRemaining(i, action);
}
 
开发者ID:streamsupport,项目名称:streamsupport,代码行数:11,代码来源:Spliterators.java


示例10: tryAdvance

import java8.util.function.Consumer; //导入依赖的package包/类
@Override
@SuppressWarnings("unchecked")
public boolean tryAdvance(Consumer<? super E> action) {
    Objects.requireNonNull(action);
    if (getFence() > index && index >= 0) {
        action.accept((E) array[index++]);
        return true;
    }
    return false;
}
 
开发者ID:streamsupport,项目名称:streamsupport,代码行数:11,代码来源:PBQueueSpliterator.java


示例11: tryAdvance

import java8.util.function.Consumer; //导入依赖的package包/类
@Override
public boolean tryAdvance(Consumer<? super T> consumer) {
    boolean hasNext;
    if (beforeSplit) {
        hasNext = aSpliterator.tryAdvance(consumer);
        if (!hasNext) {
            beforeSplit = false;
            hasNext = bSpliterator.tryAdvance(consumer);
        }
    }
    else
        hasNext = bSpliterator.tryAdvance(consumer);
    return hasNext;
}
 
开发者ID:streamsupport,项目名称:streamsupport,代码行数:15,代码来源:Streams.java


示例12: IntSource

import java8.util.function.Consumer; //导入依赖的package包/类
public IntSource(T b, Function<? super T, Spliterator.OfInt> toSpliterator,
                 Consumer<T> updater, boolean bindOnCharacteristics) {
    this.b = b;
    this.toSpliterator = toSpliterator;
    this.updater = updater;
    this.bindOnCharacteristics = bindOnCharacteristics;
}
 
开发者ID:streamsupport,项目名称:streamsupport,代码行数:8,代码来源:SpliteratorLateBindingFailFastHelper.java


示例13: tryAdvance

import java8.util.function.Consumer; //导入依赖的package包/类
@Override
public boolean tryAdvance(Consumer<? super T> action) {
    Objects.requireNonNull(action);
    if (index >= 0 && index < fence) {
        @SuppressWarnings("unchecked") T e = (T) array[index++];
        action.accept(e);
        return true;
    }
    return false;
}
 
开发者ID:streamsupport,项目名称:streamsupport,代码行数:11,代码来源:Spliterators.java


示例14: tryAdvance

import java8.util.function.Consumer; //导入依赖的package包/类
@Override
public boolean tryAdvance(Consumer<? super E> action) {
    Objects.requireNonNull(action);
    int hi = getFence(), i = index;
    if (i < hi) {
        index = i + 1;
        @SuppressWarnings("unchecked") E e = (E) getData(list)[i];
        action.accept(e);
        if (expectedModCount != getModCount(list)) {
            throw new ConcurrentModificationException();
        }
        return true;
    }
    return false;
}
 
开发者ID:streamsupport,项目名称:streamsupport,代码行数:16,代码来源:ArrayListSpliterator.java


示例15: tryAdvance

import java8.util.function.Consumer; //导入依赖的package包/类
@Override
public boolean tryAdvance(Consumer<? super E> action) {
    Objects.requireNonNull(action);
    if (!exhausted) {
        E e = null;
        ReentrantLock lock = queueLock;
        lock.lock();
        try {
            Object p;
            if ((p = current) != null || (p = getQueueFirst(queue)) != null)
                do {
                    e = getNodeItem(p);
                    p = succ(p);
                } while (e == null && p != null);
            if ((current = p) == null)
                exhausted = true;
        } finally {
            // checkInvariants();
            lock.unlock();
        }
        if (e != null) {
            action.accept(e);
            return true;
        }
    }
    return false;
}
 
开发者ID:streamsupport,项目名称:streamsupport,代码行数:28,代码来源:LBDSpliterator.java


示例16: forEach

import java8.util.function.Consumer; //导入依赖的package包/类
@Override
public void forEach(Consumer<? super E_OUT> action) {
    if (!isParallel()) {
        sourceStageSpliterator().forEachRemaining(action);
    }
    else {
        super.forEach(action);
    }
}
 
开发者ID:streamsupport,项目名称:streamsupport,代码行数:10,代码来源:ReferencePipeline.java


示例17: forEach

import java8.util.function.Consumer; //导入依赖的package包/类
@Override
public void forEach(Consumer<? super Integer> consumer) {
    if (consumer instanceof IntConsumer) {
        forEach((IntConsumer) consumer);
    }
    else {
        ((Spliterator<Integer>) spliterator()).forEachRemaining(consumer);
    }
}
 
开发者ID:streamsupport,项目名称:streamsupport,代码行数:10,代码来源:SpinedBuffer.java


示例18: forEach

import java8.util.function.Consumer; //导入依赖的package包/类
/**
 * {@inheritDoc}
 *
 * @param consumer A {@code Consumer} that is to be invoked with each
 *        element in this {@code Node}.  If this is an
 *        {@code DoubleConsumer}, it is cast to {@code DoubleConsumer}
 *        so the elements may be processed without boxing.
 */
static void forEach(Node.OfDouble this_, Consumer<? super Double> consumer) {
    if (consumer instanceof DoubleConsumer) {
        this_.forEach((DoubleConsumer) consumer);
    }
    else {
        this_.spliterator().forEachRemaining(consumer);
    }
}
 
开发者ID:streamsupport,项目名称:streamsupport,代码行数:17,代码来源:Nodes.java


示例19: forEachRemaining

import java8.util.function.Consumer; //导入依赖的package包/类
@Override
public void forEachRemaining(Consumer<? super Map.Entry<K, V>> action) {
    Objects.requireNonNull(action);
    int i, hi, mc;
    HashMap<K, V> m = map;
    Object[] tab = getTable(m);
    if ((hi = fence) < 0) {
        mc = expectedModCount = getModCount(m);
        hi = fence = (tab == null) ? 0 : tab.length;
    } else {
        mc = expectedModCount;
    }
    if (tab != null && tab.length >= hi && (i = index) >= 0
            && (i < (index = hi) || current != null)) {
        Object p = current;
        current = null;
        do {
            if (p == null) {
                p = tab[i++];
            } else {
                action.accept((Map.Entry<K, V>) p);
                p = getNextNode(p);
            }
        } while (p != null || i < hi);
        if (mc != getModCount(m)) {
            throw new ConcurrentModificationException();
        }
    }
}
 
开发者ID:streamsupport,项目名称:streamsupport,代码行数:30,代码来源:HMSpliterators.java


示例20: testRecursiveDecomposition

import java8.util.function.Consumer; //导入依赖的package包/类
void testRecursiveDecomposition(
    BiConsumer<Integer[], Consumer<Integer>> action) {
    int n = ThreadLocalRandom.current().nextInt(8);
    Integer[] a = new Integer[n];
    for (int i = 0; i < n; i++) a[i] = i + 1;
    AtomicInteger ai = new AtomicInteger(0);
    action.accept(a, ai::addAndGet);
    assertEquals(n * (n + 1) / 2, ai.get());
}
 
开发者ID:streamsupport,项目名称:streamsupport,代码行数:10,代码来源:CountedCompleter8Test.java



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Java Function类代码示例发布时间:2022-05-23
下一篇:
Java RowProcessorClient类代码示例发布时间:2022-05-23
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap