KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jrobin > core > jrrd > ConsolidationFunctionType


1 /*
2  * Copyright (C) 2001 Ciaran Treanor <ciaran@codeloop.com>
3  *
4  * Distributable under GPL license.
5  * See terms of license at gnu.org.
6  *
7  * $Id: ConsolidationFunctionType.java,v 1.1 2004/07/22 09:34:10 saxon64 Exp $
8  */

9 package org.jrobin.core.jrrd;
10
11 /**
12  * Class ConsolidationFunctionType
13  *
14  * @author <a HREF="mailto:ciaran@codeloop.com">Ciaran Treanor</a>
15  * @version $Revision: 1.1 $
16  */

17 public class ConsolidationFunctionType {
18
19     private static final int _AVERAGE = 0;
20     private static final String JavaDoc STR_AVERAGE = "AVERAGE";
21
22     /**
23      * Field AVERAGE
24      */

25     public static final ConsolidationFunctionType AVERAGE =
26             new ConsolidationFunctionType(_AVERAGE);
27     private static final int _MIN = 1;
28     private static final String JavaDoc STR_MIN = "MIN";
29
30     /**
31      * Field MIN
32      */

33     public static final ConsolidationFunctionType MIN =
34             new ConsolidationFunctionType(_MIN);
35     private static final int _MAX = 2;
36     private static final String JavaDoc STR_MAX = "MAX";
37
38     /**
39      * Field MAX
40      */

41     public static final ConsolidationFunctionType MAX =
42             new ConsolidationFunctionType(_MAX);
43     private static final int _LAST = 3;
44     private static final String JavaDoc STR_LAST = "LAST";
45
46     /**
47      * Field LAST
48      */

49     public static final ConsolidationFunctionType LAST =
50             new ConsolidationFunctionType(_LAST);
51     private int type;
52
53     private ConsolidationFunctionType(int type) {
54         this.type = type;
55     }
56
57     /**
58      * Returns a <code>ConsolidationFunctionType</code> with the given name.
59      *
60      * @param s name of the <code>ConsolidationFunctionType</code> required.
61      * @return a <code>ConsolidationFunctionType</code> with the given name.
62      */

63     public static ConsolidationFunctionType get(String JavaDoc s) {
64
65         if (s.equalsIgnoreCase(STR_AVERAGE)) {
66             return AVERAGE;
67         } else if (s.equalsIgnoreCase(STR_MIN)) {
68             return MIN;
69         } else if (s.equalsIgnoreCase(STR_MAX)) {
70             return MAX;
71         } else if (s.equalsIgnoreCase(STR_LAST)) {
72             return LAST;
73         } else {
74             throw new IllegalArgumentException JavaDoc("Invalid ConsolidationFunctionType");
75         }
76     }
77
78     /**
79      * Compares this object against the specified object.
80      *
81      * @return <code>true</code> if the objects are the same,
82      * <code>false</code> otherwise.
83      */

84     public boolean equals(Object JavaDoc o) {
85
86         if (!(o instanceof ConsolidationFunctionType)) {
87             throw new IllegalArgumentException JavaDoc("Not a ConsolidationFunctionType");
88         }
89
90         return (((ConsolidationFunctionType) o).type == type)
91                 ? true
92                 : false;
93     }
94
95     /**
96      * Returns a string representation of this object.
97      *
98      * @return a string representation of this object.
99      */

100     public String JavaDoc toString() {
101
102         String JavaDoc strType;
103
104         switch (type) {
105
106             case _AVERAGE:
107                 strType = STR_AVERAGE;
108                 break;
109
110             case _MIN:
111                 strType = STR_MIN;
112                 break;
113
114             case _MAX:
115                 strType = STR_MAX;
116                 break;
117
118             case _LAST:
119                 strType = STR_LAST;
120                 break;
121
122             default :
123                 throw new RuntimeException JavaDoc("This should never happen");
124         }
125
126         return strType;
127     }
128 }
129
Popular Tags