Java Code Examples for java.util.function.BiConsumer#accept()
The following examples show how to use
java.util.function.BiConsumer#accept() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: CayenneUpdateStage.java From agrest with Apache License 2.0 | 6 votes |
/** * Assigns child items to the appropriate parent item */ protected <T> void assignChildrenToParent(ResourceEntity<T> parentEntity, List children, BiConsumer<AgObjectId, Object> resultKeeper) { // saves a result for (Object child : children) { if (child instanceof Object[]) { Object[] ids = (Object[]) child; if (ids.length == 2) { resultKeeper.accept(new SimpleObjectId(ids[1]), (T) ids[0]); } else if (ids.length > 2) { // saves entity with a compound ID Map<String, Object> compoundKeys = new LinkedHashMap<>(); AgAttribute[] idAttributes = parentEntity.getAgEntity().getIds().toArray(new AgAttribute[0]); if (idAttributes.length == (ids.length - 1)) { for (int i = 1; i < ids.length; i++) { compoundKeys.put(idAttributes[i - 1].getName(), ids[i]); } } resultKeeper.accept(new CompoundObjectId(compoundKeys), (T) ids[0]); } } } }
Example 2
Source File: IdentityHashMap.java From hottub with GNU General Public License v2.0 | 6 votes |
@SuppressWarnings("unchecked") @Override public void forEach(BiConsumer<? super K, ? super V> action) { Objects.requireNonNull(action); int expectedModCount = modCount; Object[] t = table; for (int index = 0; index < t.length; index += 2) { Object k = t[index]; if (k != null) { action.accept((K) unmaskNull(k), (V) t[index + 1]); } if (modCount != expectedModCount) { throw new ConcurrentModificationException(); } } }
Example 3
Source File: Hashtable.java From Java8CN with Apache License 2.0 | 6 votes |
@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(); } } } }
Example 4
Source File: GuiUtils.java From green_android with GNU General Public License v3.0 | 6 votes |
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); } }
Example 5
Source File: Sourced.java From vlingo-lattice with Mozilla Public License 2.0 | 6 votes |
private <STT> void applySource(final Source<STT> source) { Class<?> type = getClass(); BiConsumer<Sourced<?>, Source<?>> consumer = null; while (type != Sourced.class) { final Map<Class<Source<?>>, BiConsumer<Sourced<?>, Source<?>>> sourcedTypeMap = registeredConsumers.get(type); if (sourcedTypeMap != null) { consumer = sourcedTypeMap.get(source.getClass()); if (consumer != null) { consumer.accept(this, source); break; } } type = type.getSuperclass(); } if (consumer == null) { throw new IllegalStateException("No such Sourced type."); } }
Example 6
Source File: WeakHashMap.java From Bytecoder with Apache License 2.0 | 6 votes |
@SuppressWarnings("unchecked") @Override public void forEach(BiConsumer<? super K, ? super V> action) { Objects.requireNonNull(action); int expectedModCount = modCount; Entry<K, V>[] tab = getTable(); for (Entry<K, V> entry : tab) { while (entry != null) { Object key = entry.get(); if (key != null) { action.accept((K)WeakHashMap.unmaskNull(key), entry.value); } entry = entry.next; if (expectedModCount != modCount) { throw new ConcurrentModificationException(); } } } }
Example 7
Source File: TupleTree.java From OSPREY3 with GNU General Public License v2.0 | 5 votes |
private void forEachIn(int[] conf, Node parent, int untilPos, BiConsumer<RCTuple,T> callback) { for (int pos=0; pos<untilPos; pos++) { // skip unassigned positions int rc = conf[pos]; if (rc == Conf.Unassigned) { continue; } // get the node for this rc, if any Node node = parent.get(pos, rc); if (node == null) { continue; } // callback if there's a tuple at this node if (node.tuple != null) { callback.accept(node.tuple, node.data); } // recurse if possible if (node.children != null) { forEachIn(conf, node, pos, callback); } } }
Example 8
Source File: TreeMap.java From Java8CN with Apache License 2.0 | 5 votes |
@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(); } } }
Example 9
Source File: ChatCommandsPluginTest.java From plugins with GNU General Public License v3.0 | 5 votes |
@Test public void testPlayerSkillLookup() throws IOException { Player player = mock(Player.class); when(player.getName()).thenReturn(PLAYER_NAME); when(client.getLocalPlayer()).thenReturn(player); when(chatCommandsConfig.lvl()).thenReturn(true); ArgumentCaptor<BiConsumer<ChatMessage, String>> captor = ArgumentCaptor.forClass(BiConsumer.class); verify(chatCommandManager).registerCommandAsync(eq("!lvl"), captor.capture()); BiConsumer<ChatMessage, String> value = captor.getValue(); SingleHiscoreSkillResult skillResult = new SingleHiscoreSkillResult(); skillResult.setPlayer(PLAYER_NAME); skillResult.setSkill(new Skill(10, 1000, -1)); when(hiscoreClient.lookup(PLAYER_NAME, HiscoreSkill.ZULRAH, null)).thenReturn(skillResult); MessageNode messageNode = mock(MessageNode.class); ChatMessage chatMessage = new ChatMessage(); chatMessage.setType(ChatMessageType.PUBLICCHAT); chatMessage.setName(PLAYER_NAME); chatMessage.setMessageNode(messageNode); value.accept(chatMessage, "!lvl zulrah"); verify(messageNode).setRuneLiteFormatMessage("<colNORMAL>Level <colHIGHLIGHT>Zulrah: 1000<colNORMAL> Rank: <colHIGHLIGHT>10"); }
Example 10
Source File: ConcurrentSkipListMap.java From JDKSourceCode1.8 with MIT License | 5 votes |
public void forEach(BiConsumer<? super K, ? super V> action) { if (action == null) throw new NullPointerException(); V v; for (Node<K,V> n = findFirst(); n != null; n = n.next) { if ((v = n.getValidValue()) != null) action.accept(n.key, v); } }
Example 11
Source File: MapBinToFromTreeTest.java From jdk8u60 with GNU General Public License v2.0 | 5 votes |
void remove(Map<HashCodeInteger, Integer> m, BiConsumer<Integer, Integer> c) { int size = m.size(); // Remove all elements thus ensuring at some point trees will be // converting back to bins for (int i = 0; i < size; i++) { m.remove(new HashCodeInteger(i)); c.accept(i, m.size()); } }
Example 12
Source File: PowsyblWriterSequenceFixTest.java From powsybl-core with Mozilla Public License 2.0 | 5 votes |
private void addStatements(TripleStoreRDF4J ts, BiConsumer<RepositoryConnection, Map<PropertyBag, IRI>> adder) { try (RepositoryConnection cnx = ts.getRepository().getConnection()) { cnx.setIsolationLevel(IsolationLevels.NONE); Map<PropertyBag, IRI> objectSubject = new HashMap<>(); adder.accept(cnx, objectSubject); } }
Example 13
Source File: ConverterAwareMappingSpannerEntityWriter.java From spring-cloud-gcp with Apache License 2.0 | 5 votes |
private static boolean attemptSetIterablePropertyWithTypeConversion(Iterable<Object> value, ValueBinder<WriteBuilder> valueBinder, Class innerType, Class<?> targetType, SpannerCustomConverter writeConverter) { if (writeConverter.canConvert(innerType, targetType)) { BiConsumer<ValueBinder<?>, Iterable> toMethod = iterablePropertyTypeToMethodMap .get(targetType); toMethod.accept(valueBinder, (value != null) ? ConversionUtils.convertIterable(value, targetType, writeConverter) : null); return true; } return false; }
Example 14
Source File: ParagraphBox.java From RichTextFX with BSD 2-Clause "Simplified" License | 5 votes |
ParagraphBox(Paragraph<PS, SEG, S> par, BiConsumer<TextFlow, PS> applyParagraphStyle, Function<StyledSegment<SEG, S>, Node> nodeFactory) { this.getStyleClass().add("paragraph-box"); this.text = new ParagraphText<>(par, nodeFactory); applyParagraphStyle.accept(this.text, par.getParagraphStyle()); // start at -1 so that the first time it is displayed, the caret at pos 0 is not // accidentally removed from its parent and moved to this node's ParagraphText // before this node gets updated to its real index and therefore removes // caret from the SceneGraph completely this.index = Var.newSimpleVar(-1); getChildren().add(text); graphic = Val.combine( graphicFactory, this.index, (f, i) -> f != null && i > -1 ? f.apply(i) : null); graphic.addListener((obs, oldG, newG) -> { if(oldG != null) { getChildren().remove(oldG); } if(newG != null) { getChildren().add(newG); } }); graphicOffset.addListener(obs -> requestLayout()); }
Example 15
Source File: ReduceOps.java From jdk8u60 with GNU General Public License v2.0 | 5 votes |
/** * Constructs a {@code TerminalOp} that implements a mutable reduce on * reference values. * * @param <T> the type of the input elements * @param <R> the type of the result * @param seedFactory a factory to produce a new base accumulator * @param accumulator a function to incorporate an element into an * accumulator * @param reducer a function to combine an accumulator into another * @return a {@code TerminalOp} implementing the reduction */ public static <T, R> TerminalOp<T, R> makeRef(Supplier<R> seedFactory, BiConsumer<R, ? super T> accumulator, BiConsumer<R,R> reducer) { Objects.requireNonNull(seedFactory); Objects.requireNonNull(accumulator); Objects.requireNonNull(reducer); class ReducingSink extends Box<R> implements AccumulatingSink<T, R, ReducingSink> { @Override public void begin(long size) { state = seedFactory.get(); } @Override public void accept(T t) { accumulator.accept(state, t); } @Override public void combine(ReducingSink other) { reducer.accept(state, other.state); } } return new ReduceOp<T, R, ReducingSink>(StreamShape.REFERENCE) { @Override public ReducingSink makeSink() { return new ReducingSink(); } }; }
Example 16
Source File: HibernateSearchConfigUtil.java From quarkus with Apache License 2.0 | 4 votes |
public static <T> void addConfig(BiConsumer<String, Object> propertyCollector, String configPath, T value) { propertyCollector.accept(configPath, value); }
Example 17
Source File: recursivestructtype.java From aws-sdk-java-v2 with Apache License 2.0 | 4 votes |
private static <T> BiConsumer<Object, T> setter(BiConsumer<Builder, T> s) { return (obj, val) -> s.accept((Builder) obj, val); }
Example 18
Source File: Map.java From openjdk-jdk8u-backup with GNU General Public License v2.0 | 4 votes |
/** * Performs the given action for each entry in this map until all entries * have been processed or the action throws an exception. Unless * otherwise specified by the implementing class, actions are performed in * the order of entry set iteration (if an iteration order is specified.) * Exceptions thrown by the action are relayed to the caller. * * @implSpec * The default implementation is equivalent to, for this {@code map}: * <pre> {@code * for (Map.Entry<K, V> entry : map.entrySet()) * action.accept(entry.getKey(), entry.getValue()); * }</pre> * * The default implementation makes no guarantees about synchronization * or atomicity properties of this method. Any implementation providing * atomicity guarantees must override this method and document its * concurrency properties. * * @param action The action to be performed for each entry * @throws NullPointerException if the specified action is null * @throws ConcurrentModificationException if an entry is found to be * removed during iteration * @since 1.8 */ default void forEach(BiConsumer<? super K, ? super V> action) { Objects.requireNonNull(action); for (Map.Entry<K, V> entry : entrySet()) { K k; V v; try { k = entry.getKey(); v = entry.getValue(); } catch(IllegalStateException ise) { // this usually means the entry is no longer in the map. throw new ConcurrentModificationException(ise); } action.accept(k, v); } }
Example 19
Source File: Board.java From lizzie with GNU General Public License v3.0 | 4 votes |
/** * Jump anywhere in the board history tree. * * @param targetNode history node to be located * @return void */ public void moveToAnyPosition(BoardHistoryNode targetNode) { List<Integer> targetParents = new ArrayList<Integer>(); List<Integer> sourceParents = new ArrayList<Integer>(); BiConsumer<BoardHistoryNode, List<Integer>> populateParent = (node, parentList) -> { Optional<BoardHistoryNode> prevNode = node.previous(); while (prevNode.isPresent()) { BoardHistoryNode p = prevNode.get(); for (int m = 0; m < p.numberOfChildren(); m++) { if (p.getVariation(m).get() == node) { parentList.add(m); } } node = p; prevNode = p.previous(); } }; // Compute the path from the current node to the root populateParent.accept(history.getCurrentHistoryNode(), sourceParents); // Compute the path from the target node to the root populateParent.accept(targetNode, targetParents); // Compute the distance from source to the deepest common answer int targetDepth = targetParents.size(); int sourceDepth = sourceParents.size(); int maxDepth = min(targetParents.size(), sourceParents.size()); int depth; for (depth = 0; depth < maxDepth; depth++) { int sourceParent = sourceParents.get(sourceDepth - depth - 1); int targetParent = targetParents.get(targetDepth - depth - 1); if (sourceParent != targetParent) { break; } } // Move all the way up to the deepest common ansestor for (int m = 0; m < sourceDepth - depth; m++) { previousMove(); } // Then all the way down to the target for (int m = targetDepth - depth; m > 0; m--) { nextVariation(targetParents.get(m - 1)); } }
Example 20
Source File: MeterRegistry.java From micrometer with Apache License 2.0 | 2 votes |
/** * Handle a meter registration failure. * * @param id The id that was attempted, but for which registration failed. * @param reason The reason why the meter registration has failed * @since 1.6.0 */ protected void meterRegistrationFailed(Meter.Id id, @Nullable String reason) { for (BiConsumer<Id, String> listener : meterRegistrationFailedListeners) { listener.accept(id, reason); } }