001    /*
002    // $Id: //open/mondrian/src/main/mondrian/olap/Category.java#13 $
003    // This software is subject to the terms of the Common Public License
004    // Agreement, available at the following URL:
005    // http://www.opensource.org/licenses/cpl.html.
006    // Copyright (C) 2003-2008 Julian Hyde
007    // All Rights Reserved.
008    // You must accept the terms of that agreement to use this software.
009    //
010    // jhyde, Feb 21, 2003
011    */
012    package mondrian.olap;
013    
014    /**
015     * <code>Category</code> enumerates the possible expression types.
016     *
017     * <p>Values of this enumeration are returned by {@link Exp#getCategory()},
018     * {@link FunDef#getParameterCategories()}, and
019     * {@link FunDef#getReturnCategory()}.
020     *
021     * <p>For modern code, the more descriptive type system
022     * ({@link mondrian.olap.type.Type}) is preferred.
023     *
024     * @author jhyde
025     * @since Feb 21, 2003
026     * @version $Id: //open/mondrian/src/main/mondrian/olap/Category.java#13 $
027     */
028    public class Category extends EnumeratedValues {
029        /**
030         * The singleton instance of <code>Category</code>.
031         */
032        public static final Category instance = new Category();
033    
034        private Category() {
035            super(
036                new String[] {
037                    "unknown", "array", "dimension", "hierarchy", "level",
038                    "logical", "member", "numeric", "set",
039                    "string", "tuple", "symbol", "cube", "value", "integer",
040                    "null", "empty", "datetime",
041                },
042                new int[] {
043                    Unknown, Array, Dimension, Hierarchy, Level,
044                    Logical, Member, Numeric, Set,
045                    String, Tuple, Symbol, Cube, Value, Integer,
046                    Null, Empty, DateTime,
047                },
048                new String[] {
049                    "Unknown", "Array", "Dimension", "Hierarchy", "Level",
050                    "Logical Expression", "Member", "Numeric Expression", "Set",
051                    "String", "Tuple", "Symbol", "Cube", "Value", "Integer",
052                    "Null", "Empty", "DateTime",
053                }
054            );
055        }
056    
057        /**
058         * Returns the singleton instance of <code>Category</code>.
059         *
060         * @return the singleton instance
061         */
062        public static Category instance() {
063            return instance;
064        }
065    
066        /**
067         * <code>Unknown</code> is an expression whose type is as yet unknown.
068         */
069        public static final int Unknown   = 0;
070    
071        /**
072         * <code>Array</code> is an expression of array type.
073         */
074        public static final int Array     = 1;
075    
076        /**
077         * <code>Dimension</code> is a dimension expression.
078         * @see Dimension
079         */
080        public static final int Dimension = 2;
081    
082        /**
083         * <code>Hierarchy</code> is a hierarchy expression.
084         * @see Hierarchy
085         */
086        public static final int Hierarchy = 3;
087    
088        /**
089         * <code>Level</code> is a level expression.
090         * @see Level
091         */
092        public static final int Level     = 4;
093    
094        /**
095         * <code>Logical</code> is a boolean expression.
096         */
097        public static final int Logical   = 5;
098    
099        /**
100         * <code>Member</code> is a member expression.
101         * @see Member
102         */
103        public static final int Member    = 6;
104    
105        /**
106         * <code>Numeric</code> is a numeric expression.
107         */
108        public static final int Numeric   = 7;
109    
110        /**
111         * <code>Set</code> is a set of members or tuples.
112         */
113        public static final int Set       = 8;
114    
115        /**
116         * <code>String</code> is a string expression.
117         */
118        public static final int String    = 9;
119    
120        /**
121         * <code>Tuple</code> is a tuple expression.
122         */
123        public static final int Tuple     = 10;
124    
125        /**
126         * <code>Symbol</code> is a symbol, for example the <code>BASC</code>
127         * keyword to the <code>Order()</code> function.
128         */
129        public static final int Symbol    = 11;
130    
131        /**
132         * <code>Cube</code> is a cube expression.
133         * @see Cube
134         */
135        public static final int Cube      = 12;
136    
137        /**
138         * <code>Value</code> is any expression yielding a string or numeric value.
139         */
140        public static final int Value     = 13;
141    
142        /**
143         * <code>Integer</code> is an integer expression. This is a subtype of
144         * {@link #Numeric}.
145         */
146        public static final int Integer   = 15;
147    
148        /**
149         * Represents a <code>Null</code> value
150         */
151        public static final int Null      = 16;
152    
153        /**
154         * Represents an empty expression.
155         */
156        public static final int Empty     = 17;
157    
158        /**
159         * Represents a DataTime expression.
160         */
161        public static final int DateTime  = 18;
162    
163        /**
164         * <code>Expression</code> is a flag which, when bitwise-OR-ed with a
165         * category value, indicates an expression (as opposed to a constant).
166         */
167        public static final int Expression = 0;
168        /** <code>Constant</code> is a flag which, when bitwise-OR-ed with a
169         * category value, indicates a constant (as opposed to an expression). */
170        public static final int Constant = 64;
171        /** <code>Mask</code> is a mask to remove flags. */
172        public static final int Mask = 31;
173    
174        /**
175         * Returns whether a category represents a scalar type.
176         *
177         * @param category Category
178         * @return Whether is scalar
179         */
180        public static boolean isScalar(int category) {
181            switch (category & Mask) {
182            case Value:
183            case Logical:
184            case Numeric:
185            case Integer:
186            case String:
187            case DateTime:
188                return true;
189            default:
190                return false;
191            }
192        }
193    }
194    
195    // End Category.java