20
20
import java .util .Set ;
21
21
import java .util .TreeSet ;
22
22
23
- public class Cookie implements Comparable <Cookie >{
23
+ public class Cookie implements Comparable <Cookie > {
24
24
private final String domain ;
25
25
private final String name ;
26
26
private final String value ;
@@ -160,7 +160,32 @@ public Set<Integer> getPorts() {
160
160
return unmodifiablePorts ;
161
161
}
162
162
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 ) {
164
189
Set <Integer > newPorts = new TreeSet <Integer >();
165
190
for (int p : ports ) {
166
191
if (p <= 0 || p > 65535 ) {
@@ -178,34 +203,8 @@ private void setPorts(Iterable<Integer> ports) {
178
203
179
204
@ Override
180
205
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 );
209
208
}
210
209
211
210
private String validateValue (String name , String value ) {
0 commit comments