View Javadoc

1   package org.apache.torque.util.functions;
2   
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  
22  /***
23   * A typesafe enum of SQL Standard function names.  Used by the 
24   * FunctionFactory and (eventually) the DB Adaptors to create SQLFunction
25   * objects. 
26   *
27   * @author <a href="mailto:greg.monroe@dukece.com">Greg Monroe</a>
28   * @version $Id
29   */
30  public class FunctionEnum implements java.io.Serializable
31  {
32      /***
33       * Serial version
34       */
35      private static final long serialVersionUID = 5963149836513364800L;
36  
37      /*** The AVG( [Distinct] EXPR ) function id */
38      public static final FunctionEnum AVG =
39                                  new FunctionEnum("AVG");
40      /*** The SUM( [Distinct] EXPR ) function id */
41      public static final FunctionEnum SUM =
42                                  new FunctionEnum("SUM");
43      /*** The MAX( [Distinct] EXPR ) function id */
44      public static final FunctionEnum MAX =
45                                  new FunctionEnum("MAX");
46      /*** The MIN( [Distinct] EXPR ) function id */
47      public static final FunctionEnum MIN =
48                                  new FunctionEnum("MIN");
49      /*** The COUNT( [Distinct] EXPR ) function id */
50      public static final FunctionEnum COUNT =
51                                  new FunctionEnum("COUNT");
52  
53      private final String s;
54  
55      /***
56       * This is a static only class.
57       * @param s
58       */
59    
60      private FunctionEnum(String s)
61      {
62          this.s = s;
63      }
64  
65      public final String toString()
66      {
67          return s;
68      }
69  
70      /***
71       * returns whether o is the same FunctionEnum as this object.
72       * Two FunctionEnums are considered equal if they contain the same String.
73       * @param o the object to compare the FunctionEnum with.
74       */
75      public boolean equals(Object o)
76      {
77          if (o == null)
78          {
79              return false;
80          }
81  
82          if (!(o instanceof FunctionEnum))
83          {
84              return false;
85          }
86  
87          FunctionEnum otherEnum = (FunctionEnum) o;
88  
89  
90          // both null: true
91          // other null, this not null: false
92          // else compare
93          return (otherEnum.s == null)
94                  ? (s == null)
95                  : otherEnum.s.equals(s);
96      }
97  
98      /***
99       * returns a hashcode for this object which is consistent with equals()
100      */
101     public int hashCode()
102     {
103         return (s == null)
104                 ? 0
105                 : s.hashCode();
106     }
107 }