View Javadoc

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;
23  import java.util.Iterator;
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
31  implements ParameterSet, ParameterSetCtrl, java.io.Serializable {
32  
33      public ParameterSetImpl()
34      {
35      }
36  
37      // ParameterSet implementation.
38  
39      public Parameter get(String name)
40      {
41          Iterator 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 name, String 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 name)
65      {
66          Iterator 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 toString()
85      {
86          return toString(0);
87      }
88  
89      public String toString(int indent)
90      {
91          StringBuffer buffer = new StringBuffer(50);
92          StringUtils.newLine(buffer,indent);
93          buffer.append(getClass().toString());
94          buffer.append(": ");
95          Iterator iterator = this.iterator();
96          while (iterator.hasNext()) {
97              buffer.append(((ParameterImpl)iterator.next()).toString(indent+2));
98          }
99          return buffer.toString();
100     }     
101 }