01: package com.vividsolutions.jump.parameter;
02:
03: import java.util.*;
04:
05: import com.vividsolutions.jts.util.Assert;
06: import com.vividsolutions.jump.util.LangUtil;
07:
08: /**
09: * A strongly-typed list of parameters for passing to a component
10: */
11: public class ParameterList {
12: private ParameterListSchema schema;
13:
14: private Map params = new HashMap();
15:
16: public ParameterList(ParameterListSchema schema) {
17: initialize(schema);
18: }
19:
20: public ParameterList(ParameterList other) {
21: initialize(other.getSchema());
22: for (Iterator i = Arrays.asList(other.getSchema().getNames())
23: .iterator(); i.hasNext();) {
24: String name = (String) i.next();
25: setParameter(name, other.getParameter(name));
26: }
27: }
28:
29: protected ParameterList initialize(ParameterListSchema schema) {
30: this .schema = schema;
31: return this ;
32: }
33:
34: public ParameterListSchema getSchema() {
35: return schema;
36: }
37:
38: public ParameterList setParameter(String name, Object value) {
39: params.put(name, value);
40: return this ;
41: }
42:
43: public boolean equals(Object obj) {
44: return equals((ParameterList) obj);
45: }
46:
47: private boolean equals(ParameterList other) {
48: if (!schema.equals(other.schema)) {
49: return false;
50: }
51: for (Iterator i = params.keySet().iterator(); i.hasNext();) {
52: String name = (String) i.next();
53: if (!LangUtil.bothNullOrEqual(params.get(name),
54: other.params.get(name))) {
55: return false;
56: }
57: }
58: return true;
59: }
60:
61: public Object getParameter(String name) {
62: return params.get(name);
63: }
64:
65: public String getParameterString(String name) {
66: return (String) params.get(name);
67: }
68:
69: public int getParameterInt(String name) {
70: Object value = params.get(name);
71: if (value instanceof String)
72: return Integer.parseInt((String) value);
73: return ((Integer) params.get(name)).intValue();
74: }
75:
76: }
|