"Fossies" - the Fresh Open Source Software Archive  

Source code changes of the file "log4j-api/src/main/java/org/apache/logging/log4j/message/MapMessage.java" between
apache-log4j-2.11.1-src.tar.gz and apache-log4j-2.11.2-src.tar.gz

About: Apache Log4j 2 is a logging library for Java. Source distribution (Java).

MapMessage.java  (apache-log4j-2.11.1-src):MapMessage.java  (apache-log4j-2.11.2-src)
skipping to change at line 19 skipping to change at line 19
* http://www.apache.org/licenses/LICENSE-2.0 * http://www.apache.org/licenses/LICENSE-2.0
* *
* Unless required by applicable law or agreed to in writing, software * Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, * distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the license for the specific language governing permissions and * See the license for the specific language governing permissions and
* limitations under the license. * limitations under the license.
*/ */
package org.apache.logging.log4j.message; package org.apache.logging.log4j.message;
import java.util.AbstractMap;
import java.util.Collections; import java.util.Collections;
import java.util.Map; import java.util.Map;
import java.util.TreeMap; import java.util.TreeMap;
import org.apache.logging.log4j.util.BiConsumer; import org.apache.logging.log4j.util.BiConsumer;
import org.apache.logging.log4j.util.Chars; import org.apache.logging.log4j.util.Chars;
import org.apache.logging.log4j.util.EnglishEnums; import org.apache.logging.log4j.util.EnglishEnums;
import org.apache.logging.log4j.util.IndexedReadOnlyStringMap; import org.apache.logging.log4j.util.IndexedReadOnlyStringMap;
import org.apache.logging.log4j.util.IndexedStringMap; import org.apache.logging.log4j.util.IndexedStringMap;
import org.apache.logging.log4j.util.MultiFormatStringBuilderFormattable; import org.apache.logging.log4j.util.MultiFormatStringBuilderFormattable;
skipping to change at line 67 skipping to change at line 68
* When set as the format specifier causes the Map to be formatted as XML. * When set as the format specifier causes the Map to be formatted as XML.
*/ */
public enum MapFormat { public enum MapFormat {
/** The map should be formatted as XML. */ /** The map should be formatted as XML. */
XML, XML,
/** The map should be formatted as JSON. */ /** The map should be formatted as JSON. */
JSON, JSON,
/** The map should be formatted the same as documented by java.util.Abst /** The map should be formatted the same as documented by {@link Abstrac
ractMap.toString(). */ tMap#toString()}. */
JAVA; JAVA,
/**
* The map should be formatted the same as documented by {@link Abstract
Map#toString()} but without quotes.
*
* @since 2.11.2
*/
JAVA_UNQUOTED;
/** /**
* Maps a format name to an {@link MapFormat} while ignoring case. * Maps a format name to an {@link MapFormat} while ignoring case.
* *
* @param format a MapFormat name * @param format a MapFormat name
* @return a MapFormat * @return a MapFormat
*/ */
public static MapFormat lookupIgnoreCase(final String format) { public static MapFormat lookupIgnoreCase(final String format) {
return XML.name().equalsIgnoreCase(format) ? XML // return XML.name().equalsIgnoreCase(format) ? XML //
: JSON.name().equalsIgnoreCase(format) ? JSON // : JSON.name().equalsIgnoreCase(format) ? JSON //
: JAVA.name().equalsIgnoreCase(format) ? JAVA // : JAVA.name().equalsIgnoreCase(format) ? JAVA //
: JAVA_UNQUOTED.name().equalsIgnoreCase(format) ? JAVA_UNQUO TED //
: null; : null;
} }
/** /**
* All {@code MapFormat} names. * All {@code MapFormat} names.
* *
* @return All {@code MapFormat} names. * @return All {@code MapFormat} names.
*/ */
public static String[] names() { public static String[] names() {
return new String[] {XML.name(), JSON.name(), JAVA.name()}; return new String[] {XML.name(), JSON.name(), JAVA.name(), JAVA_UNQU OTED.name()};
} }
} }
private final IndexedStringMap data; private final IndexedStringMap data;
/** /**
* Constructs a new instance. * Constructs a new instance.
*/ */
public MapMessage() { public MapMessage() {
this.data = new SortedArrayStringMap(); this.data = new SortedArrayStringMap();
skipping to change at line 215 skipping to change at line 224
data.putValue(entry.getKey(), entry.getValue()); data.putValue(entry.getKey(), entry.getValue());
} }
} }
/** /**
* Retrieves the value of the element with the specified key or null if the key is not present. * 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. * @param key The name of the element.
* @return The value of the element or null if the key is not present. * @return The value of the element or null if the key is not present.
*/ */
public String get(final String key) { public String get(final String key) {
Object result = data.getValue(key); final Object result = data.getValue(key);
return ParameterFormatter.deepToString(result); return ParameterFormatter.deepToString(result);
} }
/** /**
* Removes the element with the specified name. * Removes the element with the specified name.
* @param key The name of the element. * @param key The name of the element.
* @return The previous value of the element. * @return The previous value of the element.
*/ */
public String remove(final String key) { public String remove(final String key) {
final String result = get(key); final String result = get(key);
skipping to change at line 327 skipping to change at line 336
break; break;
} }
case JSON : { case JSON : {
asJson(sb); asJson(sb);
break; break;
} }
case JAVA : { case JAVA : {
asJava(sb); asJava(sb);
break; break;
} }
case JAVA_UNQUOTED:
asJavaUnquoted(sb);
break;
default : { default : {
appendMap(sb); appendMap(sb);
} }
} }
} }
return sb; return sb;
} }
/** /**
* Formats this message as an XML fragment String into the given builder. * Formats this message as an XML fragment String into the given builder.
* *
* @param sb format into this builder. * @param sb format into this builder.
*/ */
public void asXml(final StringBuilder sb) { public void asXml(final StringBuilder sb) {
sb.append("<Map>\n"); sb.append("<Map>\n");
for (int i = 0; i < data.size(); i++) { for (int i = 0; i < data.size(); i++) {
sb.append(" <Entry key=\"") sb.append(" <Entry key=\"")
.append(data.getKeyAt(i)) .append(data.getKeyAt(i))
.append("\">"); .append("\">");
int size = sb.length(); final int size = sb.length();
ParameterFormatter.recursiveDeepToString(data.getValueAt(i), sb, nul l); ParameterFormatter.recursiveDeepToString(data.getValueAt(i), sb, nul l);
StringBuilders.escapeXml(sb, size); StringBuilders.escapeXml(sb, size);
sb.append("</Entry>\n"); sb.append("</Entry>\n");
} }
sb.append("</Map>"); sb.append("</Map>");
} }
/** /**
* Formats the message and return it. * Formats the message and return it.
* @return the formatted message. * @return the formatted message.
skipping to change at line 421 skipping to change at line 433
StringBuilders.escapeJson(sb, start); StringBuilders.escapeJson(sb, start);
sb.append(Chars.DQUOTE).append(':').append(Chars.DQUOTE); sb.append(Chars.DQUOTE).append(':').append(Chars.DQUOTE);
start = sb.length(); start = sb.length();
ParameterFormatter.recursiveDeepToString(data.getValueAt(i), sb, nul l); ParameterFormatter.recursiveDeepToString(data.getValueAt(i), sb, nul l);
StringBuilders.escapeJson(sb, start); StringBuilders.escapeJson(sb, start);
sb.append(Chars.DQUOTE); sb.append(Chars.DQUOTE);
} }
sb.append('}'); sb.append('}');
} }
protected void asJavaUnquoted(final StringBuilder sb) {
asJava(sb, false);
}
protected void asJava(final StringBuilder sb) { protected void asJava(final StringBuilder sb) {
asJava(sb, true);
}
private void asJava(final StringBuilder sb, boolean quoted) {
sb.append('{'); sb.append('{');
for (int i = 0; i < data.size(); i++) { for (int i = 0; i < data.size(); i++) {
if (i > 0) { if (i > 0) {
sb.append(", "); sb.append(", ");
} }
sb.append(data.getKeyAt(i)).append(Chars.EQ).append(Chars.DQUOTE); sb.append(data.getKeyAt(i)).append(Chars.EQ);
if (quoted) {
sb.append(Chars.DQUOTE);
}
ParameterFormatter.recursiveDeepToString(data.getValueAt(i), sb, nul l); ParameterFormatter.recursiveDeepToString(data.getValueAt(i), sb, nul l);
sb.append(Chars.DQUOTE); if (quoted) {
sb.append(Chars.DQUOTE);
}
} }
sb.append('}'); sb.append('}');
} }
/** /**
* Constructs a new instance based on an existing Map. * Constructs a new instance based on an existing Map.
* @param map The Map. * @param map The Map.
* @return A new MapMessage * @return A new MapMessage
*/ */
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
skipping to change at line 455 skipping to change at line 480
public String toString() { public String toString() {
return asString(); return asString();
} }
@Override @Override
public void formatTo(final StringBuilder buffer) { public void formatTo(final StringBuilder buffer) {
format((MapFormat) null, buffer); format((MapFormat) null, buffer);
} }
@Override @Override
public void formatTo(String[] formats, StringBuilder buffer) { public void formatTo(final String[] formats, final StringBuilder buffer) {
format(getFormat(formats), buffer); format(getFormat(formats), buffer);
} }
@Override @Override
public boolean equals(final Object o) { public boolean equals(final Object o) {
if (this == o) { if (this == o) {
return true; return true;
} }
if (o == null || this.getClass() != o.getClass()) { if (o == null || this.getClass() != o.getClass()) {
return false; return false;
 End of changes. 12 change blocks. 
9 lines changed or deleted 35 lines changed or added

Home  |  About  |  Features  |  All  |  Newest  |  Dox  |  Diffs  |  RSS Feeds  |  Screenshots  |  Comments  |  Imprint  |  Privacy  |  HTTP(S)