001/* ===========================================================
002 * JFreeChart : a free chart library for the Java(tm) platform
003 * ===========================================================
004 *
005 * (C) Copyright 2000-2022, by David Gilbert and Contributors.
006 *
007 * Project Info:  http://www.jfree.org/jfreechart/index.html
008 *
009 * This library is free software; you can redistribute it and/or modify it
010 * under the terms of the GNU Lesser General Public License as published by
011 * the Free Software Foundation; either version 2.1 of the License, or
012 * (at your option) any later version.
013 *
014 * This library is distributed in the hope that it will be useful, but
015 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
016 * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
017 * License for more details.
018 *
019 * You should have received a copy of the GNU Lesser General Public
020 * License along with this library; if not, write to the Free Software
021 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301,
022 * USA.
023 *
024 * [Oracle and Java are registered trademarks of Oracle and/or its affiliates. 
025 * Other names may be trademarks of their respective owners.]
026 *
027 * -------------------
028 * AxisCollection.java
029 * -------------------
030 * (C) Copyright 2003-2022, by David Gilbert.
031 *
032 * Original Author:  David Gilbert;
033 * Contributor(s):   -;
034 *
035 */
036
037package org.jfree.chart.axis;
038
039import java.util.ArrayList;
040import java.util.List;
041import org.jfree.chart.api.RectangleEdge;
042import org.jfree.chart.internal.Args;
043
044/**
045 * A collection of axes that have been assigned to the TOP, BOTTOM, LEFT or
046 * RIGHT of a chart.  This class is used internally by JFreeChart, you won't
047 * normally need to use it yourself.
048 */
049public class AxisCollection {
050
051    /** The axes that need to be drawn at the top of the plot area. */
052    private final List<Axis> axesAtTop;
053
054    /** The axes that need to be drawn at the bottom of the plot area. */
055    private final List<Axis> axesAtBottom;
056
057    /** The axes that need to be drawn at the left of the plot area. */
058    private final List<Axis> axesAtLeft;
059
060    /** The axes that need to be drawn at the right of the plot area. */
061    private final List<Axis> axesAtRight;
062
063    /**
064     * Creates a new empty collection.
065     */
066    public AxisCollection() {
067        this.axesAtTop = new ArrayList<>();
068        this.axesAtBottom = new ArrayList<>();
069        this.axesAtLeft = new ArrayList<>();
070        this.axesAtRight = new ArrayList<>();
071    }
072
073    /**
074     * Returns a list of the axes (if any) that need to be drawn at the top of
075     * the plot area.
076     *
077     * @return A list of axes.
078     */
079    public List<Axis> getAxesAtTop() {
080        return this.axesAtTop;
081    }
082
083   /**
084    * Returns a list of the axes (if any) that need to be drawn at the bottom
085    * of the plot area.
086    *
087    * @return A list of axes.
088    */
089   public List<Axis> getAxesAtBottom() {
090        return this.axesAtBottom;
091    }
092
093    /**
094     * Returns a list of the axes (if any) that need to be drawn at the left
095     * of the plot area.
096     *
097     * @return A list of axes.
098     */
099    public List<Axis> getAxesAtLeft() {
100        return this.axesAtLeft;
101    }
102
103    /**
104    * Returns a list of the axes (if any) that need to be drawn at the right
105    * of the plot area.
106    *
107    * @return A list of axes.
108    */
109    public List<Axis> getAxesAtRight() {
110        return this.axesAtRight;
111    }
112
113    /**
114     * Adds an axis to the collection.
115     *
116     * @param axis  the axis ({@code null} not permitted).
117     * @param edge  the edge of the plot that the axis should be drawn on
118     *              ({@code null} not permitted).
119     */
120    public void add(Axis axis, RectangleEdge edge) {
121        Args.nullNotPermitted(axis, "axis");
122        Args.nullNotPermitted(edge, "edge");
123        switch (edge) {
124            case TOP:
125                this.axesAtTop.add(axis);
126                break;
127            case BOTTOM:
128                this.axesAtBottom.add(axis);
129                break;
130            case LEFT:
131                this.axesAtLeft.add(axis);
132                break;
133            case RIGHT:
134                this.axesAtRight.add(axis);
135                break;
136            default:
137                break;
138        }
139    }
140
141}