Skip to content

Commit 9e7fb38

Browse files
author
Stephane Landelle
committed
Revive obsolete methods, deprecate them instead
1 parent 59348bf commit 9e7fb38

File tree

1 file changed

+29
-30
lines changed

1 file changed

+29
-30
lines changed

src/main/java/com/ning/http/client/Cookie.java

Lines changed: 29 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
import java.util.Set;
2121
import java.util.TreeSet;
2222

23-
public class Cookie implements Comparable<Cookie>{
23+
public class Cookie implements Comparable<Cookie> {
2424
private final String domain;
2525
private final String name;
2626
private final String value;
@@ -160,7 +160,32 @@ public Set<Integer> getPorts() {
160160
return unmodifiablePorts;
161161
}
162162

163-
private void setPorts(Iterable<Integer> ports) {
163+
@Deprecated
164+
// to be removed
165+
public void setPorts(int... ports) {
166+
if (ports == null) {
167+
throw new NullPointerException("ports");
168+
}
169+
170+
int[] portsCopy = ports.clone();
171+
if (portsCopy.length == 0) {
172+
unmodifiablePorts = this.ports = Collections.emptySet();
173+
} else {
174+
Set<Integer> newPorts = new TreeSet<Integer>();
175+
for (int p : portsCopy) {
176+
if (p <= 0 || p > 65535) {
177+
throw new IllegalArgumentException("port out of range: " + p);
178+
}
179+
newPorts.add(Integer.valueOf(p));
180+
}
181+
this.ports = newPorts;
182+
unmodifiablePorts = null;
183+
}
184+
}
185+
186+
@Deprecated
187+
// to become private
188+
public void setPorts(Iterable<Integer> ports) {
164189
Set<Integer> newPorts = new TreeSet<Integer>();
165190
for (int p : ports) {
166191
if (p <= 0 || p > 65535) {
@@ -178,34 +203,8 @@ private void setPorts(Iterable<Integer> ports) {
178203

179204
@Override
180205
public String toString() {
181-
StringBuilder buf = new StringBuilder();
182-
buf.append(getName());
183-
buf.append('=');
184-
buf.append(getValue());
185-
if (getDomain() != null) {
186-
buf.append("; domain=");
187-
buf.append(getDomain());
188-
}
189-
if (getPath() != null) {
190-
buf.append("; path=");
191-
buf.append(getPath());
192-
}
193-
if (getComment() != null) {
194-
buf.append("; comment=");
195-
buf.append(getComment());
196-
}
197-
if (getMaxAge() >= 0) {
198-
buf.append("; maxAge=");
199-
buf.append(getMaxAge());
200-
buf.append('s');
201-
}
202-
if (isSecure()) {
203-
buf.append("; secure");
204-
}
205-
if (isHttpOnly()) {
206-
buf.append("; HTTPOnly");
207-
}
208-
return buf.toString();
206+
return String.format("Cookie: domain=%s, name=%s, value=%s, path=%s, maxAge=%d, secure=%s",
207+
domain, name, value, path, maxAge, secure);
209208
}
210209

211210
private String validateValue(String name, String value) {

0 commit comments

Comments
 (0)