View Javadoc

1   /*
2    * $Id: SMDMethod.java 799110 2009-07-29 22:44:26Z musachy $
3    *
4    * Licensed to the Apache Software Foundation (ASF) under one
5    * or more contributor license agreements.  See the NOTICE file
6    * distributed with this work for additional information
7    * regarding copyright ownership.  The ASF licenses this file
8    * to you under the Apache License, Version 2.0 (the
9    * "License"); you may not use this file except in compliance
10   * with the License.  You may obtain a copy of the License at
11   *
12   *  http://www.apache.org/licenses/LICENSE-2.0
13   *
14   * Unless required by applicable law or agreed to in writing,
15   * software distributed under the License is distributed on an
16   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
17   * KIND, either express or implied.  See the License for the
18   * specific language governing permissions and limitations
19   * under the License.
20   */
21  package org.apache.struts2.json.smd;
22  
23  import java.util.Set;
24  import java.util.TreeSet;
25  
26  public class SMDMethod implements Comparable {
27      private String name;
28      private Set<SMDMethodParameter> parameters = new TreeSet<SMDMethodParameter>();
29  
30      public SMDMethod(String name) {
31          this.name = name;
32      }
33  
34      public void addSMDMethodParameter(SMDMethodParameter parameter) {
35          this.parameters.add(parameter);
36      }
37  
38      public String getName() {
39          return this.name;
40      }
41  
42      public void setName(String name) {
43          this.name = name;
44      }
45  
46      public Set<SMDMethodParameter> getParameters() {
47          return this.parameters;
48      }
49  
50      public int compareTo(Object o) {
51          if (!(o instanceof SMDMethod))
52              return 1;
53          if (o == null)
54              return 1;
55          SMDMethod other = (SMDMethod) o;
56          if ((name == null) && (other.name == null))
57              return 0;
58          if (name == null)
59              return -1;
60          if (name.equals(other.name))
61              return parameters.size() - other.parameters.size();
62  
63          return name.compareTo(other.name);
64      }
65  
66      public boolean equals(Object obj) {
67          if (!(obj instanceof SMDMethod))
68              return false;
69          SMDMethod toCompare = (SMDMethod) obj;
70          if ((name == null) && (toCompare.name == null))
71              return true;
72          return (name != null) && name.equals(toCompare.name)
73                  && (parameters.size() == toCompare.parameters.size());
74      }
75  }