ensuring getters for public and private addresses return a set even if underlying addresses collection is null

This commit is contained in:
Mike Arnold 2012-03-07 09:24:19 -06:00
parent 5e6f84ec25
commit 98a3bf8084
1 changed files with 12 additions and 2 deletions

View File

@ -354,14 +354,24 @@ public class Server extends Resource {
* @return the private ip addresses assigned to the server * @return the private ip addresses assigned to the server
*/ */
public Set<Address> getPrivateAddresses() { public Set<Address> getPrivateAddresses() {
return ImmutableSet.copyOf(addresses.get(Address.Type.PRIVATE)); Set<Address> privateAddresses = addresses.get(Address.Type.PRIVATE);
if (privateAddresses == null) {
return ImmutableSet.<Address> of();
} else {
return ImmutableSet.copyOf(privateAddresses);
}
} }
/** /**
* @return the public ip addresses assigned to the server * @return the public ip addresses assigned to the server
*/ */
public Set<Address> getPublicAddresses() { public Set<Address> getPublicAddresses() {
return ImmutableSet.copyOf(addresses.get(Address.Type.PUBLIC)); Set<Address> publicAddrs = addresses.get(Address.Type.PUBLIC);
if (publicAddrs == null) {
return ImmutableSet.<Address> of();
} else {
return ImmutableSet.copyOf(publicAddrs);
}
} }
/** /**