KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > springframework > binding > method > Parameters


1 /*
2  * Copyright 2002-2006 the original author or authors.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */

16 package org.springframework.binding.method;
17
18 import java.io.Serializable JavaDoc;
19 import java.util.ArrayList JavaDoc;
20 import java.util.Arrays JavaDoc;
21 import java.util.Iterator JavaDoc;
22 import java.util.List JavaDoc;
23
24 import org.springframework.core.style.ToStringCreator;
25
26 /**
27  * An ordered list of method parameters.
28  *
29  * @author Keith
30  */

31 public class Parameters implements Serializable JavaDoc {
32
33     /**
34      * Canonical instance for an empty parameters list.
35      */

36     public static final Parameters NONE = new Parameters(0);
37
38     /**
39      * The list.
40      */

41     private List JavaDoc parameters;
42
43     /**
44      * Create a parameter list of the default size (3 elements).
45      */

46     public Parameters() {
47         this(3);
48     }
49
50     /**
51      * Create an parameter list with the specified size.
52      * @param size the size
53      */

54     public Parameters(int size) {
55         this.parameters = new ArrayList JavaDoc(size);
56     }
57
58     /**
59      * Create an parameter list with one parameter.
60      * @param parameter the single parameter
61      */

62     public Parameters(Parameter parameter) {
63         this.parameters = new ArrayList JavaDoc(1);
64         add(parameter);
65     }
66
67     /**
68      * Create an parameter list from the parameter array.
69      * @param parameters the parameters
70      */

71     public Parameters(Parameter[] parameters) {
72         this.parameters = new ArrayList JavaDoc(parameters.length);
73         addAll(parameters);
74     }
75
76     /**
77      * Add a new parameter to this list.
78      * @param parameter the parameter
79      */

80     public boolean add(Parameter parameter) {
81         return this.parameters.add(parameter);
82     }
83
84     /**
85      * Add new parameters to this list.
86      * @param parameters the parameters
87      * @return the parameters
88      */

89     public boolean addAll(Parameter[] parameters) {
90         return this.parameters.addAll(Arrays.asList(parameters));
91     }
92
93     /**
94      * Return a parameter iterator.
95      * @return the iterator
96      */

97     public Iterator JavaDoc iterator() {
98         return parameters.iterator();
99     }
100
101     /**
102      * Get an array for each parameter type.
103      * @return the types
104      */

105     public Class JavaDoc[] getTypesArray() {
106         int i = 0;
107         Class JavaDoc[] types = new Class JavaDoc[parameters.size()];
108         for (Iterator JavaDoc it = parameters.iterator(); it.hasNext();) {
109             Parameter param = (Parameter)it.next();
110             types[i] = param.getType();
111             i++;
112         }
113         return types;
114     }
115
116     /**
117      * Returns the number of parameters in this list.
118      * @return the size
119      */

120     public int size() {
121         return parameters.size();
122     }
123
124     /**
125      * Return the parameter at the provided index.
126      * @param index the parameter index
127      * @return the parameter at that index
128      */

129     public Parameter getParameter(int index) {
130         return (Parameter)parameters.get(index);
131     }
132
133     public boolean equals(Object JavaDoc obj) {
134         if (!(obj instanceof Parameters)) {
135             return false;
136         }
137         Parameters other = (Parameters)obj;
138         return parameters.equals(other.parameters);
139     }
140
141     public int hashCode() {
142         return parameters.hashCode();
143     }
144
145     public String JavaDoc toString() {
146         return new ToStringCreator(this).append("parameters", parameters).toString();
147     }
148 }
Popular Tags