Skip to content

Commit

Permalink
Merge pull request #6 from racker/rsr-36/generic_types
Browse files Browse the repository at this point in the history
RSR-36 Use generic types
  • Loading branch information
gdusbabek committed Nov 15, 2012
2 parents c47ad9f + 203d642 commit dcf0ac1
Show file tree
Hide file tree
Showing 12 changed files with 43 additions and 34 deletions.
Expand Up @@ -27,11 +27,11 @@
import java.util.Set;

public class Utils {
public static HashMap<String, Object> parseJson(String json) {
public static Map<String, Object> parseJson(String json) {
JsonObject object = (JsonObject) new JsonParser().parse(json);
Set<Map.Entry<String, JsonElement>> set = object.entrySet();
Iterator<Map.Entry<String, JsonElement>> iterator = set.iterator();
HashMap<String, Object> map = new HashMap<String, Object>();
Map<String, Object> map = new HashMap<String, Object>();

while (iterator.hasNext()) {
Map.Entry<String, JsonElement> entry = iterator.next();
Expand Down
Expand Up @@ -21,11 +21,12 @@
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.HashMap;
import java.util.Map;

public class Token {
protected String id;
protected String expires;
protected HashMap<String, Integer> tenant;
protected Map<String, Integer> tenant;

public String getId() {
return id;
Expand All @@ -45,7 +46,7 @@ public Long getExpires() {
return date.getTime();
}

public HashMap<String, Integer> getTenant() {
public Map<String, Integer> getTenant() {
return tenant;
}
}
Expand Up @@ -31,6 +31,7 @@

import java.util.Date;
import java.util.HashMap;
import java.util.Map;

public class AuthClient {
private String username;
Expand All @@ -42,7 +43,7 @@ public class AuthClient {

public Token authToken = null;

private static final HashMap<String, String> DEFAULT_AUTH_URLS = new HashMap<String, String>() {{
private static final Map<String, String> DEFAULT_AUTH_URLS = new HashMap<String, String>() {{
put(Region.US, "https://identity.api.rackspacecloud.com/v2.0");
put(Region.UK, "https://lon.identity.api.rackspacecloud.com/v2.0");
}};
Expand Down
Expand Up @@ -32,20 +32,21 @@
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

public class ConfigurationClient extends BaseClient {
public ConfigurationClient(AuthClient authClient) {
super(authClient);
}

public ArrayList<ConfigurationValue> list(HashMap<String, String> options) throws Exception {
public List<ConfigurationValue> list(Map<String, String> options) throws Exception {
Type type = new TypeToken<ConfigurationValuesContainer>() {}.getType();
List<NameValuePair> params = new ArrayList<NameValuePair>();

ClientResponse response = this.performRequest("/configuration", params, new HttpGet(), true, type);

ConfigurationValuesContainer container = (ConfigurationValuesContainer)response.getBody();
return (ArrayList<ConfigurationValue>)container.getValues();
return container.getValues();
}

public ConfigurationValue get(String id) throws Exception {
Expand Down
Expand Up @@ -33,13 +33,14 @@
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

public class ServicesClient extends BaseClient {
public ServicesClient(AuthClient authClient) {
super(authClient);
}

public ArrayList<Service> list(HashMap<String, String> options, String tag) throws Exception {
public List<Service> list(Map<String, String> options, String tag) throws Exception {
Type type = new TypeToken<ServicesContainer>() {}.getType();
List<NameValuePair> params = new ArrayList<NameValuePair>();

Expand All @@ -50,7 +51,7 @@ public ArrayList<Service> list(HashMap<String, String> options, String tag) thro
ClientResponse response = this.performRequest("/services", params, new HttpGet(), true, type);

ServicesContainer container = (ServicesContainer)response.getBody();
return (ArrayList<Service>)container.getValues();
return container.getValues();
}

public Service get(String id) throws Exception {
Expand All @@ -59,14 +60,14 @@ public Service get(String id) throws Exception {
return (Service)response.getBody();
}

public Service create(String id, String sessionId, ArrayList<String> tags, HashMap<String, String> metadata) throws Exception {
public Service create(String id, String sessionId, List<String> tags, Map<String, String> metadata) throws Exception {
Service service = new Service(id, sessionId, tags, metadata);
ClientResponse response = this.performRequestWithPayload("/services", null, new HttpPost(), service, false, null);

return new Service(id, sessionId, tags, metadata);
}

public ServicesClient update(String id, ArrayList<String> tags, HashMap<String, String> metadata) throws Exception {
public ServicesClient update(String id, List<String> tags, Map<String, String> metadata) throws Exception {
Service service = new Service(null, null, tags, metadata);

ClientResponse response = this.performRequestWithPayload("/services/" + id, null, new HttpPut(), service, true, null);
Expand Down
Expand Up @@ -30,19 +30,20 @@

import java.lang.reflect.Type;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;

public class SessionsClient extends BaseClient {
public SessionsClient(AuthClient authClient) {
super(authClient);
}

public ArrayList<Session> list(Map<String, String> options) throws Exception {
public List<Session> list(Map<String, String> options) throws Exception {
Type type = new TypeToken<SessionsContainer>() {}.getType();
ClientResponse response = this.performRequest("/sessions", null, new HttpGet(), true, type);

SessionsContainer container = (SessionsContainer)response.getBody();
return (ArrayList<Session>)container.getValues();
return container.getValues();
}

public Session get(String id) throws Exception {
Expand Down
Expand Up @@ -24,19 +24,19 @@
import org.apache.http.client.methods.HttpGet;

import java.lang.reflect.Type;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

public class ViewsClient extends BaseClient {
public ViewsClient(AuthClient authClient) {
super(authClient);
}

public ArrayList<Overview> getOverview(HashMap<String, String> options) throws Exception {
public List<Overview> getOverview(Map<String, String> options) throws Exception {
Type type = new TypeToken<OverviewContainer>() {}.getType();
ClientResponse response = this.performRequest("/views/overview", null, new HttpGet(), true, type);

OverviewContainer container = (OverviewContainer)response.getBody();
return (ArrayList<Overview>)container.getValues();
return container.getValues();
}
}
Expand Up @@ -18,12 +18,13 @@
package com.rackspacecloud.client.service_registry.objects;

import java.util.HashMap;
import java.util.Map;

public class Account {
private String id;
private HashMap<String, String> metadata = new HashMap<String, String>();
private Map<String, String> metadata = new HashMap<String, String>();

public Account(String id, HashMap<String, String> metadata) {
public Account(String id, Map<String, String> metadata) {
this.id = id;
this.metadata = metadata;
}
Expand Down
Expand Up @@ -18,14 +18,15 @@
package com.rackspacecloud.client.service_registry.objects;

import java.util.HashMap;
import java.util.Map;

public class Event {
private String id;
private Integer timestamp;
private String type;
private HashMap<String, String> payload = new HashMap<String, String>();
private Map<String, String> payload = new HashMap<String, String>();

public Event(String id, Integer timestamp, String type, HashMap<String, String> payload) {
public Event(String id, Integer timestamp, String type, Map<String, String> payload) {
this.id = id;
this.timestamp = timestamp;
this.type = type;
Expand Down
Expand Up @@ -17,22 +17,22 @@

package com.rackspacecloud.client.service_registry.objects;

import java.util.HashMap;
import java.util.Map;

public class Limits {
private HashMap<String, Object> resource;
private HashMap<String, HashMap<String, Object>> rate;
private Map<String, Object> resource;
private Map<String, Map<String, Object>> rate;

public Limits(HashMap<String, Object> resource, HashMap<String, HashMap<String, Object>> rate) {
public Limits(Map<String, Object> resource, Map<String, Map<String, Object>> rate) {
this.resource = resource;
this.rate = rate;
}

public HashMap<String, Object> getResource() {
public Map<String, Object> getResource() {
return resource;
}

public HashMap<String, HashMap<String, Object>> getRate() {
public Map<String, Map<String, Object>> getRate() {
return rate;
}
}
Expand Up @@ -17,9 +17,9 @@

package com.rackspacecloud.client.service_registry.objects;

import java.util.ArrayList;
import java.util.List;

public class Overview {
private Session session;
private ArrayList<Service> services;
private List<Service> services;
}
Expand Up @@ -21,15 +21,17 @@

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

public class Service {
private String id;
@SerializedName("session_id")
private String sessionId;
private ArrayList<String> tags = new ArrayList<String>();
private HashMap<String, String> metadata = new HashMap<String, String>();
private List<String> tags = new ArrayList<String>();
private Map<String, String> metadata = new HashMap<String, String>();

public Service(String id, String sessionId, ArrayList<String> tags, HashMap<String, String> metadata) {
public Service(String id, String sessionId, List<String> tags, Map<String, String> metadata) {
this.id = id;
this.sessionId = sessionId;
this.tags = tags;
Expand All @@ -44,11 +46,11 @@ public String getSessionId() {
return sessionId;
}

public ArrayList<String> getTags() {
public List<String> getTags() {
return tags;
}

public HashMap<String, String> getMetadata() {
public Map<String, String> getMetadata() {
return metadata;
}
}

0 comments on commit dcf0ac1

Please sign in to comment.