Source for org.jfree.chart.LegendItemCollection

   1: /* ===========================================================
   2:  * JFreeChart : a free chart library for the Java(tm) platform
   3:  * ===========================================================
   4:  *
   5:  * (C) Copyright 2000-2007, by Object Refinery Limited and Contributors.
   6:  *
   7:  * Project Info:  http://www.jfree.org/jfreechart/index.html
   8:  *
   9:  * This library is free software; you can redistribute it and/or modify it 
  10:  * under the terms of the GNU Lesser General Public License as published by 
  11:  * the Free Software Foundation; either version 2.1 of the License, or 
  12:  * (at your option) any later version.
  13:  *
  14:  * This library is distributed in the hope that it will be useful, but 
  15:  * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY 
  16:  * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public 
  17:  * License for more details.
  18:  *
  19:  * You should have received a copy of the GNU Lesser General Public
  20:  * License along with this library; if not, write to the Free Software
  21:  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, 
  22:  * USA.  
  23:  *
  24:  * [Java is a trademark or registered trademark of Sun Microsystems, Inc. 
  25:  * in the United States and other countries.]
  26:  *
  27:  * -------------------------
  28:  * LegendItemCollection.java
  29:  * -------------------------
  30:  * (C) Copyright 2002-2007, by Object Refinery Limited.
  31:  *
  32:  * Original Author:  David Gilbert (for Object Refinery Limited);
  33:  * Contributor(s):   -;
  34:  *
  35:  * Changes
  36:  * -------
  37:  * 07-Feb-2002 : Version 1 (DG);
  38:  * 24-Sep-2002 : Added get(int) and getItemCount() methods (DG);
  39:  * 02-Oct-2002 : Fixed errors reported by Checkstyle (DG);
  40:  * 18-Apr-2005 : Added equals() method and implemented Cloneable and 
  41:  *               Serializable (DG);
  42:  *
  43:  */
  44: 
  45: package org.jfree.chart;
  46: 
  47: import java.io.Serializable;
  48: import java.util.Iterator;
  49: import java.util.List;
  50: 
  51: /**
  52:  * A collection of legend items.
  53:  */
  54: public class LegendItemCollection implements Cloneable, Serializable {
  55: 
  56:     /** For serialization. */
  57:     private static final long serialVersionUID = 1365215565589815953L;
  58:     
  59:     /** Storage for the legend items. */
  60:     private List items;
  61: 
  62:     /**
  63:      * Constructs a new legend item collection, initially empty.
  64:      */
  65:     public LegendItemCollection() {
  66:         this.items = new java.util.ArrayList();
  67:     }
  68: 
  69:     /**
  70:      * Adds a legend item to the collection.
  71:      *
  72:      * @param item  the item to add.
  73:      */
  74:     public void add(LegendItem item) {
  75:         this.items.add(item);
  76:     }
  77: 
  78:     /**
  79:      * Adds the legend items from another collection to this collection.
  80:      *
  81:      * @param collection  the other collection.
  82:      */
  83:     public void addAll(LegendItemCollection collection) {
  84:         this.items.addAll(collection.items);
  85:     }
  86: 
  87:     /**
  88:      * Returns a legend item from the collection.
  89:      *
  90:      * @param index  the legend item index (zero-based).
  91:      *
  92:      * @return The legend item.
  93:      */
  94:     public LegendItem get(int index) {
  95:         return (LegendItem) this.items.get(index);
  96:     }
  97: 
  98:     /**
  99:      * Returns the number of legend items in the collection.
 100:      *
 101:      * @return The item count.
 102:      */
 103:     public int getItemCount() {
 104:         return this.items.size();
 105:     }
 106: 
 107:     /**
 108:      * Returns an iterator that provides access to all the legend items.
 109:      *
 110:      * @return An iterator.
 111:      */
 112:     public Iterator iterator() {
 113:         return this.items.iterator();
 114:     }
 115:     
 116:     /**
 117:      * Tests this collection for equality with an arbitrary object.
 118:      * 
 119:      * @param obj  the object (<code>null</code> permitted).
 120:      * 
 121:      * @return A boolean.
 122:      */
 123:     public boolean equals(Object obj) {
 124:         if (obj == this) {
 125:             return true;   
 126:         }
 127:         if (!(obj instanceof LegendItemCollection)) {
 128:             return false;   
 129:         }
 130:         LegendItemCollection that = (LegendItemCollection) obj;
 131:         if (!this.items.equals(that.items)) {
 132:             return false;   
 133:         }
 134:         return true;
 135:     }
 136: 
 137:     /**
 138:      * Returns a clone of the collection.
 139:      * 
 140:      * @return A clone.
 141:      * 
 142:      * @throws CloneNotSupportedException if an item in the collection is not
 143:      *         cloneable.
 144:      */
 145:     public Object clone() throws CloneNotSupportedException {
 146:         return super.clone();   
 147:     }
 148:     
 149: }