boolean bAXIfBad = (s_callingClsFnc != null || s_varName != null);
//To make the below code a bit more consice...END
if(!bNullOk) {
if(isNull()) {
setPAViolation(new PAViolation(PAViolation.getType_NULL()));
if(bAXIfBad) {
throwAXIllegal(s_callingClsFnc, s_varName, "isNull() equals true.");
}
return false;
}
} else if(isNull()) {
//A null array cannot be analyzed further.
declareNoViolation();
return true;
}
//The array is not null.
if(!rclArray.isValid(getLength())) {
setPAViolation(new PAViolation(PAViolation.getType_LENGTH()));
if(bAXIfBad) {
throwAXIllegal(s_callingClsFnc, s_varName, "the number of elements in the array (" + getLength() + ") is illegal according to getPARString().getPARDupNullLen().getRCLength().isValid().");
}
return false;
} else if(getLength() < 1) {
//The array is zero elements in length, and this is okay.
//An empty array can, but does not need to be analyzed further.
declareNoViolation();
return true;
}
//The string array has at least one element.
final String sLMNT = "element ";
final String sPRN_QT = " ('";
for(int i = 0; i < getLength(); i++) {
if(!bNullLmntOk && getString(i) == null) {
//A null element is bad.
setPAViolation(new PAViolation(PAViolation.getType_SLMNT_NULL(), i));
if(bAXIfBad) {
throwAXIllegal(s_callingClsFnc, s_varName, sLMNT + i + " is null.");
}
return false;
}
//If the element is null, this is okee dokee.
if(getString(i) != null && !rclLmnt.isValid(getString(i).length())) {
setPAViolation(new PAViolation(PAViolation.getType_SLMNT_LENGTH(), i));;
if(bAXIfBad) {
throwAXIllegal(s_callingClsFnc, s_varName, "the length of element " + i + sPRN_QT + getString(i) + "', length " + getString(i).length() + ") is illegal according to getPARString().getPARSElement().getRCLength().isValid().");
}
return false;
}
//Element i is either null-and-this-is-okay, or
//non-null-and-its-length-is-valid
if(getPARString().getPARSElement().hasIllegalStrings() &&
getPARString().getPARSElement().isIllegal(getString(i))) {
setPAViolation(new PAViolation(PAViolation.getType_LMNT_ILLEGAL(), i));
if(bAXIfBad) {
throwAXIllegal(s_callingClsFnc, s_varName, sLMNT + i + " is an illegal string. getPARString().getPARSElement().isIllegal('" + getString(i) + "') equals true.");
}
return false;
}
//Compare this element with every element after this one (i + 1)
for(int j = (i + 1); j < getLength(); j++) {
if(!bDupsOk) {
//Duplicates are not good.
if((getString(i) == null && getString(j) == null) ||
(getString(i) != null && getString(j) != null && getString(i).equals(getString(j)))) {
setPAViolation(new PAViolation(PAViolation.getType_LMNT_DUPLICATE(), i, j));
if(bAXIfBad) {
throwAXIllegal(s_callingClsFnc, s_varName, "elements " + i + " and " + j + " are equal: '" + getString(i) + "'.");
}
return false;
}
} //ELSE: It is okay for elements to equal one
// another.
if(!bContainmentOk) {
//It is not okay for one element to be contained
//in another. "Contained in" does not mean "equal to".
if(getString(i) != null && getString(j) != null &&
!getString(i).equals(getString(j))) {
//i and j are non-null, and unique. These two
//strings can be analyzed to see if they are
//contained in one another.
if(!bOrderedContainment ||
(bOrderedContainment && bContainOrderAscDesc)) {
//ASC: Low idxs can exist in high idxs, but not vice versa.
//DESC: High idxs can contain low idxs, but not vice versa.
if(getString(i).indexOf(getString(j)) != -1) {
setPAViolation(new PAViolation(PAViolation.getType_SLMNT_CONTAINED(), i, j, getString(i).indexOf(getString(j))));
if(bAXIfBad) {
throwAXIllegal(s_callingClsFnc, s_varName, sLMNT + i + sPRN_QT + getString(i) + "') contains (but is not equal to) element " + j + sPRN_QT + getString(j) + "') at array index " + getPAViolation().getContainedAtIdx() + ".");
}
return false;
}
}
if(!bOrderedContainment ||
(bOrderedContainment && !bContainOrderAscDesc)) {
//DESC: High idxs can exist in low idxs, but not vice versa.
//DESC: Low idxs can contain high idxs, but not vice versa.
if(getString(j).indexOf(getString(i)) != -1) {
setPAViolation(new PAViolation(PAViolation.getType_SLMNT_CONTAINED(), j, i, getString(j).indexOf(getString(i))));
if(bAXIfBad) {
throwAXIllegal(s_callingClsFnc, s_varName, sLMNT + i + sPRN_QT + getString(i) + "') is contained by (but is not equal to) element " + j + sPRN_QT + getString(j) + "') at array index " + getPAViolation().getContainedAtIdx() + ".");
}
return false;
}
}
} //ELSE: i and/or j is null, or both are non-
// null and equal to each other. Null
// strings cannot be contained in any
// other.
} //ELSE: It is okay for elements to contain (not
// equal) one another.
if(getPARString().getPAROrderDir().isOrdered()) {
//Ordering is required.
if(getPARString().getPAROrderDir().getDirectionAscDesc()) {
//Order direction is ascending
if(getString(i).compareTo(getString(j)) > 0) {
setPAViolation(new PAViolation(PAViolation.getType_LMNT_OOORDER(), i, j));
if(bAXIfBad) {
throwAXIllegal(s_callingClsFnc, s_varName, "elements " + i + " and " + j + " are both non-null, but " + i + " is greater than " + j + sPRN_QT + getString(i) + "'.compareTo('" + getString(j) + "') equals " + getString(i).compareTo(getString(j)) + ").");
}
return false;
}
//i is less than j. GOOD.
continue;
}
//Order direction is descending
if(getString(i).compareTo(getString(j)) < 0) {
setPAViolation(new PAViolation(PAViolation.getType_LMNT_OOORDER(), i, j));
if(bAXIfBad) {
throwAXIllegal(s_callingClsFnc, s_varName, "elements " + i + " and " + j + " are both non-null, but " + i + " is less than " + j + sPRN_QT + getString(i) + "'.compareTo('" + getString(j) + "') equals " + getString(i).compareTo(getString(j)) + ").");
}
return false;
}