/* 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; import xbn.util.RCLength; /**

PrimitiveArrayRule configuration regarding duplicates, null-ness and element length.

Source code:  PARDupNullLen.java

@version 0.9b @author Jeff Epstein, http://sourceforge.net/projects/xbnjava. **/ public class PARDupNullLen extends XBNObject { private boolean bDupsOk = false; private boolean bNullOk = false; private RCLength rcl = null; /**

Create an unrestricted PARDupNullLen.

Equal to PARDupNullLen(true)

**/ public PARDupNullLen() { this(true); } /**

Create a PARDupNullLen.

Equal to PARDupNullLen(b_dupsOk, true)

**/ public PARDupNullLen(boolean b_dupsOk) { this(b_dupsOk, true); } /**

Create a PARDupNullLen.

Equal to PARDupNullLen(true, rc_length)

**/ public PARDupNullLen(RCLength rc_length) { this(true, rc_length); } /**

Create a PARDupNullLen.

Equal to PARDupNullLen(b_dupsOk, b_nullOk, (new RCLength()))

**/ public PARDupNullLen(boolean b_dupsOk, boolean b_nullOk) { this(b_dupsOk, b_nullOk, (new RCLength())); } /**

Create a PARDupNullLen.

Equal to PARDupNullLen(b_dupsOk, true, rc_length)

**/ public PARDupNullLen(boolean b_dupsOk, RCLength rc_length) { this(b_dupsOk, true, rc_length); } /**

Create a PARDupNullLen.

@param b_dupsOk If true, there may be duplicate values in the array. If false, all values must be unique. See areDupsOk. @param b_nullOk If true, PrimitiveArray.isNull may be true. If false, isNull may not be true. See isNullOk. @param rc_length The range that the array's length must conform to. See getRCLength. **/ public PARDupNullLen(boolean b_dupsOk, boolean b_nullOk, RCLength rc_length) { bDupsOk = b_dupsOk; bNullOk = b_nullOk; rcl = rc_length; } /**

Create a full (deep) copy of the provided PARDupNullLen.

@param par_dupNullLen The object to copy. May not be null. **/ public PARDupNullLen(PARDupNullLen par_dupNullLen) { try { bDupsOk = par_dupNullLen.bDupsOk; } catch(NullPointerException npx) { throwAX("constructor: par_dupNullLen is null."); } bNullOk = par_dupNullLen.bNullOk; rcl = new RCLength(par_dupNullLen.rcl); } /**

Is it okay for the array to have duplicate values?

@return b_dupsOk Exactly as provided to the constructor. **/ public final boolean areDupsOk() { return bDupsOk; } /**

Is it okay for the array to be null (as a whole)?

@return b_nullOk Exactly as provided to the constructor. **/ public final boolean isNullOk() { return bNullOk; } /**

Get the RCLength defining the legal range of lengths for the array.

@return rc_length Exactly as provided to the constructor. **/ public final RCLength getRCLength() { return rcl; } /**

Does this PARDupNullLen have any restrictions?

@return (!areDupsOk()  ||  !isNullOk()  ||  getRCLength().isRestricted()) **/ public boolean isRestricted() { return (!areDupsOk() || !isNullOk() || getRCLength().isRestricted()); } /**

Is this PARDupNullLen as restricted as possible?

@return (!areDupsOk()  ||  !isNullOk()  ||  (getRCLength().getMin() > 0)) **/ public boolean isStrict() { return (!areDupsOk() && !isNullOk() && (getRCLength().getMin() > 0)); } /**

Get some information about this PARDupNullLen.

**/ public String toString() { return this.getClass().getName() + ": areDupsOk()=" + areDupsOk() + ", isNullOk()=" + isNullOk() + ", getRCLength()=[" + getRCLength() + "]"; } }