* <p>
* @param source Type: BusinessKey
* @return int
*/
public int compare(BusinessKey source) {
BooleanNullable result = null;
DataValue srcItem = null;
int srcItemIndex = 0;
if (source == null || this.getValues() == null) {
return BusinessKey.CMP_NULL;
}
//
// Iterate through each DataValues item in the Values array and compare
// it against the corresponding element in source's Values array.
//
if (this.getValues() != null) {
for (DataValue item : this.getValues()) {
srcItemIndex = srcItemIndex+1;
if (item == null) {
return BusinessKey.CMP_NULL;
//
// If source runs out of items then we must be greater
//
}
else if (srcItemIndex > source.getValues().size()) {
return BusinessKey.CMP_LONGER;
}
else {
srcItem = source.getValues().get(srcItemIndex-1);
if (srcItem == null) {
return BusinessKey.CMP_NULL;
}
}
//
// Numeric things might not be of the same class but they can all compare
// against each other so check this case first
//
if (item instanceof NumericData && srcItem instanceof NumericData) {
result = ((NumericData)item).isEqual((NumericData)srcItem);
if (result.getIsNull()) {
return BusinessKey.CMP_NULL;
}
else if (!(result.getValue())) {
result = ((NumericData)item).isGreaterThan((NumericData)srcItem);
if ((result).getValue()) {
return BusinessKey.CMP_GT;
}
return BusinessKey.CMP_LT;
}
}
else {
//
// Everthing else can only compare if it is of the same data type.
// We and the data type with 0x7F to mask off the nullable bit.
//
int myType = item.dataType()&127;
int srcType = srcItem.dataType()&127;
if (myType != srcType) {
result = item.getTextValue().isEqual(srcItem.getTextValue());
if (result.getIsNull()) {
return BusinessKey.CMP_NULL;
}
else if (!(result.getValue())) {
return BusinessKey.CMP_NE;
}
}
else {
switch (myType) {
case Constants.DV_DT_TEXT: {
result = ((TextData)item).isEqual((TextData)srcItem);
if (result.getIsNull()) {
return BusinessKey.CMP_NULL;
}
else if (!(result.getValue())) {
result = ((TextData)item).isGreaterThan((TextData)srcItem);
if ((result).getValue()) {
return BusinessKey.CMP_GT;
}
return BusinessKey.CMP_LT;
}
break;
}
case Constants.DV_DT_DATETIME: {
result = ((DateTimeData)item).isEqual((DateTimeData)srcItem);
if (result.getIsNull()) {
return BusinessKey.CMP_NULL;
}
else if (!(result.getValue())) {
result = ((DateTimeData)item).isGreaterThan((DateTimeData)srcItem);
if ((result).getValue()) {
return BusinessKey.CMP_GT;
}
return BusinessKey.CMP_LT;
}
break;
}
case Constants.DV_DT_INTERVAL: {
result = ((IntervalData)item).isEqual((IntervalData)srcItem);
if (result.getIsNull()) {
return BusinessKey.CMP_NULL;
}
else if (!(result.getValue())) {
result = ((IntervalData)item).isGreaterThan((IntervalData)srcItem);
if ((result).getValue()) {
return BusinessKey.CMP_GT;
}
return BusinessKey.CMP_LT;
}
break;
}
case Constants.DV_DT_BOOLEAN: {
result = ((BooleanData)item).isEqual((BooleanData)srcItem);
if (result.getIsNull()) {
return BusinessKey.CMP_NULL;
}
else if (!(result.getValue())) {
return BusinessKey.CMP_NE;
}
break;
}
default: {
result = item.getTextValue().isEqual(srcItem.getTextValue());
if (result.getIsNull()) {
return BusinessKey.CMP_NULL;
}
else if (!(result.getValue())) {
return BusinessKey.CMP_NE;
}
break;
}