001 /* 002 // $Id: Measure.java 243 2009-05-22 07:21:37Z jhyde $ 003 // This software is subject to the terms of the Eclipse Public License v1.0 004 // Agreement, available at the following URL: 005 // http://www.eclipse.org/legal/epl-v10.html. 006 // Copyright (C) 2006-2008 Julian Hyde 007 // All Rights Reserved. 008 // You must accept the terms of that agreement to use this software. 009 */ 010 package org.olap4j.metadata; 011 012 import java.util.*; 013 014 /** 015 * Data value of primary interest to the user browsing the cube. 016 * 017 * <p>A <code>Measure</code> provides the value of each cell, and is usually 018 * numeric. Every measure is a member of a special dimension called "Measures". 019 * 020 * @author jhyde 021 * @version $Id: Measure.java 243 2009-05-22 07:21:37Z jhyde $ 022 * @since Oct 13, 2006 023 */ 024 public interface Measure extends Member { 025 /** 026 * Returns the Aggregator of this Measure. 027 * 028 * @return Aggregator 029 */ 030 Aggregator getAggregator(); 031 032 /** 033 * Returns the data type of this Measure. 034 * 035 * @return data type 036 */ 037 Datatype getDatatype(); 038 039 /** 040 * Returns whether this Measure is visible. 041 * 042 * @return whether this Measure is visible 043 */ 044 boolean isVisible(); 045 046 /** 047 * Enumeration of the aggregate functions which can be used to derive a 048 * <code>Measure</code>. 049 * 050 * <p>The values are as specified by XMLA. 051 * For example, XMLA specifies MDMEASURE_AGGR_SUM with ordinal 1, 052 * which corresponds to the value {@link #SUM}, 053 * whose {@link #xmlaOrdinal} is 1. 054 */ 055 enum Aggregator { 056 /** 057 * Identifies that the measure was derived using the 058 * SUM aggregation function. 059 */ 060 SUM(1), 061 /** 062 * Identifies that the measure was derived using the 063 * COUNT aggregation function. 064 */ 065 COUNT(2), 066 /** 067 * Identifies that the measure was derived using the 068 * MIN aggregation function. 069 */ 070 MIN(3), 071 /** 072 * Identifies that the measure was derived using the 073 * MAX aggregation function. 074 */ 075 MAX(4), 076 /** 077 * Identifies that the measure was derived using the 078 * AVG aggregation function. 079 */ 080 AVG(5), 081 /** 082 * Identifies that the measure was derived using the 083 * VAR aggregation function. 084 */ 085 VAR(6), 086 /** 087 * Identifies that the measure was derived using the 088 * STDEV aggregation function. 089 */ 090 STD(7), 091 /** 092 * Identifies that the measure was derived from a formula that was not 093 * any single function above. 094 */ 095 CALCULATED(127), 096 097 /** 098 * Identifies that the measure was derived from an unknown aggregation 099 * function or formula. 100 */ 101 UNKNOWN(0); 102 103 private final int xmlaOrdinal; 104 105 private static final Map<Integer, Aggregator> xmlaMap = 106 new HashMap<Integer, Aggregator>(); 107 108 static { 109 for (Aggregator aggregator : values()) { 110 xmlaMap.put(aggregator.xmlaOrdinal, aggregator); 111 } 112 } 113 114 /** 115 * Creates an Aggregator. 116 * 117 * @param xmlaOrdinal Ordinal of the aggregator in the XMLA 118 * specification 119 */ 120 private Aggregator(int xmlaOrdinal) { 121 this.xmlaOrdinal = xmlaOrdinal; 122 } 123 124 /** 125 * Returns the ordinal code as specified by XMLA. 126 * 127 * <p>For example, the XMLA specification says that the ordinal of 128 * {@link #CALCULATED} is 127. 129 * 130 * @return ordinal code as specified by XMLA. 131 */ 132 public final int xmlaOrdinal() { 133 return xmlaOrdinal; 134 } 135 136 /** 137 * Looks up an Aggregator by its XMLA ordinal. 138 * 139 * @param xmlaOrdinal Ordinal of an Aggregator according to the XMLA 140 * specification. 141 * 142 * @return Aggregator with the given ordinal, or null if there is no 143 * such Aggregator 144 */ 145 public static Aggregator forXmlaOrdinal(int xmlaOrdinal) { 146 return xmlaMap.get(xmlaOrdinal); 147 } 148 } 149 } 150 151 // End Measure.java