User: norbert
Date: 00/05/22 11:43:38
Modified: src/java/org/spyderMQ/selectors Operator.java
Log:
Add functionnality for selectors ( <> == > NOT )
Revision Changes Path
1.6 +68 -11 spyderMQ/src/java/org/spyderMQ/selectors/Operator.java
Index: Operator.java
===================================================================
RCS file:
/products/cvs/ejboss/spyderMQ/src/java/org/spyderMQ/selectors/Operator.java,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -r1.5 -r1.6
--- Operator.java 2000/05/22 16:18:41 1.5
+++ Operator.java 2000/05/22 18:43:37 1.6
@@ -11,7 +11,7 @@
*
* @author Norbert Lataille ([EMAIL PROTECTED])
*
- * @version $Revision: 1.5 $
+ * @version $Revision: 1.6 $
*/
public class Operator
{
@@ -20,15 +20,15 @@
Object oper2;
Object oper3;
- public final static int EQUAL = 0; //Done for strings
- public final static int NOT = 1;
- public final static int AND = 2;//Done
- public final static int OR = 3;//Done
- public final static int GT = 4;
+ public final static int EQUAL = 0; //Done for string - integer
+ public final static int NOT = 1; //Done
+ public final static int AND = 2; //Done
+ public final static int OR = 3; //Done
+ public final static int GT = 4; //Done
public final static int GE = 5;
public final static int LT = 6;
public final static int LE = 7;
- public final static int DIFFERENT = 8;
+ public final static int DIFFERENT = 8; //Done for string - integer
public final static int ADD = 9;
public final static int SUB = 10;
public final static int NEG = 11;
@@ -69,6 +69,16 @@
this.oper3=null;
}
+ Object not() throws Exception
+ {
+ Object arg1=computeArgument(oper1);
+
+ if (arg1==null) return null;
+ if (!(arg1 instanceof Boolean)) throw new Exception("NOT: Bad object
type");
+ if (((Boolean)arg1).booleanValue()) return Boolean.FALSE;
+ else return Boolean.TRUE;
+ }
+
Object and() throws Exception
{
Object arg1=computeArgument(oper1);
@@ -119,17 +129,59 @@
{
Object arg1=computeArgument(oper1);
- if (arg1==null) return Boolean.FALSE;
+ if (arg1==null) return Boolean.FALSE;
+
if (arg1 instanceof String) {
Object arg2=computeArgument(oper2);
if (arg2==null) return Boolean.FALSE;
if (!(arg2 instanceof String)) throw new Exception("EQUAL: Bad
object type");
return new Boolean(arg1.equals(arg2));
+ } else if (arg1 instanceof Long) {
+ Object arg2=computeArgument(oper2);
+ if (arg2==null) return Boolean.FALSE;
+ if (!(arg2 instanceof Long)) throw new Exception("EQUAL: Bad
object type");
+ return new Boolean(arg1.equals(arg2));
}
throw new Exception("EQUAL: Bad object type");
}
+ Object gt() throws Exception
+ {
+ Object arg1=computeArgument(oper1);
+ if (arg1==null) return Boolean.FALSE;
+
+ if (arg1 instanceof Long) {
+ Object arg2=computeArgument(oper2);
+ if (arg2==null) return Boolean.FALSE;
+ if (!(arg2 instanceof Long)) throw new Exception("GT: Bad
object type");
+ return new Boolean(((Long)arg1).longValue() >
((Long)arg2).longValue());
+ }
+
+ throw new Exception("GT: Bad object type");
+ }
+
+ Object different() throws Exception
+ {
+ Object arg1=computeArgument(oper1);
+
+ if (arg1==null) return Boolean.FALSE;
+
+ if (arg1 instanceof String) {
+ Object arg2=computeArgument(oper2);
+ if (arg2==null) return Boolean.FALSE;
+ if (!(arg2 instanceof String)) throw new Exception("DIFFERENT:
Bad object type");
+ return new Boolean(!arg1.equals(arg2));
+ } else if (arg1 instanceof Long) {
+ Object arg2=computeArgument(oper2);
+ if (arg2==null) return Boolean.FALSE;
+ if (!(arg2 instanceof Long)) throw new Exception("DIFFERENT:
Bad object type");
+ return new Boolean(!arg1.equals(arg2));
+ }
+
+ throw new Exception("DIFFERENT: Bad object type");
+ }
+
Object computeArgument(Object arg) throws Exception
{
if (arg instanceof Identifier) {
@@ -143,9 +195,14 @@
{
switch (operation) {
- case EQUAL: return equal();
- case AND: return and();
- case OR: return or();
+
+ case EQUAL: return equal();
+ case DIFFERENT: return different();
+ case GT: return gt();
+ case NOT: return not();
+ case AND: return and();
+ case OR: return or();
+
}
throw new Exception("Unknown operation");