/* 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.XBNObject; /**

Holds information regarding violations that are detected by PrimitiveArray.isValid. See PrimitiveArray.isValid.

Source code:  PAViolation.java

@version 0.9b @author Jeff Epstein, http://sourceforge.net/projects/xbnjava. **/ public class PAViolation extends XBNObject { private int iIdxFirst = -1; private int iIdxSecond = -1; private int iType = -1; private int iContainedAtIdx = -1; /**

Create a PAViolation.

VALID

**/ public PAViolation() { this(getType_VALID()); } /**

.

NULL or LENGTH

**/ public PAViolation(int i_type) { this(i_type, -1); } /**

.

LMNT_OOBOUNDS, SLMNT_NULL, SLMNT_LENGTH or LMNT_ILLEGAL

**/ public PAViolation(int i_type, int i_idxFirst) { this(i_type, i_idxFirst, -1, -1); } /**

.

DUPLICATE or LMNT_OOORDER

**/ public PAViolation(int i_type, int i_idxFirst, int i_idxSecond) { this(i_type, i_idxFirst, i_idxSecond, -1); } /**

.

If bFALSE_IN_PRODUCTION equals true, then as much as possible is checked, to ensure these parameters are valid. If false, then the parameters are assumed to be correct.

DUPLICATE (i_containedAtIdx must equal -1), LMNT_OOORDER (i_containedAtIdx must equal -1) or SLMNT_CONTAINED.

**/ public PAViolation(int i_type, int i_idxFirst, int i_idxSecond, int i_containedAtIdx) { final String sCNSTR_ITYPE = "constructor: i_type "; final String sCNSTR_ITYPEPRN = sCNSTR_ITYPE + "("; if(bFALSE_IN_PRODUCTION) { if(i_type == getType_SLMNT_CONTAINED()) { if(i_containedAtIdx < 0) { throwAX(sCNSTR_ITYPE + "equals getType_SLMNT_CONTAINED() (" + getType_SLMNT_CONTAINED() + "), so i_containedAtIdx (" + i_containedAtIdx + ") must be greater than -1."); } } else if(i_containedAtIdx != -1) { throwAX(sCNSTR_ITYPEPRN + i_type + ") does not equal getType_SLMNT_CONTAINED() (" + getType_SLMNT_CONTAINED() + "), so i_containedAtIdx (" + i_containedAtIdx + ") must equal -1."); } if((i_type == getType_ILMNT_OOBOUNDS() || i_type == getType_SLMNT_NULL() || i_type == getType_SLMNT_LENGTH() || i_type == getType_LMNT_ILLEGAL()) && i_idxSecond != -1) { throwAX(sCNSTR_ITYPEPRN + i_type + ") equals getType_ILMNT_OOBOUNDS() (" + getType_ILMNT_OOBOUNDS() + "), getType_SLMNT_NULL() (" + getType_SLMNT_NULL() + "), getType_SLMNT_LENGTH() (" + getType_SLMNT_LENGTH() + ") or getType_LMNT_ILLEGAL() (" + getType_LMNT_ILLEGAL() + "), so i_idxSecond (" + i_idxSecond + ") must equal -1."); } else if(i_idxSecond == -1) { throwAX(sCNSTR_ITYPEPRN + i_type + ") does not equal getType_ILMNT_OOBOUNDS() (" + getType_ILMNT_OOBOUNDS() + "), getType_SLMNT_NULL() (" + getType_SLMNT_NULL() + "), getType_SLMNT_LENGTH() (" + getType_SLMNT_LENGTH() + ") or getType_LMNT_ILLEGAL() (" + getType_LMNT_ILLEGAL() + "), so i_idxSecond (" + i_idxSecond + ") must be greater than -1."); } if((i_type == getType_VALID() || i_type == getType_NULL() || i_type == getType_LENGTH()) && iIdxFirst != -1) { throwAX(sCNSTR_ITYPEPRN + i_type + ") equals getType_VALID() (" + getType_VALID() + "), getType_NULL() (" + getType_NULL() + ") or getType_LENGTH() (" + getType_LENGTH() + "), so iIdxFirst (" + i_idxSecond + ") must equal -1."); } else if(i_idxFirst == -1) { throwAX(sCNSTR_ITYPEPRN + i_type + ") does not equals getType_VALID() (" + getType_VALID() + "), getType_NULL() (" + getType_NULL() + ") or getType_LENGTH() (" + getType_LENGTH() + "), so iIdxFirst (" + i_idxSecond + ") must be greater than -1."); } } iType = i_type; iIdxFirst = i_idxFirst; iIdxSecond = i_idxSecond; iContainedAtIdx = i_containedAtIdx; } /**

Declare that this PrimitiveArray and its contents are truly valid.

Right before your version of isValid returns true, be sure to also call this function. See isValid.

Be careful when calling this function directly. You can call this function manually, but if the [thing being wrapped to look like an array] is not valid, you will get unpredictable results when using PrimitiveArray (or any of its children). Moral: Don't call this function unless you know what you're doing.

**/ protected final void declareNoViolation() { iType = -1; iIdxFirst = -1; iIdxSecond = -1; iContainedAtIdx = -1; } public final boolean hasNoViolation() { return (getType() == getType_VALID()); } public final int getType() { return iType; } public final int getIdxFirst() { return iIdxFirst; } public final int getIdxSecond() { return iIdxSecond; } public int getContainedAtIdx() { return iContainedAtIdx; } public final static int getType_VALID() { return -1; } public final static int getType_NULL() { return 0; } public final static int getType_LENGTH() { return 1; } public final static int getType_LMNT_DUPLICATE() { return 2; } public final static int getType_LMNT_OOORDER() { return 3; } public final static int getType_LMNT_ILLEGAL() { return 4; } public final static int getType_SLMNT_CONTAINED() { return 5; } public final static int getType_SLMNT_NULL() { return 6; } public final static int getType_SLMNT_LENGTH() { return 7; } public final static int getType_ILMNT_OOBOUNDS() { return 8; } }