* Replaced Cookie.setPortList(int[]) with Cookie.setPortList(int...)

* Improved DefaultCooke.setPortList() integrity check
* DefaultCookie.getPortList() returns a copy
This commit is contained in:
Trustin Lee 2009-03-13 11:51:19 +00:00
parent 395d57b6eb
commit df3ac447ff
2 changed files with 13 additions and 4 deletions

View File

@ -47,5 +47,5 @@ public interface Cookie extends Comparable<Cookie> {
boolean isDiscard();
void setDiscard(boolean discard);
int[] getPortList();
void setPortList(int[] portList);
void setPortList(int... portList);
}

View File

@ -128,11 +128,20 @@ public class DefaultCookie implements Cookie {
}
public int[] getPortList() {
return portList;
return portList.clone();
}
public void setPortList(int[] portList) {
this.portList = portList;
public void setPortList(int... portList) {
if (portList == null) {
throw new NullPointerException("portList");
}
int[] portListCopy = portList.clone();
for (int p: portListCopy) {
if (p <= 0 || p > 65535) {
throw new IllegalArgumentException("port out of range: " + p);
}
}
this.portList = portListCopy;
}
public int getMaxAge() {