當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。