View Javadoc

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.2 2006/12/21 18:02:42 tarus 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.2 $
16   */
17  public class ConsolidationFunctionType {
18  
19  	private static final int _AVERAGE = 0;
20  	private static final String 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 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 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 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 s) {
64  
65  		if (s.equalsIgnoreCase(STR_AVERAGE)) {
66  			return AVERAGE;
67  		}
68  		else if (s.equalsIgnoreCase(STR_MIN)) {
69  			return MIN;
70  		}
71  		else if (s.equalsIgnoreCase(STR_MAX)) {
72  			return MAX;
73  		}
74  		else if (s.equalsIgnoreCase(STR_LAST)) {
75  			return LAST;
76  		}
77  		else {
78  			throw new IllegalArgumentException("Invalid ConsolidationFunctionType");
79  		}
80  	}
81  
82  	/**
83  	 * Compares this object against the specified object.
84  	 *
85  	 * @return <code>true</code> if the objects are the same,
86  	 *         <code>false</code> otherwise.
87  	 */
88  	public boolean equals(Object o) {
89  
90  		if (!(o instanceof ConsolidationFunctionType)) {
91  			throw new IllegalArgumentException("Not a ConsolidationFunctionType");
92  		}
93  
94  		return (((ConsolidationFunctionType) o).type == type)
95  				? true
96  				: false;
97  	}
98  
99  	/**
100 	 * Returns a string representation of this object.
101 	 *
102 	 * @return a string representation of this object.
103 	 */
104 	public String toString() {
105 
106 		String strType;
107 
108 		switch (type) {
109 
110 			case _AVERAGE:
111 				strType = STR_AVERAGE;
112 				break;
113 
114 			case _MIN:
115 				strType = STR_MIN;
116 				break;
117 
118 			case _MAX:
119 				strType = STR_MAX;
120 				break;
121 
122 			case _LAST:
123 				strType = STR_LAST;
124 				break;
125 
126 			default :
127 				throw new RuntimeException("This should never happen");
128 		}
129 
130 		return strType;
131 	}
132 }