/* XBN Java: Generically useful, non-GUI Java code. http://sourceforge.net/projects/xbnjava Copyright (C) 1997-2003, Jeff Epstein All rights reserved. Modifications: No Redistribution in binary form, with or without modifications, are permitted provided that the following conditions are met: * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. * If modifications are made to source code then this license should indicate that fact in the "Modifications" section above. * Neither the author, nor the contributors may be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. [NOTE: This license contains NO advertising clause.] */ package xbn.array; import java.util.Vector; /**
A VectorWrapper for java.lang.Objects.
Source code: VWObject.java. Example code See the similar example code for VWObject.
Create a VWObject with default settings.
Equal to VectorWrapper()
Create a VWObject.
Equal to VectorWrapper(v_ector)
Create a VWObject.
Equal to VectorWrapper(b_orderDirAscDesc)
Create a VWObject.
Equal to VectorWrapper(v_ector, b_orderDirAscDesc)
Create a VWObject.
Equal to VectorWrapper(b_addInOrder, b_orderDirAscDesc)
Create a VWObject.
Equal to VectorWrapper(v_ector, b_addInOrder, b_orderDisAscDesc)
Add an object.
@param o_bject The object to add. May be null. **/ public final void add(Object o_bject) { getVector().addElement(o_bject); } /**Add an array of Objects.
@param a_object The Object array to add. May not be null. **/ public final void addArray(Object[] a_object) { try { for(int i = 0; i < a_object.length; i++) { add(a_object[i]); } } catch(NullPointerException npx) { throwAX("addArray: a_object is null."); } } /**Add an array of objects, as protected by the provided APObject.
Equal to addArray(ap_object.[The internally-held object array])
Get an object from the vector, at the required array index.
@param i_dx The array index. Must range 0..[size() - 1]
, inclusive.
**/
public final Object getObject(int i_dx) {
try {
return getVector().elementAt(i_dx);
} catch(ArrayIndexOutOfBoundsException aioobx) {
throwAX("getObject: i_dx (" + i_dx + ") is invalid. size()=" + size() + ".");
}
//Never reached. Required for compile.
return null;
}
/**
Get a string from the vector, at the required array index.
@returngetObject(i_dx).toString()
**/
public final String getString(int i_dx) {
return getObject(i_dx).toString();
}
/**
Is the element at the requested array index null?
@return(getObject(i_dx) == null)
**/
public final boolean isNull(int i_dx) {
return (getObject(i_dx) == null);
}
/**
Get the array of objects. This array is composed of all those objects added since this object was created, or since the last time this function was called.
@return An array containing all objects added to this object, in the same order as originally added. **/ public final Object[] getAOObject() { Object ao[] = new Object[getVector().size()]; if(ao.length == 0) { return ao; } //The array is at least one element in length. getVector().copyInto(ao); return ao; } //Cloning...START /**Get a copy of this VWObject.
@return(VWObject)clone()
**/
public final VWObject getVWIClone() {
try {
return (VWObject)clone();
} catch(CloneNotSupportedException cnsx) {
throwAX("getVWIClone [SHOULD NEVER HAPPEN!]: " + cnsx.toString());
}
//Never reached. Required for compile.
return null;
}
/**
Get a copy of this VWObject as an Object.
This recreates the internal vector, but points to the same object as this VWObject.
**/ protected final Object clone() throws CloneNotSupportedException { VWObject acbClone = new VWObject(); for(int i = 0; i < size(); i++) { acbClone.add(getObject(i)); } return acbClone; } //Cloning...END }