Introduced the notion of TypedKey for a parameter map or spec

This commit is contained in:
Inderjeet Singh 2010-02-15 14:46:42 +00:00
parent 9c8e8bd77e
commit 1925fb966c
4 changed files with 46 additions and 0 deletions

View File

@ -30,6 +30,10 @@ public final class HeaderMap extends ParamMap {
public Builder(HeaderMapSpec spec) {
super(spec);
}
public <T> Builder put(TypedKey<T> paramKey, T content) {
return put(paramKey.getName(), content);
}
@Override
public Builder put(String paramName, Object content) {

View File

@ -63,6 +63,10 @@ class ParamMap {
return contents.get(paramName);
}
public <T> T get(TypedKey<T> key) {
return get(key.getName(), key.getClassOfT());
}
@SuppressWarnings("unchecked")
public <T> T get(String key, Type typeOfValue) {
Preconditions.checkArgument(spec.checkIfCompatible(key, typeOfValue));

View File

@ -0,0 +1,19 @@
package com.google.gson.webservice.definition;
public class TypedKey<T> {
private final String name;
private final Class<T> classOfT;
public TypedKey(String name, Class<T> classOfT) {
this.name = name;
this.classOfT = classOfT;
}
public String getName() {
return name;
}
public Class<T> getClassOfT() {
return classOfT;
}
}

View File

@ -55,18 +55,37 @@ public final class WebServiceCallSpec {
return this;
}
public <T> Builder addRequestParam(TypedKey<T> paramKey, Class<T> typeOfParam) {
return addRequestParam(paramKey.getName(), typeOfParam);
}
public Builder addRequestParam(String paramName, Type type) {
reqParamsSpecBuilder.put(paramName, type);
return this;
}
public <T> Builder addRequestBodyParam(TypedKey<T> paramKey, Class<T> typeOfParam) {
return addRequestBodyParam(paramKey.getName(), typeOfParam);
}
public Builder addRequestBodyParam(String paramName, Type type) {
reqBodySpecBuilder.add(paramName, type);
return this;
}
public <T> Builder addResponseParam(TypedKey<T> paramKey, Class<T> typeOfParam) {
return addResponseParam(paramKey.getName(), typeOfParam);
}
public Builder addResponseParam(String paramName, Type type) {
resParamsSpecBuilder.put(paramName, type);
return this;
}
public <T> Builder addResponseBodyParam(TypedKey<T> paramKey, Class<T> typeOfParam) {
return addResponseBodyParam(paramKey.getName(), typeOfParam);
}
public Builder addResponseBodyParam(String paramName, Type type) {
resBodySpecBuilder.add(paramName, type);
return this;