froehlich 01/11/17 09:30:18
Added: apps/db/src/java/org/apache/avalon/db/basic/actions
TestHelper.java
Log:
new type definition
Revision Changes Path
1.1
jakarta-avalon-cornerstone/apps/db/src/java/org/apache/avalon/db/basic/actions/TestHelper.java
Index: TestHelper.java
===================================================================
/*
* Copyright (C) The Apache Software Foundation. All rights reserved.
*
* This software is published under the terms of the Apache Software License
* version 1.1, a copy of which has been included with this distribution in
* the LICENSE file.
*/
package org.apache.avalon.db.basic.actions;
import org.apache.avalon.db.actions.ActionException;
import org.apache.avalon.db.data.Column;
import org.apache.avalon.db.data.ValidationException;
import org.apache.avalon.db.data.Row;
import org.apache.avalon.db.data.impl.IntegerColumn;
import org.apache.avalon.db.data.types.StringType;
import org.apache.avalon.db.data.types.NumericType;
import org.apache.avalon.db.data.types.StringConstantType;
import org.apache.avalon.db.data.types.Type;
import org.apache.avalon.db.utils.ClassUtils;
/**
* Helper class for BSF
* @author Gerhard Froehlich <a href="mailto:[EMAIL PROTECTED]">[EMAIL
PROTECTED]</a>
* @version $Revision: 1.19 $
*/
public class TestHelper {
public boolean testEqual(Column lCol,Column rCol,Row row) throws
ActionException {
if(lCol instanceof NumericType && rCol instanceof NumericType
|| oneIsNumericType(lCol,rCol)) {
Type lNumCol = (Type)lCol;
Type rNumCol = (Type)rCol;
System.out.println("lNumCol.getPrecesion()=" +
lNumCol.getPrecesion());
System.out.println("rNumCol.getPrecesion()=" +
rNumCol.getPrecesion());
if(lNumCol.getPrecesion() == Type.PREC_INT
|| rNumCol.getPrecesion() == Type.PREC_INT) {
if(lNumCol.toInteger(row).compareTo(rNumCol.toInteger(row))
== 0) {
return true;
} else {
return false;
}
} else if(lNumCol.getPrecesion() == Type.PREC_BIGDEC
|| rNumCol.getPrecesion() == Type.PREC_BIGDEC) {
if(lNumCol.toBigDecimal(row).compareTo(rNumCol.toBigDecimal(row)) == 0) {
return true;
} else {
return false;
}
} else if(lNumCol.getPrecesion() == Type.PREC_FLOAT
|| rNumCol.getPrecesion() == Type.PREC_FLOAT) {
if(lNumCol.toFloat(row).compareTo(rNumCol.toFloat(row)) == 0)
{
return true;
} else {
return false;
}
} else if(lNumCol.getPrecesion() == Type.PREC_LONG
|| rNumCol.getPrecesion() == Type.PREC_LONG) {
if(lNumCol.toLong(row).compareTo(rNumCol.toLong(row)) == 0) {
return true;
} else {
return false;
}
} else if(lNumCol.getPrecesion() == Type.PREC_SHORT
|| rNumCol.getPrecesion() == Type.PREC_SHORT) {
if(lNumCol.toShort(row).compareTo(rNumCol.toShort(row)) == 0)
{
return true;
} else {
return false;
}
} else {
throw new ActionException("Type not supported, yet");
}
} else if(lCol instanceof StringType && rCol instanceof StringType
|| oneIsStringType(lCol,rCol)){
Type lNumCol = (Type)lCol;
Type rNumCol = (Type)rCol;
return lNumCol.toString(row).equals(rNumCol.toString(row));
} else {
throw new ActionException("Type not supported, yet");
}
}
public boolean SmallerThan(Column lCol,Column rCol,Row row) throws
ActionException {
if(lCol instanceof NumericType && rCol instanceof NumericType
|| oneIsNumericType(lCol,rCol)) {
Type lNumCol = (Type)lCol;
Type rNumCol = (Type)rCol;
if(lNumCol.getPrecesion() == Type.PREC_INT
|| rNumCol.getPrecesion() == Type.PREC_INT) {
if(lNumCol.toInteger(row).compareTo(rNumCol.toInteger(row)) <
0) {
return true;
} else {
return false;
}
} else if(lNumCol.getPrecesion() == Type.PREC_BIGDEC
|| rNumCol.getPrecesion() == Type.PREC_BIGDEC) {
if(lNumCol.toBigDecimal(row).compareTo(rNumCol.toBigDecimal(row)) < 0) {
return true;
} else {
return false;
}
} else if(lNumCol.getPrecesion() == Type.PREC_FLOAT
|| rNumCol.getPrecesion() == Type.PREC_FLOAT) {
if(lNumCol.toFloat(row).compareTo(rNumCol.toFloat(row)) < 0) {
return true;
} else {
return false;
}
} else if(lNumCol.getPrecesion() == Type.PREC_LONG
|| rNumCol.getPrecesion() == Type.PREC_LONG) {
if(lNumCol.toLong(row).compareTo(rNumCol.toLong(row)) < 0) {
return true;
} else {
return false;
}
} else if(lNumCol.getPrecesion() == Type.PREC_SHORT
|| rNumCol.getPrecesion() == Type.PREC_SHORT) {
if(lNumCol.toShort(row).compareTo(rNumCol.toShort(row)) < 0) {
return true;
} else {
return false;
}
} else {
throw new ActionException("Type not supported, yet");
}
} else if(lCol instanceof StringType && rCol instanceof StringType
|| oneIsStringType(lCol,rCol)){
Type lNumCol = (Type)lCol;
Type rNumCol = (Type)rCol;
if(lNumCol.toString(row).compareTo(rNumCol.toString(row)) < 0) {
return true;
} else {
return false;
}
} else {
throw new ActionException("Type not supported, yet");
}
}
public boolean testGreaterThan(Column lCol,Column rCol,Row row) throws
ActionException {
if(lCol instanceof NumericType && rCol instanceof NumericType
|| oneIsNumericType(lCol,rCol)) {
Type lNumCol = (Type)lCol;
Type rNumCol = (Type)rCol;
if(lNumCol.getPrecesion() == Type.PREC_INT
|| rNumCol.getPrecesion() == Type.PREC_INT) {
if(lNumCol.toInteger(row).compareTo(rNumCol.toInteger(row)) >
0) {
return true;
} else {
return false;
}
} else if(lNumCol.getPrecesion() == Type.PREC_BIGDEC
|| rNumCol.getPrecesion() == Type.PREC_BIGDEC) {
if(lNumCol.toBigDecimal(row).compareTo(rNumCol.toBigDecimal(row)) > 0) {
return true;
} else {
return false;
}
} else if(lNumCol.getPrecesion() == Type.PREC_FLOAT
|| rNumCol.getPrecesion() == Type.PREC_FLOAT) {
if(lNumCol.toFloat(row).compareTo(rNumCol.toFloat(row)) > 0) {
return true;
} else {
return false;
}
} else if(lNumCol.getPrecesion() == Type.PREC_LONG
|| rNumCol.getPrecesion() == Type.PREC_LONG) {
if(lNumCol.toLong(row).compareTo(rNumCol.toLong(row)) > 0) {
return true;
} else {
return false;
}
} else if(lNumCol.getPrecesion() == Type.PREC_SHORT
|| rNumCol.getPrecesion() == Type.PREC_SHORT) {
if(lNumCol.toShort(row).compareTo(rNumCol.toShort(row)) > 0) {
return true;
} else {
return false;
}
} else {
throw new ActionException("Type not supported, yet");
}
} else if(lCol instanceof StringType && rCol instanceof StringType
|| oneIsStringType(lCol,rCol)){
Type lNumCol = (Type)lCol;
Type rNumCol = (Type)rCol;
if(lNumCol.toString(row).compareTo(rNumCol.toString(row)) < 0) {
return true;
} else {
return false;
}
} else {
throw new ActionException("Type not supported, yet");
}
}
public boolean testNotEqual(Column lCol,Column rCol,Row row) throws
ActionException {
if(lCol instanceof NumericType && rCol instanceof NumericType
|| oneIsNumericType(lCol,rCol)) {
Type lNumCol = (Type)lCol;
Type rNumCol = (Type)rCol;
if(lNumCol.getPrecesion() == Type.PREC_INT
|| rNumCol.getPrecesion() == Type.PREC_INT) {
if(lNumCol.toInteger(row).compareTo(rNumCol.toInteger(row))
!= 0) {
return true;
} else {
return false;
}
} else if(lNumCol.getPrecesion() == Type.PREC_BIGDEC
|| rNumCol.getPrecesion() == Type.PREC_BIGDEC) {
if(lNumCol.toBigDecimal(row).compareTo(rNumCol.toBigDecimal(row)) != 0) {
return true;
} else {
return false;
}
} else if(lNumCol.getPrecesion() == Type.PREC_FLOAT
|| rNumCol.getPrecesion() == Type.PREC_FLOAT) {
if(lNumCol.toFloat(row).compareTo(rNumCol.toFloat(row)) != 0)
{
return true;
} else {
return false;
}
} else if(lNumCol.getPrecesion() == Type.PREC_LONG
|| rNumCol.getPrecesion() == Type.PREC_LONG) {
if(lNumCol.toLong(row).compareTo(rNumCol.toLong(row)) != 0) {
return true;
} else {
return false;
}
} else if(lNumCol.getPrecesion() == Type.PREC_SHORT
|| rNumCol.getPrecesion() == Type.PREC_SHORT) {
if(lNumCol.toShort(row).compareTo(rNumCol.toShort(row)) != 0)
{
return true;
} else {
return false;
}
} else {
throw new ActionException("Type not supported, yet");
}
} else if(lCol instanceof StringType && rCol instanceof StringType
|| oneIsStringType(lCol,rCol)){
Type lNumCol = (Type)lCol;
Type rNumCol = (Type)rCol;
return !lNumCol.toString(row).equals(rNumCol.toString(row));
} else {
throw new ActionException("Type not supported, yet");
}
}
public boolean testLike(String leftexpr,String rightexpr,Column col)
throws ActionException {
throw new ActionException("operation not supported ");
}
public boolean testGreaterThanOrEqual(Column lCol,Column rCol,Row row)
throws ActionException {
if(lCol instanceof NumericType && rCol instanceof NumericType
|| oneIsNumericType(lCol,rCol)) {
Type lNumCol = (Type)lCol;
Type rNumCol = (Type)rCol;
if(lNumCol.getPrecesion() == Type.PREC_INT
|| rNumCol.getPrecesion() == Type.PREC_INT) {
if(lNumCol.toInteger(row).compareTo(rNumCol.toInteger(row)) > 0
||
lNumCol.toInteger(row).compareTo(rNumCol.toInteger(row)) == 0) {
return true;
} else {
return false;
}
} else if(lNumCol.getPrecesion() == Type.PREC_BIGDEC
|| rNumCol.getPrecesion() == Type.PREC_BIGDEC) {
if(lNumCol.toBigDecimal(row).compareTo(rNumCol.toBigDecimal(row)) > 0
||
lNumCol.toBigDecimal(row).compareTo(rNumCol.toBigDecimal(row)) == 0) {
return true;
} else {
return false;
}
} else if(lNumCol.getPrecesion() == Type.PREC_FLOAT
|| rNumCol.getPrecesion() == Type.PREC_FLOAT) {
if(lNumCol.toFloat(row).compareTo(rNumCol.toFloat(row)) > 0
|| lNumCol.toFloat(row).compareTo(rNumCol.toFloat(row))
== 0) {
return true;
} else {
return false;
}
} else if(lNumCol.getPrecesion() == Type.PREC_LONG
|| rNumCol.getPrecesion() == Type.PREC_LONG) {
if(lNumCol.toLong(row).compareTo(rNumCol.toLong(row)) > 0
|| lNumCol.toLong(row).compareTo(rNumCol.toLong(row)) ==
0) {
return true;
} else {
return false;
}
} else if(lNumCol.getPrecesion() == Type.PREC_SHORT
|| rNumCol.getPrecesion() == Type.PREC_SHORT) {
if(lNumCol.toShort(row).compareTo(rNumCol.toShort(row)) > 0
|| lNumCol.toLong(row).compareTo(rNumCol.toLong(row)) ==
0) {
return true;
} else {
return false;
}
} else {
throw new ActionException("Type not supported, yet");
}
} else if(lCol instanceof StringType && rCol instanceof StringType
|| oneIsStringType(lCol,rCol)){
Type lNumCol = (Type)lCol;
Type rNumCol = (Type)rCol;
if(lNumCol.toString(row).compareTo(rNumCol.toString(row)) > 0
|| lNumCol.toString(row).compareTo(rNumCol.toString(row)) ==
0) {
return true;
} else {
return false;
}
} else {
throw new ActionException("Type not supported, yet");
}
}
public boolean testSmallerThanOrEqual(Column lCol,Column rCol,Row row)
throws ActionException {
if(lCol instanceof NumericType && rCol instanceof NumericType
|| oneIsNumericType(lCol,rCol)) {
Type lNumCol = (Type)lCol;
Type rNumCol = (Type)rCol;
if(lNumCol.getPrecesion() == Type.PREC_INT
|| rNumCol.getPrecesion() == Type.PREC_INT) {
if(lNumCol.toInteger(row).compareTo(rNumCol.toInteger(row)) < 0
||
lNumCol.toInteger(row).compareTo(rNumCol.toInteger(row)) == 0) {
return true;
} else {
return false;
}
} else if(lNumCol.getPrecesion() == Type.PREC_BIGDEC
|| rNumCol.getPrecesion() == Type.PREC_BIGDEC) {
if(lNumCol.toBigDecimal(row).compareTo(rNumCol.toBigDecimal(row)) < 0
||
lNumCol.toBigDecimal(row).compareTo(rNumCol.toBigDecimal(row)) == 0) {
return true;
} else {
return false;
}
} else if(lNumCol.getPrecesion() == Type.PREC_FLOAT
|| rNumCol.getPrecesion() == Type.PREC_FLOAT) {
if(lNumCol.toFloat(row).compareTo(rNumCol.toFloat(row)) < 0
|| lNumCol.toFloat(row).compareTo(rNumCol.toFloat(row))
== 0) {
return true;
} else {
return false;
}
} else if(lNumCol.getPrecesion() == Type.PREC_LONG
|| rNumCol.getPrecesion() == Type.PREC_LONG) {
if(lNumCol.toLong(row).compareTo(rNumCol.toLong(row)) < 0
|| lNumCol.toLong(row).compareTo(rNumCol.toLong(row)) ==
0) {
return true;
} else {
return false;
}
} else if(lNumCol.getPrecesion() == Type.PREC_SHORT
|| rNumCol.getPrecesion() == Type.PREC_SHORT) {
if(lNumCol.toShort(row).compareTo(rNumCol.toShort(row)) < 0
|| lNumCol.toLong(row).compareTo(rNumCol.toLong(row)) ==
0) {
return true;
} else {
return false;
}
} else {
throw new ActionException("Type not supported, yet");
}
} else if(lCol instanceof StringType && rCol instanceof StringType
|| oneIsStringType(lCol,rCol)){
Type lNumCol = (Type)lCol;
Type rNumCol = (Type)rCol;
if(lNumCol.toString(row).compareTo(rNumCol.toString(row)) < 0
|| lNumCol.toString(row).compareTo(rNumCol.toString(row)) ==
0) {
return true;
} else {
return false;
}
} else {
throw new ActionException("Type not supported, yet");
}
}
private boolean oneIsNumericType(Column lCol, Column rCol) {
if ((lCol instanceof NumericType && rCol instanceof
StringConstantType)
|| (lCol instanceof StringConstantType && rCol instanceof
NumericType)) {
return true;
} else {
return false;
}
}
private boolean oneIsStringType(Column lCol, Column rCol) {
if ((lCol instanceof StringType && rCol instanceof StringConstantType)
|| (lCol instanceof StringConstantType && rCol instanceof
StringType)) {
return true;
} else {
return false;
}
}
}
--
To unsubscribe, e-mail: <mailto:[EMAIL PROTECTED]>
For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>