001/* 002 * Licensed to the Apache Software Foundation (ASF) under one or more 003 * contributor license agreements. See the NOTICE file distributed with 004 * this work for additional information regarding copyright ownership. 005 * The ASF licenses this file to You under the Apache license, Version 2.0 006 * (the "License"); you may not use this file except in compliance with 007 * the License. You may obtain a copy of the License at 008 * 009 * http://www.apache.org/licenses/LICENSE-2.0 010 * 011 * Unless required by applicable law or agreed to in writing, software 012 * distributed under the License is distributed on an "AS IS" BASIS, 013 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 014 * See the license for the specific language governing permissions and 015 * limitations under the license. 016 */ 017package org.apache.logging.log4j.core.helpers; 018 019import org.apache.logging.log4j.core.config.plugins.Plugin; 020import org.apache.logging.log4j.core.config.plugins.PluginAttribute; 021import org.apache.logging.log4j.core.config.plugins.PluginFactory; 022 023/** 024 * Key/Value pair configuration item. 025 */ 026@Plugin(name = "KeyValuePair", category = "Core", printObject = true) 027public class KeyValuePair { 028 029 private final String key; 030 private final String value; 031 032 /** 033 * Constructs a key/value pair. The constructor should only be called from test classes. 034 * @param key The key. 035 * @param value The value. 036 */ 037 public KeyValuePair(final String key, final String value) { 038 this.key = key; 039 this.value = value; 040 } 041 042 /** 043 * Returns the key. 044 * @return the key. 045 */ 046 public String getKey() { 047 return key; 048 } 049 050 /** 051 * Returns the value. 052 * @return The value. 053 */ 054 public String getValue() { 055 return value; 056 } 057 058 @Override 059 public String toString() { 060 return key + "=" + value; 061 } 062 063 /** 064 * Create a Key/Value pair. 065 * @param key The key. 066 * @param value The value. 067 * @return A KeyValuePair. 068 */ 069 @PluginFactory 070 public static KeyValuePair createPair( 071 @PluginAttribute("key") final String key, 072 @PluginAttribute("value") final String value) { 073 074 return new KeyValuePair(key, value); 075 } 076}