org.apache.logging.log4j.util.TriConsumer Java Examples

The following examples show how to use org.apache.logging.log4j.util.TriConsumer. 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: OpenHashStringMap.java    From logging-log4j2 with Apache License 2.0 5 votes vote down vote up
@Override
@SuppressWarnings("unchecked")
public <VAL, STATE> void forEach(final TriConsumer<String, ? super VAL, STATE> action, final STATE state) {
    final int startSize = size;
    final K myKeys[] = this.keys;
    int pos = arraySize;

    iterating = true;
    try {
        if (containsNullKey) {
            action.accept((String) myKeys[pos], (VAL) values[pos], state);
            if (size != startSize) {
                throw new ConcurrentModificationException();
            }
        }
        --pos;
        for (; pos >= 0; pos--) {
            if (myKeys[pos] != null) {
                action.accept((String) myKeys[pos], (VAL) values[pos], state);
                if (size != startSize) {
                    throw new ConcurrentModificationException();
                }
            }
        }
    } finally {
        iterating = false;
    }
}
 
Example #2
Source File: DefaultThreadContextMap.java    From logging-log4j2 with Apache License 2.0 5 votes vote down vote up
@Override
public <V, S> void forEach(final TriConsumer<String, ? super V, S> action, final S state) {
    final Map<String, String> map = localMap.get();
    if (map == null) {
        return;
    }
    for (final Map.Entry<String, String> entry : map.entrySet()) {
        //TriConsumer should be able to handle values of any type V. In our case the values are of type String.
        @SuppressWarnings("unchecked")
        V value = (V) entry.getValue();
        action.accept(entry.getKey(), value, state);
    }
}
 
Example #3
Source File: JdkMapAdapterStringMap.java    From logging-log4j2 with Apache License 2.0 5 votes vote down vote up
@SuppressWarnings("unchecked")
@Override
public <V, S> void forEach(final TriConsumer<String, ? super V, S> action, final S state) {
    final String[] keys = getSortedKeys();
    for (int i = 0; i < keys.length; i++) {
        action.accept(keys[i], (V) map.get(keys[i]), state);
    }
}
 
Example #4
Source File: JdkMapAdapterStringMapTest.java    From logging-log4j2 with Apache License 2.0 5 votes vote down vote up
@Test
public void testNoConcurrentModificationTriConsumerPut() {
    final JdkMapAdapterStringMap original = new JdkMapAdapterStringMap();
    original.putValue("a", "aaa");
    original.putValue("b", "aaa");
    original.putValue("d", "aaa");
    original.putValue("e", "aaa");
    original.forEach(new TriConsumer<String, Object, Object>() {
        @Override
        public void accept(final String s, final Object o, final Object o2) {
            original.putValue("c", "other");
        }
    }, null);
}
 
Example #5
Source File: JdkMapAdapterStringMapTest.java    From logging-log4j2 with Apache License 2.0 5 votes vote down vote up
@Test
public void testNoConcurrentModificationTriConsumerPutValue() {
    final JdkMapAdapterStringMap original = new JdkMapAdapterStringMap();
    original.putValue("a", "aaa");
    original.putValue("b", "aaa");
    original.putValue("c", "aaa");
    original.putValue("d", "aaa");
    original.putValue("e", "aaa");
    original.forEach(new TriConsumer<String, Object, Object>() {
        @Override
        public void accept(final String s, final Object o, final Object o2) {
            original.putValue("c" + s, "other");
        }
    }, null);
}
 
Example #6
Source File: JdkMapAdapterStringMapTest.java    From logging-log4j2 with Apache License 2.0 5 votes vote down vote up
@Test
public void testNoConcurrentModificationTriConsumerRemove() {
    final JdkMapAdapterStringMap original = new JdkMapAdapterStringMap();
    original.putValue("a", "aaa");
    original.putValue("b", "aaa");
    original.putValue("c", "aaa");
    original.forEach(new TriConsumer<String, Object, Object>() {
        @Override
        public void accept(final String s, final Object o, final Object o2) {
            original.remove("a");
        }
    }, null);
}
 
Example #7
Source File: JdkMapAdapterStringMapTest.java    From logging-log4j2 with Apache License 2.0 5 votes vote down vote up
@Test
public void testNoConcurrentModificationTriConsumerClear() {
    final JdkMapAdapterStringMap original = new JdkMapAdapterStringMap();
    original.putValue("a", "aaa");
    original.putValue("b", "aaa");
    original.putValue("c", "aaa");
    original.putValue("d", "aaa");
    original.forEach(new TriConsumer<String, Object, Object>() {
        @Override
        public void accept(final String s, final Object o, final Object o2) {
            original.clear();
        }
    }, null);
}
 
Example #8
Source File: SettingsManager.java    From fabric-carpet with MIT License 4 votes vote down vote up
public void addRuleObserver(TriConsumer<ServerCommandSource, ParsedRule<?>, String> observer)
{
    observers.add(observer);
}
 
Example #9
Source File: SpecialBlockActions.java    From MiningGadgets with MIT License 4 votes vote down vote up
public static HashMap<Block, TriConsumer<World, BlockPos, BlockState>> getRegister() {
    return register;
}
 
Example #10
Source File: GameBootstrapper.java    From 2018-TowerDefence with MIT License 4 votes vote down vote up
private TriConsumer<GameMap, List<Player>, Boolean> getGameCompleteHandler() {
    return (gameMap, players, matchSuccessful) -> {
        GamePlayer winningPlayer = gameMap.getWinningPlayer();

        Player winner = players.stream()
                .filter(p -> p.getGamePlayer() == winningPlayer)
                .findFirst().orElse(null);

        StringBuilder winnerStringBuilder = new StringBuilder();

        for (Player player : players) {
            winnerStringBuilder.append(player.getName()
                    + "- score:" + player.getGamePlayer().getScore()
                    + " health:" + player.getGamePlayer().getHealth()
                    + "\n");
        }

        log.info("=======================================");
        log.info((winner == null)
                ? "The game ended in a tie"
                : "The winner is: " + winner.getName());
        log.info("=======================================");

        try {
            String roundLocation = String.format("%s/%s/endGameState.txt", gameName, FileUtils.getRoundDirectory(gameMap.getCurrentRound()));
            BufferedWriter bufferedWriter = new BufferedWriter(new FileWriter(new File(roundLocation)));

            if (winner == null) {
                winnerStringBuilder.insert(0, "The game ended in a tie" + "\n\n");
            } else {
                winnerStringBuilder.insert(0, "The winner is: " + winner.getName() + "\n\n");
            }

            if (!matchSuccessful) {
                winnerStringBuilder.insert(0, "Bot did nothing too many consecutive rounds" + "\n\n");
            }

            bufferedWriter.write(winnerStringBuilder.toString());
            bufferedWriter.flush();
            bufferedWriter.close();
        } catch (IOException e) {
            e.printStackTrace();
        }
    };
}
 
Example #11
Source File: RequestLoggingContextInjector.java    From curiostack with MIT License 4 votes vote down vote up
@Override
@SuppressWarnings("unchecked")
public <V, S> void forEach(TriConsumer<String, ? super V, S> action, S state) {
  map.forEach((key, value) -> action.accept(key, (V) value, state));
}
 
Example #12
Source File: LogEventWrapper.java    From logging-log4j2 with Apache License 2.0 4 votes vote down vote up
@Override
public <V, S> void forEach(TriConsumer<String, ? super V, S> action, S state) {
    super.forEach((k,v) -> action.accept(k, (V) v, state));
}
 
Example #13
Source File: FactoryTestStringMap.java    From logging-log4j2 with Apache License 2.0 4 votes vote down vote up
@Override
public <V, S> void forEach(final TriConsumer<String, ? super V, S> action, final S state) {
    // do nothing
}
 
Example #14
Source File: MapMessage.java    From logging-log4j2 with Apache License 2.0 2 votes vote down vote up
/**
 * Performs the given action for each key-value pair in this data structure
 * until all entries have been processed or the action throws an exception.
 * <p>
 * The third parameter lets callers pass in a stateful object to be modified with the key-value pairs,
 * so the TriConsumer implementation itself can be stateless and potentially reusable.
 * </p>
 * <p>
 * Some implementations may not support structural modifications (adding new elements or removing elements) while
 * iterating over the contents. In such implementations, attempts to add or remove elements from the
 * {@code TriConsumer}'s {@link TriConsumer#accept(Object, Object, Object) accept} method may cause a
 * {@code ConcurrentModificationException} to be thrown.
 * </p>
 *
 * @param action The action to be performed for each key-value pair in this collection
 * @param state the object to be passed as the third parameter to each invocation on the specified
 *          triconsumer
 * @param <CV> type of the consumer value
 * @param <S> type of the third parameter
 * @throws java.util.ConcurrentModificationException some implementations may not support structural modifications
 *          to this data structure while iterating over the contents with {@link #forEach(BiConsumer)} or
 *          {@link #forEach(TriConsumer, Object)}.
 * @see ReadOnlyStringMap#forEach(TriConsumer, Object)
 * @since 2.9
 */
public <CV, S> void forEach(final TriConsumer<String, ? super CV, S> action, final S state) {
    data.forEach(action, state);
}
 
Example #15
Source File: FactoryTestStringMapWithoutIntConstructor.java    From logging-log4j2 with Apache License 2.0 2 votes vote down vote up
@Override
public <V, S> void forEach(final TriConsumer<String, ? super V, S> action, final S state) {

}