Skip to content

Commit

Permalink
Refactored method name validate() to createValidType().
Browse files Browse the repository at this point in the history
  • Loading branch information
bbansal committed Jun 24, 2009
1 parent 5a07888 commit 669001f
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions src/java/voldemort/serialization/json/JsonTypeDefinition.java
Expand Up @@ -50,7 +50,7 @@ public class JsonTypeDefinition implements Serializable {
private Object type; private Object type;


public JsonTypeDefinition(Object type) { public JsonTypeDefinition(Object type) {
this.type = validate(type); this.type = createValidType(type);


} }


Expand Down Expand Up @@ -162,25 +162,25 @@ public static String format(Object type) {
} }


public void validate() { public void validate() {
validate(getType()); createValidType(getType());
} }


private Object validate(Object type) { private Object createValidType(Object type) {
if(type == null) { if(type == null) {
throw new IllegalArgumentException("Type or subtype cannot be null."); throw new IllegalArgumentException("Type or subtype cannot be null.");
} else if(type instanceof List<?>) { } else if(type instanceof List<?>) {
List<?> l = (List<?>) type; List<?> l = (List<?>) type;
if(l.size() != 1) if(l.size() != 1)
throw new IllegalArgumentException("Lists in type definition must have length exactly one."); throw new IllegalArgumentException("Lists in type definition must have length exactly one.");
return Arrays.asList(validate(l.get(0))); return Arrays.asList(createValidType(l.get(0)));
} else if(type instanceof Map<?, ?>) { } else if(type instanceof Map<?, ?>) {
Map<String, ?> m = (Map<String, ?>) type; Map<String, ?> m = (Map<String, ?>) type;
// bbansal: sort keys here for consistent with fromJson() // bbansal: sort keys here for consistent with fromJson()
Map<String, Object> newM = new LinkedHashMap<String, Object>(m.size()); Map<String, Object> newM = new LinkedHashMap<String, Object>(m.size());
List<String> keys = new ArrayList<String>((m.keySet())); List<String> keys = new ArrayList<String>((m.keySet()));
Collections.sort(keys); Collections.sort(keys);
for(String key: keys) for(String key: keys)
newM.put(key, validate(m.get(key))); newM.put(key, createValidType(m.get(key)));
return newM; return newM;
} else if(type instanceof JsonTypes) { } else if(type instanceof JsonTypes) {
// this is good // this is good
Expand Down

0 comments on commit 669001f

Please sign in to comment.