/* 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.primitive; import xbn.util.LockOneWay; import xbn.array.UtilArray; import xbn.named.Named; import xbn.named.PASNamed; import xbn.string.StringOrBuffer; /**

A PrimitiveArrayString that wraps around an array of java.lang.Objects. This class defines the string (see PrimitiveArray.getString) to be the Object's toString. Extend this class to make the string represent something else.

Source code:  PASAOObject.java.

@version 0.9b @author Jeff Epstein, http://sourceforge.net/projects/xbnjava. **/ public class PASAOObject extends PrimitiveArrayString implements LockOneWay { public final static String sPASAOO = "xbn.array.primitive.PASAOObject"; private final UtilArray uArray = new UtilArray(); private Object[] aObject = null; private boolean bLocked = false; /**

Create a PASAOObject with default values.

Equal to PASAOObject(null)

**/ public PASAOObject() { this(null); } /**

Create a PASAOObject.

Equal to PASAOObject(sPASAOO, a_object)

**/ public PASAOObject(Object[] a_object) { this(sPASAOO, a_object); } /**

Create a PASAOObject.

Equal to PASAOObject(s_fqExtendingClass, a_object, (new PARString())))

**/ public PASAOObject(String s_fqExtendingClass, Object[] a_object) { this(s_fqExtendingClass, a_object, (new PARString())); } /**

Create a PASAOObject.

Equal to PASAOObject(sPASAOO, a_object, par_string)

**/ public PASAOObject(Object[] a_object, PARString par_string) { this(sPASAOO, a_object, par_string); } /**

Create a PASAOObject.

Equal to PASAOObject(sPASAOO, a_object, (new PARString()), b_lock)

**/ public PASAOObject(Object[] a_object, boolean b_lock) { this(sPASAOO, a_object, (new PARString()), b_lock); } /**

Create a PASAOObject.

Equal to PASAOObject(sPASAOO, a_object, par_string, b_lock)

**/ public PASAOObject(Object[] a_object, PARString par_string, boolean b_lock) { this(sPASAOO, a_object, par_string, b_lock); } /**

Create a PASAOObject.

Equal to PASAOObject(s_fqExtendingClass, a_object, par_string, false)

**/ public PASAOObject(String s_fqExtendingClass, Object[] a_object, PARString par_string) { this(s_fqExtendingClass, a_object, par_string, false); } /**

Create a PASAOObject.

Equal to PASAOObject(s_fqExtendingClass, a_object, (new PARString()), b_lock)

**/ public PASAOObject(String s_fqExtendingClass, Object[] a_object, boolean b_lock) { this(s_fqExtendingClass, a_object, (new PARString()), b_lock); } /**

Create an PASAOObject.

The first line of this constructor calls PrimitiveArrayChar(s_fqExtendingClass, par_string)

@param a_object The array of Objects that should somehow appear like an array of strings. @param b_lock Should a_object be directly accessible, via getAOObject? If true, yes. If false, no. See lock and isLocked. **/ public PASAOObject(String s_fqExtendingClass, Object[] a_object, PARString par_string, boolean b_lock) { super(s_fqExtendingClass, par_string); aObject = a_object; bLocked = b_lock; } /**

How many strings exist in this PASAOObject?

@exception AssertException If isNull equals true. **/ public final int getLength() { try { return aObject.length; } catch(NullPointerException npx) { throwAX("getLength: isNull() is true."); } //Never reached. Required for compile. return -1; } /**

Get the object at the requested array index.

@param i_dx The array index. Must range 0..[getLength() - 1], inclusive @exception AssertException If isNull equals true. **/ public final Object getObject(int i_dx) { try { return aObject[i_dx]; } catch(NullPointerException npx) { throwAX("getObject: isNull() is true."); } catch(ArrayIndexOutOfBoundsException aioobx) { throwAX("get: i_dx (" + i_dx + ") is invalid. getLength()=" + getLength() + "."); } //Never reached. Required for compile. return null; } /**

Get the array of objects for direct manipulation.

@return a_object Exactly as provided to the constructor. @exception LockedException If isLocked equals false. **/ public final Object[] getAOObject() { throwLXIfLocked(isLocked(), "getAOObject"); return aObject; } /**

Is the array of objects null?

@return (a_object == null) where a_object is exactly as provided to the constructor. **/ public final boolean isNull() { return (aObject == null); } /**

Is the object at the requested array index null?

@return (a_object[i_dx] == null) where a_object is exactly as provided to the constructor. @param i_dx The array index. Must range 0..[getLength() - 1], inclusive **/ public final boolean isNull(int i_dx) { try { return (aObject[i_dx] == null); } catch(ArrayIndexOutOfBoundsException aioobx) { throwAX("get: i_dx (" + i_dx + ") is invalid. getLength()=" + getLength() + "."); } //Never reached. Required for compile. return false; } public final PASNamed getPASNamed() { try { return (new PASNamed((Named[])aObject, true)); } catch(ClassCastException ccx) { throwAX("getPASNamed: As provided to the constructor, a_object is not of type 'xbn.named.Named[]'. Currently: '" + aObject.getClass().getName() + "'."); } //Never reached. Required for compile. return null; } /**

Get the toString of the requested element.

@return getObject(i_dx).toString() **/ public String getString(int i_dx) { return getObject(i_dx).toString(); } /**

Get a new PASString representing the internally-held array of Objects (as Strings).

@return (new PASString((String[])[the internally-held array of Objects], isLocked())) **/ public final PASString getPASString() { return (new PASString((String[])aObject, isLocked())); } /**

Get a new PASString representing the toStrings() of the internally-held array of Objects.

Equal to [UtilArray].appendTSList(str_orBfr, [the internally-held array of objects], s_prefix, s_divider, s_postfix, s_ifNull, s_ifEmpty, s_ifLmntNull)

**/ public final void appendTSList(StringOrBuffer str_orBfr, String s_prefix, String s_divider, String s_postfix, String s_ifNull, String s_ifEmpty, String s_ifLmntNull) { uArray.appendTSList(str_orBfr, aObject, null, " | ", null, null, null, null); } //Required by LockOneWay...START public final void lock() { bLocked = true; } public final boolean isLocked() { return bLocked; } //Required by LockOneWay...END }