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