/* 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.AssertException; import xbn.util.RangeConfig; import xbn.util.RCLength; /**
A PrimitiveArray for ints.
Source code: PrimitiveArrayInt.java.
Create an PrimitiveArrayInt.
The first line of this constructor calls PrimitiveArray(s_fqExtendingClass, par_int)
Get the int at the requested array index.
@param i_dx The array index. Must range 0..[getLength() - 1]
, inclusive.
@exception AssertException If isNull equals true.
**/
public abstract int getInt(int i_dx);
/**
@return (new Integer(getInt(i_dx))).toString()
**/
public final String getString(int i_dx) {
return (new Integer(getInt(i_dx))).toString();
}
//Documented via super
public final boolean areLmntsEqual(int i_idxThis, PrimitiveArray pa_other, int i_idxOther) {
return areLmntsEqual(i_idxThis, (PrimitiveArrayInt)pa_other, i_idxOther);
}
/**
Is an element in this PrimitiveArrayInt equal to an element in another?
For documentation on this function, see PrimitiveArray.areLmntsEqual.
**/ public final boolean areLmntsEqual(int i_idxThis, PrimitiveArrayInt pai_other, int i_idxOther) { try { //Must get other first. throwLmntsEqualAioobx will crash //if it is passed a null pai_other. int iOther = pai_other.getInt(i_idxOther); return (getInt(i_idxThis) == iOther); } catch(NullPointerException npx) { throwAX("areLmntsEqual: pai_other is null."); } catch(ArrayIndexOutOfBoundsException aioobx) { throwLmntsEqualAioobx(i_idxThis, "pai_other", pai_other, i_idxOther); } //Never reached. Required for compile. return false; } /**Get the PARInt for direct manipulation.
@return (PARInt)constructor. **/ public final PARInt getPARInt() { return (PARInt)getPrimitiveArrayRule(); } /**Is the [object wrapped to look like an array of ints] legal?
@param s_callingClsFnc The name of the class-dot-function for use in potential error messages only. This is the place where the error message should appear that it was generated from. For example:xbn.util.PrimitiveArrayInt.crashIfInvalid
.
@param s_varName The descriptive name of the int array, for potential error messages only.
@return true If all rules configured into the PARInt are followed by the [object wrapped to look like an array of ints].
What is the maximum value contained in the array?
@exception AssertException If isNull equals true. **/ public final int getMaximum() { int iLength = -1; try { iLength = getLength(); } catch(AssertException ax) { throwAX("getMaximum: isNull() equals true."); } int iMax = getInt(0); for(int i = 1; i < iLength; i++) { if(iMax < getInt(i)) { iMax = getInt(i); } } return iMax; } /**What is the minimum value contained in the array?
@exception AssertException If isNull equals true. **/ public final int getMinimum() { int iLength = -1; try { iLength = getLength(); } catch(AssertException ax) { throwAX("getMinimum: isNull() equals true."); } int iMin = getInt(0); for(int i = 1; i < iLength; i++) { if(iMin > getInt(i)) { iMin = getInt(i); } } return iMin; } }