本文整理汇总了Java中java.util.function.Consumer.accept方法的典型用法代码示例。如果您正苦于以下问题:Java Consumer.accept方法的具体用法?Java Consumer.accept怎么用?Java Consumer.accept使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类java.util.function.Consumer
的用法示例。
在下文中一共展示了Consumer.accept方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: peek
import java.util.function.Consumer; //导入方法依赖的package包/类
@Override
public final Stream<P_OUT> peek(Consumer<? super P_OUT> action) {
Objects.requireNonNull(action);
return new StatelessOp<P_OUT, P_OUT>(this, StreamShape.REFERENCE,
0) {
@Override
Sink<P_OUT> opWrapSink(int flags, Sink<P_OUT> sink) {
return new Sink.ChainedReference<P_OUT, P_OUT>(sink) {
@Override
public void accept(P_OUT u) {
action.accept(u);
downstream.accept(u);
}
};
}
};
}
示例2: iterate
import java.util.function.Consumer; //导入方法依赖的package包/类
/**
* Returns an infinite sequential ordered {@code Stream} produced by iterative
* application of a function {@code f} to an initial element {@code seed},
* producing a {@code Stream} consisting of {@code seed}, {@code f(seed)},
* {@code f(f(seed))}, etc.
*
* <p>The first element (position {@code 0}) in the {@code Stream} will be
* the provided {@code seed}. For {@code n > 0}, the element at position
* {@code n}, will be the result of applying the function {@code f} to the
* element at position {@code n - 1}.
*
* <p>The action of applying {@code f} for one element
* <a href="../concurrent/package-summary.html#MemoryVisibility"><i>happens-before</i></a>
* the action of applying {@code f} for subsequent elements. For any given
* element the action may be performed in whatever thread the library
* chooses.
*
* @param <T> the type of stream elements
* @param seed the initial element
* @param f a function to be applied to the previous element to produce
* a new element
* @return a new sequential {@code Stream}
*/
public static<T> Stream<T> iterate(final T seed, final UnaryOperator<T> f) {
Objects.requireNonNull(f);
Spliterator<T> spliterator = new Spliterators.AbstractSpliterator<>(Long.MAX_VALUE,
Spliterator.ORDERED | Spliterator.IMMUTABLE) {
T prev;
boolean started;
@Override
public boolean tryAdvance(Consumer<? super T> action) {
Objects.requireNonNull(action);
T t;
if (started)
t = f.apply(prev);
else {
t = seed;
started = true;
}
action.accept(prev = t);
return true;
}
};
return StreamSupport.stream(spliterator, false);
}
示例3: setZoom
import java.util.function.Consumer; //导入方法依赖的package包/类
@Override
public void setZoom(final float targetZoom, final int delay) {
if (delay == 0) {
for (final Consumer<Float> cons : this.zoomChangedConsumer) {
cons.accept(targetZoom);
}
this.zoom = targetZoom;
this.targetZoom = 0;
this.zoomDelay = 0;
this.zoomTick = 0;
this.zoomStep = 0;
} else {
this.zoomTick = Game.getLoop().getTicks();
this.targetZoom = targetZoom;
this.zoomDelay = delay;
final double tickduration = 1000 / (double) Game.getLoop().getUpdateRate();
final double tickAmount = delay / tickduration;
final float totalDelta = this.targetZoom - this.zoom;
this.zoomStep = tickAmount > 0 ? (float) (totalDelta / tickAmount) : totalDelta;
}
}
示例4: tryAdvance
import java.util.function.Consumer; //导入方法依赖的package包/类
public boolean tryAdvance(Consumer<? super V> action) {
if (action == null)
throw new NullPointerException();
Object[] a = map.table;
int hi = getFence();
while (index < hi) {
Object key = a[index];
@SuppressWarnings("unchecked") V v = (V)a[index+1];
index += 2;
if (key != null) {
action.accept(v);
if (map.modCount != expectedModCount)
throw new ConcurrentModificationException();
return true;
}
}
return false;
}
示例5: monitorTask
import java.util.function.Consumer; //导入方法依赖的package包/类
/**
* Creates an instance of the {@link ProgressBarController} and starts executing the task in a new thread.
*
* @param task a lambda that accepts an instance of {@link ProgressUpdater}
*/
public void monitorTask(final Consumer<ProgressUpdater> task) {
final Task<Void> progressTask = new Task<Void>() {
@Override
public Void call() throws InterruptedException, IOException, UIInitialisationException {
task.accept((progress, message) -> {
if (progress == PROGRESS_TOTAL) {
Platform.runLater(stage::close);
}
this.updateProgress(progress, PROGRESS_TOTAL);
progressBarController.updateProgressText(message);
});
return null;
}
};
initialize(progressTask);
}
示例6: tryAdvance
import java.util.function.Consumer; //导入方法依赖的package包/类
@Override
@Synchronized
public boolean tryAdvance(@NonNull final Consumer<? super SearchHit> action) {
if (cursor < searchHits.length) {
final SearchHit searchHit = searchHits[cursor++];
update(searchHit);
action.accept(searchHit);
return true;
}
if (nextBatch == null) {
close();
return false;
}
final SearchResponse searchResponse = nextBatch.actionGet();
cursor = 0;
searchHits = searchResponse.getHits().getHits();
nextBatch = getNextBatch(searchResponse);
if (searchHits.length == 0) {
close();
return false;
}
return tryAdvance(action);
}
示例7: tryAdvance
import java.util.function.Consumer; //导入方法依赖的package包/类
public boolean tryAdvance(Consumer<? super E> action) {
Node<E> p;
if (action == null) throw new NullPointerException();
final ConcurrentLinkedQueue<E> q = this.queue;
if (!exhausted &&
((p = current) != null || (p = q.first()) != null)) {
E e;
do {
e = p.item;
if (p == (p = p.next))
p = q.first();
} while (e == null && p != null);
if ((current = p) == null)
exhausted = true;
if (e != null) {
action.accept(e);
return true;
}
}
return false;
}
示例8: forEach
import java.util.function.Consumer; //导入方法依赖的package包/类
public final void forEach(Consumer<? super Map.Entry<K,V>> action) {
Node<K,V>[] tab;
if (action == null)
throw new NullPointerException();
if (size > 0 && (tab = table) != null) {
int mc = modCount;
for (Node<K, V> e : tab) {
for (; e != null; e = e.next)
action.accept(e);
}
if (modCount != mc)
throw new ConcurrentModificationException();
}
}
示例9: initializeStateIndicator
import java.util.function.Consumer; //导入方法依赖的package包/类
private void initializeStateIndicator() {
// Find the state indicator from the inflated xml
final StackPane stateIndicator = (StackPane) lookup("#stateIndicator");
// Delegate that based on a query state updates the color of the state indicator
final Consumer<QueryState> updateColor = (queryState) -> {
final Color color = queryState.getColor();
final Color.Intensity colorIntensity = queryState.getColorIntensity();
if (queryState.equals(QueryState.UNKNOWN) || queryState.equals(QueryState.RUNNING)) {
stateIndicator.setBackground(new Background(new BackgroundFill(TRANSPARENT,
CornerRadii.EMPTY,
Insets.EMPTY)
));
} else {
stateIndicator.setBackground(new Background(new BackgroundFill(color.getColor(colorIntensity),
CornerRadii.EMPTY,
Insets.EMPTY)
));
}
};
// Update the initial color
updateColor.accept(query.getQueryState());
// Ensure that the color is updated when ever the query state is updated
query.queryStateProperty().addListener((observable, oldValue, newValue) -> updateColor.accept(newValue));
}
示例10: forEach
import java.util.function.Consumer; //导入方法依赖的package包/类
@Override
public void forEach(Consumer<? super Entry<K, V>> action) {
checkNotNull(action);
for (Entry<K, V> entry : entries) {
action.accept(entry);
}
}
示例11: compute
import java.util.function.Consumer; //导入方法依赖的package包/类
public final void compute() {
final Consumer<? super K> action;
if ((action = this.action) != null) {
for (int i = baseIndex, f, h; batch > 0 &&
(h = ((f = baseLimit) + i) >>> 1) > i;) {
addToPendingCount(1);
new ForEachKeyTask<K,V>
(this, batch >>>= 1, baseLimit = h, f, tab,
action).fork();
}
for (Node<K,V> p; (p = advance()) != null;)
action.accept(p.key);
propagateCompletion();
}
}
示例12: tryAdvance
import java.util.function.Consumer; //导入方法依赖的package包/类
public boolean tryAdvance(Consumer<? super K> action) {
TreeMap.Entry<K,V> e;
if (action == null)
throw new NullPointerException();
if (est < 0)
getEstimate(); // force initialization
if ((e = current) == null || e == fence)
return false;
current = successor(e);
action.accept(e.key);
if (tree.modCount != expectedModCount)
throw new ConcurrentModificationException();
return true;
}
示例13: forEachRemaining
import java.util.function.Consumer; //导入方法依赖的package包/类
public void forEachRemaining(Consumer<? super K> action) {
int i, hi, mc;
if (action == null)
throw new NullPointerException();
WeakHashMap<K,V> m = map;
WeakHashMap.Entry<K,V>[] tab = m.table;
if ((hi = fence) < 0) {
mc = expectedModCount = m.modCount;
hi = fence = tab.length;
}
else
mc = expectedModCount;
if (tab.length >= hi && (i = index) >= 0 &&
(i < (index = hi) || current != null)) {
WeakHashMap.Entry<K,V> p = current;
current = null; // exhaust
do {
if (p == null)
p = tab[i++];
else {
Object x = p.get();
p = p.next;
if (x != null) {
@SuppressWarnings("unchecked") K k =
(K) WeakHashMap.unmaskNull(x);
action.accept(k);
}
}
} while (p != null || i < hi);
}
if (m.modCount != mc)
throw new ConcurrentModificationException();
}
示例14: tryAdvance
import java.util.function.Consumer; //导入方法依赖的package包/类
public boolean tryAdvance(Consumer<? super V> action) {
TreeMapBST.Entry<K,V> e;
if (action == null)
throw new NullPointerException();
if (est < 0)
getEstimate(); // force initialization
if ((e = current) == null || e == fence)
return false;
current = successor(e);
action.accept(e.value);
if (tree.modCount != expectedModCount)
throw new ConcurrentModificationException();
return true;
}
示例15: solve
import java.util.function.Consumer; //导入方法依赖的package包/类
/**
* Solves the constraints of the receiving inference context.
* <p>
* This method returns
* <ul>
* <li>null, if no solution was found
* <li>otherwise, a map from each inference variable returned from {@link #getInferenceVariables()} to its
* instantiation.
* </ul>
* At this time, no partial solutions are returned in case of unsolvable constraint systems.
*/
public Map<InferenceVariable, TypeRef> solve() {
Measurement mes = collector.getMeasurement("soleve " + new SimpleDateFormat("hh:mm:ss.SSS").format(new Date()));
if (isSolved) {
mes.end();
return solution;
}
isSolved = true;
if (DEBUG) {
log("====== ====== ====== ====== ====== ====== ====== ====== ====== ====== ====== ======");
log("solving the following constraint set:");
constraints.stream().forEachOrdered(c -> log(c.toString()));
log("inference variables: "
+ inferenceVariables.stream().map(iv -> str(iv)).collect(Collectors.joining(", ")));
}
// ---------------------------------------------------------------------------
// REDUCTION
// new constraints added during reduction or incorporation will be reduced immediately (see #addConstraint()
// above) so no need for recursion, here
if (DEBUG) {
log("****** Reduction");
}
for (final TypeConstraint constraint : constraints) {
reducer.reduce(constraint);
if (isDoomed()) {
break;
}
}
// clearing the list of constraints is ok given their information has been transferred to the bound set,
// to which bounds are added but never removed.
constraints.clear();
// ---------------------------------------------------------------------------
// INCORPORATION
if (DEBUG) {
log("****** Incorporation");
}
if (!isDoomed()) {
currentBounds.incorporate();
}
// ---------------------------------------------------------------------------
// RESOLUTION
if (DEBUG) {
log("****** Resolution");
}
final boolean success = !isDoomed() ? resolve() : false;
solution = success ? currentBounds.getInstantiations() : null;
if (DEBUG) {
if (!success) {
log("NO SOLUTION FOUND");
} else {
log("SOLUTION:");
currentBounds.dumpInstantiations();
}
}
// perform onSolvedActions
for (Consumer<Optional<Map<InferenceVariable, TypeRef>>> action : onSolvedActions) {
action.accept(Optional.fromNullable(solution));
}
mes.end();
return solution;
}