001: //** Copyright Statement ***************************************************
002: //The Salmon Open Framework for Internet Applications (SOFIA)
003: // Copyright (C) 1999 - 2002, Salmon LLC
004: //
005: // This program is free software; you can redistribute it and/or
006: // modify it under the terms of the GNU General Public License version 2
007: // as published by the Free Software Foundation;
008: //
009: // This program is distributed in the hope that it will be useful,
010: // but WITHOUT ANY WARRANTY; without even the implied warranty of
011: // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
012: // GNU General Public License for more details.
013: //
014: // You should have received a copy of the GNU General Public License
015: // along with this program; if not, write to the Free Software
016: // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
017: //
018: // For more information please visit http://www.salmonllc.com
019: //** End Copyright Statement ***************************************************
020: package com.salmonllc.forms;
021:
022: /////////////////////////
023: //$Archive: /JADE/SourceCode/com/salmonllc/forms/BaseListFormComponentVector.java $
024: //$Author: Dan $
025: //$Revision: 5 $
026: //$Modtime: 10/30/02 2:58p $
027: /////////////////////////
028: import java.util.Vector;
029:
030: /**
031: * A type safe Vector that returns BaseListFormComponents and only accepts BaseListFormComponents
032: */
033: public class BaseListFormComponentVector {
034:
035: private Vector _elements;
036:
037: /**
038: * BaseListFormElementsVector constructor comment.
039: */
040: public BaseListFormComponentVector() {
041: _elements = new Vector();
042: }
043:
044: /**
045: * BaseListFormElementsVector constructor comment.
046: * @param initialCapacity int
047: */
048: public BaseListFormComponentVector(int initialCapacity) {
049: _elements = new Vector(initialCapacity);
050: }
051:
052: /**
053: * BaseListFormElementsVector constructor comment.
054: * @param initialCapacity int
055: * @param capacityIncrement int
056: */
057: public BaseListFormComponentVector(int initialCapacity,
058: int capacityIncrement) {
059: _elements = new Vector(initialCapacity, capacityIncrement);
060: }
061:
062: /**
063: * Adds the specified BaseListFormComponent to the end of this vector,
064: * increasing its size by one. The capacity of this vector is
065: * increased if its size becomes greater than its capacity.
066: *
067: * @param comp the BaseListFormComponent to be added.
068: */
069: public void addElement(BaseListFormComponent comp) {
070: _elements.addElement(comp);
071: }
072:
073: /**
074: * Tests if the specified BaseListFormComponent is a component in this vector.
075: *
076: * @param elem a BaseListFormComponent.
077: * @return <code>true</code> if the specified object is a BaseListFormComponent in
078: * this vector; <code>false</code> otherwise.
079: */
080: public final boolean contains(BaseListFormComponent elem) {
081: return _elements.contains(elem);
082: }
083:
084: /**
085: * Copies the BaseListFormComponent of this vector into the specified array.
086: * The array must be big enough to hold all the objects in this vector.
087: *
088: * @param anArray the array into which the BaseListFormComponent get copied.
089: */
090: public void copyInto(BaseListFormComponent anArray[]) {
091: _elements.copyInto(anArray);
092: }
093:
094: /**
095: * Returns the BaseListFormComponent at the specified index.
096: *
097: * @param index an index into this vector.
098: * @return the BaseListFormComponent at the specified index.
099: * @exception ArrayIndexOutOfBoundsException if an invalid index was
100: * given.
101: */
102: public BaseListFormComponent elementAt(int index) {
103: return (BaseListFormComponent) _elements.elementAt(index);
104: }
105:
106: /**
107: * Searches for the first occurence of the given argument, testing
108: * for equality using the <code>equals</code> method.
109: *
110: * @param elem an BaseListFormComponent.
111: * @return the index of the first occurrence of the argument in this
112: * vector; returns <code>-1</code> if the BaseListFormComponent is not found.
113: * @see java.lang.Object#equals(java.lang.Object)
114: */
115: public final int indexOf(BaseListFormComponent elem) {
116: return _elements.indexOf(elem);
117: }
118:
119: /**
120: * Searches for the first occurence of the given argument, beginning
121: * the search at <code>index</code>, and testing for equality using
122: * the <code>equals</code> method.
123: *
124: * @param elem an BaseListFormComponent.
125: * @param index the index to start searching from.
126: * @return the index of the first occurrence of the BaseListFormComponent argument in
127: * this vector at position <code>index</code> or later in the
128: * vector; returns <code>-1</code> if the object is not found.
129: * @see java.lang.Object#equals(java.lang.Object)
130: */
131: public int indexOf(BaseListFormComponent elem, int index) {
132: return _elements.indexOf(elem, index);
133: }
134:
135: /**
136: * Inserts the specified BaseListFormComponent as a component in this vector at the
137: * specified <code>index</code>. Each component in this vector with
138: * an index greater or equal to the specified <code>index</code> is
139: * shifted upward to have an index one greater than the value it had
140: * previously.
141: * <p>
142: * The index must be a value greater than or equal to <code>0</code>
143: * and less than or equal to the current size of the vector.
144: *
145: * @param comp the BaseListFormComponent to insert.
146: * @param index where to insert the new component.
147: * @exception ArrayIndexOutOfBoundsException if the index was invalid.
148: * @see java.util.Vector#size()
149: */
150: public void insertElementAt(BaseListFormComponent comp, int index) {
151: _elements.insertElementAt(comp, index);
152: }
153:
154: /**
155: * Returns the index of the last occurrence of the specified BaseListFormComponent in
156: * this vector.
157: *
158: * @param elem the desired BaseListFormComponent.
159: * @return the index of the last occurrence of the specified BaseListFormComponent in
160: * this vector; returns <code>-1</code> if the object is not found.
161: */
162: public final int lastIndexOf(BaseListFormComponent elem) {
163: return _elements.lastIndexOf(elem);
164: }
165:
166: /**
167: * Searches backwards for the specified BaseListFormComponent, starting from the
168: * specified index, and returns an index to it.
169: *
170: * @param elem the desired BaseListFormComponent.
171: * @param index the index to start searching from.
172: * @return the index of the last occurrence of the specified BaseListFormComponent in this
173: * vector at position less than <code>index</code> in the vector;
174: * <code>-1</code> if the object is not found.
175: */
176: public int lastIndexOf(BaseListFormComponent elem, int index) {
177: return _elements.lastIndexOf(elem, index);
178: }
179:
180: /**
181: * Removes the first occurrence of the argument from this vector. If
182: * the BaseListFormComponent is found in this vector, each component in the vector
183: * with an index greater or equal to the object's index is shifted
184: * downward to have an index one smaller than the value it had previously.
185: *
186: * @param comp the component to be removed.
187: * @return <code>true</code> if the argument was a component of this
188: * vector; <code>false</code> otherwise.
189: * @since JDK1.0
190: */
191: public boolean removeComp(BaseListFormComponent comp) {
192: return _elements.removeElement(comp);
193: }
194:
195: /**
196: * Sets the component at the specified <code>index</code> of this
197: * vector to be the specified BaseListFormComponent. The previous component at that
198: * position is discarded.
199: * <p>
200: * The index must be a value greater than or equal to <code>0</code>
201: * and less than the current size of the vector.
202: *
203: * @param comp what the component is to be set to.
204: * @param index the specified index.
205: * @exception ArrayIndexOutOfBoundsException if the index was invalid.
206: * @see java.util.Vector#size()
207: */
208: public void setElementAt(BaseListFormComponent comp, int index) {
209: _elements.setElementAt(comp, index);
210: }
211:
212: /**
213: * Returns the number of components in this vector.
214: *
215: * @return the number of components in this vector.
216: */
217: public int size() {
218: return _elements.size();
219: }
220: }
|