public SortedArrayStringMap(final ReadOnlyStringMap other) { if (other instanceof SortedArrayStringMap) { initFrom0((SortedArrayStringMap) other); } else if (other != null) { resize(ceilingNextPowerOfTwo(other.size())); other.forEach(PUT_ALL, this); } }
@Override public void putAll(final ReadOnlyStringMap source) { if (source == this || source == null || source.isEmpty()) { // this.putAll(this) does not modify this collection // this.putAll(null) does not modify this collection // this.putAll(empty ReadOnlyStringMap) does not modify this collection return; } assertNotFrozen(); assertNoConcurrentModification(); if (source instanceof SortedArrayStringMap) { if (this.size == 0) { initFrom0((SortedArrayStringMap) source); } else { merge((SortedArrayStringMap) source); } } else if (source != null) { source.forEach(PUT_ALL, this); } }
@Override public void serialize(final ReadOnlyStringMap contextData, final JsonGenerator jgen, final SerializerProvider provider) throws IOException, JsonGenerationException { jgen.writeStartObject(); contextData.forEach(WRITE_STRING_FIELD_INTO, jgen); jgen.writeEndObject(); }
@Override public void putAll(final ReadOnlyStringMap source) { assertNotFrozen(); source.forEach(PUT_ALL, map); sortedKeys = null; }
@Override public void serialize(final ReadOnlyStringMap contextData, final JsonGenerator jgen, final SerializerProvider provider) throws IOException, JsonGenerationException { final MapEntry[] pairs = new MapEntry[contextData.size()]; contextData.forEach(new BiConsumer<String, Object>() { int i = 0; @Override public void accept(final String key, final Object value) { pairs[i++] = new MapEntry(key, String.valueOf(value)); } }); jgen.writeObject(pairs); } }
private static void appendFully(final ReadOnlyStringMap contextData, final StringBuilder toAppendTo) { final StringBuilder sb = getStringBuilder(); sb.append("{"); contextData.forEach(WRITE_KEY_VALUES_INTO, sb); sb.append('}'); toAppendTo.append(sb); trimToMaxSize(sb); }
/** * {@inheritDoc} */ @Override public void format(final LogEvent event, final StringBuilder toAppendTo) { if (key == null) { // if there is no additional options, we output every single Key/Value pair for the MDC toAppendTo.append('{'); event.getContextData().forEach(APPEND_EACH, toAppendTo); toAppendTo.append('}'); } else { // otherwise they just want a single key output final Object val = event.getContextData().getValue(key); if (val != null) { toAppendTo.append(val); } } }
@Override public String convertToDatabaseColumn(final ReadOnlyStringMap contextData) { if (contextData == null) { return null; } try { final JsonNodeFactory factory = OBJECT_MAPPER.getNodeFactory(); final ObjectNode root = factory.objectNode(); contextData.forEach(new BiConsumer<String, Object>() { @Override public void accept(final String key, final Object value) { // we will cheat here and write the toString of the Object... meh, but ok. root.put(key, String.valueOf(value)); } }); return OBJECT_MAPPER.writeValueAsString(root); } catch (final Exception e) { throw new PersistenceException("Failed to convert contextData to JSON string.", e); } }
if (!contextMap.isEmpty()) { buf.append("<log4j:properties>\r\n"); contextMap.forEach(new BiConsumer<String, String>() { @Override public void accept(final String key, final String val) {
public SortedArrayStringMap(final ReadOnlyStringMap other) { if (other instanceof SortedArrayStringMap) { initFrom0((SortedArrayStringMap) other); } else if (other != null) { resize(ceilingNextPowerOfTwo(other.size())); other.forEach(PUT_ALL, this); } }
@Override public void putAll(final ReadOnlyStringMap source) { if (source == this || source == null || source.isEmpty()) { // this.putAll(this) does not modify this collection // this.putAll(null) does not modify this collection // this.putAll(empty ReadOnlyStringMap) does not modify this collection return; } assertNotFrozen(); assertNoConcurrentModification(); if (source instanceof SortedArrayStringMap) { if (this.size == 0) { initFrom0((SortedArrayStringMap) source); } else { merge((SortedArrayStringMap) source); } } else if (source != null) { source.forEach(PUT_ALL, this); } }
event.getContextData().forEach(WRITE_KEY_VALUES_INTO, builder);