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); } }
@Test public void testClear() { final MutableLogEvent mutable = new MutableLogEvent(); assertEquals("context data", 0, mutable.getContextData().size()); assertNull("context stack", mutable.getContextStack()); assertFalse("end of batch", mutable.isEndOfBatch()); assertEquals("context map", 0, mutable.getContextData().size()); assertNull("context stack", mutable.getContextStack()); assertSame("level", Level.OFF, mutable.getLevel());
@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); } }
/** * {@inheritDoc} */ @Override public void format(final LogEvent event, final StringBuilder toAppendTo) { final ReadOnlyStringMap contextData = event.getContextData(); // if there is no additional options, we output every single // Key/Value pair for the MDC in a similar format to Hashtable.toString() if (full) { if (contextData == null || contextData.size() == 0) { toAppendTo.append("{}"); return; } appendFully(contextData, toAppendTo); } else { if (keys != null) { if (contextData == null || contextData.size() == 0) { toAppendTo.append("{}"); return; } appendSelectedKeys(keys, contextData, toAppendTo); } else if (contextData != null){ // otherwise they just want a single key output final Object value = contextData.getValue(key); if (value != null) { StringBuilders.appendValue(toAppendTo, value); } } } }
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); } }