1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18 package org.apache.logging.log4j.core.util;
19
20 import org.apache.logging.log4j.core.config.Node;
21 import org.apache.logging.log4j.core.config.plugins.Plugin;
22 import org.apache.logging.log4j.core.config.plugins.PluginBuilderAttribute;
23 import org.apache.logging.log4j.core.config.plugins.PluginBuilderFactory;
24
25
26
27
28
29
30 @Plugin(name = "KeyValuePair", category = Node.CATEGORY, printObject = true)
31 public final class KeyValuePair {
32
33 private final String key;
34 private final String value;
35
36
37
38
39
40
41 public KeyValuePair(final String key, final String value) {
42 this.key = key;
43 this.value = value;
44 }
45
46
47
48
49
50 public String getKey() {
51 return key;
52 }
53
54
55
56
57
58 public String getValue() {
59 return value;
60 }
61
62 @Override
63 public String toString() {
64 return key + '=' + value;
65 }
66
67 @PluginBuilderFactory
68 public static Builder newBuilder() {
69 return new Builder();
70 }
71
72 public static class Builder implements org.apache.logging.log4j.core.util.Builder<KeyValuePair> {
73
74 @PluginBuilderAttribute
75 private String key;
76
77 @PluginBuilderAttribute
78 private String value;
79
80 public Builder setKey(final String aKey) {
81 this.key = aKey;
82 return this;
83 }
84
85 public Builder setValue(final String aValue) {
86 this.value = aValue;
87 return this;
88 }
89
90 @Override
91 public KeyValuePair build() {
92 return new KeyValuePair(key, value);
93 }
94
95 }
96
97 @Override
98 public int hashCode() {
99 final int prime = 31;
100 int result = 1;
101 result = prime * result + ((key == null) ? 0 : key.hashCode());
102 result = prime * result + ((value == null) ? 0 : value.hashCode());
103 return result;
104 }
105
106 @Override
107 public boolean equals(final Object obj) {
108 if (this == obj) {
109 return true;
110 }
111 if (obj == null) {
112 return false;
113 }
114 if (getClass() != obj.getClass()) {
115 return false;
116 }
117 final KeyValuePair other = (KeyValuePair) obj;
118 if (key == null) {
119 if (other.key != null) {
120 return false;
121 }
122 } else if (!key.equals(other.key)) {
123 return false;
124 }
125 if (value == null) {
126 if (other.value != null) {
127 return false;
128 }
129 } else if (!value.equals(other.value)) {
130 return false;
131 }
132 return true;
133 }
134 }