本文整理汇总了Java中java.util.function.BiConsumer.accept方法的典型用法代码示例。如果您正苦于以下问题:Java BiConsumer.accept方法的具体用法?Java BiConsumer.accept怎么用?Java BiConsumer.accept使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类java.util.function.BiConsumer
的用法示例。
在下文中一共展示了BiConsumer.accept方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: find
import java.util.function.BiConsumer; //导入方法依赖的package包/类
/**
* Finds the closest node or edges within the specified maximum radius.
*
* @param x the x position of the query point
* @param y the y position of the query point
* @param nodeAction the action that needs to be executed when a node is found
* @param edgeAction the action that needs to be executed when an edge is found
*/
@SuppressWarnings("squid:S1166") // No need to log the exception itself, a message is enough.
public void find(final double x, final double y,
final Consumer<Integer> nodeAction, final BiConsumer<Integer, Integer> edgeAction) {
try {
final Entry<Integer[], Geometry> result = tree.nearest(point(x, y), MAX_NEARNESS_DISTANCE, 1)
.toBlocking()
.first();
if (result.geometry() instanceof Rectangle) {
nodeAction.accept(result.value()[0]);
} else if (result.geometry() instanceof Line) {
edgeAction.accept(result.value()[0], result.value()[1]);
}
} catch (final NoSuchElementException e) {
// There is no need to log the exception itself.
LOGGER.debug("No node or edge found at position (" + x + ", " + y + ").");
}
}
示例2: runAlert
import java.util.function.BiConsumer; //导入方法依赖的package包/类
public static void runAlert(BiConsumer<Stage, AlertWindowController> setup) {
try {
// JavaFX2 doesn't actually have a standard alert template. Instead the Scene Builder app will create FXML
// files for an alert window for you, and then you customise it as you see fit. I guess it makes sense in
// an odd sort of way.
Stage dialogStage = new Stage();
dialogStage.initModality(Modality.APPLICATION_MODAL);
FXMLLoader loader = new FXMLLoader(GuiUtils.class.getResource("alert.fxml"));
Pane pane = loader.load();
AlertWindowController controller = loader.getController();
setup.accept(dialogStage, controller);
dialogStage.setScene(new Scene(pane));
dialogStage.showAndWait();
} catch (IOException e) {
// We crashed whilst trying to show the alert dialog (this should never happen). Give up!
throw new RuntimeException(e);
}
}
示例3: testWriteLock_lockUnlock
import java.util.function.BiConsumer; //导入方法依赖的package包/类
/**
* write-locking, then unlocking, an unlocked lock succeed
*/
public void testWriteLock_lockUnlock() {
StampedLock lock = new StampedLock();
for (Function<StampedLock, Long> writeLocker : writeLockers())
for (BiConsumer<StampedLock, Long> writeUnlocker : writeUnlockers()) {
assertFalse(lock.isWriteLocked());
assertFalse(lock.isReadLocked());
assertEquals(0, lock.getReadLockCount());
long s = writeLocker.apply(lock);
assertValid(lock, s);
assertTrue(lock.isWriteLocked());
assertFalse(lock.isReadLocked());
assertEquals(0, lock.getReadLockCount());
writeUnlocker.accept(lock, s);
assertUnlocked(lock);
}
}
示例4: forEach
import java.util.function.BiConsumer; //导入方法依赖的package包/类
@SuppressWarnings("unchecked")
@Override
public synchronized void forEach(BiConsumer<? super K, ? super V> action) {
Objects.requireNonNull(action); // explicit check required in case
// table is empty.
final int expectedModCount = modCount;
Entry<?, ?>[] tab = table;
for (Entry<?, ?> entry : tab) {
while (entry != null) {
action.accept((K)entry.key, (V)entry.value);
entry = entry.next;
if (expectedModCount != modCount) {
throw new ConcurrentModificationException();
}
}
}
}
示例5: forEach
import java.util.function.BiConsumer; //导入方法依赖的package包/类
public void forEach(BiConsumer<? super K, ? super V> action) {
if (action == null)
throw new NullPointerException();
int mc = modCount;
for (LinkedHashMap.Entry<K,V> e = head; e != null; e = e.after)
action.accept(e.key, e.value);
if (modCount != mc)
throw new ConcurrentModificationException();
}
示例6: pullEach
import java.util.function.BiConsumer; //导入方法依赖的package包/类
public static <T> CompletableSubscriber<T> pullEach(BiConsumer<T, Subscription> consumer) {
return new AbstractCompletableSubscriber<T>() {
@Override
public void onSubscribe(Subscription subscription) {
super.onSubscribe(subscription);
subscription.request(1);
}
@Override
public void onNext(T item) {
consumer.accept(item, subscription);
}
};
}
示例7: forEachPropertyPair
import java.util.function.BiConsumer; //导入方法依赖的package包/类
@Override
public void forEachPropertyPair(AbstractBlockBase<?> block, BiConsumer<String, String> action) {
if (get(Flags.SUBTREE, block) && (block.getDominator() == null || !get(Flags.SUBTREE, block.getDominator()))) {
action.accept("hasDefinition", "true");
}
super.forEachPropertyPair(block, action);
}
示例8: forEach
import java.util.function.BiConsumer; //导入方法依赖的package包/类
@Override
public void forEach(BiConsumer<? super K, ? super V> action) {
checkNotNull(action);
for (Entry<K, V> entry : entries) {
action.accept(entry.getKey(), entry.getValue());
}
}
示例9: getAllUniforms
import java.util.function.BiConsumer; //导入方法依赖的package包/类
public static void getAllUniforms(int program, BiConsumer<Integer,String> dest){
glUseProgram(program);
int id=0;
String name,last="";
while(!(name=glGetActiveUniform(program, id, 512)).isEmpty()){
if(last.equals(name)) break;
dest.accept(id, last=name);
id++;
}
}
示例10: test
import java.util.function.BiConsumer; //导入方法依赖的package包/类
static <E> void test(Queue<E> queue, Supplier<E> supplier,
BiConsumer<? super Queue<E>, Throwable> checker) {
Throwable x = null;
try { queue.add(supplier.get()); }
catch (Throwable e) { x = e; }
checker.accept(queue, x);
}
示例11: createList
import java.util.function.BiConsumer; //导入方法依赖的package包/类
public static <V extends DoublyLinkedPanel<V>> void createList(int count, Function<Integer, V> constructor, BiConsumer<Integer,V> forEach){
V prevField = null;
for(int i = 0; i<count; i++){
V newField = constructor.apply(i);
forEach.accept(i, newField);
DoublyLinkedPanel.link(prevField, newField);
prevField = newField;
}
}
示例12: exec
import java.util.function.BiConsumer; //导入方法依赖的package包/类
/**
* @param list
* @param fnEach
* @param <V>
*/
static <V> void exec(final List<V> list,
final BiConsumer<V, Integer> fnEach) {
final int size = list.size();
for (int idx = Values.IDX; idx < size; idx++) {
final V item = list.get(idx);
if (null != item) {
fnEach.accept(item, idx);
}
}
}
示例13: testTryUnlockWrite_failure
import java.util.function.BiConsumer; //导入方法依赖的package包/类
/**
* tryUnlockWrite fails if not write locked
*/
public void testTryUnlockWrite_failure() {
StampedLock lock = new StampedLock();
assertFalse(lock.tryUnlockWrite());
for (Function<StampedLock, Long> readLocker : readLockers())
for (BiConsumer<StampedLock, Long> readUnlocker : readUnlockers()) {
long s = assertValid(lock, readLocker.apply(lock));
assertFalse(lock.tryUnlockWrite());
assertTrue(lock.isReadLocked());
readUnlocker.accept(lock, s);
assertUnlocked(lock);
}
}
示例14: forEach
import java.util.function.BiConsumer; //导入方法依赖的package包/类
@Override
public void forEach(BiConsumer<? super K, ? super V> action) {
Objects.requireNonNull(action);
int expectedModCount = modCount;
for (Entry<K, V> e = getFirstEntry(); e != null; e = successor(e)) {
action.accept(e.key, e.value);
if (expectedModCount != modCount) {
throw new ConcurrentModificationException();
}
}
}
示例15: forEachWithIndex
import java.util.function.BiConsumer; //导入方法依赖的package包/类
/**
* 带序号迭代元组
*
* @param action 带序号的迭代函数
*/
public final void forEachWithIndex(final BiConsumer<Integer, ? super Object> action) {
requireNonNull(action, "action is null");
for (int i = 0, length = this.valueList.size(); i < length; i++)
action.accept(i, this.valueList.get(i));
}