本文整理汇总了Java中java8.util.function.Consumer类的典型用法代码示例。如果您正苦于以下问题:Java Consumer类的具体用法?Java Consumer怎么用?Java Consumer使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
Consumer类属于java8.util.function包,在下文中一共展示了Consumer类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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);
}
示例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);
}
}
}
示例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);
}
示例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;
}
}
示例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;
}
示例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;
}
示例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);
}
});
}
示例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;
}
示例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);
}
示例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;
}
示例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;
}
示例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;
}
示例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;
}
示例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;
}
示例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;
}