/* 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 xbn.XBNObject; import xbn.array.primitive.PrimitiveArray; /**
Compare the values in two PrimitiveArrays. See PrimitiveArray.
Source code: CompareArrays.java
Create a CompareArrays with default settings.
Equal to CompareArrays(new CAConfig())
Create a CompareArrays.
@param ca_config Defines the rules used when comparing the two PrimitiveArrays. May not be null. See getCAConfig. **/ public CompareArrays(CAConfig ca_config) { throwAXIfNull(ca_config, "ca_config", sCNSTR); cac = ca_config; } /**Get the CAConfig for direct maniplation.
@return ca_config Exactly as provided to the constructor. **/ public CAConfig getCAConfig() { return cac; } /**Declare if it should be assumed (by hasRqdValues) that both the required and actual PrimitiveArrays are (individually) valid and ready for comparison. See hasRqdValues and PrimitiveArray.wasValidated.
Get with doAssumePAsValid.
hasRqdValues expects that both pa_rqd.wasValidated()
and pa_actual.wasValidated()
equal true and pa_rqd.getPrimitiveArrayRule().getPARDupNullLen().areDupsOk()
, pa_rqd.getPrimitiveArrayRule().getPARDupNullLen().isNullOk()
and pa_actual.getPrimitiveArrayRule().getPARDupNullLen().isNullOk()
all equal false.
If pa_actual and pa_rqd are both definitely valid--you knew this before you even created the PrimitiveArrays--then don't waste time validating them. Just call this function with "true", and the hasRqdValues function will just assume that the above requirements have been met, without checking. Understand you will get unpredictable results if you use this function but shouldn't.
This function first calls setAssumePARqdValid(b_assumePAsValid)
and then setAssumePAActlValid(b_assumePAsValid)
Should it be assumed (by hasRqdValues) that both the required and actual PrimitiveArrays are (individually) valid and ready for comparison?
Set with setAssumePAsValid.
(doAssumePARqdValid() && doAssumePAActlValid())
**/
public final boolean doAssumePAsValid() {
return (doAssumePARqdValid() && doAssumePAActlValid());
}
/**
Declare if it should be assumed (by hasRqdValues) that the required PrimitiveArray is (individually) valid and ready for comparison. See setAssumePAsValid for information.
Get with doAssumePARqdValid.
Should it be assumed (by hasRqdValues) that the required PrimitiveArray is (individually) valid and ready for comparison?
@return b_assumePARqdValid Exactly as provided to setAssumePARqdValid **/ public final boolean doAssumePARqdValid() { return bAssumePARqdValid; } /**Declare if it should be assumed (by hasRqdValues) that the actual PrimitiveArray is (individually) valid and ready for comparison. See setAssumePAsValid for information.
Get with doAssumePARqdValid.
Should it be assumed (by hasRqdValues) that the actual PrimitiveArray is (individually) valid and ready for comparison?
@return b_assumePAActlValid Exactly as provided to setAssumePAActlValid **/ public final boolean doAssumePAActlValid() { return bAssumePAActlValid; } /**Are the actual values legal, according to both the rules in CAConfig and the "required" values?
Equal to hasRqdValues(null, null, null, pa_rqd, pa_actual)
Are the actual values legal, according to both the rules in CAConfig and the "required" values?
@param s_callingClsFnc The fully-qualified 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.array.CompareArrays.hasRqdValues
. If any of s_callingClsFnc, s_rqdName, or s_actualName are non-null, when this function would normally return false, it will instead throw an AssertException, with a descriptive error message.
@param s_rqdName The descriptive name of pa_rqd, for potential error messages only.
@param s_actualName The descriptive name of pa_actual, for potential error messages only.
@param pa_rqd The required values. May not be null, nor a different type than pa_actual.
@param pa_actual The actual values to analyze and validate. May not be null, nor a different type than pa_rqd.
@return true pa_actual has required valuse, as determined by the rules in the CAConfig and pa_rqd.
If the actual values are illegal crash with an explanation. Otherwise do nothing.
Equal to crashIfBadValues("xbn.array.CompareArrays.crashIfBadValues", "pa_rqd" ,"pa_actual", pa_rqd, pa_actual)
If the actual values are illegal crash with an explanation. Otherwise do nothing.
Equal to hasRqdValues("xbn.array.CompareArrays.crashIfBadValues", "pa_rqd" ,"pa_actual", pa_rqd, pa_actual)
(supressing the return value)
Before calling hasRqdValues, all string parameters are analyzed to ensure they are non-null and at least one character in length.
**/ public void crashIfBadValues(String s_callingClsFnc, String s_rqdName, String s_actualName, PrimitiveArray pa_rqd, PrimitiveArray pa_actual) { throwAXIfBadStr(s_callingClsFnc, "s_callingClsFnc", "crashIfBadValues"); throwAXIfBadStr(s_rqdName, "s_rqdName", "crashIfBadValues"); throwAXIfBadStr(s_actualName, "s_actualName", "crashIfBadValues"); boolean bUNRTRND = hasRqdValues(s_callingClsFnc, s_rqdName, s_actualName, pa_rqd, pa_actual); } /**Used internally, by hasRqdValues. See the code for hasRqdValues.
**/ protected void throwAXBad(String s_callingClsFnc, String s_actualName, PrimitiveArray pa_rqd, PrimitiveArray pa_actual, String s_currently) { final String sQT = "'"; throwAX(s_callingClsFnc + ": '" + s_actualName + "' does not have required values, as required by [" + getCAConfig().toString() + "] where pa_rqd is [" + pa_rqd.getList(sQT, "', '", sQT) + "]. Values that *do* exist in pa_actual: [" + pa_actual.getList(sQT, "', '", sQT) + "]. Currently, " + s_currently); } }