User: norbert
Date: 00/05/30 16:17:01
Modified: src/java/org/spyderMQ/selectors Operator.java
Log:
Add new operators to the Selector object
Revision Changes Path
1.11 +88 -31 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.10
retrieving revision 1.11
diff -u -r1.10 -r1.11
--- Operator.java 2000/05/30 23:04:07 1.10
+++ Operator.java 2000/05/30 23:17:01 1.11
@@ -11,7 +11,7 @@
*
* @author Norbert Lataille ([EMAIL PROTECTED])
*
- * @version $Revision: 1.10 $
+ * @version $Revision: 1.11 $
*/
public class Operator
{
@@ -26,15 +26,15 @@
int class1;
int class2;
- 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; //Done for string - integer
+ public final static int EQUAL = 0; //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; //Integer
+ public final static int GE = 5; //Integer
+ public final static int LT = 6; //Integer
+ public final static int LE = 7; //Integer
+ public final static int DIFFERENT = 8; //String Integer
public final static int ADD = 9;
public final static int SUB = 10;
public final static int NEG = 11;
@@ -80,6 +80,31 @@
this.oper3=null;
}
+ //Operation 0
+ Object equal() throws Exception
+ {
+ computeArgument1();
+
+ if (arg1==null) return Boolean.FALSE;
+
+ switch (class1) {
+ case STRING:
+ computeArgument2();
+ if (arg2==null) return Boolean.FALSE;
+ if (class2!=STRING) throw new Exception("EQUAL: Bad
object type");
+ return new Boolean(arg1.equals(arg2));
+ case LONG:
+ computeArgument2();
+ if (arg2==null) return Boolean.FALSE;
+ if (class2!=LONG) throw new Exception("EQUAL: Bad
object type");
+ return new Boolean(arg1.equals(arg2));
+ default:
+ throw new Exception("EQUAL: Bad object type");
+ }
+
+ }
+
+ //Operation 1
Object not() throws Exception
{
computeArgument1();
@@ -90,6 +115,7 @@
else return Boolean.TRUE;
}
+ //Operation 2
Object and() throws Exception
{
computeArgument1();
@@ -113,6 +139,7 @@
throw new Exception("AND: Bad object type");
}
+ //Operation 3
Object or() throws Exception
{
computeArgument1();
@@ -136,30 +163,40 @@
throw new Exception("OR: Bad object type");
}
- Object equal() throws Exception
+ //Operation 4
+ Object gt() throws Exception
{
- computeArgument1();
+ computeArgument1();
+ if (arg1==null) return Boolean.FALSE;
+
+ if (class1==LONG) {
+ computeArgument2();
+ if (arg2==null) return Boolean.FALSE;
+ if (class2!=LONG) throw new Exception("GT: Bad object type");
+ return new Boolean(((Long)arg1).longValue() >
((Long)arg2).longValue());
+ }
+ throw new Exception("GT: Bad object type");
+ }
+
+ //Operation 5
+ Object ge() throws Exception
+ {
+ computeArgument1();
if (arg1==null) return Boolean.FALSE;
- switch (class1) {
- case STRING:
- computeArgument2();
- if (arg2==null) return Boolean.FALSE;
- if (class2!=STRING) throw new Exception("EQUAL: Bad
object type");
- return new Boolean(arg1.equals(arg2));
- case LONG:
- computeArgument2();
- if (arg2==null) return Boolean.FALSE;
- if (class2!=LONG) throw new Exception("EQUAL: Bad
object type");
- return new Boolean(arg1.equals(arg2));
- default:
- throw new Exception("EQUAL: Bad object type");
+ if (class1==LONG) {
+ computeArgument2();
+ if (arg2==null) return Boolean.FALSE;
+ if (class2!=LONG) throw new Exception("GE: Bad object type");
+ return new Boolean(((Long)arg1).longValue() >=
((Long)arg2).longValue());
}
+ throw new Exception("GE: Bad object type");
}
- Object gt() throws Exception
+ //Operation 6
+ Object lt() throws Exception
{
computeArgument1();
if (arg1==null) return Boolean.FALSE;
@@ -167,13 +204,30 @@
if (class1==LONG) {
computeArgument2();
if (arg2==null) return Boolean.FALSE;
- if (class2!=LONG) throw new Exception("GT: Bad object type");
- return new Boolean(((Long)arg1).longValue() >
((Long)arg2).longValue());
+ if (class2!=LONG) throw new Exception("LT: Bad object type");
+ return new Boolean(((Long)arg1).longValue() <
((Long)arg2).longValue());
}
- throw new Exception("GT: Bad object type");
+ throw new Exception("LT: Bad object type");
+ }
+
+ //Operation 7
+ Object le() throws Exception
+ {
+ computeArgument1();
+ if (arg1==null) return Boolean.FALSE;
+
+ if (class1==LONG) {
+ computeArgument2();
+ if (arg2==null) return Boolean.FALSE;
+ if (class2!=LONG) throw new Exception("LE: Bad object type");
+ return new Boolean(((Long)arg1).longValue() <=
((Long)arg2).longValue());
+ }
+
+ throw new Exception("LE: Bad object type");
}
+ //Operation 8
Object different() throws Exception
{
computeArgument1();
@@ -250,11 +304,14 @@
switch (operation) {
case EQUAL: return equal();
- case DIFFERENT: return different();
- case GT: return gt();
case NOT: return not();
case AND: return and();
case OR: return or();
+ case GT: return gt();
+ case GE: return ge();
+ case LT: return lt();
+ case LE: return le();
+ case DIFFERENT: return different();
}