1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28 package org.apache.hc.core5.http.message;
29
30 import java.io.Serializable;
31 import java.util.Objects;
32
33 import org.apache.hc.core5.annotation.Contract;
34 import org.apache.hc.core5.annotation.ThreadingBehavior;
35 import org.apache.hc.core5.http.NameValuePair;
36 import org.apache.hc.core5.util.Args;
37 import org.apache.hc.core5.util.LangUtils;
38 import org.apache.hc.core5.util.TextUtils;
39
40
41
42
43
44
45 @Contract(threading = ThreadingBehavior.IMMUTABLE)
46 public class BasicNameValuePair implements NameValuePair, Serializable {
47
48 private static final long serialVersionUID = -6437800749411518984L;
49
50 private final String name;
51 private final String value;
52
53
54
55
56
57
58
59 public BasicNameValuePair(final String name, final String value) {
60 super();
61 this.name = Args.notNull(name, "Name");
62 this.value = value;
63 }
64
65 @Override
66 public String getName() {
67 return this.name;
68 }
69
70 @Override
71 public String getValue() {
72 return this.value;
73 }
74
75 @Override
76 public String toString() {
77
78
79 if (this.value == null) {
80 return name;
81 }
82 final int len = this.name.length() + 1 + this.value.length();
83 final StringBuilder buffer = new StringBuilder(len);
84 buffer.append(this.name);
85 buffer.append("=");
86 buffer.append(this.value);
87 return buffer.toString();
88 }
89
90 @Override
91 public boolean equals(final Object obj) {
92 if (this == obj) {
93 return true;
94 }
95 if (obj instanceof BasicNameValuePair) {
96 final BasicNameValuePair that = (BasicNameValuePair) obj;
97 return this.name.equalsIgnoreCase(that.name) && Objects.equals(this.value, that.value);
98 }
99 return false;
100 }
101
102 @Override
103 public int hashCode() {
104 int hash = LangUtils.HASH_SEED;
105 hash = LangUtils.hashCode(hash, TextUtils.toLowerCase(this.name));
106 hash = LangUtils.hashCode(hash, this.value);
107 return hash;
108 }
109
110 }