Java Code Examples for org.apache.logging.log4j.util.BiConsumer#accept()

The following examples show how to use org.apache.logging.log4j.util.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: JsonWriter.java    From logging-log4j2 with Apache License 2.0 6 votes vote down vote up
public <S> void writeString(
        final BiConsumer<StringBuilder, S> emitter,
        final S state) {
    Objects.requireNonNull(emitter, "emitter");
    stringBuilder.append('"');
    formattableBuffer.setLength(0);
    emitter.accept(formattableBuffer, state);
    final int length = formattableBuffer.length();
    // Handle max. string length complying input.
    if (length <= maxStringLength) {
        quoteString(formattableBuffer, 0, length);
    }
    // Handle max. string length violating input.
    else {
        quoteString(formattableBuffer, 0, maxStringLength);
        stringBuilder.append(quotedTruncatedStringSuffix);
    }
    stringBuilder.append('"');
}
 
Example 2
Source File: OpenHashStringMap.java    From logging-log4j2 with Apache License 2.0 5 votes vote down vote up
@Override
@SuppressWarnings("unchecked")
public <VAL> void forEach(final BiConsumer<String, ? super VAL> action) {
    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]);
            if (size != startSize) {
                throw new ConcurrentModificationException();
            }
        }
        --pos;
        for (; pos >= 0; pos--) {
            if (myKeys[pos] != null) {
                action.accept((String) myKeys[pos], (VAL) values[pos]);
                if (size != startSize) {
                    throw new ConcurrentModificationException();
                }
            }
        }
    } finally {
        iterating = false;
    }
}
 
Example 3
Source File: DefaultThreadContextMap.java    From logging-log4j2 with Apache License 2.0 5 votes vote down vote up
@Override
public <V> void forEach(final BiConsumer<String, ? super V> action) {
    final Map<String, String> map = localMap.get();
    if (map == null) {
        return;
    }
    for (final Map.Entry<String, String> entry : map.entrySet()) {
        //BiConsumer 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);
    }
}
 
Example 4
Source File: JdkMapAdapterStringMap.java    From logging-log4j2 with Apache License 2.0 5 votes vote down vote up
@SuppressWarnings("unchecked")
@Override
public <V> void forEach(final BiConsumer<String, ? super V> action) {
    final String[] keys = getSortedKeys();
    for (int i = 0; i < keys.length; i++) {
        action.accept(keys[i], (V) map.get(keys[i]));
    }
}
 
Example 5
Source File: Log4jPropertySource.java    From Javacord with Apache License 2.0 4 votes vote down vote up
@Override
public void forEach(BiConsumer<String, String> action) {
    action.accept("log4j.isThreadContextMapInheritable", "true");
}
 
Example 6
Source File: Log4jPropertySource.java    From Javacord with Apache License 2.0 4 votes vote down vote up
@Override
public void forEach(BiConsumer<String, String> action) {
    action.accept("log4j.isThreadContextMapInheritable", "true");
}
 
Example 7
Source File: LogEventWrapper.java    From logging-log4j2 with Apache License 2.0 4 votes vote down vote up
@Override
public <V> void forEach(BiConsumer<String, ? super V> action) {
    super.forEach((k,v) -> action.accept(k, (V) v));
}