KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > pluto > portalImpl > om > common > impl > ParameterSetImpl


1 /*
2  * Copyright 2003,2004 The Apache Software Foundation.
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 /*
17
18  */

19
20 package org.apache.pluto.portalImpl.om.common.impl;
21
22 import java.util.HashSet JavaDoc;
23 import java.util.Iterator JavaDoc;
24
25 import org.apache.pluto.om.common.Parameter;
26 import org.apache.pluto.om.common.ParameterSet;
27 import org.apache.pluto.om.common.ParameterSetCtrl;
28 import org.apache.pluto.util.StringUtils;
29
30 public class ParameterSetImpl extends HashSet JavaDoc
31 implements ParameterSet, ParameterSetCtrl, java.io.Serializable JavaDoc {
32
33     public ParameterSetImpl()
34     {
35     }
36
37     // ParameterSet implementation.
38

39     public Parameter get(String JavaDoc name)
40     {
41         Iterator JavaDoc iterator = this.iterator();
42         while (iterator.hasNext()) {
43             Parameter parameter = (Parameter)iterator.next();
44             if (parameter.getName().equals(name)) {
45                 return parameter;
46             }
47         }
48         return null;
49     }
50
51     // ParameterSetCtrl implementation.
52

53     public Parameter add(String JavaDoc name, String JavaDoc value)
54     {
55         ParameterImpl parameter = new ParameterImpl();
56         parameter.setName(name);
57         parameter.setValue(value);
58
59         super.add(parameter);
60
61         return parameter;
62     }
63
64     public Parameter remove(String JavaDoc name)
65     {
66         Iterator JavaDoc iterator = this.iterator();
67         while (iterator.hasNext()) {
68             Parameter parameter = (Parameter)iterator.next();
69             if (parameter.getName().equals(name)) {
70                 super.remove(parameter);
71                 return parameter;
72             }
73         }
74         return null;
75     }
76
77     public void remove(Parameter parameter)
78     {
79         super.remove(parameter);
80     }
81
82     // additional methods.
83

84     public String JavaDoc toString()
85     {
86         return toString(0);
87     }
88
89     public String JavaDoc toString(int indent)
90     {
91         StringBuffer JavaDoc buffer = new StringBuffer JavaDoc(50);
92         StringUtils.newLine(buffer,indent);
93         buffer.append(getClass().toString());
94         buffer.append(": ");
95         Iterator JavaDoc iterator = this.iterator();
96         while (iterator.hasNext()) {
97             buffer.append(((ParameterImpl)iterator.next()).toString(indent+2));
98         }
99         return buffer.toString();
100     }
101 }
102
Popular Tags