001    /*
002     * Copyright (C) 2001 Ciaran Treanor <ciaran@codeloop.com>
003     *
004     * Distributable under GPL license.
005     * See terms of license at gnu.org.
006     *
007     * $Id: ConsolidationFunctionType.java,v 1.2 2006/12/21 18:02:42 tarus Exp $
008     */
009    package org.jrobin.core.jrrd;
010    
011    /**
012     * Class ConsolidationFunctionType
013     *
014     * @author <a href="mailto:ciaran@codeloop.com">Ciaran Treanor</a>
015     * @version $Revision: 1.2 $
016     */
017    public class ConsolidationFunctionType {
018    
019            private static final int _AVERAGE = 0;
020            private static final String STR_AVERAGE = "AVERAGE";
021    
022            /**
023             * Field AVERAGE
024             */
025            public static final ConsolidationFunctionType AVERAGE =
026                            new ConsolidationFunctionType(_AVERAGE);
027            private static final int _MIN = 1;
028            private static final String STR_MIN = "MIN";
029    
030            /**
031             * Field MIN
032             */
033            public static final ConsolidationFunctionType MIN =
034                            new ConsolidationFunctionType(_MIN);
035            private static final int _MAX = 2;
036            private static final String STR_MAX = "MAX";
037    
038            /**
039             * Field MAX
040             */
041            public static final ConsolidationFunctionType MAX =
042                            new ConsolidationFunctionType(_MAX);
043            private static final int _LAST = 3;
044            private static final String STR_LAST = "LAST";
045    
046            /**
047             * Field LAST
048             */
049            public static final ConsolidationFunctionType LAST =
050                            new ConsolidationFunctionType(_LAST);
051            private int type;
052    
053            private ConsolidationFunctionType(int type) {
054                    this.type = type;
055            }
056    
057            /**
058             * Returns a <code>ConsolidationFunctionType</code> with the given name.
059             *
060             * @param s name of the <code>ConsolidationFunctionType</code> required.
061             * @return a <code>ConsolidationFunctionType</code> with the given name.
062             */
063            public static ConsolidationFunctionType get(String s) {
064    
065                    if (s.equalsIgnoreCase(STR_AVERAGE)) {
066                            return AVERAGE;
067                    }
068                    else if (s.equalsIgnoreCase(STR_MIN)) {
069                            return MIN;
070                    }
071                    else if (s.equalsIgnoreCase(STR_MAX)) {
072                            return MAX;
073                    }
074                    else if (s.equalsIgnoreCase(STR_LAST)) {
075                            return LAST;
076                    }
077                    else {
078                            throw new IllegalArgumentException("Invalid ConsolidationFunctionType");
079                    }
080            }
081    
082            /**
083             * Compares this object against the specified object.
084             *
085             * @return <code>true</code> if the objects are the same,
086             *         <code>false</code> otherwise.
087             */
088            public boolean equals(Object o) {
089    
090                    if (!(o instanceof ConsolidationFunctionType)) {
091                            throw new IllegalArgumentException("Not a ConsolidationFunctionType");
092                    }
093    
094                    return (((ConsolidationFunctionType) o).type == type)
095                                    ? true
096                                    : false;
097            }
098    
099            /**
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    }