001 /*
002 // $Id: DimensionType.java 247 2009-06-20 05:52:40Z 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) 2005-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.type;
011
012 import org.olap4j.metadata.Dimension;
013 import org.olap4j.metadata.Hierarchy;
014 import org.olap4j.metadata.Level;
015
016 /**
017 * The type of an expression which represents a Dimension.
018 *
019 * @author jhyde
020 * @since Feb 17, 2005
021 * @version $Id: DimensionType.java 247 2009-06-20 05:52:40Z jhyde $
022 */
023 public class DimensionType implements Type {
024 private final Dimension dimension;
025 private final String digest;
026
027 public static final DimensionType Unknown = new DimensionType(null);
028
029 /**
030 * Creates a type representing a dimension.
031 *
032 * @param dimension Dimension which values of this type must belong to, or
033 * null if not known
034 */
035 public DimensionType(Dimension dimension) {
036 this.dimension = dimension;
037 StringBuilder buf = new StringBuilder("DimensionType<");
038 if (dimension != null) {
039 buf.append("dimension=").append(dimension.getUniqueName());
040 }
041 buf.append(">");
042 this.digest = buf.toString();
043 }
044
045 public boolean usesDimension(Dimension dimension, boolean maybe) {
046 if (this.dimension == null) {
047 return maybe;
048 } else {
049 return this.dimension.equals(dimension);
050 }
051 }
052
053 public Hierarchy getHierarchy() {
054 return dimension == null
055 ? null
056 : dimension.getHierarchies().size() > 1
057 ? null
058 : dimension.getHierarchies().get(0);
059 }
060
061 public Level getLevel() {
062 return null;
063 }
064
065 public Dimension getDimension() {
066 return dimension;
067 }
068
069 public String toString() {
070 return digest;
071 }
072 }
073
074 // End DimensionType.java