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


Java Consumer类代码示例

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


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

示例1: tryAdvance

import java9.util.function.Consumer; //导入依赖的package包/类
@Override
public boolean tryAdvance(Consumer<? super T> 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:retrostreams,项目名称:android-retrostreams,代码行数:21,代码来源:WhileOps.java

示例2: forEachRemaining

import java9.util.function.Consumer; //导入依赖的package包/类
@Override
public void forEachRemaining(Consumer<? super T> consumer) {
    if (curNode == null)
        return;

    if (tryAdvanceSpliterator == null) {
        if (lastNodeSpliterator == null) {
            Deque<Node<T>> stack = initStack();
            Node<T> leaf;
            while ((leaf = findNextLeafNode(stack)) != null) {
                leaf.forEach(consumer);
            }
            curNode = null;
        }
        else
            lastNodeSpliterator.forEachRemaining(consumer);
    }
    else
        while(tryAdvance(consumer)) { }
}
 
开发者ID:retrostreams,项目名称:android-retrostreams,代码行数:21,代码来源:Nodes.java

示例3: tryAdvance

import java9.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:retrostreams,项目名称:android-retrostreams,代码行数:19,代码来源:StreamSpliterators.java

示例4: forEachRemaining

import java9.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:retrostreams,项目名称:android-retrostreams,代码行数:27,代码来源:StreamSpliterators.java

示例5: tryAdvance

import java9.util.function.Consumer; //导入依赖的package包/类
@Override
public boolean tryAdvance(Consumer<? super K> action) {
    Objects.requireNonNull(action);
    int hi;
    Object[] tab = getTable(map);
    if (tab != null && tab.length >= (hi = getFence()) && index >= 0) {
        while (current != null || index < hi) {
            if (current == null) {
                current = tab[index++];
            } else {
                K k = getNodeKey(current);
                current = getNextNode(current);
                action.accept(k);
                if (expectedModCount != getModCount(map)) {
                    throw new ConcurrentModificationException();
                }
                return true;
            }
        }
    }
    return false;
}
 
开发者ID:retrostreams,项目名称:android-retrostreams,代码行数:23,代码来源:HMSpliterators.java

示例6: forEachRemaining

import java9.util.function.Consumer; //导入依赖的package包/类
@Override
public void forEachRemaining(Consumer<? super E> action) {
    Objects.requireNonNull(action);
    int i, hi, mc; // hoist accesses and checks from loop
    Object[] a;
    ArrayList<E> lst = list;
    if ((a = getData(lst)) != null) {
        if ((hi = fence) < 0) {
            mc = getModCount(lst);
            hi = getSize(lst);
        }
        else {
            mc = expectedModCount;
        }
        if ((i = index) >= 0 && (index = hi) <= a.length) {
            for (; i < hi; ++i) {
                @SuppressWarnings("unchecked") E e = (E) a[i];
                action.accept(e);
            }
            if (mc == getModCount(lst)) {
                return;
            }
        }
    }
    throw new ConcurrentModificationException();
}
 
开发者ID:retrostreams,项目名称:android-retrostreams,代码行数:27,代码来源:ArrayListSpliterator.java

示例7: tryAdvance

import java9.util.function.Consumer; //导入依赖的package包/类
@Override
public boolean tryAdvance(Consumer<? super E> action) {
    Objects.requireNonNull(action);
    if (!exhausted) {
        E e = null;
        fullyLock();
        try {
            Object p;
            if ((p = current) != null || (p = getHeadNext(queue)) != null)
                do {
                    e = getNodeItem(p);
                    p = succ(p);
                } while (e == null && p != null);
            if ((current = p) == null)
                exhausted = true;
        } finally {
            fullyUnlock();
        }
        if (e != null) {
            action.accept(e);
            return true;
        }
    }
    return false;
}
 
开发者ID:retrostreams,项目名称:android-retrostreams,代码行数:26,代码来源:LBQSpliterator.java

示例8: forEachRemaining

import java9.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:retrostreams,项目名称:android-retrostreams,代码行数:17,代码来源:RASpliterator.java

示例9: forEachRemaining

import java9.util.function.Consumer; //导入依赖的package包/类
@Override
public void forEachRemaining(Consumer<? super T> action) {
    Objects.requireNonNull(action);
    Object eol = endOfList;
    Object p;
    int n;
    if ((n = getEst()) > 0 && (p = current) != eol) {
        current = eol;
        est = 0;
        do {
            T item = getNodeItem(p);
            p = getNextNode(p);
            action.accept(item);
        } while (p != eol && --n > 0);
    }
    if (expectedModCount != getModCount(list)) {
        throw new ConcurrentModificationException();
    }
}
 
开发者ID:retrostreams,项目名称:android-retrostreams,代码行数:20,代码来源:LinkedListSpliterator.java

示例10: tryAdvance

import java9.util.function.Consumer; //导入依赖的package包/类
@Override
public boolean tryAdvance(Consumer<? super T> action) {
    Objects.requireNonNull(action);
    Object eol = endOfList;
    Object p;
    if (getEst() > 0 && (p = current) != eol) {
        --est;
        T item = getNodeItem(p);
        current = getNextNode(p);
        action.accept(item);
        if (expectedModCount != getModCount(list)) {
            throw new ConcurrentModificationException();
        }
        return true;
    }
    return false;
}
 
开发者ID:retrostreams,项目名称:android-retrostreams,代码行数:18,代码来源:LinkedListSpliterator.java

示例11: forEachRemaining

import java9.util.function.Consumer; //导入依赖的package包/类
@Override
@SuppressWarnings("unchecked")
public void forEachRemaining(Consumer<? super E> action) {
    Objects.requireNonNull(action);
    PriorityQueue<E> q = pq;
    if (fence < 0) { fence = getSize(q); expectedModCount = getModCount(q); }
    Object[] a = getQueue(q);
    int i, hi; E e;
    for (i = index, index = hi = fence; i < hi; i++) {
        if ((e = (E) a[i]) == null) {
            break;      // must be CME
        }
        action.accept(e);
    }
    if (getModCount(q) != expectedModCount) {
        throw new ConcurrentModificationException();
    }
}
 
开发者ID:retrostreams,项目名称:android-retrostreams,代码行数:19,代码来源:PQueueSpliterator.java

示例12: tryAdvance

import java9.util.function.Consumer; //导入依赖的package包/类
@Override
@SuppressWarnings("unchecked")
public boolean tryAdvance(Consumer<? super E> action) {
    Objects.requireNonNull(action);
    PriorityQueue<E> q = pq;
    if (fence < 0) { fence = getSize(q); expectedModCount = getModCount(q); }
    int i;
    if ((i = index) < fence) {
        index = i + 1;
        E e;
        if ((e = (E) getQueue(q)[i]) == null
            || getModCount(q) != expectedModCount) {
            throw new ConcurrentModificationException();
        }
        action.accept(e);
        return true;
    }
    return false;
}
 
开发者ID:retrostreams,项目名称:android-retrostreams,代码行数:20,代码来源:PQueueSpliterator.java

示例13: tryAdvance

import java9.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:retrostreams,项目名称:android-retrostreams,代码行数:11,代码来源:PBQueueSpliterator.java

示例14: forEachRemaining

import java9.util.function.Consumer; //导入依赖的package包/类
@Override
public void forEachRemaining(Consumer<? super E> action) {
    Objects.requireNonNull(action);
    Object[] a = getData(deq);
    int m = a.length - 1, f = getFence(), i = index;
    index = f;
    while (i != f) {
        @SuppressWarnings("unchecked") E e = (E) a[i];
        i = (i + 1) & m;
        if (e == null) {
            throw new ConcurrentModificationException();
        }
        action.accept(e);
    }
}
 
开发者ID:retrostreams,项目名称:android-retrostreams,代码行数:16,代码来源:ArrayDequeSpliterator.java

示例15: uniAcceptStage

import java9.util.function.Consumer; //导入依赖的package包/类
private CompletableFuture<Void> uniAcceptStage(Executor e,
        Consumer<? super T> f) {
    Objects.requireNonNull(f);
    Object r;
    if ((r = result) != null)
        return uniAcceptNow(r, e, f);
    CompletableFuture<Void> d = newIncompleteFuture();
    unipush(new UniAccept<T>(e, d, this, f));
    return d;
}
 
开发者ID:retrostreams,项目名称:android-retrofuture,代码行数:11,代码来源:CompletableFuture.java


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