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 org.apache.pluto.om.common.*;
23  import org.apache.pluto.util.StringUtils;
24  import java.util.*;
25  
26  public class ParameterSetImpl extends HashSet
27  implements ParameterSet, ParameterSetCtrl, java.io.Serializable {
28  
29      public ParameterSetImpl()
30      {
31      }
32  
33      // ParameterSet implementation.
34  
35      public Parameter get(String name)
36      {
37          Iterator iterator = this.iterator();
38          while (iterator.hasNext()) {
39              Parameter parameter = (Parameter)iterator.next();
40              if (parameter.getName().equals(name)) {
41                  return parameter;
42              }
43          }
44          return null;
45      }
46  
47      // ParameterSetCtrl implementation.
48  
49      public Parameter add(String name, String value)
50      {
51          ParameterImpl parameter = new ParameterImpl();
52          parameter.setName(name);
53          parameter.setValue(value);
54  
55          super.add(parameter);
56  
57          return parameter;
58      }
59  
60      public Parameter remove(String name)
61      {
62          Iterator iterator = this.iterator();
63          while (iterator.hasNext()) {
64              Parameter parameter = (Parameter)iterator.next();
65              if (parameter.getName().equals(name)) {
66                  super.remove(parameter);
67                  return parameter;
68              }
69          }
70          return null;
71      }
72  
73      public void remove(Parameter parameter)
74      {
75          super.remove(parameter);
76      }
77  
78      // additional methods.
79      
80      public String toString()
81      {
82          return toString(0);
83      }
84  
85      public String toString(int indent)
86      {
87          StringBuffer buffer = new StringBuffer(50);
88          StringUtils.newLine(buffer,indent);
89          buffer.append(getClass().toString());
90          buffer.append(": ");
91          Iterator iterator = this.iterator();
92          while (iterator.hasNext()) {
93              buffer.append(((ParameterImpl)iterator.next()).toString(indent+2));
94          }
95          return buffer.toString();
96      }     
97  }