/** * 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> * 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 BiConsumer}'s {@link BiConsumer#accept(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 <CV> type of the consumer value * @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(BiConsumer) * @since 2.9 */ public <CV> void forEach(final BiConsumer<String, ? super CV> action) { data.forEach(action); }
/** * Returns the message data as an unmodifiable Map. * @return the message data as an unmodifiable map. */ @SuppressWarnings("unchecked") public Map<String, V> getData() { final TreeMap<String, V> result = new TreeMap<>(); // returned map must be sorted for (int i = 0; i < data.size(); i++) { // The Eclipse compiler does not need the typecast to V, but the Oracle compiler sure does. result.put(data.getKeyAt(i), (V) data.getValueAt(i)); } return Collections.unmodifiableMap(result); }
/** * Adds all the elements from the specified Map. * @param map The Map to add. */ public void putAll(final Map<String, String> map) { for (final Map.Entry<String, String> entry : map.entrySet()) { data.putValue(entry.getKey(), entry.getValue()); } }
/** * Returns the data elements as if they were parameters on the logging event. * @return the data elements. */ @Override public Object[] getParameters() { final Object[] result = new Object[data.size()]; for (int i = 0; i < data.size(); i++) { result[i] = data.getValueAt(i); } return result; }
/** @deprecated use {@link #getStringMap()} instead */ @Deprecated protected Map<String, List<String>> getMap() { final Map<String, List<String>> result = new HashMap<>(map.size()); map.forEach(new BiConsumer<String, List<String>>() { @Override public void accept(final String key, final List<String> value) { result.put(key, value); } }); return result; }
/** * Clear the data. */ public void clear() { data.clear(); }
/** * Retrieves the value of the element with the specified key or null if the key is not present. * @param key The name of the element. * @return The value of the element or null if the key is not present. */ public String get(final String key) { Object result = data.getValue(key); return ParameterFormatter.deepToString(result); }
/** * Returns {@code true} if this data structure contains the specified key, {@code false} otherwise. * * @param key the key whose presence to check. May be {@code null}. * @return {@code true} if this data structure contains the specified key, {@code false} otherwise * @since 2.9 */ public boolean containsKey(final String key) { return data.containsKey(key); }
/** * Removes the element with the specified name. * @param key The name of the element. * @return The previous value of the element. */ public String remove(final String key) { final String result = get(key); data.remove(key); return result; }
/** * Returns the data elements as if they were parameters on the logging event. * @return the data elements. */ @Override public Object[] getParameters() { final Object[] result = new Object[data.size()]; for (int i = 0; i < data.size(); i++) { result[i] = data.getValueAt(i); } return result; }
/** * Clear the data. */ public void clear() { data.clear(); }
/** * Retrieves the value of the element with the specified key or null if the key is not present. * @param key The name of the element. * @return The value of the element or null if the key is not present. */ public String get(final String key) { return data.getValue(key); }
/** * Returns {@code true} if this data structure contains the specified key, {@code false} otherwise. * * @param key the key whose presence to check. May be {@code null}. * @return {@code true} if this data structure contains the specified key, {@code false} otherwise * @since 2.9 */ public boolean containsKey(final String key) { return data.containsKey(key); }
protected void appendMap(final StringBuilder sb) { for (int i = 0; i < data.size(); i++) { if (i > 0) { sb.append(' '); } sb.append(data.getKeyAt(i)).append(Chars.EQ).append(Chars.DQUOTE); ParameterFormatter.recursiveDeepToString(data.getValueAt(i), sb, null); sb.append(Chars.DQUOTE); } }
/** * Adds an item to the data Map. * @param key The name of the data item. * @param value The value of the data item. */ public void put(final String key, final String value) { if (value == null) { throw new IllegalArgumentException("No value provided for key " + key); } validate(key, value); data.putValue(key, value); }
/** * 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); }
protected void asJava(final StringBuilder sb) { sb.append('{'); for (int i = 0; i < data.size(); i++) { if (i > 0) { sb.append(", "); } sb.append(data.getKeyAt(i)).append(Chars.EQ).append(Chars.DQUOTE); ParameterFormatter.recursiveDeepToString(data.getValueAt(i), sb, null); sb.append(Chars.DQUOTE); } sb.append('}'); }
/** * Adds an item to the data Map. * @param key The name of the data item. * @param value The value of the data item. * @return this object * @since 2.9 */ @SuppressWarnings("unchecked") public M with(final String key, final double value) { validate(key, value); data.putValue(key, value); return (M) this; }
/** * 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> * 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 BiConsumer}'s {@link BiConsumer#accept(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 <CV> type of the consumer value * @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(BiConsumer) * @since 2.9 */ public <CV> void forEach(final BiConsumer<String, ? super CV> action) { data.forEach(action); }