类org.apache.logging.log4j.util.TriConsumer源码实例Demo

下面列出了怎么用org.apache.logging.log4j.util.TriConsumer的API类实例代码及写法,或者点击链接到github查看源代码。

源代码1 项目: logging-log4j2   文件: OpenHashStringMap.java
@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;
    }
}
 
源代码2 项目: logging-log4j2   文件: DefaultThreadContextMap.java
@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);
    }
}
 
源代码3 项目: logging-log4j2   文件: JdkMapAdapterStringMap.java
@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);
    }
}
 
@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);
}
 
@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);
}
 
@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);
}
 
@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);
}
 
源代码8 项目: fabric-carpet   文件: SettingsManager.java
public void addRuleObserver(TriConsumer<ServerCommandSource, ParsedRule<?>, String> observer)
{
    observers.add(observer);
}
 
源代码9 项目: MiningGadgets   文件: SpecialBlockActions.java
public static HashMap<Block, TriConsumer<World, BlockPos, BlockState>> getRegister() {
    return register;
}
 
源代码10 项目: 2018-TowerDefence   文件: GameBootstrapper.java
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();
        }
    };
}
 
源代码11 项目: curiostack   文件: RequestLoggingContextInjector.java
@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));
}
 
源代码12 项目: logging-log4j2   文件: LogEventWrapper.java
@Override
public <V, S> void forEach(TriConsumer<String, ? super V, S> action, S state) {
    super.forEach((k,v) -> action.accept(k, (V) v, state));
}
 
源代码13 项目: logging-log4j2   文件: FactoryTestStringMap.java
@Override
public <V, S> void forEach(final TriConsumer<String, ? super V, S> action, final S state) {
    // do nothing
}
 
源代码14 项目: logging-log4j2   文件: MapMessage.java
/**
 * 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);
}
 
@Override
public <V, S> void forEach(final TriConsumer<String, ? super V, S> action, final S state) {

}
 
 类所在包
 类方法
 同包方法