1 /* 2 * Licensed to the Apache Software Foundation (ASF) under one or more 3 * contributor license agreements. See the NOTICE file distributed with 4 * this work for additional information regarding copyright ownership. 5 * The ASF licenses this file to You under the Apache license, Version 2.0 6 * (the "License"); you may not use this file except in compliance with 7 * the License. You may obtain a copy of the License at 8 * 9 * http://www.apache.org/licenses/LICENSE-2.0 10 * 11 * Unless required by applicable law or agreed to in writing, software 12 * distributed under the License is distributed on an "AS IS" BASIS, 13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 * See the license for the specific language governing permissions and 15 * limitations under the license. 16 */ 17 package org.apache.logging.log4j.core.util; 18 19 import org.apache.logging.log4j.core.config.plugins.Plugin; 20 import org.apache.logging.log4j.core.config.plugins.PluginAttribute; 21 import org.apache.logging.log4j.core.config.plugins.PluginFactory; 22 23 /** 24 * Key/Value pair configuration item. 25 */ 26 @Plugin(name = "KeyValuePair", category = "Core", printObject = true) 27 public final class KeyValuePair { 28 29 private final String key; 30 private final String value; 31 32 /** 33 * Constructs a key/value pair. The constructor should only be called from test classes. 34 * @param key The key. 35 * @param value The value. 36 */ 37 public KeyValuePair(final String key, final String value) { 38 this.key = key; 39 this.value = value; 40 } 41 42 /** 43 * Returns the key. 44 * @return the key. 45 */ 46 public String getKey() { 47 return key; 48 } 49 50 /** 51 * Returns the value. 52 * @return The value. 53 */ 54 public String getValue() { 55 return value; 56 } 57 58 @Override 59 public String toString() { 60 return key + '=' + value; 61 } 62 63 /** 64 * Create a Key/Value pair. 65 * @param key The key. 66 * @param value The value. 67 * @return A KeyValuePair. 68 */ 69 @PluginFactory 70 public static KeyValuePair createPair( 71 @PluginAttribute("key") final String key, 72 @PluginAttribute("value") final String value) { 73 74 return new KeyValuePair(key, value); 75 } 76 }