001    /*
002    // $Id: Axis.java 125 2008-11-02 07:43:12Z jhyde $
003    // This software is subject to the terms of the Common Public License
004    // Agreement, available at the following URL:
005    // http://www.opensource.org/licenses/cpl.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;
011    
012    import java.util.Locale;
013    
014    /**
015     * Enumeration of axis types.
016     *
017     * <p>The most commonly used values are
018     * <code>COLUMNS</code> (the first axis of a 2-dimensional query),
019     * <code>ROWS</code> (the second axis of a 2-dimensional query) and
020     * <code>FILTER</code> (also known as the slicer axis, denoted by a
021     * <code>WHERE</code> clause in an MDX statement).
022     *
023     * @author jhyde
024     * @version $Id: Axis.java 125 2008-11-02 07:43:12Z jhyde $
025     * @since Oct 23, 2006
026     */
027    public enum Axis {
028        UNUSED,
029        FILTER,
030        COLUMNS,
031        ROWS,
032        PAGES,
033        CHAPTERS,
034        SECTIONS;
035    
036        /**
037         * Returns the ordinal which is to be used for retrieving this axis from
038         * the {@link org.olap4j.CellSet#getAxes()}, or retrieving its
039         * coordinate from {@link Cell#getCoordinateList()}.
040         *
041         * <p>The axis ordinal is two less than the {@link #ordinal} value which
042         * every <code>enum</code> value possesses. Hence, {@link #UNUSED} is -2
043         * and {@link #FILTER} is -1 (because they are not treated the same as the
044         * other axes), {@link #COLUMNS} is 0, {@link #ROWS} is 1, and so forth.
045         *
046         * @return Axis ordinal
047         */
048        public int axisOrdinal() {
049            return axisOrdinal;
050        }
051    
052        /**
053         * Returns localized name for this Axis.
054         *
055         * @param locale Locale for which to give the name
056         * @return localized name for this Axis
057         */
058        public String getCaption(Locale locale) {
059            // todo: localize
060            return name();
061        }
062    
063        /**
064         * Returns the axis with a given {@link #axisOrdinal()}.
065         *
066         * @param axisOrdinal Axis ordinal
067         * @return Axis whose {@link #axisOrdinal()} is as given
068         */
069        public static Axis forOrdinal(int axisOrdinal) {
070            Axis axis = values()[axisOrdinal + 2];
071            assert axis.axisOrdinal() == axisOrdinal;
072            return axis;
073        }
074    
075        private final int axisOrdinal = ordinal() - 2;
076    
077        /**
078         * The largest legal value for {@link #forOrdinal(int)}.
079         */
080        public static final int MAX_ORDINAL = SECTIONS.axisOrdinal();
081    }
082    
083    // End Axis.java