KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > mondrian > olap > type > SetType


1 /*
2 // $Id: //open/mondrian/src/main/mondrian/olap/type/SetType.java#5 $
3 // This software is subject to the terms of the Common Public License
4 // Agreement, available at the following URL:
5 // http://www.opensource.org/licenses/cpl.html.
6 // Copyright (C) 2005-2006 Julian Hyde
7 // All Rights Reserved.
8 // You must accept the terms of that agreement to use this software.
9 */

10 package mondrian.olap.type;
11
12 import mondrian.olap.Dimension;
13 import mondrian.olap.Hierarchy;
14 import mondrian.olap.Level;
15
16 /**
17  * Set type.
18  *
19  * @author jhyde
20  * @since Feb 17, 2005
21  * @version $Id: //open/mondrian/src/main/mondrian/olap/type/SetType.java#5 $
22  */

23 public class SetType implements Type {
24
25     private final Type elementType;
26
27     /**
28      * Creates a type representing a set of elements of a given type.
29      *
30      * @param elementType The type of the elements in the set, or null if not
31      * known
32      */

33     public SetType(Type elementType) {
34         assert elementType instanceof MemberType ||
35                 elementType instanceof TupleType;
36         this.elementType = elementType;
37     }
38
39     /**
40      * Returns the type of the elements of this set.
41      */

42     public Type getElementType() {
43         return elementType;
44     }
45
46     public boolean usesDimension(Dimension dimension, boolean maybe) {
47         if (elementType == null) {
48             return maybe;
49         }
50         return elementType.usesDimension(dimension, maybe);
51     }
52
53     public Dimension getDimension() {
54         return elementType == null ? null :
55                 elementType.getDimension();
56     }
57
58     public Hierarchy getHierarchy() {
59         return elementType == null ? null :
60                 elementType.getHierarchy();
61     }
62
63     public Level getLevel() {
64         return elementType == null ? null :
65                 elementType.getLevel();
66     }
67
68     /**
69      * Returns the dimensionality of this SetType. If set contains members,
70      * returns 1, otherwise returns the width of the tuples.
71      *
72      * @return Dimensionality of this SetType
73      */

74     public int getArity() {
75         return elementType instanceof TupleType ?
76             ((TupleType) elementType).elementTypes.length :
77             1;
78     }
79 }
80
81 // End SetType.java
82
Popular Tags