01: /*
02: * User: Michael Rettig
03: * Date: Sep 20, 2002
04: * Time: 8:25:46 PM
05: */
06: package net.sourceforge.jaxor.parser;
07:
08: import java.util.ArrayList;
09: import java.util.Collections;
10: import java.util.Iterator;
11: import java.util.List;
12:
13: public class ParamList {
14: private final List _list = new ArrayList();
15:
16: public void add(Param param) {
17: _list.add(param);
18: }
19:
20: public String getMethodParams() {
21: StringBuffer params = new StringBuffer();
22: Iterator itr = _list.iterator();
23: while (itr.hasNext()) {
24: Param param = (Param) itr.next();
25: params.append("final " + param.getType() + " "
26: + param.getName());
27: if (itr.hasNext()) {
28: params.append(", ");
29: }
30: }
31: return params.toString();
32: }
33:
34: public String getMethodParamsWithComma() {
35: if (_list.size() == 0)
36: return "";
37: return getMethodParams() + ",";
38: }
39:
40: public Iterator iterator() {
41: return _list.iterator();
42: }
43:
44: public String toArray() {
45: StringBuffer params = new StringBuffer("new Object[]{");
46: Iterator itr = _list.iterator();
47: while (itr.hasNext()) {
48: Param param = (Param) itr.next();
49: params.append(param.getName());
50: if (itr.hasNext()) {
51: params.append(", ");
52: }
53: }
54: params.append("}");
55: return params.toString();
56: }
57:
58: public String getMethodVars() {
59: StringBuffer params = new StringBuffer();
60: Iterator itr = _list.iterator();
61: while (itr.hasNext()) {
62: Param param = (Param) itr.next();
63: params.append(param.getName());
64: if (itr.hasNext()) {
65: params.append(", ");
66: }
67: }
68: return params.toString();
69: }
70:
71: public String getMethodVarsWithComma() {
72: if (_list.size() == 0)
73: return "";
74: return getMethodVars() + ",";
75: }
76:
77: public int size() {
78: return _list.size();
79: }
80:
81: public List getList() {
82: return Collections.unmodifiableList(_list);
83: }
84: }
|