Repository: logging-log4j2 Updated Branches: refs/heads/master df481a19c -> 12d9c1b7f
LOG4J2-1683, LOG4J2-1677, LOG4J2-1678, LOG4J2-1679 introduce interfaces IndexedStringMap and IndexedReadOnlyStringMap that allow indexed access to the sorted key-value pairs in a StringMap Project: http://git-wip-us.apache.org/repos/asf/logging-log4j2/repo Commit: http://git-wip-us.apache.org/repos/asf/logging-log4j2/commit/12d9c1b7 Tree: http://git-wip-us.apache.org/repos/asf/logging-log4j2/tree/12d9c1b7 Diff: http://git-wip-us.apache.org/repos/asf/logging-log4j2/diff/12d9c1b7 Branch: refs/heads/master Commit: 12d9c1b7fa6cbf501cf9fbe70e55b81ccc153d8a Parents: df481a1 Author: rpopma <[email protected]> Authored: Mon Nov 14 23:22:21 2016 +0900 Committer: rpopma <[email protected]> Committed: Mon Nov 14 23:22:21 2016 +0900 ---------------------------------------------------------------------- .../log4j/util/IndexedReadOnlyStringMap.java | 46 ++++++++++++++++++++ .../logging/log4j/util/IndexedStringMap.java | 28 ++++++++++++ .../log4j/util/SortedArrayStringMap.java | 2 +- .../logging/log4j/core/filter/MapFilter.java | 11 ++--- .../log4j/core/filter/StructuredDataFilter.java | 4 +- .../core/filter/ThreadContextMapFilter.java | 6 +-- 6 files changed, 86 insertions(+), 11 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/12d9c1b7/log4j-api/src/main/java/org/apache/logging/log4j/util/IndexedReadOnlyStringMap.java ---------------------------------------------------------------------- diff --git a/log4j-api/src/main/java/org/apache/logging/log4j/util/IndexedReadOnlyStringMap.java b/log4j-api/src/main/java/org/apache/logging/log4j/util/IndexedReadOnlyStringMap.java new file mode 100644 index 0000000..b06ab34 --- /dev/null +++ b/log4j-api/src/main/java/org/apache/logging/log4j/util/IndexedReadOnlyStringMap.java @@ -0,0 +1,46 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache license, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the license for the specific language governing permissions and + * limitations under the license. + */ +package org.apache.logging.log4j.util; + +/** + * An extension of {@code ReadOnlyStringMap} that views all key-value pairs as a sequence ordered by key, and allows + * keys and values to be accessed by their index in the sequence. + * + * @see ReadOnlyStringMap + * @since 2.8 + */ +public interface IndexedReadOnlyStringMap extends ReadOnlyStringMap { + + /** + * Viewing all key-value pairs as a sequence sorted by key, this method returns the key at the specified index, + * or {@code null} if the specified index is less than zero or greater or equal to the size of this collection. + * + * @param index the index of the key to return + * @return the key at the specified index or {@code null} + */ + String getKeyAt(final int index); + + /** + * Viewing all key-value pairs as a sequence sorted by key, this method returns the value at the specified index, + * or {@code null} if the specified index is less than zero or greater or equal to the size of this collection. + * + * @param index the index of the value to return + * @return the value at the specified index or {@code null} + */ + <V> V getValueAt(final int index); + +} http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/12d9c1b7/log4j-api/src/main/java/org/apache/logging/log4j/util/IndexedStringMap.java ---------------------------------------------------------------------- diff --git a/log4j-api/src/main/java/org/apache/logging/log4j/util/IndexedStringMap.java b/log4j-api/src/main/java/org/apache/logging/log4j/util/IndexedStringMap.java new file mode 100644 index 0000000..99c27a0 --- /dev/null +++ b/log4j-api/src/main/java/org/apache/logging/log4j/util/IndexedStringMap.java @@ -0,0 +1,28 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache license, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the license for the specific language governing permissions and + * limitations under the license. + */ +package org.apache.logging.log4j.util; + +/** + * An extension of {@code StringMap} that views all key-value pairs as a sequence ordered by key, and allows + * keys and values to be accessed by their index in the sequence. + * + * @see IndexedReadOnlyStringMap + * @see StringMap + * @since 2.8 + */ +public interface IndexedStringMap extends IndexedReadOnlyStringMap, StringMap { +} http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/12d9c1b7/log4j-api/src/main/java/org/apache/logging/log4j/util/SortedArrayStringMap.java ---------------------------------------------------------------------- diff --git a/log4j-api/src/main/java/org/apache/logging/log4j/util/SortedArrayStringMap.java b/log4j-api/src/main/java/org/apache/logging/log4j/util/SortedArrayStringMap.java index dbb95a2..24df831 100644 --- a/log4j-api/src/main/java/org/apache/logging/log4j/util/SortedArrayStringMap.java +++ b/log4j-api/src/main/java/org/apache/logging/log4j/util/SortedArrayStringMap.java @@ -50,7 +50,7 @@ import org.apache.logging.log4j.status.StatusLogger; * * @since 2.7 */ -public class SortedArrayStringMap implements StringMap { +public class SortedArrayStringMap implements IndexedStringMap { /** * The default initial capacity. http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/12d9c1b7/log4j-core/src/main/java/org/apache/logging/log4j/core/filter/MapFilter.java ---------------------------------------------------------------------- diff --git a/log4j-core/src/main/java/org/apache/logging/log4j/core/filter/MapFilter.java b/log4j-core/src/main/java/org/apache/logging/log4j/core/filter/MapFilter.java index f856a2d..85dc73e 100644 --- a/log4j-core/src/main/java/org/apache/logging/log4j/core/filter/MapFilter.java +++ b/log4j-core/src/main/java/org/apache/logging/log4j/core/filter/MapFilter.java @@ -36,6 +36,8 @@ import org.apache.logging.log4j.core.util.KeyValuePair; import org.apache.logging.log4j.message.MapMessage; import org.apache.logging.log4j.message.Message; import org.apache.logging.log4j.util.BiConsumer; +import org.apache.logging.log4j.util.IndexedReadOnlyStringMap; +import org.apache.logging.log4j.util.IndexedStringMap; import org.apache.logging.log4j.util.PerformanceSensitive; import org.apache.logging.log4j.util.ReadOnlyStringMap; import org.apache.logging.log4j.util.SortedArrayStringMap; @@ -47,8 +49,7 @@ import org.apache.logging.log4j.util.SortedArrayStringMap; @PerformanceSensitive("allocation") public class MapFilter extends AbstractFilter { - //private final Map<String, List<String>> map; - private final SortedArrayStringMap map; + private final IndexedStringMap map; private final boolean isAnd; protected MapFilter(final Map<String, List<String>> map, final boolean oper, final Result onMatch, final Result onMismatch) { @@ -225,11 +226,11 @@ public class MapFilter extends AbstractFilter { } /** - * Returns the SortedArrayStringMap with {@code List<String>} values that this MapFilter was constructed with. - * @return the SortedArrayStringMap with {@code List<String>} values to match against + * Returns the IndexedStringMap with {@code List<String>} values that this MapFilter was constructed with. + * @return the IndexedStringMap with {@code List<String>} values to match against * @since 2.8 */ - protected SortedArrayStringMap getStringMap() { + protected IndexedReadOnlyStringMap getStringMap() { return map; } http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/12d9c1b7/log4j-core/src/main/java/org/apache/logging/log4j/core/filter/StructuredDataFilter.java ---------------------------------------------------------------------- diff --git a/log4j-core/src/main/java/org/apache/logging/log4j/core/filter/StructuredDataFilter.java b/log4j-core/src/main/java/org/apache/logging/log4j/core/filter/StructuredDataFilter.java index a4a661a..9e46d27 100644 --- a/log4j-core/src/main/java/org/apache/logging/log4j/core/filter/StructuredDataFilter.java +++ b/log4j-core/src/main/java/org/apache/logging/log4j/core/filter/StructuredDataFilter.java @@ -34,8 +34,8 @@ import org.apache.logging.log4j.core.config.plugins.PluginFactory; import org.apache.logging.log4j.core.util.KeyValuePair; import org.apache.logging.log4j.message.Message; import org.apache.logging.log4j.message.StructuredDataMessage; +import org.apache.logging.log4j.util.IndexedReadOnlyStringMap; import org.apache.logging.log4j.util.PerformanceSensitive; -import org.apache.logging.log4j.util.SortedArrayStringMap; import org.apache.logging.log4j.util.StringBuilders; /** @@ -73,7 +73,7 @@ public final class StructuredDataFilter extends MapFilter { protected Result filter(final StructuredDataMessage message) { boolean match = false; - final SortedArrayStringMap map = getStringMap(); + final IndexedReadOnlyStringMap map = getStringMap(); for (int i = 0; i < map.size(); i++) { final StringBuilder toMatch = getValue(message, map.getKeyAt(i)); if (toMatch != null) { http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/12d9c1b7/log4j-core/src/main/java/org/apache/logging/log4j/core/filter/ThreadContextMapFilter.java ---------------------------------------------------------------------- diff --git a/log4j-core/src/main/java/org/apache/logging/log4j/core/filter/ThreadContextMapFilter.java b/log4j-core/src/main/java/org/apache/logging/log4j/core/filter/ThreadContextMapFilter.java index 7c28f35..f4613f1 100644 --- a/log4j-core/src/main/java/org/apache/logging/log4j/core/filter/ThreadContextMapFilter.java +++ b/log4j-core/src/main/java/org/apache/logging/log4j/core/filter/ThreadContextMapFilter.java @@ -24,6 +24,7 @@ import java.util.Map; import org.apache.logging.log4j.Level; import org.apache.logging.log4j.Marker; +import org.apache.logging.log4j.core.ContextDataInjector; import org.apache.logging.log4j.core.Filter; import org.apache.logging.log4j.core.LogEvent; import org.apache.logging.log4j.core.Logger; @@ -33,13 +34,12 @@ import org.apache.logging.log4j.core.config.plugins.PluginAliases; import org.apache.logging.log4j.core.config.plugins.PluginAttribute; import org.apache.logging.log4j.core.config.plugins.PluginElement; import org.apache.logging.log4j.core.config.plugins.PluginFactory; -import org.apache.logging.log4j.core.ContextDataInjector; import org.apache.logging.log4j.core.impl.ContextDataInjectorFactory; import org.apache.logging.log4j.core.util.KeyValuePair; import org.apache.logging.log4j.message.Message; +import org.apache.logging.log4j.util.IndexedReadOnlyStringMap; import org.apache.logging.log4j.util.PerformanceSensitive; import org.apache.logging.log4j.util.ReadOnlyStringMap; -import org.apache.logging.log4j.util.SortedArrayStringMap; /** * Filter based on a value in the Thread Context Map (MDC). @@ -99,7 +99,7 @@ public class ThreadContextMapFilter extends MapFilter { boolean match = false; if (useMap) { ReadOnlyStringMap currentContextData = null; - final SortedArrayStringMap map = getStringMap(); + final IndexedReadOnlyStringMap map = getStringMap(); for (int i = 0; i < map.size(); i++) { if (currentContextData == null) { currentContextData = currentContextData();
