switch to old google collections syntax to avoid conflict between guava and google collections

This commit is contained in:
Adrian Cole 2010-04-26 23:46:22 -07:00
parent 1af5fccb0c
commit e3a816e6cd
10 changed files with 235 additions and 221 deletions

View File

@ -116,7 +116,8 @@ public class EC2RestClientModule extends AbstractModule {
@Singleton
@EC2
Region provideCurrentRegion(@EC2 Map<Region, URI> regionMap, @EC2 URI currentUri) {
ImmutableBiMap<URI, Region> map = ImmutableBiMap.copyOf(regionMap).inverse();
ImmutableBiMap<URI, Region> map = ImmutableBiMap.<Region, URI> builder().putAll(regionMap)
.build().inverse();
Region region = map.get(currentUri);
assert region != null : currentUri + " not in " + map;
return region;

View File

@ -18,11 +18,13 @@
*/
package org.jclouds.aws.ec2.domain;
import com.google.common.collect.*;
import com.google.inject.internal.Nullable;
import static com.google.common.base.Preconditions.checkNotNull;
import com.google.common.collect.ImmutableMultimap;
import com.google.common.collect.LinkedHashMultimap;
import com.google.common.collect.Multimap;
import com.google.inject.internal.Nullable;
/**
* Defines the mapping of volumes for
* {@link org.jclouds.aws.ec2.services.InstanceClient#setBlockDeviceMappingForInstanceInRegion}.
@ -31,38 +33,43 @@ import static com.google.common.base.Preconditions.checkNotNull;
*/
public class BlockDeviceMapping {
private final Multimap<String, RunningInstance.EbsBlockDevice> ebsBlockDevices =
LinkedHashMultimap.create();
private final Multimap<String, RunningInstance.EbsBlockDevice> ebsBlockDevices = LinkedHashMultimap
.create();
public BlockDeviceMapping() {
}
public BlockDeviceMapping() {
}
/**
* Creates block device mapping from the list of {@link RunningInstance.EbsBlockDevice devices}.
*
* This method copies the values of the list.
* @param ebsBlockDevices
* devices to be changed for the volume. This cannot be null.
*/
public BlockDeviceMapping(Multimap<String, RunningInstance.EbsBlockDevice> ebsBlockDevices) {
this.ebsBlockDevices.putAll(checkNotNull(ebsBlockDevices,
/*or throw*/ "EbsBlockDevices can't be null"));
}
/**
* Creates block device mapping from the list of {@link RunningInstance.EbsBlockDevice devices}.
*
* This method copies the values of the list.
*
* @param ebsBlockDevices
* devices to be changed for the volume. This cannot be null.
*/
public BlockDeviceMapping(Multimap<String, RunningInstance.EbsBlockDevice> ebsBlockDevices) {
this.ebsBlockDevices.putAll(checkNotNull(ebsBlockDevices,
/* or throw */"EbsBlockDevices can't be null"));
}
/**
* Adds a {@link RunningInstance.EbsBlockDevice} to the mapping.
* @param deviceName name of the device to apply the mapping. Can be null.
* @param ebsBlockDevice
* ebsBlockDevice to be added. This cannot be null.
* @return the same instance for method chaining purposes
*/
public BlockDeviceMapping addEbsBlockDevice(@Nullable String deviceName, RunningInstance.EbsBlockDevice ebsBlockDevice) {
this.ebsBlockDevices.put(deviceName, checkNotNull(ebsBlockDevice,
/*or throw*/ "EbsBlockDevice can't be null"));
return this;
}
/**
* Adds a {@link RunningInstance.EbsBlockDevice} to the mapping.
*
* @param deviceName
* name of the device to apply the mapping. Can be null.
* @param ebsBlockDevice
* ebsBlockDevice to be added. This cannot be null.
* @return the same instance for method chaining purposes
*/
public BlockDeviceMapping addEbsBlockDevice(@Nullable String deviceName,
RunningInstance.EbsBlockDevice ebsBlockDevice) {
this.ebsBlockDevices.put(deviceName, checkNotNull(ebsBlockDevice,
/* or throw */"EbsBlockDevice can't be null"));
return this;
}
public Multimap<String, RunningInstance.EbsBlockDevice> getEbsBlockDevices() {
return ImmutableMultimap.copyOf(ebsBlockDevices);
}
public Multimap<String, RunningInstance.EbsBlockDevice> getEbsBlockDevices() {
return ImmutableMultimap.<String, RunningInstance.EbsBlockDevice> builder().putAll(
ebsBlockDevices).build();
}
}

View File

@ -128,7 +128,7 @@ public class S3RestClientModule extends AbstractModule {
@Singleton
@S3
Region getDefaultRegion(@S3 URI uri, @S3 Map<Region, URI> map) {
return ImmutableBiMap.copyOf(map).inverse().get(uri);
return ImmutableBiMap.<Region, URI> builder().putAll(map).build().inverse().get(uri);
}
@Provides

View File

@ -110,7 +110,7 @@ public class SQSRestClientModule extends AbstractModule {
@Singleton
@SQS
Region getDefaultRegion(@SQS URI uri, @SQS Map<Region, URI> map) {
return ImmutableBiMap.copyOf(map).inverse().get(uri);
return ImmutableBiMap.<Region, URI> builder().putAll(map).build().inverse().get(uri);
}
@Provides

View File

@ -49,7 +49,7 @@ public class QueueHandler extends ParseSax.HandlerWithResult<Queue> {
@Inject
QueueHandler(Provider<UriBuilder> uriBuilderProvider, @SQS Map<Region, URI> regionMap) {
this.uriBuilderProvider = uriBuilderProvider;
this.regionBiMap = ImmutableBiMap.copyOf(regionMap);
this.regionBiMap = ImmutableBiMap.<Region, URI> builder().putAll(regionMap).build();
}
public Queue getResult() {

View File

@ -46,7 +46,7 @@ public class BaseRegexQueueHandler {
@Inject
protected BaseRegexQueueHandler(Map<Region, URI> regionMap) {
this.uriToRegion = ImmutableBiMap.copyOf(regionMap).inverse();
this.uriToRegion = ImmutableBiMap.<Region, URI> builder().putAll(regionMap).build().inverse();
}
public Set<Queue> parse(String in) {

View File

@ -43,6 +43,7 @@ import com.google.common.util.concurrent.ListenableFuture;
*
* @author Adrian Cole
*/
@SuppressWarnings("deprecation")
@Singleton
public class SyncProxy implements InvocationHandler {
@ -60,7 +61,7 @@ public class SyncProxy implements InvocationHandler {
private final Map<Method, Method> methodMap;
private final Map<Method, Method> syncMethodMap;
private final Map<Method, Long> timeoutMap;
private static final Set<Method> objectMethods = ImmutableSet.copyOf(Object.class.getMethods());
private static final Set<Method> objectMethods = ImmutableSet.of(Object.class.getMethods());
@Inject
public SyncProxy(Class<?> declaring, Object delegate) throws SecurityException,

View File

@ -18,14 +18,14 @@
*/
package org.jclouds.gogrid.domain;
import com.google.common.collect.ImmutableSortedSet;
import com.google.common.primitives.Longs;
import com.google.gson.annotations.SerializedName;
import java.util.Date;
import java.util.Map;
import java.util.Set;
import java.util.SortedSet;
import com.google.common.primitives.Longs;
import com.google.gson.annotations.SerializedName;
/**
* Represents any job in GoGrid system
* (jobs include server creation, stopping, etc)
@ -47,7 +47,7 @@ public class Job implements Comparable<Job> {
private JobState currentState;
private int attempts;
private String owner;
private SortedSet<JobProperties> history;
private Set<JobProperties> history;
@SerializedName("detail") /*NOTE: as of Feb 28, 10,
there is a contradiction b/w the name in
documentation (details) and actual param
@ -108,8 +108,8 @@ public class Job implements Comparable<Job> {
return owner;
}
public SortedSet<JobProperties> getHistory() {
return ImmutableSortedSet.copyOf(history);
public Set<JobProperties> getHistory() {
return history;
}
public Map<String, String> getDetails() {

View File

@ -18,12 +18,11 @@
*/
package org.jclouds.gogrid.domain;
import com.google.common.collect.ImmutableSortedSet;
import java.util.Set;
import com.google.common.primitives.Longs;
import com.google.gson.annotations.SerializedName;
import java.util.SortedSet;
/**
* @author Oleksiy Yarmula
*/
@ -35,7 +34,7 @@ public class LoadBalancer implements Comparable<LoadBalancer> {
@SerializedName("virtualip")
private IpPortPair virtualIp;
@SerializedName("realiplist")
private SortedSet<IpPortPair> realIpList;
private Set<IpPortPair> realIpList;
private LoadBalancerType type;
private LoadBalancerPersistenceType persistence;
private LoadBalancerOs os;
@ -48,7 +47,7 @@ public class LoadBalancer implements Comparable<LoadBalancer> {
}
public LoadBalancer(long id, String name, String description,
IpPortPair virtualIp, SortedSet<IpPortPair> realIpList, LoadBalancerType type,
IpPortPair virtualIp, Set<IpPortPair> realIpList, LoadBalancerType type,
LoadBalancerPersistenceType persistence, LoadBalancerOs os,
LoadBalancerState state) {
this.id = id;
@ -78,8 +77,8 @@ public class LoadBalancer implements Comparable<LoadBalancer> {
return virtualIp;
}
public SortedSet<IpPortPair> getRealIpList() {
return ImmutableSortedSet.copyOf(realIpList);
public Set<IpPortPair> getRealIpList() {
return realIpList;
}
public LoadBalancerType getType() {

View File

@ -23,204 +23,210 @@
*/
package org.jclouds.gogrid.domain;
import com.google.common.collect.ImmutableSortedSet;
import java.util.Date;
import java.util.Set;
import com.google.common.primitives.Longs;
import com.google.gson.annotations.SerializedName;
import java.util.Date;
import java.util.SortedSet;
/**
* @author Oleksiy Yarmula
*/
public class ServerImage implements Comparable<ServerImage> {
private long id;
private String name;
private String friendlyName;
private String description;
private Option os;
private Option architecture;
private ServerImageType type;
private ServerImageState state;
private double price;
private String location;
private boolean isActive;
private boolean isPublic;
private Date createdTime;
private Date updatedTime;
@SerializedName("billingtokens")
private SortedSet<BillingToken> billingTokens;
private Customer owner;
private long id;
private String name;
private String friendlyName;
private String description;
private Option os;
private Option architecture;
private ServerImageType type;
private ServerImageState state;
private double price;
private String location;
private boolean isActive;
private boolean isPublic;
private Date createdTime;
private Date updatedTime;
@SerializedName("billingtokens")
private Set<BillingToken> billingTokens;
private Customer owner;
/**
* A no-args constructor is required for deserialization
*/
public ServerImage() {
}
/**
* A no-args constructor is required for deserialization
*/
public ServerImage() {
}
public ServerImage(long id, String name, String friendlyName,
String description, Option os, Option architecture,
ServerImageType type, ServerImageState state, double price, String location,
boolean active, boolean aPublic, Date createdTime,
Date updatedTime, SortedSet<BillingToken> billingTokens, Customer owner) {
this.id = id;
this.name = name;
this.friendlyName = friendlyName;
this.description = description;
this.os = os;
this.architecture = architecture;
this.type = type;
this.state = state;
this.price = price;
this.location = location;
isActive = active;
isPublic = aPublic;
this.createdTime = createdTime;
this.updatedTime = updatedTime;
this.billingTokens = billingTokens;
this.owner = owner;
}
public ServerImage(long id, String name, String friendlyName, String description, Option os,
Option architecture, ServerImageType type, ServerImageState state, double price,
String location, boolean active, boolean aPublic, Date createdTime, Date updatedTime,
Set<BillingToken> billingTokens, Customer owner) {
this.id = id;
this.name = name;
this.friendlyName = friendlyName;
this.description = description;
this.os = os;
this.architecture = architecture;
this.type = type;
this.state = state;
this.price = price;
this.location = location;
isActive = active;
isPublic = aPublic;
this.createdTime = createdTime;
this.updatedTime = updatedTime;
this.billingTokens = billingTokens;
this.owner = owner;
}
public long getId() {
return id;
}
public long getId() {
return id;
}
public String getName() {
return name;
}
public String getName() {
return name;
}
public String getFriendlyName() {
return friendlyName;
}
public String getFriendlyName() {
return friendlyName;
}
public String getDescription() {
return description;
}
public String getDescription() {
return description;
}
public Option getOs() {
return os;
}
public Option getOs() {
return os;
}
public Option getArchitecture() {
return architecture;
}
public Option getArchitecture() {
return architecture;
}
public ServerImageType getType() {
return type;
}
public ServerImageType getType() {
return type;
}
public ServerImageState getState() {
return state;
}
public ServerImageState getState() {
return state;
}
public double getPrice() {
return price;
}
public double getPrice() {
return price;
}
public String getLocation() {
return location;
}
public String getLocation() {
return location;
}
public boolean isActive() {
return isActive;
}
public boolean isActive() {
return isActive;
}
public boolean isPublic() {
return isPublic;
}
public boolean isPublic() {
return isPublic;
}
public Date getCreatedTime() {
return createdTime;
}
public Date getCreatedTime() {
return createdTime;
}
public Date getUpdatedTime() {
return updatedTime;
}
public Date getUpdatedTime() {
return updatedTime;
}
public SortedSet<BillingToken> getBillingTokens() {
return ImmutableSortedSet.copyOf(billingTokens);
}
public Set<BillingToken> getBillingTokens() {
return billingTokens;
}
public Customer getOwner() {
return owner;
}
public Customer getOwner() {
return owner;
}
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
@Override
public boolean equals(Object o) {
if (this == o)
return true;
if (o == null || getClass() != o.getClass())
return false;
ServerImage that = (ServerImage) o;
ServerImage that = (ServerImage) o;
if (id != that.id) return false;
if (isActive != that.isActive) return false;
if (isPublic != that.isPublic) return false;
if (Double.compare(that.price, price) != 0) return false;
if (architecture != null ? !architecture.equals(that.architecture) : that.architecture != null) return false;
if (billingTokens != null ? !billingTokens.equals(that.billingTokens) : that.billingTokens != null)
return false;
if (!createdTime.equals(that.createdTime)) return false;
if (description != null ? !description.equals(that.description) : that.description != null) return false;
if (friendlyName != null ? !friendlyName.equals(that.friendlyName) : that.friendlyName != null) return false;
if (location != null ? !location.equals(that.location) : that.location != null) return false;
if (!name.equals(that.name)) return false;
if (!os.equals(that.os)) return false;
if (owner != null ? !owner.equals(that.owner) : that.owner != null) return false;
if (!state.equals(that.state)) return false;
if (!type.equals(that.type)) return false;
if (updatedTime != null ? !updatedTime.equals(that.updatedTime) : that.updatedTime != null) return false;
if (id != that.id)
return false;
if (isActive != that.isActive)
return false;
if (isPublic != that.isPublic)
return false;
if (Double.compare(that.price, price) != 0)
return false;
if (architecture != null ? !architecture.equals(that.architecture)
: that.architecture != null)
return false;
if (billingTokens != null ? !billingTokens.equals(that.billingTokens)
: that.billingTokens != null)
return false;
if (!createdTime.equals(that.createdTime))
return false;
if (description != null ? !description.equals(that.description) : that.description != null)
return false;
if (friendlyName != null ? !friendlyName.equals(that.friendlyName)
: that.friendlyName != null)
return false;
if (location != null ? !location.equals(that.location) : that.location != null)
return false;
if (!name.equals(that.name))
return false;
if (!os.equals(that.os))
return false;
if (owner != null ? !owner.equals(that.owner) : that.owner != null)
return false;
if (!state.equals(that.state))
return false;
if (!type.equals(that.type))
return false;
if (updatedTime != null ? !updatedTime.equals(that.updatedTime) : that.updatedTime != null)
return false;
return true;
}
return true;
}
@Override
public int hashCode() {
int result;
long temp;
result = (int) (id ^ (id >>> 32));
result = 31 * result + name.hashCode();
result = 31 * result + (friendlyName != null ? friendlyName.hashCode() : 0);
result = 31 * result + (description != null ? description.hashCode() : 0);
result = 31 * result + os.hashCode();
result = 31 * result + type.hashCode();
result = 31 * result + state.hashCode();
temp = price != +0.0d ? Double.doubleToLongBits(price) : 0L;
result = 31 * result + (int) (temp ^ (temp >>> 32));
result = 31 * result + (location != null ? location.hashCode() : 0);
result = 31 * result + (isActive ? 1 : 0);
result = 31 * result + (isPublic ? 1 : 0);
result = 31 * result + createdTime.hashCode();
result = 31 * result + (updatedTime != null ? updatedTime.hashCode() : 0);
result = 31 * result + (billingTokens != null ? billingTokens.hashCode() : 0);
result = 31 * result + (owner != null ? owner.hashCode() : 0);
return result;
}
@Override
public int hashCode() {
int result;
long temp;
result = (int) (id ^ (id >>> 32));
result = 31 * result + name.hashCode();
result = 31 * result + (friendlyName != null ? friendlyName.hashCode() : 0);
result = 31 * result + (description != null ? description.hashCode() : 0);
result = 31 * result + os.hashCode();
result = 31 * result + type.hashCode();
result = 31 * result + state.hashCode();
temp = price != +0.0d ? Double.doubleToLongBits(price) : 0L;
result = 31 * result + (int) (temp ^ (temp >>> 32));
result = 31 * result + (location != null ? location.hashCode() : 0);
result = 31 * result + (isActive ? 1 : 0);
result = 31 * result + (isPublic ? 1 : 0);
result = 31 * result + createdTime.hashCode();
result = 31 * result + (updatedTime != null ? updatedTime.hashCode() : 0);
result = 31 * result + (billingTokens != null ? billingTokens.hashCode() : 0);
result = 31 * result + (owner != null ? owner.hashCode() : 0);
return result;
}
@Override
public int compareTo(ServerImage o) {
return Longs.compare(id, o.getId());
}
@Override
public int compareTo(ServerImage o) {
return Longs.compare(id, o.getId());
}
@Override
public String toString() {
return "ServerImage{" +
"id=" + id +
", name='" + name + '\'' +
", friendlyName='" + friendlyName + '\'' +
", description='" + description + '\'' +
", os=" + os +
", architecture=" + architecture +
", type=" + type +
", state=" + state +
", price=" + price +
", location='" + location + '\'' +
", isActive=" + isActive +
", isPublic=" + isPublic +
", createdTime=" + createdTime +
", updatedTime=" + updatedTime +
", billingTokens=" + billingTokens +
", owner=" + owner +
'}';
}
@Override
public String toString() {
return "ServerImage{" + "id=" + id + ", name='" + name + '\'' + ", friendlyName='"
+ friendlyName + '\'' + ", description='" + description + '\'' + ", os=" + os
+ ", architecture=" + architecture + ", type=" + type + ", state=" + state
+ ", price=" + price + ", location='" + location + '\'' + ", isActive=" + isActive
+ ", isPublic=" + isPublic + ", createdTime=" + createdTime + ", updatedTime="
+ updatedTime + ", billingTokens=" + billingTokens + ", owner=" + owner + '}';
}
}