|
24 | 24 | * @version $Id$
|
25 | 25 | * @since Oct 23, 2006
|
26 | 26 | */
|
27 |
| -public enum Axis { |
28 |
| - UNUSED, |
29 |
| - FILTER, |
30 |
| - COLUMNS, |
31 |
| - ROWS, |
32 |
| - PAGES, |
33 |
| - CHAPTERS, |
34 |
| - SECTIONS; |
| 27 | +public interface Axis { |
35 | 28 |
|
36 | 29 | /**
|
37 |
| - * Returns the ordinal which is to be used for retrieving this axis from |
38 |
| - * the {@link org.olap4j.CellSet#getAxes()}, or retrieving its |
39 |
| - * coordinate from {@link Cell#getCoordinateList()}. |
| 30 | + * Returns the name of this axis, e.g. "COLUMNS", "SLICER", "AXIS(17)". |
40 | 31 | *
|
41 |
| - * <p>The axis ordinal is two less than the {@link #ordinal} value which |
42 |
| - * every <code>enum</code> value possesses. Hence, {@link #UNUSED} is -2 |
43 |
| - * and {@link #FILTER} is -1 (because they are not treated the same as the |
44 |
| - * other axes), {@link #COLUMNS} is 0, {@link #ROWS} is 1, and so forth. |
45 |
| - * |
46 |
| - * @return Axis ordinal |
| 32 | + * @return Name of the axis |
47 | 33 | */
|
48 |
| - public int axisOrdinal() { |
49 |
| - return axisOrdinal; |
50 |
| - } |
| 34 | + String name(); |
51 | 35 |
|
52 | 36 | /**
|
53 |
| - * Returns localized name for this Axis. |
| 37 | + * Returns whether this is the filter (slicer) axis. |
54 | 38 | *
|
55 |
| - * @param locale Locale for which to give the name |
56 |
| - * @return localized name for this Axis |
| 39 | + * @return whether this is the filter axis |
57 | 40 | */
|
58 |
| - public String getCaption(Locale locale) { |
59 |
| - // todo: localize |
60 |
| - return name(); |
61 |
| - } |
| 41 | + boolean isFilter(); |
62 | 42 |
|
63 | 43 | /**
|
64 |
| - * Returns the axis with a given {@link #axisOrdinal()}. |
65 |
| - * |
66 |
| - * @param axisOrdinal Axis ordinal |
67 |
| - * @return Axis whose {@link #axisOrdinal()} is as given |
| 44 | + * @deprecated Will be removed before olap4j 1.0. |
68 | 45 | */
|
69 |
| - public static Axis forOrdinal(int axisOrdinal) { |
70 |
| - Axis axis = values()[axisOrdinal + 2]; |
71 |
| - assert axis.axisOrdinal() == axisOrdinal; |
72 |
| - return axis; |
| 46 | + public static final Standard UNUSED = null; |
| 47 | + |
| 48 | + /** |
| 49 | + * @deprecated Will be removed before olap4j 1.0. |
| 50 | + */ |
| 51 | + public static final Standard NONE = null; |
| 52 | + |
| 53 | + /** |
| 54 | + * Abbreviation for {@link org.olap4j.Axis.Standard#FILTER}. |
| 55 | + */ |
| 56 | + public static final Standard FILTER = Standard.FILTER; |
| 57 | + public static final Standard COLUMNS = Standard.COLUMNS; |
| 58 | + public static final Standard ROWS = Standard.ROWS; |
| 59 | + public static final Standard PAGES = Standard.PAGES; |
| 60 | + public static final Standard SECTIONS = Standard.SECTIONS; |
| 61 | + public static final Standard CHAPTERS = Standard.CHAPTERS; |
| 62 | + |
| 63 | + /** |
| 64 | + * Enumeration of standard, named axes descriptors. |
| 65 | + */ |
| 66 | + public enum Standard implements Axis { |
| 67 | + /** Filter axis. */ |
| 68 | + FILTER, |
| 69 | + |
| 70 | + /** COLUMNS axis, also known as X axis and AXIS(0). */ |
| 71 | + COLUMNS, |
| 72 | + |
| 73 | + /** ROWS axis, also known as Y axis and AXIS(1). */ |
| 74 | + ROWS, |
| 75 | + |
| 76 | + /** PAGES axis, also known as AXIS(2). */ |
| 77 | + PAGES, |
| 78 | + |
| 79 | + /** CHAPTERS axis, also known as AXIS(3). */ |
| 80 | + CHAPTERS, |
| 81 | + |
| 82 | + /** SECTIONS axis, also known as AXIS(4). */ |
| 83 | + SECTIONS; |
| 84 | + |
| 85 | + public int axisOrdinal() { |
| 86 | + return ordinal() - 1; |
| 87 | + } |
| 88 | + |
| 89 | + public boolean isFilter() { |
| 90 | + return this == FILTER; |
| 91 | + } |
| 92 | + |
| 93 | + public String getCaption(Locale locale) { |
| 94 | + // TODO: localize |
| 95 | + return name(); |
| 96 | + } |
73 | 97 | }
|
74 | 98 |
|
75 |
| - private final int axisOrdinal = ordinal() - 2; |
| 99 | + class Factory { |
| 100 | + private static final Standard[] STANDARD_VALUES = Standard.values(); |
| 101 | + |
| 102 | + /** |
| 103 | + * Returns the axis with a given {@code axisOrdinal}. |
| 104 | + * |
| 105 | + * <p>For example, {@code forOrdinal(0)} returns the COLUMNS axis; |
| 106 | + * {@code forOrdinal(-1)} returns the SLICER axis; |
| 107 | + * {@code forOrdinal(100)} returns AXIS(100). |
| 108 | + * |
| 109 | + * @param ordinal Axis ordinal |
| 110 | + * @return Axis whose ordinal is as given |
| 111 | + */ |
| 112 | + public static Axis forOrdinal(final int ordinal) { |
| 113 | + if (ordinal < -1) { |
| 114 | + throw new IllegalArgumentException( |
| 115 | + "Axis ordinal must be -1 or higher"); |
| 116 | + } |
| 117 | + if (ordinal + 1 < STANDARD_VALUES.length) { |
| 118 | + return STANDARD_VALUES[ordinal + 1]; |
| 119 | + } |
| 120 | + return new Axis() { |
| 121 | + public String toString() { |
| 122 | + return name(); |
| 123 | + } |
| 124 | + |
| 125 | + public String name() { |
| 126 | + return "AXIS(" + ordinal + ")"; |
| 127 | + } |
| 128 | + |
| 129 | + public boolean isFilter() { |
| 130 | + return false; |
| 131 | + } |
| 132 | + |
| 133 | + public int axisOrdinal() { |
| 134 | + return ordinal; |
| 135 | + } |
| 136 | + |
| 137 | + public String getCaption(Locale locale) { |
| 138 | + // TODO: localize |
| 139 | + return name(); |
| 140 | + } |
| 141 | + }; |
| 142 | + } |
| 143 | + } |
76 | 144 |
|
77 | 145 | /**
|
78 |
| - * The largest legal value for {@link #forOrdinal(int)}. |
| 146 | + * Returns the ordinal which is to be used for retrieving this axis from |
| 147 | + * the {@link org.olap4j.CellSet#getAxes()}, or retrieving its |
| 148 | + * coordinate from {@link Cell#getCoordinateList()}. |
| 149 | + * |
| 150 | + * <p>For example: |
| 151 | + * <ul> |
| 152 | + * <li>-1 {@link org.olap4j.Axis.Standard#FILTER FILTER}</li> |
| 153 | + * <li>0 {@link org.olap4j.Axis.Standard#COLUMNS COLUMNS}</li> |
| 154 | + * <li>1 {@link org.olap4j.Axis.Standard#ROWS ROWS}</li> |
| 155 | + * <li>2 {@link org.olap4j.Axis.Standard#PAGES PAGES}</li> |
| 156 | + * <li>3 {@link org.olap4j.Axis.Standard#CHAPTERS CHAPTERS}</li> |
| 157 | + * <li>4 {@link org.olap4j.Axis.Standard#SECTIONS SECTIONS}</li> |
| 158 | + * <li>5 {@link org.olap4j.Axis.Standard#SECTIONS SECTIONS}</li> |
| 159 | + * <li>6 AXES(6)</li> |
| 160 | + * <li>123 AXES(123)</li> |
| 161 | + * </ul> |
| 162 | + * |
| 163 | + * @return ordinal of this axis |
| 164 | + */ |
| 165 | + int axisOrdinal(); |
| 166 | + |
| 167 | + /** |
| 168 | + * Returns localized name for this Axis. |
| 169 | + * |
| 170 | + * <p>Examples: "FILTER", "ROWS", "COLUMNS", "AXIS(10)". |
| 171 | + * |
| 172 | + * @param locale Locale for which to give the name |
| 173 | + * @return localized name for this Axis |
79 | 174 | */
|
80 |
| - public static final int MAX_ORDINAL = SECTIONS.axisOrdinal(); |
| 175 | + String getCaption(Locale locale); |
81 | 176 | }
|
82 | 177 |
|
83 | 178 | // End Axis.java
|
0 commit comments