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 @Singleton
@EC2 @EC2
Region provideCurrentRegion(@EC2 Map<Region, URI> regionMap, @EC2 URI currentUri) { 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); Region region = map.get(currentUri);
assert region != null : currentUri + " not in " + map; assert region != null : currentUri + " not in " + map;
return region; return region;

View File

@ -18,51 +18,58 @@
*/ */
package org.jclouds.aws.ec2.domain; 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 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 * Defines the mapping of volumes for
* {@link org.jclouds.aws.ec2.services.InstanceClient#setBlockDeviceMappingForInstanceInRegion}. * {@link org.jclouds.aws.ec2.services.InstanceClient#setBlockDeviceMappingForInstanceInRegion}.
* *
* @author Oleksiy Yarmula * @author Oleksiy Yarmula
*/ */
public class BlockDeviceMapping { public class BlockDeviceMapping {
private final Multimap<String, RunningInstance.EbsBlockDevice> ebsBlockDevices = private final Multimap<String, RunningInstance.EbsBlockDevice> ebsBlockDevices = LinkedHashMultimap
LinkedHashMultimap.create(); .create();
public BlockDeviceMapping() { public BlockDeviceMapping() {
} }
/** /**
* Creates block device mapping from the list of {@link RunningInstance.EbsBlockDevice devices}. * Creates block device mapping from the list of {@link RunningInstance.EbsBlockDevice devices}.
* *
* This method copies the values of the list. * This method copies the values of the list.
* @param ebsBlockDevices *
* devices to be changed for the volume. This cannot be null. * @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, public BlockDeviceMapping(Multimap<String, RunningInstance.EbsBlockDevice> ebsBlockDevices) {
/*or throw*/ "EbsBlockDevices can't be null")); this.ebsBlockDevices.putAll(checkNotNull(ebsBlockDevices,
} /* or throw */"EbsBlockDevices can't be null"));
}
/** /**
* Adds a {@link RunningInstance.EbsBlockDevice} to the mapping. * Adds a {@link RunningInstance.EbsBlockDevice} to the mapping.
* @param deviceName name of the device to apply the mapping. Can be null. *
* @param ebsBlockDevice * @param deviceName
* ebsBlockDevice to be added. This cannot be null. * name of the device to apply the mapping. Can be null.
* @return the same instance for method chaining purposes * @param ebsBlockDevice
*/ * ebsBlockDevice to be added. This cannot be null.
public BlockDeviceMapping addEbsBlockDevice(@Nullable String deviceName, RunningInstance.EbsBlockDevice ebsBlockDevice) { * @return the same instance for method chaining purposes
this.ebsBlockDevices.put(deviceName, checkNotNull(ebsBlockDevice, */
/*or throw*/ "EbsBlockDevice can't be null")); public BlockDeviceMapping addEbsBlockDevice(@Nullable String deviceName,
return this; RunningInstance.EbsBlockDevice ebsBlockDevice) {
} this.ebsBlockDevices.put(deviceName, checkNotNull(ebsBlockDevice,
/* or throw */"EbsBlockDevice can't be null"));
return this;
}
public Multimap<String, RunningInstance.EbsBlockDevice> getEbsBlockDevices() { public Multimap<String, RunningInstance.EbsBlockDevice> getEbsBlockDevices() {
return ImmutableMultimap.copyOf(ebsBlockDevices); return ImmutableMultimap.<String, RunningInstance.EbsBlockDevice> builder().putAll(
} ebsBlockDevices).build();
}
} }

View File

@ -128,7 +128,7 @@ public class S3RestClientModule extends AbstractModule {
@Singleton @Singleton
@S3 @S3
Region getDefaultRegion(@S3 URI uri, @S3 Map<Region, URI> map) { 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 @Provides

View File

@ -110,7 +110,7 @@ public class SQSRestClientModule extends AbstractModule {
@Singleton @Singleton
@SQS @SQS
Region getDefaultRegion(@SQS URI uri, @SQS Map<Region, URI> map) { 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 @Provides

View File

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

View File

@ -46,7 +46,7 @@ public class BaseRegexQueueHandler {
@Inject @Inject
protected BaseRegexQueueHandler(Map<Region, URI> regionMap) { 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) { public Set<Queue> parse(String in) {

View File

@ -43,6 +43,7 @@ import com.google.common.util.concurrent.ListenableFuture;
* *
* @author Adrian Cole * @author Adrian Cole
*/ */
@SuppressWarnings("deprecation")
@Singleton @Singleton
public class SyncProxy implements InvocationHandler { 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> methodMap;
private final Map<Method, Method> syncMethodMap; private final Map<Method, Method> syncMethodMap;
private final Map<Method, Long> timeoutMap; 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 @Inject
public SyncProxy(Class<?> declaring, Object delegate) throws SecurityException, public SyncProxy(Class<?> declaring, Object delegate) throws SecurityException,

View File

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

View File

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

View File

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