本文整理汇总了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;
}
示例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);
}
}
示例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);
}
示例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();
}
}
示例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();
}
示例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;
}
示例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);
}
}
示例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;
}
示例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;
}
示例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;
}
示例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;
}
示例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);
}
示例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;
}
示例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]);
}
示例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);
}