/*
 * 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.core.util;

import java.io.Serializable;

import org.apache.logging.log4j.core.config.plugins.Plugin;
import org.apache.logging.log4j.core.config.plugins.PluginAttribute;
import org.apache.logging.log4j.core.config.plugins.PluginFactory;

/**
 * Key/Value pair configuration item.
 * 
 * @since 2.1 implements {@link Serializable}
 * @since 2.1 implements {@link #hashCode()} and {@link #equals(Object)}  
 */
@Plugin(name = "KeyValuePair", category = "Core", printObject = true)
public final class KeyValuePair implements Serializable {

    private static final long serialVersionUID = 4331228262821046866L;
    
    private final String key;
    private final String value;

    /**
     * Constructs a key/value pair. The constructor should only be called from test classes.
     * @param key The key.
     * @param value The value.
     */
    public KeyValuePair(final String key, final String value) {
        this.key = key;
        this.value = value;
    }

    /**
     * Returns the key.
     * @return the key.
     */
    public String getKey() {
        return key;
    }

    /**
     * Returns the value.
     * @return The value.
     */
    public String getValue() {
        return value;
    }

    @Override
    public String toString() {
        return key + '=' + value;
    }

    /**
     * Create a Key/Value pair.
     * @param key The key.
     * @param value The value.
     * @return A KeyValuePair.
     */
    @PluginFactory
    public static KeyValuePair createPair(
            @PluginAttribute("key") final String key,
            @PluginAttribute("value") final  String value) {

        return new KeyValuePair(key, value);
    }

    @Override
    public int hashCode() {
        final int prime = 31;
        int result = 1;
        result = prime * result + ((key == null) ? 0 : key.hashCode());
        result = prime * result + ((value == null) ? 0 : value.hashCode());
        return result;
    }

    @Override
    public boolean equals(Object obj) {
        if (this == obj) {
            return true;
        }
        if (obj == null) {
            return false;
        }
        if (getClass() != obj.getClass()) {
            return false;
        }
        KeyValuePair other = (KeyValuePair) obj;
        if (key == null) {
            if (other.key != null) {
                return false;
            }
        } else if (!key.equals(other.key)) {
            return false;
        }
        if (value == null) {
            if (other.value != null) {
                return false;
            }
        } else if (!value.equals(other.value)) {
            return false;
        }
        return true;
    }
}

@@ -794,16 +794,17 @@
 se.%0A */%0A
+%0A
 package 
@@ -840,16 +840,127 @@
 .util;%0A%0A
+import java.io.InvalidObjectException;%0Aimport java.io.ObjectInputStream;%0Aimport java.io.ObjectStreamException;%0A
 import j
@@ -1095,24 +1095,31 @@
 ugins.Plugin
+Builder
 Attribute;%0Ai
@@ -1171,24 +1171,31 @@
 ugins.Plugin
+Builder
 Factory;%0A%0A/*
@@ -2263,222 +2263,613 @@
     
-/**%0A     * Create a Key/Value pair.%0A     * @param key The key.%0A     * @param value The value.
+@PluginBuilderFactory%0A    public static Builder newBuilder() %7B%0A        return new Builder();%0A    %7D%0A%0A    protected Object writeReplace() throws ObjectStreamException %7B
 %0A     
-* @
+   
 return 
-A KeyValuePair.
+newBuilder().setKey(this.key).setValue(this.value);
 %0A    
- */
+%7D%0A
 %0A    
-@PluginFactory%0A    public static KeyValuePair createPair(%0A     
+private void readObject(final ObjectInputStream stream) throws InvalidObjectException %7B%0A        throw new InvalidObjectException(%22Builder proxy required%22);%0A    %7D%0A%0A    public static class Builder implements org.apache.logging.log4j.core.util.Builder%3CKeyValuePair%3E, Serializable %7B%0A%0A        private static final long serialVersionUID = 1L;%0A%0A
        
+ 
 @Plugin
+Builder
 Attr
@@ -2877,21 +2877,24 @@
 bute
-(%22key%22) final
+%0A        private
  Str
@@ -2904,14 +2904,11 @@
  key
-,%0A    
+;%0A%0A
     
@@ -2918,16 +2918,23 @@
  @Plugin
+Builder
 Attribut
@@ -2938,86 +2938,520 @@
 bute
-(%22value%22) final  String value) %7B%0A%0A        return new KeyValuePair(key, value);
+%0A        private String value;%0A%0A        public Builder setKey(final String key) %7B%0A            this.key = key;%0A            return this;%0A        %7D%0A%0A        public Builder setValue(final String value) %7B%0A            this.value = value;%0A            return this;%0A        %7D%0A%0A        @Override%0A        public KeyValuePair build() %7B%0A            return new KeyValuePair(key, value);%0A        %7D%0A%0A        protected Object readResolve() throws ObjectStreamException %7B%0A            return new KeyValuePair(key, value);%0A        %7D
 %0A   

Convert to builder with serialization proxy.