當前位置: 首頁>>代碼示例>>Java>>正文


Java Consumer.accept方法代碼示例

本文整理匯總了Java中java9.util.function.Consumer.accept方法的典型用法代碼示例。如果您正苦於以下問題:Java Consumer.accept方法的具體用法?Java Consumer.accept怎麽用?Java Consumer.accept使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在java9.util.function.Consumer的用法示例。


在下文中一共展示了Consumer.accept方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: tryAdvance

import java9.util.function.Consumer; //導入方法依賴的package包/類
@Override
public boolean tryAdvance(Consumer<? super E> action) {
    Objects.requireNonNull(action);
    Object[] a = getData(deq);
    int m = a.length - 1, f = getFence(), i = index;
    if (i != fence) {
        @SuppressWarnings("unchecked") E e = (E) a[i];
        index = (i + 1) & m;
        if (e == null) {
            throw new ConcurrentModificationException();
        }
        action.accept(e);
        return true;
    }
    return false;
}
 
開發者ID:retrostreams,項目名稱:android-retrostreams,代碼行數:17,代碼來源:ArrayDequeSpliterator.java

示例2: tryAdvance

import java9.util.function.Consumer; //導入方法依賴的package包/類
@Override
public boolean tryAdvance(Consumer<? super T> action) {
    if (takeOrDrop) {
        takeOrDrop = false;
        boolean adv;
        boolean dropped = false;
        while ((adv = s.tryAdvance(this)) &&  // If advanced one element
               checkCancelOnCount() &&        // and if not cancelled
               p.test(t)) {                   // and test on element passes
            dropped = true;                   // then drop element
        }

        // Report advanced element, if any
        if (adv) {
            // Cancel all further dropping if one or more elements
            // were previously dropped
            if (dropped)
                cancel.set(true);
            action.accept(t);
        }
        return adv;
    }
    else {
        return s.tryAdvance(action);
    }
}
 
開發者ID:retrostreams,項目名稱:android-retrostreams,代碼行數:27,代碼來源:WhileOps.java

示例3: 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

示例4: 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

示例5: 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

示例6: 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

示例7: 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

示例8: tryAdvance

import java9.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:retrostreams,項目名稱:android-retrostreams,代碼行數:16,代碼來源:ArrayListSpliterator.java

示例9: tryAdvance

import java9.util.function.Consumer; //導入方法依賴的package包/類
public boolean tryAdvance(Consumer<? super E> action) {
    Objects.requireNonNull(action);
    int hi = getFence(), i = index;
    if (i < hi) {
        index = i + 1;
        action.accept(list.get(i));
        checkAbsListModCount(alist, expectedModCount);
        return true;
    }
    return false;
}
 
開發者ID:retrostreams,項目名稱:android-retrostreams,代碼行數:12,代碼來源:RASpliterator.java

示例10: tryAdvance

import java9.util.function.Consumer; //導入方法依賴的package包/類
@Override
public boolean tryAdvance(Consumer<? super T> action) {
    Objects.requireNonNull(action);

    while (permitStatus() != PermitStatus.NO_MORE) {
        if (!s.tryAdvance(this))
            return false;
        else if (acquirePermits(1) == 1) {
            action.accept(tmpSlot);
            tmpSlot = null;
            return true;
        }
    }
    return false;
}
 
開發者ID:retrostreams,項目名稱:android-retrostreams,代碼行數:16,代碼來源:StreamSpliterators.java

示例11: tryAdvance

import java9.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:retrostreams,項目名稱:android-retrostreams,代碼行數:16,代碼來源:VectorSpliterator.java

示例12: forEachFrom

import java9.util.function.Consumer; //導入方法依賴的package包/類
/**
 * Runs action on each element found during a traversal starting at p.
 * If p is null, traversal starts at head.
 */
void forEachFrom(Consumer<? super E> action, Object p) {
    // Extract batches of elements while holding the lock; then
    // run the action on the elements while not
    final int batchSize = 64;       // max number of elements per batch
    Object[] es = null;             // container for batch of elements
    int n, len = 0;
    do {
        fullyLock();
        try {
            if (es == null) {
                if (p == null) p = getHeadNext(queue);
                for (Object q = p; q != null; q = succ(q))
                    if (getNodeItem(q) != null && ++len == batchSize)
                        break;
                es = new Object[len];
            }
            for (n = 0; p != null && n < len; p = succ(p))
                if ((es[n] = getNodeItem(p)) != null)
                    n++;
        } finally {
            fullyUnlock();
        }
        for (int i = 0; i < n; i++) {
            @SuppressWarnings("unchecked") E e = (E) es[i];
            action.accept(e);
        }
    } while (n > 0 && p != null);
}
 
開發者ID:retrostreams,項目名稱:android-retrostreams,代碼行數:33,代碼來源:LBQSpliterator.java

示例13: tryAdvance

import java9.util.function.Consumer; //導入方法依賴的package包/類
@Override
public boolean tryAdvance(Consumer<? super T> action) {
    Objects.requireNonNull(action);
    if (it == null) {
        it = collection.iterator();
        est = collection.size();
    }
    if (it.hasNext()) {
        action.accept(it.next());
        return true;
    }
    return false;
}
 
開發者ID:retrostreams,項目名稱:android-retrostreams,代碼行數:14,代碼來源:Spliterators.java

示例14: forEachRemaining

import java9.util.function.Consumer; //導入方法依賴的package包/類
@Override
@SuppressWarnings("unchecked")
public void forEachRemaining(Consumer<? super E> action) {
    Objects.requireNonNull(action);
    int hi = getFence(), lo = index;
    Object[] a = array;
    index = hi;                 // ensure exhaustion
    for (int i = lo; i < hi; i++)
        action.accept((E) a[i]);
}
 
開發者ID:retrostreams,項目名稱:android-retrostreams,代碼行數:11,代碼來源:PBQueueSpliterator.java

示例15: forEachFrom

import java9.util.function.Consumer; //導入方法依賴的package包/類
/**
 * Runs action on each element found during a traversal starting at p.
 * If p is null, traversal starts at head.
 */
void forEachFrom(Consumer<? super E> action, Object p) {
    // Extract batches of elements while holding the lock; then
    // run the action on the elements while not
    ReentrantLock lock = queueLock;
    final int batchSize = 64;       // max number of elements per batch
    Object[] es = null;             // container for batch of elements
    int n, len = 0;
    do {
        lock.lock();
        try {
            if (es == null) {
                if (p == null) p = getQueueFirst(queue);
                for (Object q = p; q != null; q = succ(q))
                    if (getNodeItem(q) != null && ++len == batchSize)
                        break;
                es = new Object[len];
            }
            for (n = 0; p != null && n < len; p = succ(p))
                if ((es[n] = getNodeItem(p)) != null)
                    n++;
        } finally {
            // checkInvariants();
            lock.unlock();
        }
        for (int i = 0; i < n; i++) {
            @SuppressWarnings("unchecked") E e = (E) es[i];
            action.accept(e);
        }
    } while (n > 0 && p != null);
}
 
開發者ID:retrostreams,項目名稱:android-retrostreams,代碼行數:35,代碼來源:LBDSpliterator.java


注:本文中的java9.util.function.Consumer.accept方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。