01: package com.vividsolutions.jump.parameter;
02:
03: import java.util.*;
04:
05: /**
06: * The schema for a {@link ParameterList}.
07: * Parameter names should be case-retentive (i.e. comparisons are case-insensitive,
08: * but the case is maintained).
09: */
10: public class ParameterListSchema {
11:
12: private String[] paramNames;
13: private Class[] paramClasses;
14: private Map nameMap = new HashMap();
15:
16: public ParameterListSchema(String[] paramNames, Class[] paramClasses) {
17: initialize(paramNames, paramClasses);
18: }
19:
20: protected ParameterListSchema initialize(String[] paramNames,
21: Class[] paramClasses) {
22: this .paramNames = paramNames;
23: this .paramClasses = paramClasses;
24:
25: for (int i = 0; i < paramNames.length; i++) {
26: nameMap.put(paramNames[i], new Integer(i));
27: }
28: return this ;
29: }
30:
31: public String[] getNames() {
32: return paramNames;
33: }
34:
35: public Class[] getClasses() {
36: return paramClasses;
37: }
38:
39: public boolean isValidName(String name) {
40: return nameMap.containsKey(name);
41: }
42:
43: public boolean equals(Object obj) {
44: return equals((ParameterListSchema) obj);
45: }
46:
47: private boolean equals(ParameterListSchema other) {
48: if (paramNames.length != other.paramNames.length) {
49: return false;
50: }
51: for (int i = 0; i < paramNames.length; i++) {
52: if (!paramNames[i].equals(other.paramNames[i])) {
53: return false;
54: }
55: }
56: for (int i = 0; i < paramNames.length; i++) {
57: if (paramClasses[i] != other.paramClasses[i]) {
58: return false;
59: }
60: }
61: return true;
62: }
63:
64: public Class getClass(String name) {
65: return paramClasses[((Integer) nameMap.get(name)).intValue()];
66: }
67: }
|