下面列出了org.apache.logging.log4j.util.BiConsumer#accept ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
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('"');
}
@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;
}
}
@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);
}
}
@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]));
}
}
@Override
public void forEach(BiConsumer<String, String> action) {
action.accept("log4j.isThreadContextMapInheritable", "true");
}
@Override
public void forEach(BiConsumer<String, String> action) {
action.accept("log4j.isThreadContextMapInheritable", "true");
}
@Override
public <V> void forEach(BiConsumer<String, ? super V> action) {
super.forEach((k,v) -> action.accept(k, (V) v));
}