[jboss-svn-commits] JBL Code SVN: r17089 - in labs/jbossrules/branches/temporal_rete/drools-core/src: main/java/org/drools/base/evaluators and 16 other directories.
jboss-svn-commits at lists.jboss.org
jboss-svn-commits at lists.jboss.org
Fri Dec 7 09:10:28 EST 2007
Author: tirelli
Date: 2007-12-07 09:10:27 -0500 (Fri, 07 Dec 2007)
New Revision: 17089
Added:
labs/jbossrules/branches/temporal_rete/drools-core/src/main/java/org/drools/base/evaluators/AfterEvaluatorDefinition.java
labs/jbossrules/branches/temporal_rete/drools-core/src/main/java/org/drools/base/evaluators/ComparableEvaluatorsDefinition.java
labs/jbossrules/branches/temporal_rete/drools-core/src/main/java/org/drools/base/evaluators/EqualityEvaluatorsDefinition.java
labs/jbossrules/branches/temporal_rete/drools-core/src/main/java/org/drools/base/evaluators/EvaluatorDefinition.java
labs/jbossrules/branches/temporal_rete/drools-core/src/main/java/org/drools/base/evaluators/EvaluatorDefinitionRegistry.java
labs/jbossrules/branches/temporal_rete/drools-core/src/main/java/org/drools/base/evaluators/EvaluatorRegistry.java
labs/jbossrules/branches/temporal_rete/drools-core/src/main/java/org/drools/base/evaluators/MatchesEvaluatorsDefinition.java
labs/jbossrules/branches/temporal_rete/drools-core/src/main/java/org/drools/base/evaluators/SetEvaluatorsDefinition.java
labs/jbossrules/branches/temporal_rete/drools-core/src/main/java/org/drools/base/evaluators/SoundslikeEvaluatorsDefinition.java
labs/jbossrules/branches/temporal_rete/drools-core/src/main/java/org/drools/util/DateUtils.java
Removed:
labs/jbossrules/branches/temporal_rete/drools-core/src/main/java/org/drools/base/evaluators/ArrayFactory.java
labs/jbossrules/branches/temporal_rete/drools-core/src/main/java/org/drools/base/evaluators/BaseMemberOfEvaluator.java
labs/jbossrules/branches/temporal_rete/drools-core/src/main/java/org/drools/base/evaluators/BaseNotMemberOfEvaluator.java
labs/jbossrules/branches/temporal_rete/drools-core/src/main/java/org/drools/base/evaluators/BigDecimalFactory.java
labs/jbossrules/branches/temporal_rete/drools-core/src/main/java/org/drools/base/evaluators/BigIntegerFactory.java
labs/jbossrules/branches/temporal_rete/drools-core/src/main/java/org/drools/base/evaluators/BooleanFactory.java
labs/jbossrules/branches/temporal_rete/drools-core/src/main/java/org/drools/base/evaluators/ByteFactory.java
labs/jbossrules/branches/temporal_rete/drools-core/src/main/java/org/drools/base/evaluators/CharacterFactory.java
labs/jbossrules/branches/temporal_rete/drools-core/src/main/java/org/drools/base/evaluators/DateFactory.java
labs/jbossrules/branches/temporal_rete/drools-core/src/main/java/org/drools/base/evaluators/DoubleFactory.java
labs/jbossrules/branches/temporal_rete/drools-core/src/main/java/org/drools/base/evaluators/EvaluatorFactory.java
labs/jbossrules/branches/temporal_rete/drools-core/src/main/java/org/drools/base/evaluators/FactTemplateFactory.java
labs/jbossrules/branches/temporal_rete/drools-core/src/main/java/org/drools/base/evaluators/FloatFactory.java
labs/jbossrules/branches/temporal_rete/drools-core/src/main/java/org/drools/base/evaluators/IntegerFactory.java
labs/jbossrules/branches/temporal_rete/drools-core/src/main/java/org/drools/base/evaluators/LongFactory.java
labs/jbossrules/branches/temporal_rete/drools-core/src/main/java/org/drools/base/evaluators/ObjectFactory.java
labs/jbossrules/branches/temporal_rete/drools-core/src/main/java/org/drools/base/evaluators/ShortFactory.java
labs/jbossrules/branches/temporal_rete/drools-core/src/main/java/org/drools/base/evaluators/StringFactory.java
Modified:
labs/jbossrules/branches/temporal_rete/drools-core/src/main/java/org/drools/base/ValueType.java
labs/jbossrules/branches/temporal_rete/drools-core/src/main/java/org/drools/base/evaluators/Operator.java
labs/jbossrules/branches/temporal_rete/drools-core/src/main/java/org/drools/base/mvel/MVELCalendarCoercion.java
labs/jbossrules/branches/temporal_rete/drools-core/src/main/java/org/drools/base/mvel/MVELDateCoercion.java
labs/jbossrules/branches/temporal_rete/drools-core/src/main/java/org/drools/common/BetaConstraints.java
labs/jbossrules/branches/temporal_rete/drools-core/src/main/java/org/drools/common/DefaultBetaConstraints.java
labs/jbossrules/branches/temporal_rete/drools-core/src/main/java/org/drools/common/DoubleBetaConstraints.java
labs/jbossrules/branches/temporal_rete/drools-core/src/main/java/org/drools/common/EmptyBetaConstraints.java
labs/jbossrules/branches/temporal_rete/drools-core/src/main/java/org/drools/common/InstanceEqualsConstraint.java
labs/jbossrules/branches/temporal_rete/drools-core/src/main/java/org/drools/common/InstanceNotEqualsConstraint.java
labs/jbossrules/branches/temporal_rete/drools-core/src/main/java/org/drools/common/QuadroupleBetaConstraints.java
labs/jbossrules/branches/temporal_rete/drools-core/src/main/java/org/drools/common/SingleBetaConstraints.java
labs/jbossrules/branches/temporal_rete/drools-core/src/main/java/org/drools/common/TripleBetaConstraints.java
labs/jbossrules/branches/temporal_rete/drools-core/src/main/java/org/drools/common/TupleStartEqualsConstraint.java
labs/jbossrules/branches/temporal_rete/drools-core/src/main/java/org/drools/reteoo/AccumulateNode.java
labs/jbossrules/branches/temporal_rete/drools-core/src/main/java/org/drools/reteoo/AlphaNode.java
labs/jbossrules/branches/temporal_rete/drools-core/src/main/java/org/drools/reteoo/CollectNode.java
labs/jbossrules/branches/temporal_rete/drools-core/src/main/java/org/drools/reteoo/ExistsNode.java
labs/jbossrules/branches/temporal_rete/drools-core/src/main/java/org/drools/reteoo/FromNode.java
labs/jbossrules/branches/temporal_rete/drools-core/src/main/java/org/drools/reteoo/JoinNode.java
labs/jbossrules/branches/temporal_rete/drools-core/src/main/java/org/drools/reteoo/NotNode.java
labs/jbossrules/branches/temporal_rete/drools-core/src/main/java/org/drools/rule/AndCompositeRestriction.java
labs/jbossrules/branches/temporal_rete/drools-core/src/main/java/org/drools/rule/AndConstraint.java
labs/jbossrules/branches/temporal_rete/drools-core/src/main/java/org/drools/rule/LiteralConstraint.java
labs/jbossrules/branches/temporal_rete/drools-core/src/main/java/org/drools/rule/LiteralRestriction.java
labs/jbossrules/branches/temporal_rete/drools-core/src/main/java/org/drools/rule/MultiRestrictionFieldConstraint.java
labs/jbossrules/branches/temporal_rete/drools-core/src/main/java/org/drools/rule/OrCompositeRestriction.java
labs/jbossrules/branches/temporal_rete/drools-core/src/main/java/org/drools/rule/OrConstraint.java
labs/jbossrules/branches/temporal_rete/drools-core/src/main/java/org/drools/rule/PredicateConstraint.java
labs/jbossrules/branches/temporal_rete/drools-core/src/main/java/org/drools/rule/ReturnValueConstraint.java
labs/jbossrules/branches/temporal_rete/drools-core/src/main/java/org/drools/rule/ReturnValueRestriction.java
labs/jbossrules/branches/temporal_rete/drools-core/src/main/java/org/drools/rule/VariableConstraint.java
labs/jbossrules/branches/temporal_rete/drools-core/src/main/java/org/drools/rule/VariableRestriction.java
labs/jbossrules/branches/temporal_rete/drools-core/src/main/java/org/drools/spi/AlphaNodeFieldConstraint.java
labs/jbossrules/branches/temporal_rete/drools-core/src/main/java/org/drools/spi/BetaNodeFieldConstraint.java
labs/jbossrules/branches/temporal_rete/drools-core/src/main/java/org/drools/spi/Evaluator.java
labs/jbossrules/branches/temporal_rete/drools-core/src/main/java/org/drools/spi/Restriction.java
labs/jbossrules/branches/temporal_rete/drools-core/src/main/java/org/drools/temporal/SessionPseudoClock.java
labs/jbossrules/branches/temporal_rete/drools-core/src/test/java/org/drools/base/EvaluatorFactoryTest.java
labs/jbossrules/branches/temporal_rete/drools-core/src/test/java/org/drools/base/mvel/MVELCalendarCoercionTest.java
labs/jbossrules/branches/temporal_rete/drools-core/src/test/java/org/drools/base/mvel/MVELDateCoercionTest.java
labs/jbossrules/branches/temporal_rete/drools-core/src/test/java/org/drools/common/BaseBetaConstraintsTest.java
labs/jbossrules/branches/temporal_rete/drools-core/src/test/java/org/drools/common/TripleBetaConstraintsTest.java
labs/jbossrules/branches/temporal_rete/drools-core/src/test/java/org/drools/event/AgendaEventSupportTest.java
labs/jbossrules/branches/temporal_rete/drools-core/src/test/java/org/drools/event/RuleBaseEventListenerTest.java
labs/jbossrules/branches/temporal_rete/drools-core/src/test/java/org/drools/examples/manners/BaseMannersTest.java
labs/jbossrules/branches/temporal_rete/drools-core/src/test/java/org/drools/reteoo/AlphaNodeTest.java
labs/jbossrules/branches/temporal_rete/drools-core/src/test/java/org/drools/reteoo/CompositeObjectSinkAdapterTest.java
labs/jbossrules/branches/temporal_rete/drools-core/src/test/java/org/drools/reteoo/FromNodeTest.java
labs/jbossrules/branches/temporal_rete/drools-core/src/test/java/org/drools/reteoo/QueryTerminalNodeTest.java
labs/jbossrules/branches/temporal_rete/drools-core/src/test/java/org/drools/rule/FieldConstraintTest.java
labs/jbossrules/branches/temporal_rete/drools-core/src/test/java/org/drools/spi/MockConstraint.java
labs/jbossrules/branches/temporal_rete/drools-core/src/test/java/org/drools/util/FieldIndexEntryTest.java
labs/jbossrules/branches/temporal_rete/drools-core/src/test/java/org/drools/util/FieldIndexHashTableTest.java
Log:
JBRULES-1356: adding support to pluggable evaluators in core
Modified: labs/jbossrules/branches/temporal_rete/drools-core/src/main/java/org/drools/base/ValueType.java
===================================================================
--- labs/jbossrules/branches/temporal_rete/drools-core/src/main/java/org/drools/base/ValueType.java 2007-12-07 13:39:06 UTC (rev 17088)
+++ labs/jbossrules/branches/temporal_rete/drools-core/src/main/java/org/drools/base/ValueType.java 2007-12-07 14:10:27 UTC (rev 17089)
@@ -6,144 +6,100 @@
import java.util.Date;
import org.drools.RuntimeDroolsException;
-import org.drools.base.evaluators.ArrayFactory;
-import org.drools.base.evaluators.BigDecimalFactory;
-import org.drools.base.evaluators.BigIntegerFactory;
-import org.drools.base.evaluators.BooleanFactory;
-import org.drools.base.evaluators.ByteFactory;
-import org.drools.base.evaluators.CharacterFactory;
-import org.drools.base.evaluators.DateFactory;
-import org.drools.base.evaluators.DoubleFactory;
-import org.drools.base.evaluators.EvaluatorFactory;
-import org.drools.base.evaluators.FloatFactory;
-import org.drools.base.evaluators.IntegerFactory;
-import org.drools.base.evaluators.LongFactory;
-import org.drools.base.evaluators.ObjectFactory;
-import org.drools.base.evaluators.Operator;
-import org.drools.base.evaluators.ShortFactory;
-import org.drools.base.evaluators.StringFactory;
import org.drools.facttemplates.FactTemplate;
-import org.drools.spi.Evaluator;
public class ValueType
implements
Serializable {
- private static final long serialVersionUID = 400L;
+ private static final long serialVersionUID = 400L;
public static final ValueType NULL_TYPE = new ValueType( "null",
null,
- SimpleValueType.NULL,
- null );
+ SimpleValueType.NULL);
// wrapper types
public static final ValueType CHAR_TYPE = new ValueType( "Character",
Character.class,
- SimpleValueType.CHAR,
- CharacterFactory.getInstance() );
+ SimpleValueType.CHAR );
public static final ValueType BYTE_TYPE = new ValueType( "Byte",
Byte.class,
- SimpleValueType.INTEGER,
- ByteFactory.getInstance() );
+ SimpleValueType.INTEGER);
public static final ValueType SHORT_TYPE = new ValueType( "Short",
Short.class,
- SimpleValueType.INTEGER,
- ShortFactory.getInstance() );
+ SimpleValueType.INTEGER );
public static final ValueType INTEGER_TYPE = new ValueType( "Integer",
Integer.class,
- SimpleValueType.INTEGER,
- IntegerFactory.getInstance() );
+ SimpleValueType.INTEGER );
public static final ValueType LONG_TYPE = new ValueType( "Long",
Long.class,
- SimpleValueType.INTEGER,
- LongFactory.getInstance() );
+ SimpleValueType.INTEGER );
public static final ValueType FLOAT_TYPE = new ValueType( "Float",
Float.class,
- SimpleValueType.DECIMAL,
- FloatFactory.getInstance() );
+ SimpleValueType.DECIMAL );
public static final ValueType DOUBLE_TYPE = new ValueType( "Double",
Double.class,
- SimpleValueType.DECIMAL,
- DoubleFactory.getInstance() );
+ SimpleValueType.DECIMAL );
public static final ValueType BOOLEAN_TYPE = new ValueType( "Boolean",
Boolean.class,
- SimpleValueType.BOOLEAN,
- BooleanFactory.getInstance() );
+ SimpleValueType.BOOLEAN );
// primitive types
public static final ValueType PCHAR_TYPE = new ValueType( "char",
Character.TYPE,
- SimpleValueType.CHAR,
- CharacterFactory.getInstance() );
+ SimpleValueType.CHAR );
public static final ValueType PBYTE_TYPE = new ValueType( "byte",
Byte.TYPE,
- SimpleValueType.INTEGER,
- ByteFactory.getInstance() );
+ SimpleValueType.INTEGER );
public static final ValueType PSHORT_TYPE = new ValueType( "short",
Short.TYPE,
- SimpleValueType.INTEGER,
- ShortFactory.getInstance() );
+ SimpleValueType.INTEGER );
public static final ValueType PINTEGER_TYPE = new ValueType( "int",
Integer.TYPE,
- SimpleValueType.INTEGER,
- IntegerFactory.getInstance() );
+ SimpleValueType.INTEGER );
public static final ValueType PLONG_TYPE = new ValueType( "long",
Long.TYPE,
- SimpleValueType.INTEGER,
- LongFactory.getInstance() );
+ SimpleValueType.INTEGER );
public static final ValueType PFLOAT_TYPE = new ValueType( "float",
Float.TYPE,
- SimpleValueType.DECIMAL,
- FloatFactory.getInstance() );
+ SimpleValueType.DECIMAL );
public static final ValueType PDOUBLE_TYPE = new ValueType( "double",
Double.TYPE,
- SimpleValueType.DECIMAL,
- DoubleFactory.getInstance() );
+ SimpleValueType.DECIMAL );
public static final ValueType PBOOLEAN_TYPE = new ValueType( "boolean",
Boolean.TYPE,
- SimpleValueType.BOOLEAN,
- BooleanFactory.getInstance() );
+ SimpleValueType.BOOLEAN );
// other types
public static final ValueType DATE_TYPE = new ValueType( "Date",
Date.class,
- SimpleValueType.DATE,
- DateFactory.getInstance() );
+ SimpleValueType.DATE );
public static final ValueType ARRAY_TYPE = new ValueType( "Array",
Object[].class,
- SimpleValueType.LIST,
- ArrayFactory.getInstance() );
+ SimpleValueType.LIST );
public static final ValueType STRING_TYPE = new ValueType( "String",
String.class,
- SimpleValueType.STRING,
- StringFactory.getInstance() );
+ SimpleValueType.STRING );
public static final ValueType OBJECT_TYPE = new ValueType( "Object",
Object.class,
- SimpleValueType.OBJECT,
- ObjectFactory.getInstance() );
+ SimpleValueType.OBJECT );
public static final ValueType FACTTEMPLATE_TYPE = new ValueType( "FactTemplate",
FactTemplate.class,
- SimpleValueType.UNKNOWN,
- ObjectFactory.getInstance() );
+ SimpleValueType.UNKNOWN );
public static final ValueType BIG_DECIMAL_TYPE = new ValueType( "BigDecimal",
BigDecimal.class,
- SimpleValueType.OBJECT,
- BigDecimalFactory.getInstance() );
+ SimpleValueType.OBJECT );
public static final ValueType BIG_INTEGER_TYPE = new ValueType( "BigInteger",
BigInteger.class,
- SimpleValueType.OBJECT,
- BigIntegerFactory.getInstance() );
+ SimpleValueType.OBJECT );
private final String name;
private final Class classType;
- private final EvaluatorFactory evaluatorFactory;
private final int simpleType;
private ValueType(final String name,
final Class classType,
- final int simpleType,
- final EvaluatorFactory evaluatorFactory) {
+ final int simpleType) {
this.name = name;
this.classType = classType;
this.simpleType = simpleType;
- this.evaluatorFactory = evaluatorFactory;
}
private Object readResolve() throws java.io.ObjectStreamException {
@@ -162,10 +118,6 @@
return this.simpleType;
}
- public Evaluator getEvaluator(final Operator operator) {
- return this.evaluatorFactory.getEvaluator( operator );
- }
-
public static ValueType determineValueType(final Class clazz) {
if ( clazz == null ) {
return ValueType.NULL_TYPE;
@@ -244,42 +196,18 @@
public boolean isNumber() {
return (this.simpleType == SimpleValueType.INTEGER || this.simpleType == SimpleValueType.DECIMAL || this.simpleType == SimpleValueType.CHAR);
- // return (this.classType == Integer.TYPE) ||
- // (this.classType == Long.TYPE) ||
- // (this.classType == Float.TYPE) ||
- // (this.classType == Double.TYPE) ||
- // (this.classType == Byte.TYPE) ||
- // (this.classType == Short.TYPE) ||
- // (this.classType == Character.TYPE) ||
- // (this.classType == Character.class) ||
- // (Number.class.isAssignableFrom( this.classType ));
}
public boolean isIntegerNumber() {
return this.simpleType == SimpleValueType.INTEGER;
- // return (this.classType == Integer.TYPE) ||
- // (this.classType == Long.TYPE) ||
- // (this.classType == Integer.class) ||
- // (this.classType == Long.class) ||
- // (this.classType == Character.class) ||
- // (this.classType == Character.TYPE) ||
- // (this.classType == Byte.TYPE) ||
- // (this.classType == Short.TYPE) ||
- // (this.classType == Byte.class) ||
- // (this.classType == Short.class);
}
public boolean isFloatNumber() {
return this.simpleType == SimpleValueType.DECIMAL;
- // return (this.classType == Float.TYPE) ||
- // (this.classType == Double.TYPE) ||
- // (this.classType == Float.class) ||
- // (this.classType == Double.class);
}
public boolean isChar() {
return this.simpleType == SimpleValueType.CHAR;
- // return ((this.classType == Character.class) || (this.classType == Character.TYPE));
}
}
Added: labs/jbossrules/branches/temporal_rete/drools-core/src/main/java/org/drools/base/evaluators/AfterEvaluatorDefinition.java
===================================================================
--- labs/jbossrules/branches/temporal_rete/drools-core/src/main/java/org/drools/base/evaluators/AfterEvaluatorDefinition.java (rev 0)
+++ labs/jbossrules/branches/temporal_rete/drools-core/src/main/java/org/drools/base/evaluators/AfterEvaluatorDefinition.java 2007-12-07 14:10:27 UTC (rev 17089)
@@ -0,0 +1,252 @@
+/*
+ * Copyright 2007 JBoss Inc
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ * Created on Dec 6, 2007
+ */
+package org.drools.base.evaluators;
+
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.Map;
+
+import org.drools.RuntimeDroolsException;
+import org.drools.base.BaseEvaluator;
+import org.drools.base.ValueType;
+import org.drools.common.InternalWorkingMemory;
+import org.drools.rule.VariableRestriction.LongVariableContextEntry;
+import org.drools.rule.VariableRestriction.VariableContextEntry;
+import org.drools.spi.Evaluator;
+import org.drools.spi.Extractor;
+import org.drools.spi.FieldValue;
+
+/**
+ * The implementation of the 'after' evaluator definition
+ *
+ * @author etirelli
+ */
+public class AfterEvaluatorDefinition
+ implements
+ EvaluatorDefinition {
+
+ private static final String[] SUPPORTED_ID = {"after"};
+
+ private Map<String, AfterEvaluator> cache = Collections.emptyMap();
+
+ /**
+ * @inheridDoc
+ */
+ public Evaluator getEvaluator(ValueType type,
+ Operator operator) {
+ return this.getEvaluator( type,
+ operator.getOperatorString(),
+ operator.isNegated(),
+ null );
+ }
+
+ /**
+ * @inheridDoc
+ */
+ public Evaluator getEvaluator(ValueType type,
+ Operator operator,
+ String parameterText) {
+ return this.getEvaluator( type,
+ operator.getOperatorString(),
+ operator.isNegated(),
+ parameterText );
+ }
+
+ /**
+ * @inheritDoc
+ */
+ public Evaluator getEvaluator(final ValueType type,
+ final String operatorId,
+ final boolean isNegated,
+ final String parameterText) {
+ if ( this.cache == Collections.EMPTY_MAP ) {
+ this.cache = new HashMap<String, AfterEvaluator>();
+ }
+ String key = isNegated + ":" + parameterText;
+ AfterEvaluator eval = this.cache.get( key );
+ if ( eval == null ) {
+ eval = new AfterEvaluator( type,
+ isNegated,
+ parameterText );
+ this.cache.put( key,
+ eval );
+ }
+ return eval;
+ }
+
+ /**
+ * @inheritDoc
+ */
+ public String[] getEvaluatorIds() {
+ return SUPPORTED_ID;
+ }
+
+ /**
+ * @inheritDoc
+ */
+ public boolean isNegatable() {
+ return true;
+ }
+
+ /**
+ * @inheritDoc
+ */
+ public boolean operatesOnFactHandles() {
+ return true;
+ }
+
+ /**
+ * @inheritDoc
+ */
+ public boolean supportsType(ValueType type) {
+ // supports all types, since it operates over fact handles
+ // Note: should we change this interface to allow checking of event classes only?
+ return true;
+ }
+
+ /**
+ * Implements the 'after' evaluator itself
+ */
+ public static class AfterEvaluator extends BaseEvaluator {
+ private static final long serialVersionUID = -4833205637340977934L;
+
+ private static final Operator POSITIVE = Operator.addOperatorToRegistry( "after",
+ false );
+ private static final Operator NEGATIVE = Operator.addOperatorToRegistry( "after",
+ true );
+
+ private long initRange;
+ private long finalRange;
+
+ public AfterEvaluator(final ValueType type,
+ final boolean isNegated,
+ final String parameters) {
+ super( type,
+ isNegated ? NEGATIVE : POSITIVE );
+ this.parseParameters( parameters );
+ }
+
+ /**
+ * This methods tries to parse the string of parameters to customize
+ * the evaluator.
+ *
+ * @param parameters
+ */
+ private void parseParameters(String parameters) {
+ if ( parameters == null || parameters.trim().length() == 0 ) {
+ // open bounded range
+ this.initRange = 1;
+ this.finalRange = Long.MAX_VALUE;
+ return;
+ }
+
+ try {
+ String[] ranges = parameters.split( "," );
+ if ( ranges.length == 1 ) {
+ // deterministic point in time
+ this.initRange = Long.parseLong( ranges[0] );
+ this.finalRange = this.initRange;
+ } else if ( ranges.length == 2 ) {
+ // regular range
+ this.initRange = Long.parseLong( ranges[0] );
+ this.finalRange = Long.parseLong( ranges[1] );
+ } else {
+ throw new RuntimeDroolsException( "[After Evaluator]: Not possible to parse parameters: '" + parameters + "'" );
+ }
+ } catch ( NumberFormatException e ) {
+ throw new RuntimeDroolsException( "[After Evaluator]: Not possible to parse parameters: '" + parameters + "'",
+ e );
+ }
+ }
+
+ public boolean evaluate(InternalWorkingMemory workingMemory,
+ final Extractor extractor,
+ final Object object1,
+ final FieldValue object2) {
+ throw new RuntimeDroolsException( "The 'after' operator can only be used to compare one event to another, and never to compare to literal constraints." );
+ }
+
+ public boolean evaluateCachedRight(InternalWorkingMemory workingMemory,
+ final VariableContextEntry context,
+ final Object left) {
+ if ( context.rightNull ) {
+ return false;
+ }
+ long dist = ((LongVariableContextEntry) context).right - context.declaration.getExtractor().getLongValue( workingMemory,
+ left );
+ return dist >= this.initRange && dist <= this.finalRange;
+ }
+
+ public boolean evaluateCachedLeft(InternalWorkingMemory workingMemory,
+ final VariableContextEntry context,
+ final Object right) {
+ if ( context.extractor.isNullValue( workingMemory,
+ right ) ) {
+ return false;
+ }
+ long dist = context.extractor.getLongValue( workingMemory,
+ right ) - ((LongVariableContextEntry) context).left;
+
+ return dist >= this.initRange && dist <= this.finalRange;
+ }
+
+ public boolean evaluate(InternalWorkingMemory workingMemory,
+ final Extractor extractor1,
+ final Object object1,
+ final Extractor extractor2,
+ final Object object2) {
+ if ( extractor1.isNullValue( workingMemory,
+ object1 ) ) {
+ return false;
+ }
+ long dist = extractor1.getLongValue( workingMemory,
+ object1 ) - extractor2.getLongValue( workingMemory,
+ object2 );
+ return dist >= this.initRange && dist <= this.finalRange;
+ }
+
+ public String toString() {
+ return "after[" + initRange + ", " + finalRange + "]";
+ }
+
+ /* (non-Javadoc)
+ * @see java.lang.Object#hashCode()
+ */
+ @Override
+ public int hashCode() {
+ final int PRIME = 31;
+ int result = super.hashCode();
+ result = PRIME * result + (int) (finalRange ^ (finalRange >>> 32));
+ result = PRIME * result + (int) (initRange ^ (initRange >>> 32));
+ return result;
+ }
+
+ /* (non-Javadoc)
+ * @see java.lang.Object#equals(java.lang.Object)
+ */
+ @Override
+ public boolean equals(Object obj) {
+ if ( this == obj ) return true;
+ if ( !super.equals( obj ) ) return false;
+ if ( getClass() != obj.getClass() ) return false;
+ final AfterEvaluator other = (AfterEvaluator) obj;
+ return finalRange == other.finalRange && initRange == other.initRange;
+ }
+ }
+
+}
Deleted: labs/jbossrules/branches/temporal_rete/drools-core/src/main/java/org/drools/base/evaluators/ArrayFactory.java
===================================================================
--- labs/jbossrules/branches/temporal_rete/drools-core/src/main/java/org/drools/base/evaluators/ArrayFactory.java 2007-12-07 13:39:06 UTC (rev 17088)
+++ labs/jbossrules/branches/temporal_rete/drools-core/src/main/java/org/drools/base/evaluators/ArrayFactory.java 2007-12-07 14:10:27 UTC (rev 17089)
@@ -1,471 +0,0 @@
-package org.drools.base.evaluators;
-
-/*
- * Copyright 2005 JBoss Inc
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-import org.drools.base.BaseEvaluator;
-import org.drools.base.ValueType;
-import org.drools.common.InternalWorkingMemory;
-import org.drools.rule.VariableRestriction.ObjectVariableContextEntry;
-import org.drools.rule.VariableRestriction.VariableContextEntry;
-import org.drools.spi.Evaluator;
-import org.drools.spi.Extractor;
-import org.drools.spi.FieldValue;
-import org.drools.util.ShadowProxyUtils;
-
-/**
- * For handling simple (non collection) array types.
- * @author Michael Neale
- */
-public class ArrayFactory
- implements
- EvaluatorFactory {
-
- private static final long serialVersionUID = 400L;
- private static EvaluatorFactory INSTANCE = new ArrayFactory();
-
- private ArrayFactory() {
-
- }
-
- public static EvaluatorFactory getInstance() {
- if ( ArrayFactory.INSTANCE == null ) {
- ArrayFactory.INSTANCE = new ArrayFactory();
- }
- return ArrayFactory.INSTANCE;
- }
-
- public Evaluator getEvaluator(final Operator operator) {
- if ( operator == Operator.EQUAL ) {
- return ArrayEqualEvaluator.INSTANCE;
- } else if ( operator == Operator.NOT_EQUAL ) {
- return ArrayNotEqualEvaluator.INSTANCE;
- } else if ( operator == Operator.CONTAINS ) {
- return ArrayContainsEvaluator.INSTANCE;
- } else if ( operator == Operator.EXCLUDES ) {
- return ArrayExcludesEvaluator.INSTANCE;
- } else if ( operator == Operator.NOT_CONTAINS ) {
- return ArrayExcludesEvaluator.INSTANCE; // 'not contains' and 'excludes' are synonyms
- } else if ( operator == Operator.MEMBEROF ) {
- return ArrayMemberOfEvaluator.INSTANCE;
- } else if ( operator == Operator.NOTMEMBEROF ) {
- return ArrayNotMemberOfEvaluator.INSTANCE;
- } else {
- throw new RuntimeException( "Operator '" + operator + "' does not exist for ArrayEvaluator" );
- }
- }
-
- static class ArrayEqualEvaluator extends BaseEvaluator {
- /**
- *
- */
- private static final long serialVersionUID = 400L;
- public final static Evaluator INSTANCE = new ArrayEqualEvaluator();
-
- private ArrayEqualEvaluator() {
- super( ValueType.ARRAY_TYPE,
- Operator.EQUAL );
- }
-
- public boolean evaluate(InternalWorkingMemory workingMemory,
- final Extractor extractor,
- final Object object1,
- final FieldValue object2) {
- final Object value1 = extractor.getValue( workingMemory,
- object1 );
- final Object value2 = object2.getValue();
- if ( value1 == null ) {
- return value2 == null;
- }
- return value1.equals( value2 );
- }
-
- public boolean evaluateCachedRight(InternalWorkingMemory workingMemory,
- final VariableContextEntry context,
- final Object left) {
- final Object value = context.declaration.getExtractor().getValue( workingMemory,
- left );
- if ( value == null ) {
- return ((ObjectVariableContextEntry) context).right == null;
- }
- return value.equals( ((ObjectVariableContextEntry) context).right );
- }
-
- public boolean evaluateCachedLeft(InternalWorkingMemory workingMemory,
- final VariableContextEntry context,
- final Object right) {
- final Object value = context.extractor.getValue( workingMemory,
- right );
- if ( ((ObjectVariableContextEntry) context).left == null ) {
- return value == null;
- }
- return ((ObjectVariableContextEntry) context).left.equals( value );
- }
-
- public boolean evaluate(InternalWorkingMemory workingMemory,
- final Extractor extractor1,
- final Object object1,
- final Extractor extractor2,
- final Object object2) {
- final Object value1 = extractor1.getValue( workingMemory,
- object1 );
- final Object value2 = extractor2.getValue( workingMemory,
- object2 );
- if ( value1 == null ) {
- return value2 == null;
- }
- return value1.equals( value2 );
- }
-
- public String toString() {
- return "Array ==";
- }
-
- }
-
- static class ArrayNotEqualEvaluator extends BaseEvaluator {
- /**
- *
- */
- private static final long serialVersionUID = 400L;
- public final static Evaluator INSTANCE = new ArrayNotEqualEvaluator();
-
- private ArrayNotEqualEvaluator() {
- super( ValueType.ARRAY_TYPE,
- Operator.NOT_EQUAL );
- }
-
- public boolean evaluate(InternalWorkingMemory workingMemory,
- final Extractor extractor,
- final Object object1,
- final FieldValue object2) {
- final Object value1 = extractor.getValue( workingMemory,
- object1 );
- final Object value2 = object2.getValue();
- if ( value1 == null ) {
- return value2 != null;
- }
- return !value1.equals( value2 );
- }
-
- public boolean evaluateCachedRight(InternalWorkingMemory workingMemory,
- final VariableContextEntry context,
- final Object left) {
- final Object value = context.declaration.getExtractor().getValue( workingMemory,
- left );
- if ( value == null ) {
- return ((ObjectVariableContextEntry) context).right != null;
- }
- return !value.equals( ((ObjectVariableContextEntry) context).right );
- }
-
- public boolean evaluateCachedLeft(InternalWorkingMemory workingMemory,
- final VariableContextEntry context,
- final Object right) {
- final Object value = context.extractor.getValue( workingMemory,
- right );
- if ( ((ObjectVariableContextEntry) context).left == null ) {
- return value != null;
- }
- return !((ObjectVariableContextEntry) context).left.equals( value );
- }
-
- public boolean evaluate(InternalWorkingMemory workingMemory,
- final Extractor extractor1,
- final Object object1,
- final Extractor extractor2,
- final Object object2) {
- final Object value1 = extractor1.getValue( workingMemory,
- object1 );
- final Object value2 = extractor2.getValue( workingMemory,
- object2 );
- if ( value1 == null ) {
- return value2 != null;
- }
- return !value1.equals( value2 );
- }
-
- public String toString() {
- return "Array !=";
- }
- }
-
- static class ArrayContainsEvaluator extends BaseEvaluator {
- /**
- *
- */
- private static final long serialVersionUID = 400L;
- public final static Evaluator INSTANCE = new ArrayContainsEvaluator();
-
- private ArrayContainsEvaluator() {
- super( ValueType.ARRAY_TYPE,
- Operator.CONTAINS );
- }
-
- public boolean evaluate(InternalWorkingMemory workingMemory,
- final Extractor extractor,
- final Object object1,
- final FieldValue object2) {
- final Object value = object2.getValue();
- final Object[] array = (Object[]) extractor.getValue( workingMemory,
- object1 );
- if ( array == null ) return false;
- return ShadowProxyUtils.contains( array,
- value );
- }
-
- public boolean evaluateCachedRight(InternalWorkingMemory workingMemory,
- final VariableContextEntry context,
- final Object left) {
- final Object value = context.declaration.getExtractor().getValue( workingMemory,
- left );
- final Object[] array = (Object[]) ((ObjectVariableContextEntry) context).right;
- if ( array == null ) return false;
- return ShadowProxyUtils.contains( array,
- value );
- }
-
- public boolean evaluateCachedLeft(InternalWorkingMemory workingMemory,
- final VariableContextEntry context,
- final Object right) {
- final Object value = ((ObjectVariableContextEntry) context).left;
- final Object[] array = (Object[]) context.extractor.getValue( workingMemory,
- right );
- if ( array == null ) return false;
- return ShadowProxyUtils.contains( array,
- value );
- }
-
- public boolean evaluate(InternalWorkingMemory workingMemory,
- final Extractor extractor1,
- final Object object1,
- final Extractor extractor2,
- final Object object2) {
- final Object value = extractor2.getValue( workingMemory,
- object2 );
- final Object[] array = (Object[]) extractor1.getValue( workingMemory,
- object1 );
-
- if ( array == null ) return false;
- return ShadowProxyUtils.contains( array,
- value );
- }
-
- public String toString() {
- return "Array contains";
- }
- }
-
- static class ArrayExcludesEvaluator extends BaseEvaluator {
- /**
- *
- */
- private static final long serialVersionUID = 400L;
- public final static Evaluator INSTANCE = new ArrayExcludesEvaluator();
-
- private ArrayExcludesEvaluator() {
- super( ValueType.ARRAY_TYPE,
- Operator.EXCLUDES );
- }
-
- public boolean evaluate(InternalWorkingMemory workingMemory,
- final Extractor extractor,
- final Object object1,
- final FieldValue object2) {
- final Object value = object2.getValue();
- final Object[] array = (Object[]) extractor.getValue( workingMemory,
- object1 );
- if ( array == null ) return true;
- return !ShadowProxyUtils.contains( array,
- value );
- }
-
- public boolean evaluateCachedRight(InternalWorkingMemory workingMemory,
- final VariableContextEntry context,
- final Object left) {
- final Object value = context.declaration.getExtractor().getValue( workingMemory,
- left );
- final Object[] array = (Object[]) ((ObjectVariableContextEntry) context).right;
- if ( array == null ) return true;
- return !ShadowProxyUtils.contains( array,
- value );
- }
-
- public boolean evaluateCachedLeft(InternalWorkingMemory workingMemory,
- final VariableContextEntry context,
- final Object right) {
- final Object value = ((ObjectVariableContextEntry) context).left;
- final Object[] array = (Object[]) context.extractor.getValue( workingMemory,
- right );
- if ( array == null ) return true;
- return !ShadowProxyUtils.contains( array,
- value );
- }
-
- public boolean evaluate(InternalWorkingMemory workingMemory,
- final Extractor extractor1,
- final Object object1,
- final Extractor extractor2,
- final Object object2) {
- final Object value = extractor2.getValue( workingMemory,
- object2 );
- final Object[] array = (Object[]) extractor1.getValue( workingMemory,
- object1 );
-
- if ( array == null ) return true;
- return !ShadowProxyUtils.contains( array,
- value );
- }
-
- public String toString() {
- return "Array excludes";
- }
- }
-
- static class ArrayMemberOfEvaluator extends BaseEvaluator {
- /**
- *
- */
- private static final long serialVersionUID = 400L;
- public final static Evaluator INSTANCE = new ArrayMemberOfEvaluator();
-
- private ArrayMemberOfEvaluator() {
- super( ValueType.ARRAY_TYPE,
- Operator.MEMBEROF );
- }
-
- public boolean evaluate(InternalWorkingMemory workingMemory,
- final Extractor extractor,
- final Object object1,
- final FieldValue object2) {
- final Object[] array = (Object[]) object2.getValue();
- final Object value = extractor.getValue( workingMemory,
- object1 );
- if ( array == null ) return false;
- return ShadowProxyUtils.contains( array,
- value );
- }
-
- public boolean evaluateCachedRight(InternalWorkingMemory workingMemory,
- final VariableContextEntry context,
- final Object left) {
- final Object[] array = (Object[]) context.declaration.getExtractor().getValue( workingMemory,
- left );
- final Object value = ((ObjectVariableContextEntry) context).right;
- if ( array == null ) return false;
- return ShadowProxyUtils.contains( array,
- value );
- }
-
- public boolean evaluateCachedLeft(InternalWorkingMemory workingMemory,
- final VariableContextEntry context,
- final Object right) {
- final Object[] array = (Object[]) ((ObjectVariableContextEntry) context).left;
- final Object value = context.extractor.getValue( workingMemory,
- right );
- if ( array == null ) return false;
- return ShadowProxyUtils.contains( array,
- value );
- }
-
- public boolean evaluate(InternalWorkingMemory workingMemory,
- final Extractor extractor1,
- final Object object1,
- final Extractor extractor2,
- final Object object2) {
- final Object[] array = (Object[]) extractor2.getValue( workingMemory,
- object2 );
- final Object value = extractor1.getValue( workingMemory,
- object1 );
-
- if ( array == null ) return false;
- return ShadowProxyUtils.contains( array,
- value );
- }
-
- public String toString() {
- return "Array memberOf";
- }
- }
-
- static class ArrayNotMemberOfEvaluator extends BaseEvaluator {
- /**
- *
- */
- private static final long serialVersionUID = 400L;
- public final static Evaluator INSTANCE = new ArrayNotMemberOfEvaluator();
-
- private ArrayNotMemberOfEvaluator() {
- super( ValueType.ARRAY_TYPE,
- Operator.NOTMEMBEROF );
- }
-
- public boolean evaluate(InternalWorkingMemory workingMemory,
- final Extractor extractor,
- final Object object1,
- final FieldValue object2) {
- final Object[] array = (Object[]) object2.getValue();
- final Object value = extractor.getValue( workingMemory,
- object1 );
- if ( array == null ) return true;
- return !ShadowProxyUtils.contains( array,
- value );
- }
-
- public boolean evaluateCachedRight(InternalWorkingMemory workingMemory,
- final VariableContextEntry context,
- final Object left) {
- final Object[] array = (Object[]) context.declaration.getExtractor().getValue( workingMemory,
- left );
- final Object value = ((ObjectVariableContextEntry) context).right;
- if ( array == null ) return true;
- return !ShadowProxyUtils.contains( array,
- value );
- }
-
- public boolean evaluateCachedLeft(InternalWorkingMemory workingMemory,
- final VariableContextEntry context,
- final Object right) {
- final Object[] array = (Object[]) ((ObjectVariableContextEntry) context).left;
- final Object value = context.extractor.getValue( workingMemory,
- right );
- if ( array == null ) return true;
- return !ShadowProxyUtils.contains( array,
- value );
- }
-
- public boolean evaluate(InternalWorkingMemory workingMemory,
- final Extractor extractor1,
- final Object object1,
- final Extractor extractor2,
- final Object object2) {
- final Object[] array = (Object[]) extractor2.getValue( workingMemory,
- object2 );
- final Object value = extractor1.getValue( workingMemory,
- object1 );
-
- if ( array == null ) return true;
- return !ShadowProxyUtils.contains( array,
- value );
- }
-
- public String toString() {
- return "Array not memberOf";
- }
- }
-
-
-}
\ No newline at end of file
Deleted: labs/jbossrules/branches/temporal_rete/drools-core/src/main/java/org/drools/base/evaluators/BaseMemberOfEvaluator.java
===================================================================
--- labs/jbossrules/branches/temporal_rete/drools-core/src/main/java/org/drools/base/evaluators/BaseMemberOfEvaluator.java 2007-12-07 13:39:06 UTC (rev 17088)
+++ labs/jbossrules/branches/temporal_rete/drools-core/src/main/java/org/drools/base/evaluators/BaseMemberOfEvaluator.java 2007-12-07 14:10:27 UTC (rev 17089)
@@ -1,86 +0,0 @@
-/**
- *
- */
-package org.drools.base.evaluators;
-
-import java.util.Collection;
-
-import org.drools.base.BaseEvaluator;
-import org.drools.base.ValueType;
-import org.drools.common.InternalWorkingMemory;
-import org.drools.rule.VariableRestriction.ObjectVariableContextEntry;
-import org.drools.rule.VariableRestriction.VariableContextEntry;
-import org.drools.spi.Extractor;
-import org.drools.spi.FieldValue;
-import org.drools.util.ShadowProxyUtils;
-
-/**
- * This is a base class for MemberOf Evaluators
- *
- * @author etirelli
- */
-public abstract class BaseMemberOfEvaluator extends BaseEvaluator {
-
- public BaseMemberOfEvaluator(ValueType type,
- Operator operator) {
- super( type,
- operator );
- }
-
- public boolean evaluate(InternalWorkingMemory workingMemory,
- final Extractor extractor,
- final Object object1, final FieldValue object2) {
- if( object2.isNull() ) {
- return false;
- } else if( ! object2.isCollectionField() ) {
- throw new ClassCastException("Can't check if an attribute is member of an object of class "+object2.getValue().getClass() );
- }
- final Collection col = (Collection) object2.getValue();
- final Object value = extractor.getValue( workingMemory, object1 );
- return ShadowProxyUtils.contains( col, value );
- }
-
- public boolean evaluateCachedRight(InternalWorkingMemory workingMemory,
- final VariableContextEntry context, final Object left) {
- final Object object = context.declaration.getExtractor().getValue( workingMemory, left );
- if( object == null ) {
- return false;
- } else if( ! ( object instanceof Collection ) ) {
- throw new ClassCastException("Can't check if an attribute is member of an object of class "+object.getClass() );
- }
- final Collection col = (Collection) object;
- final Object value = ((ObjectVariableContextEntry) context).right;
- return ShadowProxyUtils.contains( col, value );
- }
-
- public boolean evaluateCachedLeft(InternalWorkingMemory workingMemory,
- final VariableContextEntry context, final Object right) {
- final Object object = ((ObjectVariableContextEntry) context).left;
- if( object == null ) {
- return false;
- } else if( ! ( object instanceof Collection ) ) {
- throw new ClassCastException("Can't check if an attribute is member of an object of class "+object.getClass() );
- }
- final Collection col = (Collection) object;
- final Object value = context.extractor.getValue( workingMemory, right );
- return ShadowProxyUtils.contains( col, value );
- }
-
- public boolean evaluate(InternalWorkingMemory workingMemory,
- final Extractor extractor1,
- final Object object1,
- final Extractor extractor2, final Object object2) {
- final Object object = extractor2.getValue( workingMemory, object2 );
- if( object == null ) {
- return false;
- } else if( ! ( object instanceof Collection ) ) {
- throw new ClassCastException("Can't check if an attribute is member of an object of class "+object.getClass() );
- }
- final Collection col = (Collection) object;
- final Object value = extractor1.getValue( workingMemory, object1 );
- return ShadowProxyUtils.contains( col, value );
- }
-
- public abstract String toString();
-
-}
Deleted: labs/jbossrules/branches/temporal_rete/drools-core/src/main/java/org/drools/base/evaluators/BaseNotMemberOfEvaluator.java
===================================================================
--- labs/jbossrules/branches/temporal_rete/drools-core/src/main/java/org/drools/base/evaluators/BaseNotMemberOfEvaluator.java 2007-12-07 13:39:06 UTC (rev 17088)
+++ labs/jbossrules/branches/temporal_rete/drools-core/src/main/java/org/drools/base/evaluators/BaseNotMemberOfEvaluator.java 2007-12-07 14:10:27 UTC (rev 17089)
@@ -1,87 +0,0 @@
-/**
- *
- */
-package org.drools.base.evaluators;
-
-import java.util.Collection;
-
-import org.drools.base.BaseEvaluator;
-import org.drools.base.ValueType;
-import org.drools.common.InternalWorkingMemory;
-import org.drools.rule.VariableRestriction.ObjectVariableContextEntry;
-import org.drools.rule.VariableRestriction.VariableContextEntry;
-import org.drools.spi.Extractor;
-import org.drools.spi.FieldValue;
-import org.drools.util.ShadowProxyUtils;
-
-/**
- * This is a base class for Not MemberOf Evaluators
- *
- * @author etirelli
- *
- */
-public abstract class BaseNotMemberOfEvaluator extends BaseEvaluator {
-
- public BaseNotMemberOfEvaluator(ValueType type,
- Operator operator) {
- super( type,
- operator );
- }
-
- public boolean evaluate(InternalWorkingMemory workingMemory,
- final Extractor extractor,
- final Object object1, final FieldValue object2) {
- if( object2.isNull() ) {
- return false;
- } else if( ! object2.isCollectionField() ) {
- throw new ClassCastException("Can't check if an attribute is not member of an object of class "+object2.getValue().getClass() );
- }
- final Collection col = (Collection) object2.getValue();
- final Object value = extractor.getValue( workingMemory, object1 );
- return ! ShadowProxyUtils.contains( col, value );
- }
-
- public boolean evaluateCachedRight(InternalWorkingMemory workingMemory,
- final VariableContextEntry context, final Object left) {
- final Object object = context.declaration.getExtractor().getValue( workingMemory, left );
- if( object == null ) {
- return false;
- } else if( ! ( object instanceof Collection ) ) {
- throw new ClassCastException("Can't check if an attribute is not member of an object of class "+object.getClass() );
- }
- final Collection col = (Collection) object;
- final Object value = ((ObjectVariableContextEntry) context).right;
- return ! ShadowProxyUtils.contains( col, value );
- }
-
- public boolean evaluateCachedLeft(InternalWorkingMemory workingMemory,
- final VariableContextEntry context, final Object right) {
- final Object object = ((ObjectVariableContextEntry) context).left;
- if( object == null ) {
- return false;
- } else if( ! ( object instanceof Collection ) ) {
- throw new ClassCastException("Can't check if an attribute is not member of an object of class "+object.getClass() );
- }
- final Collection col = (Collection) object;
- final Object value = context.extractor.getValue( workingMemory, right );
- return ! ShadowProxyUtils.contains( col, value );
- }
-
- public boolean evaluate(InternalWorkingMemory workingMemory,
- final Extractor extractor1,
- final Object object1,
- final Extractor extractor2, final Object object2) {
- final Object object = extractor2.getValue( workingMemory, object2 );
- if( object == null ) {
- return false;
- } else if( ! ( object instanceof Collection ) ) {
- throw new ClassCastException("Can't check if an attribute is not member of an object of class "+object.getClass() );
- }
- final Collection col = (Collection) object;
- final Object value = extractor1.getValue( workingMemory, object1 );
- return ! ShadowProxyUtils.contains( col, value );
- }
-
- public abstract String toString();
-
-}
Deleted: labs/jbossrules/branches/temporal_rete/drools-core/src/main/java/org/drools/base/evaluators/BigDecimalFactory.java
===================================================================
--- labs/jbossrules/branches/temporal_rete/drools-core/src/main/java/org/drools/base/evaluators/BigDecimalFactory.java 2007-12-07 13:39:06 UTC (rev 17088)
+++ labs/jbossrules/branches/temporal_rete/drools-core/src/main/java/org/drools/base/evaluators/BigDecimalFactory.java 2007-12-07 14:10:27 UTC (rev 17089)
@@ -1,442 +0,0 @@
-package org.drools.base.evaluators;
-
-/*
- * Copyright 2005 JBoss Inc
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-import java.math.BigDecimal;
-
-import org.drools.base.BaseEvaluator;
-import org.drools.base.ValueType;
-import org.drools.common.InternalWorkingMemory;
-import org.drools.rule.VariableRestriction.ObjectVariableContextEntry;
-import org.drools.rule.VariableRestriction.VariableContextEntry;
-import org.drools.spi.Evaluator;
-import org.drools.spi.Extractor;
-import org.drools.spi.FieldValue;
-
-public class BigDecimalFactory
- implements
- EvaluatorFactory {
-
- private static final long serialVersionUID = 400L;
- private static EvaluatorFactory INSTANCE = new BigDecimalFactory();
-
- private BigDecimalFactory() {
-
- }
-
- public static EvaluatorFactory getInstance() {
- if ( BigDecimalFactory.INSTANCE == null ) {
- BigDecimalFactory.INSTANCE = new BigDecimalFactory();
- }
- return BigDecimalFactory.INSTANCE;
- }
-
- public Evaluator getEvaluator(final Operator operator) {
- if ( operator == Operator.EQUAL ) {
- return BigDecimalEqualEvaluator.INSTANCE;
- } else if ( operator == Operator.NOT_EQUAL ) {
- return BigDecimalNotEqualEvaluator.INSTANCE;
- } else if ( operator == Operator.LESS ) {
- return BigDecimalLessEvaluator.INSTANCE;
- } else if ( operator == Operator.LESS_OR_EQUAL ) {
- return BigDecimalLessOrEqualEvaluator.INSTANCE;
- } else if ( operator == Operator.GREATER ) {
- return BigDecimalGreaterEvaluator.INSTANCE;
- } else if ( operator == Operator.GREATER_OR_EQUAL ) {
- return BigDecimalGreaterOrEqualEvaluator.INSTANCE;
- } else if ( operator == Operator.MEMBEROF ) {
- return BigDecimalMemberOfEvaluator.INSTANCE;
- } else if ( operator == Operator.NOTMEMBEROF ) {
- return BigDecimalNotMemberOfEvaluator.INSTANCE;
- } else {
- throw new RuntimeException( "Operator '" + operator + "' does not exist for BigDecimalEvaluator" );
- }
- }
-
- static class BigDecimalEqualEvaluator extends BaseEvaluator {
- /**
- *
- */
- private static final long serialVersionUID = 400L;
- public final static Evaluator INSTANCE = new BigDecimalEqualEvaluator();
-
- private BigDecimalEqualEvaluator() {
- super( ValueType.BIG_DECIMAL_TYPE,
- Operator.EQUAL );
- }
-
- public boolean evaluate(InternalWorkingMemory workingMemory,
- final Extractor extractor,
- final Object object1, final FieldValue object2) {
- final Object value1 = extractor.getValue( workingMemory, object1 );
- final Object value2 = object2.getValue();
- if ( value1 == null ) {
- return value2 == null;
- }
- return value1.equals( value2 );
- }
-
- public boolean evaluateCachedRight(InternalWorkingMemory workingMemory,
- final VariableContextEntry context, final Object left) {
- final Object value = context.declaration.getExtractor().getValue( workingMemory, left );
- if ( value == null ) {
- return ((ObjectVariableContextEntry) context).right == null;
- }
- return value.equals( ((ObjectVariableContextEntry) context).right );
- }
-
- public boolean evaluateCachedLeft(InternalWorkingMemory workingMemory,
- final VariableContextEntry context, final Object right) {
- final Object value = context.extractor.getValue( workingMemory, right );
- if ( ((ObjectVariableContextEntry) context).left == null ) {
- return value == null;
- }
- return ((ObjectVariableContextEntry) context).left.equals( value );
- }
-
- public boolean evaluate(InternalWorkingMemory workingMemory,
- final Extractor extractor1,
- final Object object1,
- final Extractor extractor2, final Object object2) {
- final Object value1 = extractor1.getValue( workingMemory, object1 );
- final Object value2 = extractor2.getValue( workingMemory, object2 );
- if ( value1 == null ) {
- return value2 == null;
- }
- return value1.equals( value2 );
- }
-
- public String toString() {
- return "BigDecimal ==";
- }
-
- }
-
- static class BigDecimalNotEqualEvaluator extends BaseEvaluator {
- /**
- *
- */
- private static final long serialVersionUID = 400L;
- public final static Evaluator INSTANCE = new BigDecimalNotEqualEvaluator();
-
- private BigDecimalNotEqualEvaluator() {
- super( ValueType.BIG_DECIMAL_TYPE,
- Operator.NOT_EQUAL );
- }
-
- public boolean evaluate(InternalWorkingMemory workingMemory,
- final Extractor extractor,
- final Object object1, final FieldValue object2) {
- final Object value1 = extractor.getValue( workingMemory, object1 );
- final Object value2 = object2.getValue();
- if ( value1 == null ) {
- return value2 != null;
- }
- return !value1.equals( value2 );
- }
-
- public boolean evaluateCachedRight(InternalWorkingMemory workingMemory,
- final VariableContextEntry context, final Object left) {
- final Object value = context.declaration.getExtractor().getValue( workingMemory, left );
- if ( value == null ) {
- return ((ObjectVariableContextEntry) context).right != null;
- }
- return !value.equals( ((ObjectVariableContextEntry) context).right );
- }
-
- public boolean evaluateCachedLeft(InternalWorkingMemory workingMemory,
- final VariableContextEntry context, final Object right) {
- final Object value = context.extractor.getValue( workingMemory, right );
- if ( ((ObjectVariableContextEntry) context).left == null ) {
- return value != null;
- }
- return !((ObjectVariableContextEntry) context).left.equals( value );
- }
-
- public boolean evaluate(InternalWorkingMemory workingMemory,
- final Extractor extractor1,
- final Object object1,
- final Extractor extractor2, final Object object2) {
- final Object value1 = extractor1.getValue( workingMemory, object1 );
- final Object value2 = extractor2.getValue( workingMemory, object2 );
- if ( value1 == null ) {
- return value2 != null;
- }
- return !value1.equals( value2 );
- }
-
- public String toString() {
- return "BigDecimal !=";
- }
- }
-
- static class BigDecimalLessEvaluator extends BaseEvaluator {
- /**
- *
- */
- private static final long serialVersionUID = 400L;
- public final static Evaluator INSTANCE = new BigDecimalLessEvaluator();
-
- private BigDecimalLessEvaluator() {
- super( ValueType.BIG_DECIMAL_TYPE,
- Operator.LESS );
- }
-
- public boolean evaluate(InternalWorkingMemory workingMemory,
- final Extractor extractor,
- final Object object1, final FieldValue object2) {
- if( extractor.isNullValue( workingMemory, object1 ) ) {
- return false;
- }
- final BigDecimal comp = (BigDecimal) extractor.getValue( workingMemory, object1 );
- return comp.compareTo( (BigDecimal) object2.getValue() ) < 0;
- }
-
- public boolean evaluateCachedRight(InternalWorkingMemory workingMemory,
- final VariableContextEntry context, final Object left) {
- if( context.rightNull ) {
- return false;
- }
- final BigDecimal comp = (BigDecimal) ((ObjectVariableContextEntry) context).right;
- return comp.compareTo( (BigDecimal) context.declaration.getExtractor().getValue( workingMemory, left ) ) < 0;
- }
-
- public boolean evaluateCachedLeft(InternalWorkingMemory workingMemory,
- final VariableContextEntry context, final Object right) {
- if( context.extractor.isNullValue( workingMemory, right ) ) {
- return false;
- }
- final BigDecimal comp = (BigDecimal) context.extractor.getValue( workingMemory, right );
- return comp.compareTo( (BigDecimal) ((ObjectVariableContextEntry) context).left ) < 0;
- }
-
- public boolean evaluate(InternalWorkingMemory workingMemory,
- final Extractor extractor1,
- final Object object1,
- final Extractor extractor2, final Object object2) {
- if( extractor1.isNullValue( workingMemory, object1 ) ) {
- return false;
- }
- final BigDecimal comp = (BigDecimal) extractor1.getValue( workingMemory, object1 );
- return comp.compareTo( (BigDecimal) extractor2.getValue( workingMemory, object2 ) ) < 0;
- }
-
- public String toString() {
- return "BigDecimal <";
- }
- }
-
- static class BigDecimalLessOrEqualEvaluator extends BaseEvaluator {
- /**
- *
- */
- private static final long serialVersionUID = 400L;
- public final static Evaluator INSTANCE = new BigDecimalLessOrEqualEvaluator();
-
- private BigDecimalLessOrEqualEvaluator() {
- super( ValueType.BIG_DECIMAL_TYPE,
- Operator.LESS_OR_EQUAL );
- }
-
- public boolean evaluate(InternalWorkingMemory workingMemory,
- final Extractor extractor,
- final Object object1, final FieldValue object2) {
- if( extractor.isNullValue( workingMemory, object1 ) ) {
- return false;
- }
- final BigDecimal comp = (BigDecimal) extractor.getValue( workingMemory, object1 );
- return comp.compareTo( (BigDecimal) object2.getValue() ) <= 0;
- }
-
- public boolean evaluateCachedRight(InternalWorkingMemory workingMemory,
- final VariableContextEntry context, final Object left) {
- if( context.rightNull ) {
- return false;
- }
- final BigDecimal comp = (BigDecimal) ((ObjectVariableContextEntry) context).right;
- return comp.compareTo( (BigDecimal) context.declaration.getExtractor().getValue( workingMemory, left ) ) <= 0;
- }
-
- public boolean evaluateCachedLeft(InternalWorkingMemory workingMemory,
- final VariableContextEntry context, final Object right) {
- if( context.extractor.isNullValue( workingMemory, right ) ) {
- return false;
- }
- final BigDecimal comp = (BigDecimal) context.extractor.getValue( workingMemory, right );
- return comp.compareTo( (BigDecimal) ((ObjectVariableContextEntry) context).left ) <= 0;
- }
-
- public boolean evaluate(InternalWorkingMemory workingMemory,
- final Extractor extractor1,
- final Object object1,
- final Extractor extractor2, final Object object2) {
- if( extractor1.isNullValue( workingMemory, object1 ) ) {
- return false;
- }
- final BigDecimal comp = (BigDecimal) extractor1.getValue( workingMemory, object1 );
- return comp.compareTo( (BigDecimal) extractor2.getValue( workingMemory, object2 ) ) <= 0;
- }
-
- public String toString() {
- return "BigDecimal <=";
- }
- }
-
- static class BigDecimalGreaterEvaluator extends BaseEvaluator {
- /**
- *
- */
- private static final long serialVersionUID = 400L;
- public final static Evaluator INSTANCE = new BigDecimalGreaterEvaluator();
-
- private BigDecimalGreaterEvaluator() {
- super( ValueType.BIG_DECIMAL_TYPE,
- Operator.GREATER );
- }
-
- public boolean evaluate(InternalWorkingMemory workingMemory,
- final Extractor extractor,
- final Object object1, final FieldValue object2) {
- if( extractor.isNullValue( workingMemory, object1 ) ) {
- return false;
- }
- final BigDecimal comp = (BigDecimal) extractor.getValue( workingMemory, object1 );
- return comp.compareTo( (BigDecimal) object2.getValue() ) > 0;
- }
-
- public boolean evaluateCachedRight(InternalWorkingMemory workingMemory,
- final VariableContextEntry context, final Object left) {
- if( context.rightNull ) {
- return false;
- }
- final BigDecimal comp = (BigDecimal) ((ObjectVariableContextEntry) context).right;
- return comp.compareTo( (BigDecimal) context.declaration.getExtractor().getValue( workingMemory, left ) ) > 0;
- }
-
- public boolean evaluateCachedLeft(InternalWorkingMemory workingMemory,
- final VariableContextEntry context, final Object right) {
- if( context.extractor.isNullValue( workingMemory, right ) ) {
- return false;
- }
- final BigDecimal comp = (BigDecimal) context.extractor.getValue( workingMemory, right );
- return comp.compareTo( (BigDecimal) ((ObjectVariableContextEntry) context).left ) > 0;
- }
-
- public boolean evaluate(InternalWorkingMemory workingMemory,
- final Extractor extractor1,
- final Object object1,
- final Extractor extractor2, final Object object2) {
- if( extractor1.isNullValue( workingMemory, object1 ) ) {
- return false;
- }
- final BigDecimal comp = (BigDecimal) extractor1.getValue( workingMemory, object1 );
- return comp.compareTo( (BigDecimal) extractor2.getValue( workingMemory, object2 ) ) > 0;
- }
-
- public String toString() {
- return "BigDecimal >";
- }
- }
-
- static class BigDecimalGreaterOrEqualEvaluator extends BaseEvaluator {
- /**
- *
- */
- private static final long serialVersionUID = 400L;
- private final static Evaluator INSTANCE = new BigDecimalGreaterOrEqualEvaluator();
-
- private BigDecimalGreaterOrEqualEvaluator() {
- super( ValueType.BIG_DECIMAL_TYPE,
- Operator.GREATER_OR_EQUAL );
- }
-
- public boolean evaluate(InternalWorkingMemory workingMemory,
- final Extractor extractor,
- final Object object1, final FieldValue object2) {
- if( extractor.isNullValue( workingMemory, object1 ) ) {
- return false;
- }
- final BigDecimal comp = (BigDecimal) extractor.getValue( workingMemory, object1 );
- return comp.compareTo( (BigDecimal) object2.getValue() ) >= 0;
- }
-
- public boolean evaluateCachedRight(InternalWorkingMemory workingMemory,
- final VariableContextEntry context, final Object left) {
- if( context.rightNull ) {
- return false;
- }
- final BigDecimal comp = (BigDecimal) ((ObjectVariableContextEntry) context).right;
- return comp.compareTo( (BigDecimal) context.declaration.getExtractor().getValue( workingMemory, left ) ) >= 0;
- }
-
- public boolean evaluateCachedLeft(InternalWorkingMemory workingMemory,
- final VariableContextEntry context, final Object right) {
- if( context.extractor.isNullValue( workingMemory, right ) ) {
- return false;
- }
- final BigDecimal comp = (BigDecimal) context.extractor.getValue( workingMemory, right );
- return comp.compareTo( (BigDecimal) ((ObjectVariableContextEntry) context).left ) >= 0;
- }
-
- public boolean evaluate(InternalWorkingMemory workingMemory,
- final Extractor extractor1,
- final Object object1,
- final Extractor extractor2, final Object object2) {
- if( extractor1.isNullValue( workingMemory, object1 ) ) {
- return false;
- }
- final BigDecimal comp = (BigDecimal) extractor1.getValue( workingMemory, object1 );
- return comp.compareTo( (BigDecimal) extractor2.getValue( workingMemory, object2 ) ) >= 0;
- }
-
- public String toString() {
- return "BigDecimal >=";
- }
- }
-
- static class BigDecimalMemberOfEvaluator extends BaseMemberOfEvaluator {
-
- private static final long serialVersionUID = 400L;
- public final static Evaluator INSTANCE = new BigDecimalMemberOfEvaluator();
-
- private BigDecimalMemberOfEvaluator() {
- super( ValueType.BIG_DECIMAL_TYPE,
- Operator.MEMBEROF );
- }
-
- public String toString() {
- return "BigDecimal memberOf";
- }
- }
-
- static class BigDecimalNotMemberOfEvaluator extends BaseNotMemberOfEvaluator {
- /**
- *
- */
- private static final long serialVersionUID = 400L;
- public final static Evaluator INSTANCE = new BigDecimalNotMemberOfEvaluator();
-
- private BigDecimalNotMemberOfEvaluator() {
- super( ValueType.BIG_DECIMAL_TYPE,
- Operator.NOTMEMBEROF );
- }
-
- public String toString() {
- return "BigDecimal not memberOf";
- }
- }
-}
\ No newline at end of file
Deleted: labs/jbossrules/branches/temporal_rete/drools-core/src/main/java/org/drools/base/evaluators/BigIntegerFactory.java
===================================================================
--- labs/jbossrules/branches/temporal_rete/drools-core/src/main/java/org/drools/base/evaluators/BigIntegerFactory.java 2007-12-07 13:39:06 UTC (rev 17088)
+++ labs/jbossrules/branches/temporal_rete/drools-core/src/main/java/org/drools/base/evaluators/BigIntegerFactory.java 2007-12-07 14:10:27 UTC (rev 17089)
@@ -1,442 +0,0 @@
-package org.drools.base.evaluators;
-
-/*
- * Copyright 2005 JBoss Inc
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-import java.math.BigInteger;
-
-import org.drools.base.BaseEvaluator;
-import org.drools.base.ValueType;
-import org.drools.common.InternalWorkingMemory;
-import org.drools.rule.VariableRestriction.ObjectVariableContextEntry;
-import org.drools.rule.VariableRestriction.VariableContextEntry;
-import org.drools.spi.Evaluator;
-import org.drools.spi.Extractor;
-import org.drools.spi.FieldValue;
-
-public class BigIntegerFactory
- implements
- EvaluatorFactory {
-
- private static final long serialVersionUID = 400L;
- private static EvaluatorFactory INSTANCE = new BigIntegerFactory();
-
- private BigIntegerFactory() {
-
- }
-
- public static EvaluatorFactory getInstance() {
- if ( BigIntegerFactory.INSTANCE == null ) {
- BigIntegerFactory.INSTANCE = new BigIntegerFactory();
- }
- return BigIntegerFactory.INSTANCE;
- }
-
- public Evaluator getEvaluator(final Operator operator) {
- if ( operator == Operator.EQUAL ) {
- return BigIntegerEqualEvaluator.INSTANCE;
- } else if ( operator == Operator.NOT_EQUAL ) {
- return BigIntegerNotEqualEvaluator.INSTANCE;
- } else if ( operator == Operator.LESS ) {
- return BigIntegerLessEvaluator.INSTANCE;
- } else if ( operator == Operator.LESS_OR_EQUAL ) {
- return BigIntegerLessOrEqualEvaluator.INSTANCE;
- } else if ( operator == Operator.GREATER ) {
- return BigIntegerGreaterEvaluator.INSTANCE;
- } else if ( operator == Operator.GREATER_OR_EQUAL ) {
- return BigIntegerGreaterOrEqualEvaluator.INSTANCE;
- } else if ( operator == Operator.MEMBEROF ) {
- return BigIntegerMemberOfEvaluator.INSTANCE;
- } else if ( operator == Operator.NOTMEMBEROF ) {
- return BigIntegerNotMemberOfEvaluator.INSTANCE;
- } else {
- throw new RuntimeException( "Operator '" + operator + "' does not exist for BigIntegerEvaluator" );
- }
- }
-
- static class BigIntegerEqualEvaluator extends BaseEvaluator {
- /**
- *
- */
- private static final long serialVersionUID = 400L;
- public final static Evaluator INSTANCE = new BigIntegerEqualEvaluator();
-
- private BigIntegerEqualEvaluator() {
- super( ValueType.BIG_INTEGER_TYPE,
- Operator.EQUAL );
- }
-
- public boolean evaluate(InternalWorkingMemory workingMemory,
- final Extractor extractor,
- final Object object1, final FieldValue object2) {
- final Object value1 = extractor.getValue( workingMemory, object1 );
- final Object value2 = object2.getValue();
- if ( value1 == null ) {
- return value2 == null;
- }
- return value1.equals( value2 );
- }
-
- public boolean evaluateCachedRight(InternalWorkingMemory workingMemory,
- final VariableContextEntry context, final Object left) {
- final Object value = context.declaration.getExtractor().getValue( workingMemory, left );
- if ( value == null ) {
- return ((ObjectVariableContextEntry) context).right == null;
- }
- return value.equals( ((ObjectVariableContextEntry) context).right );
- }
-
- public boolean evaluateCachedLeft(InternalWorkingMemory workingMemory,
- final VariableContextEntry context, final Object right) {
- final Object value = context.extractor.getValue( workingMemory, right );
- if ( ((ObjectVariableContextEntry) context).left == null ) {
- return value == null;
- }
- return ((ObjectVariableContextEntry) context).left.equals( value );
- }
-
- public boolean evaluate(InternalWorkingMemory workingMemory,
- final Extractor extractor1,
- final Object object1,
- final Extractor extractor2, final Object object2) {
- final Object value1 = extractor1.getValue( workingMemory, object1 );
- final Object value2 = extractor2.getValue( workingMemory, object2 );
- if ( value1 == null ) {
- return value2 == null;
- }
- return value1.equals( value2 );
- }
-
- public String toString() {
- return "BigInteger ==";
- }
- }
-
- static class BigIntegerNotEqualEvaluator extends BaseEvaluator {
- /**
- *
- */
- private static final long serialVersionUID = 400L;
- public final static Evaluator INSTANCE = new BigIntegerNotEqualEvaluator();
-
- private BigIntegerNotEqualEvaluator() {
- super( ValueType.BIG_INTEGER_TYPE,
- Operator.NOT_EQUAL );
- }
-
- public boolean evaluate(InternalWorkingMemory workingMemory,
- final Extractor extractor,
- final Object object1, final FieldValue object2) {
- final Object value1 = extractor.getValue( workingMemory, object1 );
- final Object value2 = object2.getValue();
- if ( value1 == null ) {
- return value2 != null;
- }
- return !value1.equals( value2 );
- }
-
- public boolean evaluateCachedRight(InternalWorkingMemory workingMemory,
- final VariableContextEntry context, final Object left) {
- final Object value = context.declaration.getExtractor().getValue( workingMemory, left );
- if ( value == null ) {
- return ((ObjectVariableContextEntry) context).right != null;
- }
- return !value.equals( ((ObjectVariableContextEntry) context).right );
- }
-
- public boolean evaluateCachedLeft(InternalWorkingMemory workingMemory,
- final VariableContextEntry context, final Object right) {
- final Object value = context.extractor.getValue( workingMemory, right );
- if ( ((ObjectVariableContextEntry) context).left == null ) {
- return value != null;
- }
- return !((ObjectVariableContextEntry) context).left.equals( value );
- }
-
- public boolean evaluate(InternalWorkingMemory workingMemory,
- final Extractor extractor1,
- final Object object1,
- final Extractor extractor2, final Object object2) {
- final Object value1 = extractor1.getValue( workingMemory, object1 );
- final Object value2 = extractor2.getValue( workingMemory, object2 );
- if ( value1 == null ) {
- return value2 != null;
- }
- return !value1.equals( value2 );
- }
-
- public String toString() {
- return "BigInteger !=";
- }
- }
-
- static class BigIntegerLessEvaluator extends BaseEvaluator {
- /**
- *
- */
- private static final long serialVersionUID = 400L;
- public final static Evaluator INSTANCE = new BigIntegerLessEvaluator();
-
- private BigIntegerLessEvaluator() {
- super( ValueType.BIG_INTEGER_TYPE,
- Operator.LESS );
- }
-
- public boolean evaluate(InternalWorkingMemory workingMemory,
- final Extractor extractor,
- final Object object1, final FieldValue object2) {
- if( extractor.isNullValue( workingMemory, object1 ) ) {
- return false;
- }
- final BigInteger comp = (BigInteger) extractor.getValue( workingMemory, object1 );
- return comp.compareTo( (BigInteger) object2.getValue() ) < 0;
- }
-
- public boolean evaluateCachedRight(InternalWorkingMemory workingMemory,
- final VariableContextEntry context, final Object left) {
- if( context.rightNull ) {
- return false;
- }
- final BigInteger comp = (BigInteger) ((ObjectVariableContextEntry) context).right;
- return comp.compareTo( (BigInteger) context.declaration.getExtractor().getValue( workingMemory, left ) ) < 0;
- }
-
- public boolean evaluateCachedLeft(InternalWorkingMemory workingMemory,
- final VariableContextEntry context, final Object right) {
- if( context.extractor.isNullValue( workingMemory, right ) ) {
- return false;
- }
- final BigInteger comp = (BigInteger) context.extractor.getValue( workingMemory, right );
- return comp.compareTo( (BigInteger) ((ObjectVariableContextEntry) context).left ) < 0;
- }
-
- public boolean evaluate(InternalWorkingMemory workingMemory,
- final Extractor extractor1,
- final Object object1,
- final Extractor extractor2, final Object object2) {
- if( extractor1.isNullValue( workingMemory, object1 ) ) {
- return false;
- }
- final BigInteger comp = (BigInteger) extractor1.getValue( workingMemory, object1 );
- return comp.compareTo( (BigInteger) extractor2.getValue( workingMemory, object2 ) ) < 0;
- }
-
- public String toString() {
- return "BigInteger <";
- }
- }
-
- static class BigIntegerLessOrEqualEvaluator extends BaseEvaluator {
- /**
- *
- */
- private static final long serialVersionUID = 400L;
- public final static Evaluator INSTANCE = new BigIntegerLessOrEqualEvaluator();
-
- private BigIntegerLessOrEqualEvaluator() {
- super( ValueType.BIG_INTEGER_TYPE,
- Operator.LESS_OR_EQUAL );
- }
-
- public boolean evaluate(InternalWorkingMemory workingMemory,
- final Extractor extractor,
- final Object object1, final FieldValue object2) {
- if( extractor.isNullValue( workingMemory, object1 ) ) {
- return false;
- }
- final BigInteger comp = (BigInteger) extractor.getValue( workingMemory, object1 );
- return comp.compareTo( (BigInteger) object2.getValue() ) <= 0;
- }
-
- public boolean evaluateCachedRight(InternalWorkingMemory workingMemory,
- final VariableContextEntry context, final Object left) {
- if( context.rightNull ) {
- return false;
- }
- final BigInteger comp = (BigInteger) ((ObjectVariableContextEntry) context).right;
- return comp.compareTo( (BigInteger) context.declaration.getExtractor().getValue( workingMemory, left ) ) <= 0;
- }
-
- public boolean evaluateCachedLeft(InternalWorkingMemory workingMemory,
- final VariableContextEntry context, final Object right) {
- if( context.extractor.isNullValue( workingMemory, right ) ) {
- return false;
- }
- final BigInteger comp = (BigInteger) context.extractor.getValue( workingMemory, right );
- return comp.compareTo( (BigInteger) ((ObjectVariableContextEntry) context).left ) <= 0;
- }
-
- public boolean evaluate(InternalWorkingMemory workingMemory,
- final Extractor extractor1,
- final Object object1,
- final Extractor extractor2, final Object object2) {
- if( extractor1.isNullValue( workingMemory, object1 ) ) {
- return false;
- }
- final BigInteger comp = (BigInteger) extractor1.getValue( workingMemory, object1 );
- return comp.compareTo( (BigInteger) extractor2.getValue( workingMemory, object2 ) ) <= 0;
- }
-
- public String toString() {
- return "BigInteger <=";
- }
- }
-
- static class BigIntegerGreaterEvaluator extends BaseEvaluator {
- /**
- *
- */
- private static final long serialVersionUID = 400L;
- public final static Evaluator INSTANCE = new BigIntegerGreaterEvaluator();
-
- private BigIntegerGreaterEvaluator() {
- super( ValueType.BIG_INTEGER_TYPE,
- Operator.GREATER );
- }
-
- public boolean evaluate(InternalWorkingMemory workingMemory,
- final Extractor extractor,
- final Object object1, final FieldValue object2) {
- if( extractor.isNullValue( workingMemory, object1 ) ) {
- return false;
- }
- final BigInteger comp = (BigInteger) extractor.getValue( workingMemory, object1 );
- return comp.compareTo( (BigInteger) object2.getValue() ) > 0;
- }
-
- public boolean evaluateCachedRight(InternalWorkingMemory workingMemory,
- final VariableContextEntry context, final Object left) {
- if( context.rightNull ) {
- return false;
- }
- final BigInteger comp = (BigInteger) ((ObjectVariableContextEntry) context).right;
- return comp.compareTo( (BigInteger) context.declaration.getExtractor().getValue( workingMemory, left ) ) > 0;
- }
-
- public boolean evaluateCachedLeft(InternalWorkingMemory workingMemory,
- final VariableContextEntry context, final Object right) {
- if( context.extractor.isNullValue( workingMemory, right ) ) {
- return false;
- }
- final BigInteger comp = (BigInteger) context.extractor.getValue( workingMemory, right );
- return comp.compareTo( (BigInteger) ((ObjectVariableContextEntry) context).left ) > 0;
- }
-
- public boolean evaluate(InternalWorkingMemory workingMemory,
- final Extractor extractor1,
- final Object object1,
- final Extractor extractor2, final Object object2) {
- if( extractor1.isNullValue( workingMemory, object1 ) ) {
- return false;
- }
- final BigInteger comp = (BigInteger) extractor1.getValue( workingMemory, object1 );
- return comp.compareTo( (BigInteger) extractor2.getValue( workingMemory, object2 ) ) > 0;
- }
-
- public String toString() {
- return "BigInteger >";
- }
- }
-
- static class BigIntegerGreaterOrEqualEvaluator extends BaseEvaluator {
- /**
- *
- */
- private static final long serialVersionUID = 400L;
- private final static Evaluator INSTANCE = new BigIntegerGreaterOrEqualEvaluator();
-
- private BigIntegerGreaterOrEqualEvaluator() {
- super( ValueType.BIG_INTEGER_TYPE,
- Operator.GREATER_OR_EQUAL );
- }
-
- public boolean evaluate(InternalWorkingMemory workingMemory,
- final Extractor extractor,
- final Object object1, final FieldValue object2) {
- if( extractor.isNullValue( workingMemory, object1 ) ) {
- return false;
- }
- final BigInteger comp = (BigInteger) extractor.getValue( workingMemory, object1 );
- return comp.compareTo( (BigInteger) object2.getValue() ) >= 0;
- }
-
- public boolean evaluateCachedRight(InternalWorkingMemory workingMemory,
- final VariableContextEntry context, final Object left) {
- if( context.rightNull ) {
- return false;
- }
- final BigInteger comp = (BigInteger) ((ObjectVariableContextEntry) context).right;
- return comp.compareTo( (BigInteger) context.declaration.getExtractor().getValue( workingMemory, left ) ) >= 0;
- }
-
- public boolean evaluateCachedLeft(InternalWorkingMemory workingMemory,
- final VariableContextEntry context, final Object right) {
- if( context.extractor.isNullValue( workingMemory, right ) ) {
- return false;
- }
- final BigInteger comp = (BigInteger) context.extractor.getValue( workingMemory, right );
- return comp.compareTo( (BigInteger) ((ObjectVariableContextEntry) context).left ) >= 0;
- }
-
- public boolean evaluate(InternalWorkingMemory workingMemory,
- final Extractor extractor1,
- final Object object1,
- final Extractor extractor2, final Object object2) {
- if( extractor1.isNullValue( workingMemory, object1 ) ) {
- return false;
- }
- final BigInteger comp = (BigInteger) extractor1.getValue( workingMemory, object1 );
- return comp.compareTo( (BigInteger) extractor2.getValue( workingMemory, object2 ) ) >= 0;
- }
-
- public String toString() {
- return "BigInteger >=";
- }
- }
-
- static class BigIntegerMemberOfEvaluator extends BaseMemberOfEvaluator {
-
- private static final long serialVersionUID = 400L;
- public final static Evaluator INSTANCE = new BigIntegerMemberOfEvaluator();
-
- private BigIntegerMemberOfEvaluator() {
- super( ValueType.BIG_INTEGER_TYPE,
- Operator.MEMBEROF );
- }
-
- public String toString() {
- return "BigInteger memberOf";
- }
- }
-
- static class BigIntegerNotMemberOfEvaluator extends BaseNotMemberOfEvaluator {
- /**
- *
- */
- private static final long serialVersionUID = 400L;
- public final static Evaluator INSTANCE = new BigIntegerNotMemberOfEvaluator();
-
- private BigIntegerNotMemberOfEvaluator() {
- super( ValueType.BIG_INTEGER_TYPE,
- Operator.NOTMEMBEROF );
- }
-
- public String toString() {
- return "BigInteger not memberOf";
- }
- }
-
-}
\ No newline at end of file
Deleted: labs/jbossrules/branches/temporal_rete/drools-core/src/main/java/org/drools/base/evaluators/BooleanFactory.java
===================================================================
--- labs/jbossrules/branches/temporal_rete/drools-core/src/main/java/org/drools/base/evaluators/BooleanFactory.java 2007-12-07 13:39:06 UTC (rev 17088)
+++ labs/jbossrules/branches/temporal_rete/drools-core/src/main/java/org/drools/base/evaluators/BooleanFactory.java 2007-12-07 14:10:27 UTC (rev 17089)
@@ -1,218 +0,0 @@
-package org.drools.base.evaluators;
-
-/*
- * Copyright 2005 JBoss Inc
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-import org.drools.base.BaseEvaluator;
-import org.drools.base.ValueType;
-import org.drools.common.InternalWorkingMemory;
-import org.drools.rule.VariableRestriction.BooleanVariableContextEntry;
-import org.drools.rule.VariableRestriction.VariableContextEntry;
-import org.drools.spi.Evaluator;
-import org.drools.spi.Extractor;
-import org.drools.spi.FieldValue;
-
-public class BooleanFactory
- implements
- EvaluatorFactory {
-
- private static final long serialVersionUID = 400L;
- private static EvaluatorFactory INSTANCE = new BooleanFactory();
-
- private BooleanFactory() {
-
- }
-
- public static EvaluatorFactory getInstance() {
- if ( BooleanFactory.INSTANCE == null ) {
- BooleanFactory.INSTANCE = new BooleanFactory();
- }
- return BooleanFactory.INSTANCE;
- }
-
- public Evaluator getEvaluator(final Operator operator) {
- if ( operator == Operator.EQUAL ) {
- return BooleanEqualEvaluator.INSTANCE;
- } else if ( operator == Operator.NOT_EQUAL ) {
- return BooleanNotEqualEvaluator.INSTANCE;
- } else if ( operator == Operator.MEMBEROF ) {
- return BooleanMemberOfEvaluator.INSTANCE;
- } else if ( operator == Operator.NOTMEMBEROF ) {
- return BooleanNotMemberOfEvaluator.INSTANCE;
- } else {
- throw new RuntimeException( "Operator '" + operator + "' does not exist for BooleanEvaluator" );
- }
- }
-
- static class BooleanEqualEvaluator extends BaseEvaluator {
- /**
- *
- */
- private static final long serialVersionUID = 400L;
- private final static Evaluator INSTANCE = new BooleanEqualEvaluator();
-
- private BooleanEqualEvaluator() {
- super( ValueType.PBOOLEAN_TYPE,
- Operator.EQUAL );
- }
-
- public boolean evaluate(InternalWorkingMemory workingMemory,
- final Extractor extractor,
- final Object object1, final FieldValue object2) {
- if ( extractor.isNullValue( workingMemory, object1 ) ) {
- return object2.isNull();
- } else if ( object2.isNull() ) {
- return false;
- }
-
- return extractor.getBooleanValue( workingMemory, object1 ) == object2.getBooleanValue();
- }
-
- public boolean evaluateCachedRight(InternalWorkingMemory workingMemory,
- final VariableContextEntry context, final Object left) {
- if ( context.declaration.getExtractor().isNullValue( workingMemory, left ) ) {
- return context.isRightNull();
- } else if ( context.isRightNull() ) {
- return false;
- }
-
- return context.declaration.getExtractor().getBooleanValue( workingMemory, left ) == ((BooleanVariableContextEntry) context).right;
- }
-
- public boolean evaluateCachedLeft(InternalWorkingMemory workingMemory,
- final VariableContextEntry context, final Object object2) {
- if ( context.extractor.isNullValue( workingMemory, object2 )) {
- return context.isLeftNull();
- } else if ( context.isLeftNull() ) {
- return false;
- }
-
- return context.extractor.getBooleanValue( workingMemory, object2 ) == ((BooleanVariableContextEntry) context).left;
- }
-
- public boolean evaluate(InternalWorkingMemory workingMemory,
- final Extractor extractor1,
- final Object object1,
- final Extractor extractor2, final Object object2) {
- if (extractor1.isNullValue( workingMemory, object1 )) {
- return extractor2.isNullValue( workingMemory, object2 );
- } else if (extractor2.isNullValue( workingMemory, object2 )) {
- return false;
- }
-
- return extractor1.getBooleanValue( workingMemory, object1 ) == extractor2.getBooleanValue( workingMemory, object2 );
- }
-
- public String toString() {
- return "Boolean ==";
- }
-
- }
-
- static class BooleanNotEqualEvaluator extends BaseEvaluator {
- /**
- *
- */
- private static final long serialVersionUID = 400L;
- public final static Evaluator INSTANCE = new BooleanNotEqualEvaluator();
-
- private BooleanNotEqualEvaluator() {
- super( ValueType.PBOOLEAN_TYPE,
- Operator.NOT_EQUAL );
- }
-
- public boolean evaluate(InternalWorkingMemory workingMemory,
- final Extractor extractor,
- final Object object1, final FieldValue object2) {
- if ( extractor.isNullValue( workingMemory, object1 ) ) {
- return !object2.isNull();
- } else if ( object2.isNull() ) {
- return true;
- }
-
- return extractor.getBooleanValue( workingMemory, object1 ) != object2.getBooleanValue();
- }
-
- public boolean evaluateCachedRight(InternalWorkingMemory workingMemory,
- final VariableContextEntry context, final Object left) {
- if ( context.declaration.getExtractor().isNullValue( workingMemory, left ) ) {
- return !context.isRightNull();
- } else if ( context.isRightNull() ) {
- return true;
- }
- return context.declaration.getExtractor().getBooleanValue( workingMemory, left ) != ((BooleanVariableContextEntry) context).right;
- }
-
- public boolean evaluateCachedLeft(InternalWorkingMemory workingMemory,
- final VariableContextEntry context, final Object object2) {
- if ( context.extractor.isNullValue( workingMemory, object2 )) {
- return !context.isLeftNull();
- } else if ( context.isLeftNull() ) {
- return true;
- }
-
- return context.extractor.getBooleanValue( workingMemory, object2 ) != ((BooleanVariableContextEntry) context).left;
- }
-
- public boolean evaluate(InternalWorkingMemory workingMemory,
- final Extractor extractor1,
- final Object object1,
- final Extractor extractor2, final Object object2) {
- if (extractor1.isNullValue( workingMemory, object1 )) {
- return !extractor2.isNullValue( workingMemory, object2 );
- } else if (extractor2.isNullValue( workingMemory, object2 )) {
- return true;
- }
-
- return extractor1.getBooleanValue( workingMemory, object1 ) != extractor1.getBooleanValue( workingMemory, object2 );
- }
-
- public String toString() {
- return "Boolean !=";
- }
- }
-
- static class BooleanMemberOfEvaluator extends BaseMemberOfEvaluator {
-
- private static final long serialVersionUID = 400L;
- public final static Evaluator INSTANCE = new BooleanMemberOfEvaluator();
-
- private BooleanMemberOfEvaluator() {
- super( ValueType.PBOOLEAN_TYPE,
- Operator.MEMBEROF );
- }
-
- public String toString() {
- return "Boolean memberOf";
- }
- }
-
- static class BooleanNotMemberOfEvaluator extends BaseNotMemberOfEvaluator {
-
- private static final long serialVersionUID = 400L;
- public final static Evaluator INSTANCE = new BooleanNotMemberOfEvaluator();
-
- private BooleanNotMemberOfEvaluator() {
- super( ValueType.PBOOLEAN_TYPE,
- Operator.NOTMEMBEROF );
- }
-
- public String toString() {
- return "Boolean not memberOf";
- }
- }
-
-}
\ No newline at end of file
Deleted: labs/jbossrules/branches/temporal_rete/drools-core/src/main/java/org/drools/base/evaluators/ByteFactory.java
===================================================================
--- labs/jbossrules/branches/temporal_rete/drools-core/src/main/java/org/drools/base/evaluators/ByteFactory.java 2007-12-07 13:39:06 UTC (rev 17088)
+++ labs/jbossrules/branches/temporal_rete/drools-core/src/main/java/org/drools/base/evaluators/ByteFactory.java 2007-12-07 14:10:27 UTC (rev 17089)
@@ -1,435 +0,0 @@
-package org.drools.base.evaluators;
-
-/*
- * Copyright 2005 JBoss Inc
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-import org.drools.base.BaseEvaluator;
-import org.drools.base.ValueType;
-import org.drools.common.InternalWorkingMemory;
-import org.drools.rule.VariableRestriction.LongVariableContextEntry;
-import org.drools.rule.VariableRestriction.VariableContextEntry;
-import org.drools.spi.Evaluator;
-import org.drools.spi.Extractor;
-import org.drools.spi.FieldValue;
-
-public class ByteFactory
- implements
- EvaluatorFactory {
-
- private static final long serialVersionUID = 400L;
- private static EvaluatorFactory INSTANCE = new ByteFactory();
-
- private ByteFactory() {
-
- }
-
- public static EvaluatorFactory getInstance() {
- if ( ByteFactory.INSTANCE == null ) {
- ByteFactory.INSTANCE = new ByteFactory();
- }
- return ByteFactory.INSTANCE;
- }
-
- public Evaluator getEvaluator(final Operator operator) {
- if ( operator == Operator.EQUAL ) {
- return ByteEqualEvaluator.INSTANCE;
- } else if ( operator == Operator.NOT_EQUAL ) {
- return ByteNotEqualEvaluator.INSTANCE;
- } else if ( operator == Operator.LESS ) {
- return ByteLessEvaluator.INSTANCE;
- } else if ( operator == Operator.LESS_OR_EQUAL ) {
- return ByteLessOrEqualEvaluator.INSTANCE;
- } else if ( operator == Operator.GREATER ) {
- return ByteGreaterEvaluator.INSTANCE;
- } else if ( operator == Operator.GREATER_OR_EQUAL ) {
- return ByteGreaterOrEqualEvaluator.INSTANCE;
- } else if ( operator == Operator.MEMBEROF ) {
- return ByteMemberOfEvaluator.INSTANCE;
- } else if ( operator == Operator.NOTMEMBEROF ) {
- return ByteNotMemberOfEvaluator.INSTANCE;
- } else {
- throw new RuntimeException( "Operator '" + operator + "' does not exist for ByteEvaluator" );
- }
- }
-
- static class ByteEqualEvaluator extends BaseEvaluator {
- /**
- *
- */
- private static final long serialVersionUID = 400L;
- public final static Evaluator INSTANCE = new ByteEqualEvaluator();
-
- private ByteEqualEvaluator() {
- super( ValueType.PBYTE_TYPE,
- Operator.EQUAL );
- }
-
- public boolean evaluate(InternalWorkingMemory workingMemory,
- final Extractor extractor,
- final Object object1, final FieldValue object2) {
- if ( extractor.isNullValue( workingMemory, object1 ) ) {
- return object2.isNull();
- } else if ( object2.isNull() ) {
- return false;
- }
-
- return extractor.getByteValue( workingMemory, object1 ) == object2.getByteValue();
- }
-
- public boolean evaluateCachedRight(InternalWorkingMemory workingMemory,
- final VariableContextEntry context, final Object left) {
- if ( context.declaration.getExtractor().isNullValue( workingMemory, left ) ) {
- return context.isRightNull();
- } else if ( context.isRightNull() ) {
- return false;
- }
-
- return context.declaration.getExtractor().getByteValue( workingMemory, left ) == ((LongVariableContextEntry) context).right;
- }
-
- public boolean evaluateCachedLeft(InternalWorkingMemory workingMemory,
- final VariableContextEntry context, final Object right) {
- if ( context.extractor.isNullValue( workingMemory, right )) {
- return context.isLeftNull();
- } else if ( context.isLeftNull() ) {
- return false;
- }
-
- return ((LongVariableContextEntry) context).left == context.extractor.getByteValue( workingMemory, right );
- }
-
- public boolean evaluate(InternalWorkingMemory workingMemory,
- final Extractor extractor1,
- final Object object1,
- final Extractor extractor2, final Object object2) {
- if (extractor1.isNullValue( workingMemory, object1 )) {
- return extractor2.isNullValue( workingMemory, object2 );
- } else if (extractor2.isNullValue( workingMemory, object2 )) {
- return false;
- }
-
- return extractor1.getByteValue( workingMemory, object1 ) == extractor2.getByteValue( workingMemory, object2 );
- }
-
- public String toString() {
- return "Byte ==";
- }
-
- }
-
- static class ByteNotEqualEvaluator extends BaseEvaluator {
- /**
- *
- */
- private static final long serialVersionUID = 400L;
- public final static Evaluator INSTANCE = new ByteNotEqualEvaluator();
-
- private ByteNotEqualEvaluator() {
- super( ValueType.PBYTE_TYPE,
- Operator.NOT_EQUAL );
- }
-
- public boolean evaluate(InternalWorkingMemory workingMemory,
- final Extractor extractor,
- final Object object1, final FieldValue object2) {
- if ( extractor.isNullValue( workingMemory, object1 ) ) {
- return !object2.isNull();
- } else if ( object2.isNull() ) {
- return true;
- }
-
- return extractor.getByteValue( workingMemory, object1 ) != object2.getByteValue();
- }
-
- public boolean evaluateCachedRight(InternalWorkingMemory workingMemory,
- final VariableContextEntry context, final Object left) {
- if ( context.declaration.getExtractor().isNullValue( workingMemory, left ) ) {
- return !context.isRightNull();
- } else if ( context.isRightNull() ) {
- return true;
- }
-
- return context.declaration.getExtractor().getByteValue( workingMemory, left ) != ((LongVariableContextEntry) context).right;
- }
-
- public boolean evaluateCachedLeft(InternalWorkingMemory workingMemory,
- final VariableContextEntry context, final Object object2) {
- if ( context.extractor.isNullValue( workingMemory, object2 ) ) {
- return !context.isLeftNull();
- } else if ( context.isLeftNull() ) {
- return true;
- }
-
- return ((LongVariableContextEntry) context).left != context.extractor.getByteValue( workingMemory, object2 );
- }
-
- public boolean evaluate(InternalWorkingMemory workingMemory,
- final Extractor extractor1,
- final Object object1,
- final Extractor extractor2, final Object object2) {
- if (extractor1.isNullValue( workingMemory, object1 )) {
- return !extractor2.isNullValue( workingMemory, object2 );
- } else if (extractor2.isNullValue( workingMemory, object2 )) {
- return true;
- }
-
- return extractor1.getByteValue( workingMemory, object1 ) != extractor2.getByteValue( workingMemory, object2 );
- }
-
- public String toString() {
- return "Byte !=";
- }
- }
-
- static class ByteLessEvaluator extends BaseEvaluator {
- /**
- *
- */
- private static final long serialVersionUID = 400L;
- public final static Evaluator INSTANCE = new ByteLessEvaluator();
-
- private ByteLessEvaluator() {
- super( ValueType.PBYTE_TYPE,
- Operator.LESS );
- }
-
- public boolean evaluate(InternalWorkingMemory workingMemory,
- final Extractor extractor,
- final Object object1, final FieldValue object2) {
- if( extractor.isNullValue( workingMemory, object1 ) ) {
- return false;
- }
- return extractor.getByteValue( workingMemory, object1 ) < object2.getByteValue();
- }
-
- public boolean evaluateCachedRight(InternalWorkingMemory workingMemory,
- final VariableContextEntry context, final Object left) {
- if( context.rightNull ) {
- return false;
- }
- return ((LongVariableContextEntry) context).right < context.declaration.getExtractor().getByteValue( workingMemory, left );
- }
-
- public boolean evaluateCachedLeft(InternalWorkingMemory workingMemory,
- final VariableContextEntry context, final Object right) {
- if( context.extractor.isNullValue( workingMemory, right ) ) {
- return false;
- }
- return context.extractor.getByteValue( workingMemory, right ) < ((LongVariableContextEntry) context).left;
- }
-
- public boolean evaluate(InternalWorkingMemory workingMemory,
- final Extractor extractor1,
- final Object object1,
- final Extractor extractor2, final Object object2) {
- if( extractor1.isNullValue( workingMemory, object1 ) ) {
- return false;
- }
- return extractor1.getByteValue( workingMemory, object1 ) < extractor2.getByteValue( workingMemory, object2 );
- }
-
- public String toString() {
- return "Byte <";
- }
- }
-
- static class ByteLessOrEqualEvaluator extends BaseEvaluator {
- /**
- *
- */
- private static final long serialVersionUID = 400L;
- public final static Evaluator INSTANCE = new ByteLessOrEqualEvaluator();
-
- private ByteLessOrEqualEvaluator() {
- super( ValueType.PBYTE_TYPE,
- Operator.LESS_OR_EQUAL );
- }
-
- public boolean evaluate(InternalWorkingMemory workingMemory,
- final Extractor extractor,
- final Object object1, final FieldValue object2) {
- if( extractor.isNullValue( workingMemory, object1 ) ) {
- return false;
- }
- return extractor.getByteValue( workingMemory, object1 ) <= object2.getByteValue();
- }
-
- public boolean evaluateCachedRight(InternalWorkingMemory workingMemory,
- final VariableContextEntry context, final Object left) {
- if( context.rightNull ) {
- return false;
- }
- return ((LongVariableContextEntry) context).right <= context.declaration.getExtractor().getByteValue( workingMemory, left );
- }
-
- public boolean evaluateCachedLeft(InternalWorkingMemory workingMemory,
- final VariableContextEntry context, final Object right) {
- if( context.extractor.isNullValue( workingMemory, right ) ) {
- return false;
- }
- return context.extractor.getByteValue( workingMemory, right ) <= ((LongVariableContextEntry) context).left;
- }
-
- public boolean evaluate(InternalWorkingMemory workingMemory,
- final Extractor extractor1,
- final Object object1,
- final Extractor extractor2, final Object object2) {
- if( extractor1.isNullValue( workingMemory, object1 ) ) {
- return false;
- }
- return extractor1.getByteValue( workingMemory, object1 ) <= extractor2.getByteValue( workingMemory, object2 );
- }
-
- public String toString() {
- return "Byte <=";
- }
- }
-
- static class ByteGreaterEvaluator extends BaseEvaluator {
- /**
- *
- */
- private static final long serialVersionUID = 400L;
- public final static Evaluator INSTANCE = new ByteGreaterEvaluator();
-
- private ByteGreaterEvaluator() {
- super( ValueType.PBYTE_TYPE,
- Operator.GREATER );
- }
-
- public boolean evaluate(InternalWorkingMemory workingMemory,
- final Extractor extractor,
- final Object object1, final FieldValue object2) {
- if( extractor.isNullValue( workingMemory, object1 ) ) {
- return false;
- }
- return extractor.getByteValue( workingMemory, object1 ) > object2.getByteValue();
- }
-
- public boolean evaluateCachedRight(InternalWorkingMemory workingMemory,
- final VariableContextEntry context, final Object left) {
- if( context.rightNull ) {
- return false;
- }
- return ((LongVariableContextEntry) context).right > context.declaration.getExtractor().getByteValue( workingMemory, left );
- }
-
- public boolean evaluateCachedLeft(InternalWorkingMemory workingMemory,
- final VariableContextEntry context, final Object right) {
- if( context.extractor.isNullValue( workingMemory, right ) ) {
- return false;
- }
- return context.extractor.getByteValue( workingMemory, right ) > ((LongVariableContextEntry) context).left;
- }
-
- public boolean evaluate(InternalWorkingMemory workingMemory,
- final Extractor extractor1,
- final Object object1,
- final Extractor extractor2, final Object object2) {
- if( extractor1.isNullValue( workingMemory, object1 ) ) {
- return false;
- }
- return extractor1.getByteValue( workingMemory, object1 ) > extractor2.getByteValue( workingMemory, object2 );
- }
-
- public String toString() {
- return "Byte >";
- }
- }
-
- static class ByteGreaterOrEqualEvaluator extends BaseEvaluator {
- /**
- *
- */
- private static final long serialVersionUID = 400L;
- private final static Evaluator INSTANCE = new ByteGreaterOrEqualEvaluator();
-
- private ByteGreaterOrEqualEvaluator() {
- super( ValueType.PBYTE_TYPE,
- Operator.GREATER_OR_EQUAL );
- }
-
- public boolean evaluate(InternalWorkingMemory workingMemory,
- final Extractor extractor,
- final Object object1, final FieldValue object2) {
- if( extractor.isNullValue( workingMemory, object1 ) ) {
- return false;
- }
- return extractor.getByteValue( workingMemory, object1 ) >= object2.getByteValue();
- }
-
- public boolean evaluateCachedRight(InternalWorkingMemory workingMemory,
- final VariableContextEntry context, final Object left) {
- if( context.rightNull ) {
- return false;
- }
- return ((LongVariableContextEntry) context).right >= context.declaration.getExtractor().getByteValue( workingMemory, left );
- }
-
- public boolean evaluateCachedLeft(InternalWorkingMemory workingMemory,
- final VariableContextEntry context, final Object right) {
- if( context.extractor.isNullValue( workingMemory, right ) ) {
- return false;
- }
- return context.extractor.getByteValue( workingMemory, right ) >= ((LongVariableContextEntry) context).left;
- }
-
- public boolean evaluate(InternalWorkingMemory workingMemory,
- final Extractor extractor1,
- final Object object1,
- final Extractor extractor2, final Object object2) {
- if( extractor1.isNullValue( workingMemory, object1 ) ) {
- return false;
- }
- return extractor1.getByteValue( workingMemory, object1 ) >= extractor2.getByteValue( workingMemory, object2 );
- }
-
- public String toString() {
- return "Byte >=";
- }
- }
-
- static class ByteMemberOfEvaluator extends BaseMemberOfEvaluator {
-
- private static final long serialVersionUID = 400L;
- public final static Evaluator INSTANCE = new ByteMemberOfEvaluator();
-
- private ByteMemberOfEvaluator() {
- super( ValueType.PBYTE_TYPE,
- Operator.MEMBEROF );
- }
-
- public String toString() {
- return "Byte memberOf";
- }
- }
-
- static class ByteNotMemberOfEvaluator extends BaseNotMemberOfEvaluator {
-
- private static final long serialVersionUID = 400L;
- public final static Evaluator INSTANCE = new ByteNotMemberOfEvaluator();
-
- private ByteNotMemberOfEvaluator() {
- super( ValueType.PBYTE_TYPE,
- Operator.NOTMEMBEROF );
- }
-
- public String toString() {
- return "Byte not memberOf";
- }
- }
-
-}
\ No newline at end of file
Deleted: labs/jbossrules/branches/temporal_rete/drools-core/src/main/java/org/drools/base/evaluators/CharacterFactory.java
===================================================================
--- labs/jbossrules/branches/temporal_rete/drools-core/src/main/java/org/drools/base/evaluators/CharacterFactory.java 2007-12-07 13:39:06 UTC (rev 17088)
+++ labs/jbossrules/branches/temporal_rete/drools-core/src/main/java/org/drools/base/evaluators/CharacterFactory.java 2007-12-07 14:10:27 UTC (rev 17089)
@@ -1,434 +0,0 @@
-package org.drools.base.evaluators;
-
-/*
- * Copyright 2005 JBoss Inc
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-import org.drools.base.BaseEvaluator;
-import org.drools.base.ValueType;
-import org.drools.common.InternalWorkingMemory;
-import org.drools.rule.VariableRestriction.CharVariableContextEntry;
-import org.drools.rule.VariableRestriction.VariableContextEntry;
-import org.drools.spi.Evaluator;
-import org.drools.spi.Extractor;
-import org.drools.spi.FieldValue;
-
-public class CharacterFactory
- implements
- EvaluatorFactory {
-
- private static final long serialVersionUID = 400L;
- private static EvaluatorFactory INSTANCE = new CharacterFactory();
-
- private CharacterFactory() {
-
- }
-
- public static EvaluatorFactory getInstance() {
- if ( CharacterFactory.INSTANCE == null ) {
- CharacterFactory.INSTANCE = new CharacterFactory();
- }
- return CharacterFactory.INSTANCE;
- }
-
- public Evaluator getEvaluator(final Operator operator) {
- if ( operator == Operator.EQUAL ) {
- return CharacterEqualEvaluator.INSTANCE;
- } else if ( operator == Operator.NOT_EQUAL ) {
- return CharacterNotEqualEvaluator.INSTANCE;
- } else if ( operator == Operator.LESS ) {
- return CharacterLessEvaluator.INSTANCE;
- } else if ( operator == Operator.LESS_OR_EQUAL ) {
- return CharacterLessOrEqualEvaluator.INSTANCE;
- } else if ( operator == Operator.GREATER ) {
- return CharacterGreaterEvaluator.INSTANCE;
- } else if ( operator == Operator.GREATER_OR_EQUAL ) {
- return CharacterGreaterOrEqualEvaluator.INSTANCE;
- } else if ( operator == Operator.MEMBEROF ) {
- return CharacterMemberOfEvaluator.INSTANCE;
- } else if ( operator == Operator.NOTMEMBEROF ) {
- return CharacterNotMemberOfEvaluator.INSTANCE;
- } else {
- throw new RuntimeException( "Operator '" + operator + "' does not exist for CharacterEvaluator" );
- }
- }
-
- static class CharacterEqualEvaluator extends BaseEvaluator {
- /**
- *
- */
- private static final long serialVersionUID = 400L;
- public final static Evaluator INSTANCE = new CharacterEqualEvaluator();
-
- private CharacterEqualEvaluator() {
- super( ValueType.PCHAR_TYPE,
- Operator.EQUAL );
- }
-
- public boolean evaluate(InternalWorkingMemory workingMemory,
- final Extractor extractor,
- final Object object1, final FieldValue object2) {
- if ( extractor.isNullValue( workingMemory, object1 ) ) {
- return object2.isNull();
- } else if ( object2.isNull() ) {
- return false;
- }
-
- return extractor.getCharValue( workingMemory, object1 ) == object2.getCharValue();
- }
-
- public boolean evaluateCachedRight(InternalWorkingMemory workingMemory,
- final VariableContextEntry context, final Object left) {
- if ( context.declaration.getExtractor().isNullValue( workingMemory, left ) ) {
- return context.isRightNull();
- } else if ( context.isRightNull() ) {
- return false;
- }
-
- return context.declaration.getExtractor().getCharValue( workingMemory, left ) == ((CharVariableContextEntry) context).right;
- }
-
- public boolean evaluateCachedLeft(InternalWorkingMemory workingMemory,
- final VariableContextEntry context, final Object right) {
- if ( context.extractor.isNullValue( workingMemory, right )) {
- return context.isLeftNull();
- } else if ( context.isLeftNull() ) {
- return false;
- }
-
- return ((CharVariableContextEntry) context).left == context.extractor.getCharValue( workingMemory, right );
- }
-
- public boolean evaluate(InternalWorkingMemory workingMemory,
- final Extractor extractor1,
- final Object object1,
- final Extractor extractor2, final Object object2) {
- if (extractor1.isNullValue( workingMemory, object1 )) {
- return extractor2.isNullValue( workingMemory, object2 );
- } else if (extractor2.isNullValue( workingMemory, object2 )) {
- return false;
- }
-
- return extractor1.getCharValue( workingMemory, object1 ) == extractor2.getCharValue( workingMemory, object2 );
- }
-
- public String toString() {
- return "Character ==";
- }
- }
-
- static class CharacterNotEqualEvaluator extends BaseEvaluator {
- /**
- *
- */
- private static final long serialVersionUID = 400L;
- public final static Evaluator INSTANCE = new CharacterNotEqualEvaluator();
-
- private CharacterNotEqualEvaluator() {
- super( ValueType.PCHAR_TYPE,
- Operator.NOT_EQUAL );
- }
-
- public boolean evaluate(InternalWorkingMemory workingMemory,
- final Extractor extractor,
- final Object object1, final FieldValue object2) {
- if ( extractor.isNullValue( workingMemory, object1 ) ) {
- return !object2.isNull();
- } else if ( object2.isNull() ) {
- return true;
- }
-
- return extractor.getCharValue( workingMemory, object1 ) != object2.getCharValue();
- }
-
- public boolean evaluateCachedRight(InternalWorkingMemory workingMemory,
- final VariableContextEntry context, final Object left) {
- if ( context.declaration.getExtractor().isNullValue( workingMemory, left ) ) {
- return !context.isRightNull();
- } else if ( context.isRightNull() ) {
- return true;
- }
-
- return context.declaration.getExtractor().getCharValue( workingMemory, left ) != ((CharVariableContextEntry) context).right;
- }
-
- public boolean evaluateCachedLeft(InternalWorkingMemory workingMemory,
- final VariableContextEntry context, final Object right) {
- if ( context.extractor.isNullValue( workingMemory, right ) ) {
- return !context.isLeftNull();
- } else if ( context.isLeftNull() ) {
- return true;
- }
-
- return ((CharVariableContextEntry) context).left != context.extractor.getCharValue( workingMemory, right );
- }
-
- public boolean evaluate(InternalWorkingMemory workingMemory,
- final Extractor extractor1,
- final Object object1,
- final Extractor extractor2, final Object object2) {
- if (extractor1.isNullValue( workingMemory, object1 )) {
- return !extractor2.isNullValue( workingMemory, object2 );
- } else if (extractor2.isNullValue( workingMemory, object2 )) {
- return true;
- }
-
- return extractor1.getCharValue( workingMemory, object1 ) != extractor2.getCharValue( workingMemory, object2 );
- }
-
- public String toString() {
- return "Character !=";
- }
- }
-
- static class CharacterLessEvaluator extends BaseEvaluator {
- /**
- *
- */
- private static final long serialVersionUID = 400L;
- public final static Evaluator INSTANCE = new CharacterLessEvaluator();
-
- private CharacterLessEvaluator() {
- super( ValueType.PCHAR_TYPE,
- Operator.LESS );
- }
-
- public boolean evaluate(InternalWorkingMemory workingMemory,
- final Extractor extractor,
- final Object object1, final FieldValue object2) {
- if( extractor.isNullValue( workingMemory, object1 ) ) {
- return false;
- }
- return extractor.getCharValue( workingMemory, object1 ) < object2.getCharValue();
- }
-
- public boolean evaluateCachedRight(InternalWorkingMemory workingMemory,
- final VariableContextEntry context, final Object left) {
- if( context.rightNull ) {
- return false;
- }
- return ((CharVariableContextEntry) context).right < context.declaration.getExtractor().getCharValue( workingMemory, left );
- }
-
- public boolean evaluateCachedLeft(InternalWorkingMemory workingMemory,
- final VariableContextEntry context, final Object right) {
- if( context.extractor.isNullValue( workingMemory, right ) ) {
- return false;
- }
- return context.extractor.getCharValue( workingMemory, right ) < ((CharVariableContextEntry) context).left;
- }
-
- public boolean evaluate(InternalWorkingMemory workingMemory,
- final Extractor extractor1,
- final Object object1,
- final Extractor extractor2, final Object object2) {
- if( extractor1.isNullValue( workingMemory, object1 ) ) {
- return false;
- }
- return extractor1.getCharValue( workingMemory, object1 ) < extractor2.getCharValue( workingMemory, object2 );
- }
-
- public String toString() {
- return "Character <";
- }
- }
-
- static class CharacterLessOrEqualEvaluator extends BaseEvaluator {
- /**
- *
- */
- private static final long serialVersionUID = 400L;
- public final static Evaluator INSTANCE = new CharacterLessOrEqualEvaluator();
-
- private CharacterLessOrEqualEvaluator() {
- super( ValueType.PCHAR_TYPE,
- Operator.LESS_OR_EQUAL );
- }
-
- public boolean evaluate(InternalWorkingMemory workingMemory,
- final Extractor extractor,
- final Object object1, final FieldValue object2) {
- if( extractor.isNullValue( workingMemory, object1 ) ) {
- return false;
- }
- return extractor.getCharValue( workingMemory, object1 ) <= object2.getCharValue();
- }
-
- public boolean evaluateCachedRight(InternalWorkingMemory workingMemory,
- final VariableContextEntry context, final Object left) {
- if( context.rightNull ) {
- return false;
- }
- return ((CharVariableContextEntry) context).right <= context.declaration.getExtractor().getCharValue( workingMemory, left );
- }
-
- public boolean evaluateCachedLeft(InternalWorkingMemory workingMemory,
- final VariableContextEntry context, final Object right) {
- if( context.extractor.isNullValue( workingMemory, right ) ) {
- return false;
- }
- return context.extractor.getCharValue( workingMemory, right ) <= ((CharVariableContextEntry) context).left;
- }
-
- public boolean evaluate(InternalWorkingMemory workingMemory,
- final Extractor extractor1,
- final Object object1,
- final Extractor extractor2, final Object object2) {
- if( extractor1.isNullValue( workingMemory, object1 ) ) {
- return false;
- }
- return extractor1.getCharValue( workingMemory, object1 ) <= extractor2.getCharValue( workingMemory, object2 );
- }
-
- public String toString() {
- return "Character <=";
- }
- }
-
- static class CharacterGreaterEvaluator extends BaseEvaluator {
- /**
- *
- */
- private static final long serialVersionUID = 400L;
- public final static Evaluator INSTANCE = new CharacterGreaterEvaluator();
-
- private CharacterGreaterEvaluator() {
- super( ValueType.PCHAR_TYPE,
- Operator.GREATER );
- }
-
- public boolean evaluate(InternalWorkingMemory workingMemory,
- final Extractor extractor,
- final Object object1, final FieldValue object2) {
- if( extractor.isNullValue( workingMemory, object1 ) ) {
- return false;
- }
- return extractor.getCharValue( workingMemory, object1 ) > object2.getCharValue();
- }
-
- public boolean evaluateCachedRight(InternalWorkingMemory workingMemory,
- final VariableContextEntry context, final Object left) {
- if( context.rightNull ) {
- return false;
- }
- return ((CharVariableContextEntry) context).right > context.declaration.getExtractor().getCharValue( workingMemory, left );
- }
-
- public boolean evaluateCachedLeft(InternalWorkingMemory workingMemory,
- final VariableContextEntry context, final Object right) {
- if( context.extractor.isNullValue( workingMemory, right ) ) {
- return false;
- }
- return context.extractor.getCharValue( workingMemory, right ) > ((CharVariableContextEntry) context).left;
- }
-
- public boolean evaluate(InternalWorkingMemory workingMemory,
- final Extractor extractor1,
- final Object object1,
- final Extractor extractor2, final Object object2) {
- if( extractor1.isNullValue( workingMemory, object1 ) ) {
- return false;
- }
- return extractor1.getCharValue( workingMemory, object1 ) > extractor2.getCharValue( workingMemory, object2 );
- }
-
- public String toString() {
- return "Character >";
- }
- }
-
- static class CharacterGreaterOrEqualEvaluator extends BaseEvaluator {
- /**
- *
- */
- private static final long serialVersionUID = 400L;
- private final static Evaluator INSTANCE = new CharacterGreaterOrEqualEvaluator();
-
- private CharacterGreaterOrEqualEvaluator() {
- super( ValueType.PCHAR_TYPE,
- Operator.GREATER_OR_EQUAL );
- }
-
- public boolean evaluate(InternalWorkingMemory workingMemory,
- final Extractor extractor,
- final Object object1, final FieldValue object2) {
- if( extractor.isNullValue( workingMemory, object1 ) ) {
- return false;
- }
- return extractor.getCharValue( workingMemory, object1 ) >= object2.getCharValue();
- }
-
- public boolean evaluateCachedRight(InternalWorkingMemory workingMemory,
- final VariableContextEntry context, final Object left) {
- if( context.rightNull ) {
- return false;
- }
- return ((CharVariableContextEntry) context).right >= context.declaration.getExtractor().getCharValue( workingMemory, left );
- }
-
- public boolean evaluateCachedLeft(InternalWorkingMemory workingMemory,
- final VariableContextEntry context, final Object right) {
- if( context.extractor.isNullValue( workingMemory, right ) ) {
- return false;
- }
- return context.extractor.getCharValue( workingMemory, right ) >= ((CharVariableContextEntry) context).left;
- }
-
- public boolean evaluate(InternalWorkingMemory workingMemory,
- final Extractor extractor1,
- final Object object1,
- final Extractor extractor2, final Object object2) {
- if( extractor1.isNullValue( workingMemory, object1 ) ) {
- return false;
- }
- return extractor1.getCharValue( workingMemory, object1 ) >= extractor2.getCharValue( workingMemory, object2 );
- }
-
- public String toString() {
- return "Character >=";
- }
- }
-
- static class CharacterMemberOfEvaluator extends BaseMemberOfEvaluator {
-
- private static final long serialVersionUID = 400L;
- public final static Evaluator INSTANCE = new CharacterMemberOfEvaluator();
-
- private CharacterMemberOfEvaluator() {
- super( ValueType.PCHAR_TYPE,
- Operator.MEMBEROF );
- }
-
- public String toString() {
- return "Character memberOf";
- }
- }
-
- static class CharacterNotMemberOfEvaluator extends BaseNotMemberOfEvaluator {
-
- private static final long serialVersionUID = 400L;
- public final static Evaluator INSTANCE = new CharacterNotMemberOfEvaluator();
-
- private CharacterNotMemberOfEvaluator() {
- super( ValueType.PCHAR_TYPE,
- Operator.NOTMEMBEROF );
- }
-
- public String toString() {
- return "Character not memberOf";
- }
- }
-
-}
\ No newline at end of file
Added: labs/jbossrules/branches/temporal_rete/drools-core/src/main/java/org/drools/base/evaluators/ComparableEvaluatorsDefinition.java
===================================================================
--- labs/jbossrules/branches/temporal_rete/drools-core/src/main/java/org/drools/base/evaluators/ComparableEvaluatorsDefinition.java (rev 0)
+++ labs/jbossrules/branches/temporal_rete/drools-core/src/main/java/org/drools/base/evaluators/ComparableEvaluatorsDefinition.java 2007-12-07 14:10:27 UTC (rev 17089)
@@ -0,0 +1,2571 @@
+/*
+ * Copyright 2007 JBoss Inc
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ * Created on Dec 6, 2007
+ */
+package org.drools.base.evaluators;
+
+import java.math.BigDecimal;
+import java.math.BigInteger;
+import java.util.Date;
+
+import org.drools.base.BaseEvaluator;
+import org.drools.base.ValueType;
+import org.drools.common.InternalWorkingMemory;
+import org.drools.rule.VariableRestriction.CharVariableContextEntry;
+import org.drools.rule.VariableRestriction.DoubleVariableContextEntry;
+import org.drools.rule.VariableRestriction.LongVariableContextEntry;
+import org.drools.rule.VariableRestriction.ObjectVariableContextEntry;
+import org.drools.rule.VariableRestriction.VariableContextEntry;
+import org.drools.spi.Evaluator;
+import org.drools.spi.Extractor;
+import org.drools.spi.FieldValue;
+import org.drools.util.DateUtils;
+
+/**
+ * This class defines all the comparable built in
+ * evaluators like >, >=, etc.
+ *
+ * @author etirelli
+ */
+public class ComparableEvaluatorsDefinition implements EvaluatorDefinition {
+
+ private static final String[] SUPPORTED_IDS = { Operator.LESS.getOperatorString(), Operator.LESS_OR_EQUAL.getOperatorString(),
+ Operator.GREATER.getOperatorString(), Operator.GREATER_OR_EQUAL.getOperatorString() };
+ private EvaluatorRegistry evaluators = new EvaluatorRegistry() {
+ private static final long serialVersionUID = 4782368623L;
+ {
+ addEvaluator( ValueType.BIG_DECIMAL_TYPE, Operator.LESS, BigDecimalLessEvaluator.INSTANCE );
+ addEvaluator( ValueType.BIG_DECIMAL_TYPE, Operator.LESS_OR_EQUAL, BigDecimalLessOrEqualEvaluator.INSTANCE );
+ addEvaluator( ValueType.BIG_DECIMAL_TYPE, Operator.GREATER, BigDecimalGreaterEvaluator.INSTANCE );
+ addEvaluator( ValueType.BIG_DECIMAL_TYPE, Operator.GREATER_OR_EQUAL, BigDecimalGreaterOrEqualEvaluator.INSTANCE );
+ addEvaluator( ValueType.BIG_INTEGER_TYPE, Operator.LESS, BigIntegerLessEvaluator.INSTANCE );
+ addEvaluator( ValueType.BIG_INTEGER_TYPE, Operator.LESS_OR_EQUAL, BigIntegerLessOrEqualEvaluator.INSTANCE );
+ addEvaluator( ValueType.BIG_INTEGER_TYPE, Operator.GREATER, BigIntegerGreaterEvaluator.INSTANCE );
+ addEvaluator( ValueType.BIG_INTEGER_TYPE, Operator.GREATER_OR_EQUAL, BigIntegerGreaterOrEqualEvaluator.INSTANCE );
+ addEvaluator( ValueType.BYTE_TYPE, Operator.LESS, ByteLessEvaluator.INSTANCE );
+ addEvaluator( ValueType.BYTE_TYPE, Operator.LESS_OR_EQUAL, ByteLessOrEqualEvaluator.INSTANCE );
+ addEvaluator( ValueType.BYTE_TYPE, Operator.GREATER, ByteGreaterEvaluator.INSTANCE );
+ addEvaluator( ValueType.BYTE_TYPE, Operator.GREATER_OR_EQUAL, ByteGreaterOrEqualEvaluator.INSTANCE );
+ addEvaluator( ValueType.PBYTE_TYPE, Operator.LESS, ByteLessEvaluator.INSTANCE );
+ addEvaluator( ValueType.PBYTE_TYPE, Operator.LESS_OR_EQUAL, ByteLessOrEqualEvaluator.INSTANCE );
+ addEvaluator( ValueType.PBYTE_TYPE, Operator.GREATER, ByteGreaterEvaluator.INSTANCE );
+ addEvaluator( ValueType.PBYTE_TYPE, Operator.GREATER_OR_EQUAL, ByteGreaterOrEqualEvaluator.INSTANCE );
+ addEvaluator( ValueType.CHAR_TYPE, Operator.LESS, CharacterLessEvaluator.INSTANCE );
+ addEvaluator( ValueType.CHAR_TYPE, Operator.LESS_OR_EQUAL, CharacterLessOrEqualEvaluator.INSTANCE );
+ addEvaluator( ValueType.CHAR_TYPE, Operator.GREATER, CharacterGreaterEvaluator.INSTANCE );
+ addEvaluator( ValueType.CHAR_TYPE, Operator.GREATER_OR_EQUAL, CharacterGreaterOrEqualEvaluator.INSTANCE );
+ addEvaluator( ValueType.PCHAR_TYPE, Operator.LESS, CharacterLessEvaluator.INSTANCE );
+ addEvaluator( ValueType.PCHAR_TYPE, Operator.LESS_OR_EQUAL, CharacterLessOrEqualEvaluator.INSTANCE );
+ addEvaluator( ValueType.PCHAR_TYPE, Operator.GREATER, CharacterGreaterEvaluator.INSTANCE );
+ addEvaluator( ValueType.PCHAR_TYPE, Operator.GREATER_OR_EQUAL, CharacterGreaterOrEqualEvaluator.INSTANCE );
+ addEvaluator( ValueType.DATE_TYPE, Operator.LESS, DateLessEvaluator.INSTANCE );
+ addEvaluator( ValueType.DATE_TYPE, Operator.LESS_OR_EQUAL, DateLessOrEqualEvaluator.INSTANCE );
+ addEvaluator( ValueType.DATE_TYPE, Operator.GREATER, DateGreaterEvaluator.INSTANCE );
+ addEvaluator( ValueType.DATE_TYPE, Operator.GREATER_OR_EQUAL, DateGreaterOrEqualEvaluator.INSTANCE );
+ addEvaluator( ValueType.DOUBLE_TYPE, Operator.LESS, DoubleLessEvaluator.INSTANCE );
+ addEvaluator( ValueType.DOUBLE_TYPE, Operator.LESS_OR_EQUAL, DoubleLessOrEqualEvaluator.INSTANCE );
+ addEvaluator( ValueType.DOUBLE_TYPE, Operator.GREATER, DoubleGreaterEvaluator.INSTANCE );
+ addEvaluator( ValueType.DOUBLE_TYPE, Operator.GREATER_OR_EQUAL, DoubleGreaterOrEqualEvaluator.INSTANCE );
+ addEvaluator( ValueType.PDOUBLE_TYPE, Operator.LESS, DoubleLessEvaluator.INSTANCE );
+ addEvaluator( ValueType.PDOUBLE_TYPE, Operator.LESS_OR_EQUAL, DoubleLessOrEqualEvaluator.INSTANCE );
+ addEvaluator( ValueType.PDOUBLE_TYPE, Operator.GREATER, DoubleGreaterEvaluator.INSTANCE );
+ addEvaluator( ValueType.PDOUBLE_TYPE, Operator.GREATER_OR_EQUAL, DoubleGreaterOrEqualEvaluator.INSTANCE );
+ addEvaluator( ValueType.FLOAT_TYPE, Operator.LESS, FloatLessEvaluator.INSTANCE );
+ addEvaluator( ValueType.FLOAT_TYPE, Operator.LESS_OR_EQUAL, FloatLessOrEqualEvaluator.INSTANCE );
+ addEvaluator( ValueType.FLOAT_TYPE, Operator.GREATER, FloatGreaterEvaluator.INSTANCE );
+ addEvaluator( ValueType.FLOAT_TYPE, Operator.GREATER_OR_EQUAL, FloatGreaterOrEqualEvaluator.INSTANCE );
+ addEvaluator( ValueType.PFLOAT_TYPE, Operator.LESS, FloatLessEvaluator.INSTANCE );
+ addEvaluator( ValueType.PFLOAT_TYPE, Operator.LESS_OR_EQUAL, FloatLessOrEqualEvaluator.INSTANCE );
+ addEvaluator( ValueType.PFLOAT_TYPE, Operator.GREATER, FloatGreaterEvaluator.INSTANCE );
+ addEvaluator( ValueType.PFLOAT_TYPE, Operator.GREATER_OR_EQUAL, FloatGreaterOrEqualEvaluator.INSTANCE );
+ addEvaluator( ValueType.INTEGER_TYPE, Operator.LESS, IntegerLessEvaluator.INSTANCE );
+ addEvaluator( ValueType.INTEGER_TYPE, Operator.LESS_OR_EQUAL, IntegerLessOrEqualEvaluator.INSTANCE );
+ addEvaluator( ValueType.INTEGER_TYPE, Operator.GREATER, IntegerGreaterEvaluator.INSTANCE );
+ addEvaluator( ValueType.INTEGER_TYPE, Operator.GREATER_OR_EQUAL, IntegerGreaterOrEqualEvaluator.INSTANCE );
+ addEvaluator( ValueType.PINTEGER_TYPE, Operator.LESS, IntegerLessEvaluator.INSTANCE );
+ addEvaluator( ValueType.PINTEGER_TYPE, Operator.LESS_OR_EQUAL, IntegerLessOrEqualEvaluator.INSTANCE );
+ addEvaluator( ValueType.PINTEGER_TYPE, Operator.GREATER, IntegerGreaterEvaluator.INSTANCE );
+ addEvaluator( ValueType.PINTEGER_TYPE, Operator.GREATER_OR_EQUAL, IntegerGreaterOrEqualEvaluator.INSTANCE );
+ addEvaluator( ValueType.LONG_TYPE, Operator.LESS, LongLessEvaluator.INSTANCE );
+ addEvaluator( ValueType.LONG_TYPE, Operator.LESS_OR_EQUAL, LongLessOrEqualEvaluator.INSTANCE );
+ addEvaluator( ValueType.LONG_TYPE, Operator.GREATER, LongGreaterEvaluator.INSTANCE );
+ addEvaluator( ValueType.LONG_TYPE, Operator.GREATER_OR_EQUAL, LongGreaterOrEqualEvaluator.INSTANCE );
+ addEvaluator( ValueType.PLONG_TYPE, Operator.LESS, LongLessEvaluator.INSTANCE );
+ addEvaluator( ValueType.PLONG_TYPE, Operator.LESS_OR_EQUAL, LongLessOrEqualEvaluator.INSTANCE );
+ addEvaluator( ValueType.PLONG_TYPE, Operator.GREATER, LongGreaterEvaluator.INSTANCE );
+ addEvaluator( ValueType.PLONG_TYPE, Operator.GREATER_OR_EQUAL, LongGreaterOrEqualEvaluator.INSTANCE );
+ addEvaluator( ValueType.OBJECT_TYPE, Operator.LESS, ObjectLessEvaluator.INSTANCE );
+ addEvaluator( ValueType.OBJECT_TYPE, Operator.LESS_OR_EQUAL, ObjectLessOrEqualEvaluator.INSTANCE );
+ addEvaluator( ValueType.OBJECT_TYPE, Operator.GREATER, ObjectGreaterEvaluator.INSTANCE );
+ addEvaluator( ValueType.OBJECT_TYPE, Operator.GREATER_OR_EQUAL, ObjectGreaterOrEqualEvaluator.INSTANCE );
+ addEvaluator( ValueType.SHORT_TYPE, Operator.LESS, ShortLessEvaluator.INSTANCE );
+ addEvaluator( ValueType.SHORT_TYPE, Operator.LESS_OR_EQUAL, ShortLessOrEqualEvaluator.INSTANCE );
+ addEvaluator( ValueType.SHORT_TYPE, Operator.GREATER, ShortGreaterEvaluator.INSTANCE );
+ addEvaluator( ValueType.SHORT_TYPE, Operator.GREATER_OR_EQUAL, ShortGreaterOrEqualEvaluator.INSTANCE );
+ addEvaluator( ValueType.PSHORT_TYPE, Operator.LESS, ShortLessEvaluator.INSTANCE );
+ addEvaluator( ValueType.PSHORT_TYPE, Operator.LESS_OR_EQUAL, ShortLessOrEqualEvaluator.INSTANCE );
+ addEvaluator( ValueType.PSHORT_TYPE, Operator.GREATER, ShortGreaterEvaluator.INSTANCE );
+ addEvaluator( ValueType.PSHORT_TYPE, Operator.GREATER_OR_EQUAL, ShortGreaterOrEqualEvaluator.INSTANCE );
+ }
+ };
+
+ /**
+ * @inheridDoc
+ */
+ public Evaluator getEvaluator(ValueType type,
+ Operator operator) {
+ return this.evaluators.getEvaluator( type,
+ operator );
+ }
+
+ /**
+ * @inheridDoc
+ */
+ public Evaluator getEvaluator(ValueType type,
+ Operator operator,
+ String parameterText) {
+ return this.evaluators.getEvaluator( type,
+ operator );
+ }
+
+ public Evaluator getEvaluator(final ValueType type,
+ final String operatorId,
+ final boolean isNegated,
+ final String parameterText) {
+ return this.evaluators.getEvaluator( type,
+ Operator.determineOperator( operatorId,
+ isNegated ) );
+ }
+
+ public String[] getEvaluatorIds() {
+ return SUPPORTED_IDS;
+ }
+
+ public boolean isNegatable() {
+ return false;
+ }
+
+ public boolean operatesOnFactHandles() {
+ return false;
+ }
+
+ public boolean supportsType(ValueType type) {
+ return this.evaluators.supportsType( type );
+ }
+
+ /* *********************************************************
+ * Evaluator Implementations
+ * *********************************************************
+ */
+ static class BigDecimalLessEvaluator extends BaseEvaluator {
+ /**
+ *
+ */
+ private static final long serialVersionUID = 400L;
+ public final static Evaluator INSTANCE = new BigDecimalLessEvaluator();
+
+ private BigDecimalLessEvaluator() {
+ super( ValueType.BIG_DECIMAL_TYPE,
+ Operator.LESS );
+ }
+
+ public boolean evaluate(InternalWorkingMemory workingMemory,
+ final Extractor extractor,
+ final Object object1, final FieldValue object2) {
+ if( extractor.isNullValue( workingMemory, object1 ) ) {
+ return false;
+ }
+ final BigDecimal comp = (BigDecimal) extractor.getValue( workingMemory, object1 );
+ return comp.compareTo( (BigDecimal) object2.getValue() ) < 0;
+ }
+
+ public boolean evaluateCachedRight(InternalWorkingMemory workingMemory,
+ final VariableContextEntry context, final Object left) {
+ if( context.rightNull ) {
+ return false;
+ }
+ final BigDecimal comp = (BigDecimal) ((ObjectVariableContextEntry) context).right;
+ return comp.compareTo( (BigDecimal) context.declaration.getExtractor().getValue( workingMemory, left ) ) < 0;
+ }
+
+ public boolean evaluateCachedLeft(InternalWorkingMemory workingMemory,
+ final VariableContextEntry context, final Object right) {
+ if( context.extractor.isNullValue( workingMemory, right ) ) {
+ return false;
+ }
+ final BigDecimal comp = (BigDecimal) context.extractor.getValue( workingMemory, right );
+ return comp.compareTo( (BigDecimal) ((ObjectVariableContextEntry) context).left ) < 0;
+ }
+
+ public boolean evaluate(InternalWorkingMemory workingMemory,
+ final Extractor extractor1,
+ final Object object1,
+ final Extractor extractor2, final Object object2) {
+ if( extractor1.isNullValue( workingMemory, object1 ) ) {
+ return false;
+ }
+ final BigDecimal comp = (BigDecimal) extractor1.getValue( workingMemory, object1 );
+ return comp.compareTo( (BigDecimal) extractor2.getValue( workingMemory, object2 ) ) < 0;
+ }
+
+ public String toString() {
+ return "BigDecimal <";
+ }
+ }
+
+ static class BigDecimalLessOrEqualEvaluator extends BaseEvaluator {
+ /**
+ *
+ */
+ private static final long serialVersionUID = 400L;
+ public final static Evaluator INSTANCE = new BigDecimalLessOrEqualEvaluator();
+
+ private BigDecimalLessOrEqualEvaluator() {
+ super( ValueType.BIG_DECIMAL_TYPE,
+ Operator.LESS_OR_EQUAL );
+ }
+
+ public boolean evaluate(InternalWorkingMemory workingMemory,
+ final Extractor extractor,
+ final Object object1, final FieldValue object2) {
+ if( extractor.isNullValue( workingMemory, object1 ) ) {
+ return false;
+ }
+ final BigDecimal comp = (BigDecimal) extractor.getValue( workingMemory, object1 );
+ return comp.compareTo( (BigDecimal) object2.getValue() ) <= 0;
+ }
+
+ public boolean evaluateCachedRight(InternalWorkingMemory workingMemory,
+ final VariableContextEntry context, final Object left) {
+ if( context.rightNull ) {
+ return false;
+ }
+ final BigDecimal comp = (BigDecimal) ((ObjectVariableContextEntry) context).right;
+ return comp.compareTo( (BigDecimal) context.declaration.getExtractor().getValue( workingMemory, left ) ) <= 0;
+ }
+
+ public boolean evaluateCachedLeft(InternalWorkingMemory workingMemory,
+ final VariableContextEntry context, final Object right) {
+ if( context.extractor.isNullValue( workingMemory, right ) ) {
+ return false;
+ }
+ final BigDecimal comp = (BigDecimal) context.extractor.getValue( workingMemory, right );
+ return comp.compareTo( (BigDecimal) ((ObjectVariableContextEntry) context).left ) <= 0;
+ }
+
+ public boolean evaluate(InternalWorkingMemory workingMemory,
+ final Extractor extractor1,
+ final Object object1,
+ final Extractor extractor2, final Object object2) {
+ if( extractor1.isNullValue( workingMemory, object1 ) ) {
+ return false;
+ }
+ final BigDecimal comp = (BigDecimal) extractor1.getValue( workingMemory, object1 );
+ return comp.compareTo( (BigDecimal) extractor2.getValue( workingMemory, object2 ) ) <= 0;
+ }
+
+ public String toString() {
+ return "BigDecimal <=";
+ }
+ }
+
+ static class BigDecimalGreaterEvaluator extends BaseEvaluator {
+ /**
+ *
+ */
+ private static final long serialVersionUID = 400L;
+ public final static Evaluator INSTANCE = new BigDecimalGreaterEvaluator();
+
+ private BigDecimalGreaterEvaluator() {
+ super( ValueType.BIG_DECIMAL_TYPE,
+ Operator.GREATER );
+ }
+
+ public boolean evaluate(InternalWorkingMemory workingMemory,
+ final Extractor extractor,
+ final Object object1, final FieldValue object2) {
+ if( extractor.isNullValue( workingMemory, object1 ) ) {
+ return false;
+ }
+ final BigDecimal comp = (BigDecimal) extractor.getValue( workingMemory, object1 );
+ return comp.compareTo( (BigDecimal) object2.getValue() ) > 0;
+ }
+
+ public boolean evaluateCachedRight(InternalWorkingMemory workingMemory,
+ final VariableContextEntry context, final Object left) {
+ if( context.rightNull ) {
+ return false;
+ }
+ final BigDecimal comp = (BigDecimal) ((ObjectVariableContextEntry) context).right;
+ return comp.compareTo( (BigDecimal) context.declaration.getExtractor().getValue( workingMemory, left ) ) > 0;
+ }
+
+ public boolean evaluateCachedLeft(InternalWorkingMemory workingMemory,
+ final VariableContextEntry context, final Object right) {
+ if( context.extractor.isNullValue( workingMemory, right ) ) {
+ return false;
+ }
+ final BigDecimal comp = (BigDecimal) context.extractor.getValue( workingMemory, right );
+ return comp.compareTo( (BigDecimal) ((ObjectVariableContextEntry) context).left ) > 0;
+ }
+
+ public boolean evaluate(InternalWorkingMemory workingMemory,
+ final Extractor extractor1,
+ final Object object1,
+ final Extractor extractor2, final Object object2) {
+ if( extractor1.isNullValue( workingMemory, object1 ) ) {
+ return false;
+ }
+ final BigDecimal comp = (BigDecimal) extractor1.getValue( workingMemory, object1 );
+ return comp.compareTo( (BigDecimal) extractor2.getValue( workingMemory, object2 ) ) > 0;
+ }
+
+ public String toString() {
+ return "BigDecimal >";
+ }
+ }
+
+ static class BigDecimalGreaterOrEqualEvaluator extends BaseEvaluator {
+ /**
+ *
+ */
+ private static final long serialVersionUID = 400L;
+ private final static Evaluator INSTANCE = new BigDecimalGreaterOrEqualEvaluator();
+
+ private BigDecimalGreaterOrEqualEvaluator() {
+ super( ValueType.BIG_DECIMAL_TYPE,
+ Operator.GREATER_OR_EQUAL );
+ }
+
+ public boolean evaluate(InternalWorkingMemory workingMemory,
+ final Extractor extractor,
+ final Object object1, final FieldValue object2) {
+ if( extractor.isNullValue( workingMemory, object1 ) ) {
+ return false;
+ }
+ final BigDecimal comp = (BigDecimal) extractor.getValue( workingMemory, object1 );
+ return comp.compareTo( (BigDecimal) object2.getValue() ) >= 0;
+ }
+
+ public boolean evaluateCachedRight(InternalWorkingMemory workingMemory,
+ final VariableContextEntry context, final Object left) {
+ if( context.rightNull ) {
+ return false;
+ }
+ final BigDecimal comp = (BigDecimal) ((ObjectVariableContextEntry) context).right;
+ return comp.compareTo( (BigDecimal) context.declaration.getExtractor().getValue( workingMemory, left ) ) >= 0;
+ }
+
+ public boolean evaluateCachedLeft(InternalWorkingMemory workingMemory,
+ final VariableContextEntry context, final Object right) {
+ if( context.extractor.isNullValue( workingMemory, right ) ) {
+ return false;
+ }
+ final BigDecimal comp = (BigDecimal) context.extractor.getValue( workingMemory, right );
+ return comp.compareTo( (BigDecimal) ((ObjectVariableContextEntry) context).left ) >= 0;
+ }
+
+ public boolean evaluate(InternalWorkingMemory workingMemory,
+ final Extractor extractor1,
+ final Object object1,
+ final Extractor extractor2, final Object object2) {
+ if( extractor1.isNullValue( workingMemory, object1 ) ) {
+ return false;
+ }
+ final BigDecimal comp = (BigDecimal) extractor1.getValue( workingMemory, object1 );
+ return comp.compareTo( (BigDecimal) extractor2.getValue( workingMemory, object2 ) ) >= 0;
+ }
+
+ public String toString() {
+ return "BigDecimal >=";
+ }
+ }
+
+ static class BigIntegerLessEvaluator extends BaseEvaluator {
+ /**
+ *
+ */
+ private static final long serialVersionUID = 400L;
+ public final static Evaluator INSTANCE = new BigIntegerLessEvaluator();
+
+ private BigIntegerLessEvaluator() {
+ super( ValueType.BIG_INTEGER_TYPE,
+ Operator.LESS );
+ }
+
+ public boolean evaluate(InternalWorkingMemory workingMemory,
+ final Extractor extractor,
+ final Object object1, final FieldValue object2) {
+ if( extractor.isNullValue( workingMemory, object1 ) ) {
+ return false;
+ }
+ final BigInteger comp = (BigInteger) extractor.getValue( workingMemory, object1 );
+ return comp.compareTo( (BigInteger) object2.getValue() ) < 0;
+ }
+
+ public boolean evaluateCachedRight(InternalWorkingMemory workingMemory,
+ final VariableContextEntry context, final Object left) {
+ if( context.rightNull ) {
+ return false;
+ }
+ final BigInteger comp = (BigInteger) ((ObjectVariableContextEntry) context).right;
+ return comp.compareTo( (BigInteger) context.declaration.getExtractor().getValue( workingMemory, left ) ) < 0;
+ }
+
+ public boolean evaluateCachedLeft(InternalWorkingMemory workingMemory,
+ final VariableContextEntry context, final Object right) {
+ if( context.extractor.isNullValue( workingMemory, right ) ) {
+ return false;
+ }
+ final BigInteger comp = (BigInteger) context.extractor.getValue( workingMemory, right );
+ return comp.compareTo( (BigInteger) ((ObjectVariableContextEntry) context).left ) < 0;
+ }
+
+ public boolean evaluate(InternalWorkingMemory workingMemory,
+ final Extractor extractor1,
+ final Object object1,
+ final Extractor extractor2, final Object object2) {
+ if( extractor1.isNullValue( workingMemory, object1 ) ) {
+ return false;
+ }
+ final BigInteger comp = (BigInteger) extractor1.getValue( workingMemory, object1 );
+ return comp.compareTo( (BigInteger) extractor2.getValue( workingMemory, object2 ) ) < 0;
+ }
+
+ public String toString() {
+ return "BigInteger <";
+ }
+ }
+
+ static class BigIntegerLessOrEqualEvaluator extends BaseEvaluator {
+ /**
+ *
+ */
+ private static final long serialVersionUID = 400L;
+ public final static Evaluator INSTANCE = new BigIntegerLessOrEqualEvaluator();
+
+ private BigIntegerLessOrEqualEvaluator() {
+ super( ValueType.BIG_INTEGER_TYPE,
+ Operator.LESS_OR_EQUAL );
+ }
+
+ public boolean evaluate(InternalWorkingMemory workingMemory,
+ final Extractor extractor,
+ final Object object1, final FieldValue object2) {
+ if( extractor.isNullValue( workingMemory, object1 ) ) {
+ return false;
+ }
+ final BigInteger comp = (BigInteger) extractor.getValue( workingMemory, object1 );
+ return comp.compareTo( (BigInteger) object2.getValue() ) <= 0;
+ }
+
+ public boolean evaluateCachedRight(InternalWorkingMemory workingMemory,
+ final VariableContextEntry context, final Object left) {
+ if( context.rightNull ) {
+ return false;
+ }
+ final BigInteger comp = (BigInteger) ((ObjectVariableContextEntry) context).right;
+ return comp.compareTo( (BigInteger) context.declaration.getExtractor().getValue( workingMemory, left ) ) <= 0;
+ }
+
+ public boolean evaluateCachedLeft(InternalWorkingMemory workingMemory,
+ final VariableContextEntry context, final Object right) {
+ if( context.extractor.isNullValue( workingMemory, right ) ) {
+ return false;
+ }
+ final BigInteger comp = (BigInteger) context.extractor.getValue( workingMemory, right );
+ return comp.compareTo( (BigInteger) ((ObjectVariableContextEntry) context).left ) <= 0;
+ }
+
+ public boolean evaluate(InternalWorkingMemory workingMemory,
+ final Extractor extractor1,
+ final Object object1,
+ final Extractor extractor2, final Object object2) {
+ if( extractor1.isNullValue( workingMemory, object1 ) ) {
+ return false;
+ }
+ final BigInteger comp = (BigInteger) extractor1.getValue( workingMemory, object1 );
+ return comp.compareTo( (BigInteger) extractor2.getValue( workingMemory, object2 ) ) <= 0;
+ }
+
+ public String toString() {
+ return "BigInteger <=";
+ }
+ }
+
+ static class BigIntegerGreaterEvaluator extends BaseEvaluator {
+ /**
+ *
+ */
+ private static final long serialVersionUID = 400L;
+ public final static Evaluator INSTANCE = new BigIntegerGreaterEvaluator();
+
+ private BigIntegerGreaterEvaluator() {
+ super( ValueType.BIG_INTEGER_TYPE,
+ Operator.GREATER );
+ }
+
+ public boolean evaluate(InternalWorkingMemory workingMemory,
+ final Extractor extractor,
+ final Object object1, final FieldValue object2) {
+ if( extractor.isNullValue( workingMemory, object1 ) ) {
+ return false;
+ }
+ final BigInteger comp = (BigInteger) extractor.getValue( workingMemory, object1 );
+ return comp.compareTo( (BigInteger) object2.getValue() ) > 0;
+ }
+
+ public boolean evaluateCachedRight(InternalWorkingMemory workingMemory,
+ final VariableContextEntry context, final Object left) {
+ if( context.rightNull ) {
+ return false;
+ }
+ final BigInteger comp = (BigInteger) ((ObjectVariableContextEntry) context).right;
+ return comp.compareTo( (BigInteger) context.declaration.getExtractor().getValue( workingMemory, left ) ) > 0;
+ }
+
+ public boolean evaluateCachedLeft(InternalWorkingMemory workingMemory,
+ final VariableContextEntry context, final Object right) {
+ if( context.extractor.isNullValue( workingMemory, right ) ) {
+ return false;
+ }
+ final BigInteger comp = (BigInteger) context.extractor.getValue( workingMemory, right );
+ return comp.compareTo( (BigInteger) ((ObjectVariableContextEntry) context).left ) > 0;
+ }
+
+ public boolean evaluate(InternalWorkingMemory workingMemory,
+ final Extractor extractor1,
+ final Object object1,
+ final Extractor extractor2, final Object object2) {
+ if( extractor1.isNullValue( workingMemory, object1 ) ) {
+ return false;
+ }
+ final BigInteger comp = (BigInteger) extractor1.getValue( workingMemory, object1 );
+ return comp.compareTo( (BigInteger) extractor2.getValue( workingMemory, object2 ) ) > 0;
+ }
+
+ public String toString() {
+ return "BigInteger >";
+ }
+ }
+
+ static class BigIntegerGreaterOrEqualEvaluator extends BaseEvaluator {
+ /**
+ *
+ */
+ private static final long serialVersionUID = 400L;
+ private final static Evaluator INSTANCE = new BigIntegerGreaterOrEqualEvaluator();
+
+ private BigIntegerGreaterOrEqualEvaluator() {
+ super( ValueType.BIG_INTEGER_TYPE,
+ Operator.GREATER_OR_EQUAL );
+ }
+
+ public boolean evaluate(InternalWorkingMemory workingMemory,
+ final Extractor extractor,
+ final Object object1, final FieldValue object2) {
+ if( extractor.isNullValue( workingMemory, object1 ) ) {
+ return false;
+ }
+ final BigInteger comp = (BigInteger) extractor.getValue( workingMemory, object1 );
+ return comp.compareTo( (BigInteger) object2.getValue() ) >= 0;
+ }
+
+ public boolean evaluateCachedRight(InternalWorkingMemory workingMemory,
+ final VariableContextEntry context, final Object left) {
+ if( context.rightNull ) {
+ return false;
+ }
+ final BigInteger comp = (BigInteger) ((ObjectVariableContextEntry) context).right;
+ return comp.compareTo( (BigInteger) context.declaration.getExtractor().getValue( workingMemory, left ) ) >= 0;
+ }
+
+ public boolean evaluateCachedLeft(InternalWorkingMemory workingMemory,
+ final VariableContextEntry context, final Object right) {
+ if( context.extractor.isNullValue( workingMemory, right ) ) {
+ return false;
+ }
+ final BigInteger comp = (BigInteger) context.extractor.getValue( workingMemory, right );
+ return comp.compareTo( (BigInteger) ((ObjectVariableContextEntry) context).left ) >= 0;
+ }
+
+ public boolean evaluate(InternalWorkingMemory workingMemory,
+ final Extractor extractor1,
+ final Object object1,
+ final Extractor extractor2, final Object object2) {
+ if( extractor1.isNullValue( workingMemory, object1 ) ) {
+ return false;
+ }
+ final BigInteger comp = (BigInteger) extractor1.getValue( workingMemory, object1 );
+ return comp.compareTo( (BigInteger) extractor2.getValue( workingMemory, object2 ) ) >= 0;
+ }
+
+ public String toString() {
+ return "BigInteger >=";
+ }
+ }
+
+ static class ByteLessEvaluator extends BaseEvaluator {
+ /**
+ *
+ */
+ private static final long serialVersionUID = 400L;
+ public final static Evaluator INSTANCE = new ByteLessEvaluator();
+
+ private ByteLessEvaluator() {
+ super( ValueType.PBYTE_TYPE,
+ Operator.LESS );
+ }
+
+ public boolean evaluate(InternalWorkingMemory workingMemory,
+ final Extractor extractor,
+ final Object object1, final FieldValue object2) {
+ if( extractor.isNullValue( workingMemory, object1 ) ) {
+ return false;
+ }
+ return extractor.getByteValue( workingMemory, object1 ) < object2.getByteValue();
+ }
+
+ public boolean evaluateCachedRight(InternalWorkingMemory workingMemory,
+ final VariableContextEntry context, final Object left) {
+ if( context.rightNull ) {
+ return false;
+ }
+ return ((LongVariableContextEntry) context).right < context.declaration.getExtractor().getByteValue( workingMemory, left );
+ }
+
+ public boolean evaluateCachedLeft(InternalWorkingMemory workingMemory,
+ final VariableContextEntry context, final Object right) {
+ if( context.extractor.isNullValue( workingMemory, right ) ) {
+ return false;
+ }
+ return context.extractor.getByteValue( workingMemory, right ) < ((LongVariableContextEntry) context).left;
+ }
+
+ public boolean evaluate(InternalWorkingMemory workingMemory,
+ final Extractor extractor1,
+ final Object object1,
+ final Extractor extractor2, final Object object2) {
+ if( extractor1.isNullValue( workingMemory, object1 ) ) {
+ return false;
+ }
+ return extractor1.getByteValue( workingMemory, object1 ) < extractor2.getByteValue( workingMemory, object2 );
+ }
+
+ public String toString() {
+ return "Byte <";
+ }
+ }
+
+ static class ByteLessOrEqualEvaluator extends BaseEvaluator {
+ /**
+ *
+ */
+ private static final long serialVersionUID = 400L;
+ public final static Evaluator INSTANCE = new ByteLessOrEqualEvaluator();
+
+ private ByteLessOrEqualEvaluator() {
+ super( ValueType.PBYTE_TYPE,
+ Operator.LESS_OR_EQUAL );
+ }
+
+ public boolean evaluate(InternalWorkingMemory workingMemory,
+ final Extractor extractor,
+ final Object object1, final FieldValue object2) {
+ if( extractor.isNullValue( workingMemory, object1 ) ) {
+ return false;
+ }
+ return extractor.getByteValue( workingMemory, object1 ) <= object2.getByteValue();
+ }
+
+ public boolean evaluateCachedRight(InternalWorkingMemory workingMemory,
+ final VariableContextEntry context, final Object left) {
+ if( context.rightNull ) {
+ return false;
+ }
+ return ((LongVariableContextEntry) context).right <= context.declaration.getExtractor().getByteValue( workingMemory, left );
+ }
+
+ public boolean evaluateCachedLeft(InternalWorkingMemory workingMemory,
+ final VariableContextEntry context, final Object right) {
+ if( context.extractor.isNullValue( workingMemory, right ) ) {
+ return false;
+ }
+ return context.extractor.getByteValue( workingMemory, right ) <= ((LongVariableContextEntry) context).left;
+ }
+
+ public boolean evaluate(InternalWorkingMemory workingMemory,
+ final Extractor extractor1,
+ final Object object1,
+ final Extractor extractor2, final Object object2) {
+ if( extractor1.isNullValue( workingMemory, object1 ) ) {
+ return false;
+ }
+ return extractor1.getByteValue( workingMemory, object1 ) <= extractor2.getByteValue( workingMemory, object2 );
+ }
+
+ public String toString() {
+ return "Byte <=";
+ }
+ }
+
+ static class ByteGreaterEvaluator extends BaseEvaluator {
+ /**
+ *
+ */
+ private static final long serialVersionUID = 400L;
+ public final static Evaluator INSTANCE = new ByteGreaterEvaluator();
+
+ private ByteGreaterEvaluator() {
+ super( ValueType.PBYTE_TYPE,
+ Operator.GREATER );
+ }
+
+ public boolean evaluate(InternalWorkingMemory workingMemory,
+ final Extractor extractor,
+ final Object object1, final FieldValue object2) {
+ if( extractor.isNullValue( workingMemory, object1 ) ) {
+ return false;
+ }
+ return extractor.getByteValue( workingMemory, object1 ) > object2.getByteValue();
+ }
+
+ public boolean evaluateCachedRight(InternalWorkingMemory workingMemory,
+ final VariableContextEntry context, final Object left) {
+ if( context.rightNull ) {
+ return false;
+ }
+ return ((LongVariableContextEntry) context).right > context.declaration.getExtractor().getByteValue( workingMemory, left );
+ }
+
+ public boolean evaluateCachedLeft(InternalWorkingMemory workingMemory,
+ final VariableContextEntry context, final Object right) {
+ if( context.extractor.isNullValue( workingMemory, right ) ) {
+ return false;
+ }
+ return context.extractor.getByteValue( workingMemory, right ) > ((LongVariableContextEntry) context).left;
+ }
+
+ public boolean evaluate(InternalWorkingMemory workingMemory,
+ final Extractor extractor1,
+ final Object object1,
+ final Extractor extractor2, final Object object2) {
+ if( extractor1.isNullValue( workingMemory, object1 ) ) {
+ return false;
+ }
+ return extractor1.getByteValue( workingMemory, object1 ) > extractor2.getByteValue( workingMemory, object2 );
+ }
+
+ public String toString() {
+ return "Byte >";
+ }
+ }
+
+ static class ByteGreaterOrEqualEvaluator extends BaseEvaluator {
+ /**
+ *
+ */
+ private static final long serialVersionUID = 400L;
+ private final static Evaluator INSTANCE = new ByteGreaterOrEqualEvaluator();
+
+ private ByteGreaterOrEqualEvaluator() {
+ super( ValueType.PBYTE_TYPE,
+ Operator.GREATER_OR_EQUAL );
+ }
+
+ public boolean evaluate(InternalWorkingMemory workingMemory,
+ final Extractor extractor,
+ final Object object1, final FieldValue object2) {
+ if( extractor.isNullValue( workingMemory, object1 ) ) {
+ return false;
+ }
+ return extractor.getByteValue( workingMemory, object1 ) >= object2.getByteValue();
+ }
+
+ public boolean evaluateCachedRight(InternalWorkingMemory workingMemory,
+ final VariableContextEntry context, final Object left) {
+ if( context.rightNull ) {
+ return false;
+ }
+ return ((LongVariableContextEntry) context).right >= context.declaration.getExtractor().getByteValue( workingMemory, left );
+ }
+
+ public boolean evaluateCachedLeft(InternalWorkingMemory workingMemory,
+ final VariableContextEntry context, final Object right) {
+ if( context.extractor.isNullValue( workingMemory, right ) ) {
+ return false;
+ }
+ return context.extractor.getByteValue( workingMemory, right ) >= ((LongVariableContextEntry) context).left;
+ }
+
+ public boolean evaluate(InternalWorkingMemory workingMemory,
+ final Extractor extractor1,
+ final Object object1,
+ final Extractor extractor2, final Object object2) {
+ if( extractor1.isNullValue( workingMemory, object1 ) ) {
+ return false;
+ }
+ return extractor1.getByteValue( workingMemory, object1 ) >= extractor2.getByteValue( workingMemory, object2 );
+ }
+
+ public String toString() {
+ return "Byte >=";
+ }
+ }
+
+ static class CharacterLessEvaluator extends BaseEvaluator {
+ /**
+ *
+ */
+ private static final long serialVersionUID = 400L;
+ public final static Evaluator INSTANCE = new CharacterLessEvaluator();
+
+ private CharacterLessEvaluator() {
+ super( ValueType.PCHAR_TYPE,
+ Operator.LESS );
+ }
+
+ public boolean evaluate(InternalWorkingMemory workingMemory,
+ final Extractor extractor,
+ final Object object1, final FieldValue object2) {
+ if( extractor.isNullValue( workingMemory, object1 ) ) {
+ return false;
+ }
+ return extractor.getCharValue( workingMemory, object1 ) < object2.getCharValue();
+ }
+
+ public boolean evaluateCachedRight(InternalWorkingMemory workingMemory,
+ final VariableContextEntry context, final Object left) {
+ if( context.rightNull ) {
+ return false;
+ }
+ return ((CharVariableContextEntry) context).right < context.declaration.getExtractor().getCharValue( workingMemory, left );
+ }
+
+ public boolean evaluateCachedLeft(InternalWorkingMemory workingMemory,
+ final VariableContextEntry context, final Object right) {
+ if( context.extractor.isNullValue( workingMemory, right ) ) {
+ return false;
+ }
+ return context.extractor.getCharValue( workingMemory, right ) < ((CharVariableContextEntry) context).left;
+ }
+
+ public boolean evaluate(InternalWorkingMemory workingMemory,
+ final Extractor extractor1,
+ final Object object1,
+ final Extractor extractor2, final Object object2) {
+ if( extractor1.isNullValue( workingMemory, object1 ) ) {
+ return false;
+ }
+ return extractor1.getCharValue( workingMemory, object1 ) < extractor2.getCharValue( workingMemory, object2 );
+ }
+
+ public String toString() {
+ return "Character <";
+ }
+ }
+
+ static class CharacterLessOrEqualEvaluator extends BaseEvaluator {
+ /**
+ *
+ */
+ private static final long serialVersionUID = 400L;
+ public final static Evaluator INSTANCE = new CharacterLessOrEqualEvaluator();
+
+ private CharacterLessOrEqualEvaluator() {
+ super( ValueType.PCHAR_TYPE,
+ Operator.LESS_OR_EQUAL );
+ }
+
+ public boolean evaluate(InternalWorkingMemory workingMemory,
+ final Extractor extractor,
+ final Object object1, final FieldValue object2) {
+ if( extractor.isNullValue( workingMemory, object1 ) ) {
+ return false;
+ }
+ return extractor.getCharValue( workingMemory, object1 ) <= object2.getCharValue();
+ }
+
+ public boolean evaluateCachedRight(InternalWorkingMemory workingMemory,
+ final VariableContextEntry context, final Object left) {
+ if( context.rightNull ) {
+ return false;
+ }
+ return ((CharVariableContextEntry) context).right <= context.declaration.getExtractor().getCharValue( workingMemory, left );
+ }
+
+ public boolean evaluateCachedLeft(InternalWorkingMemory workingMemory,
+ final VariableContextEntry context, final Object right) {
+ if( context.extractor.isNullValue( workingMemory, right ) ) {
+ return false;
+ }
+ return context.extractor.getCharValue( workingMemory, right ) <= ((CharVariableContextEntry) context).left;
+ }
+
+ public boolean evaluate(InternalWorkingMemory workingMemory,
+ final Extractor extractor1,
+ final Object object1,
+ final Extractor extractor2, final Object object2) {
+ if( extractor1.isNullValue( workingMemory, object1 ) ) {
+ return false;
+ }
+ return extractor1.getCharValue( workingMemory, object1 ) <= extractor2.getCharValue( workingMemory, object2 );
+ }
+
+ public String toString() {
+ return "Character <=";
+ }
+ }
+
+ static class CharacterGreaterEvaluator extends BaseEvaluator {
+ /**
+ *
+ */
+ private static final long serialVersionUID = 400L;
+ public final static Evaluator INSTANCE = new CharacterGreaterEvaluator();
+
+ private CharacterGreaterEvaluator() {
+ super( ValueType.PCHAR_TYPE,
+ Operator.GREATER );
+ }
+
+ public boolean evaluate(InternalWorkingMemory workingMemory,
+ final Extractor extractor,
+ final Object object1, final FieldValue object2) {
+ if( extractor.isNullValue( workingMemory, object1 ) ) {
+ return false;
+ }
+ return extractor.getCharValue( workingMemory, object1 ) > object2.getCharValue();
+ }
+
+ public boolean evaluateCachedRight(InternalWorkingMemory workingMemory,
+ final VariableContextEntry context, final Object left) {
+ if( context.rightNull ) {
+ return false;
+ }
+ return ((CharVariableContextEntry) context).right > context.declaration.getExtractor().getCharValue( workingMemory, left );
+ }
+
+ public boolean evaluateCachedLeft(InternalWorkingMemory workingMemory,
+ final VariableContextEntry context, final Object right) {
+ if( context.extractor.isNullValue( workingMemory, right ) ) {
+ return false;
+ }
+ return context.extractor.getCharValue( workingMemory, right ) > ((CharVariableContextEntry) context).left;
+ }
+
+ public boolean evaluate(InternalWorkingMemory workingMemory,
+ final Extractor extractor1,
+ final Object object1,
+ final Extractor extractor2, final Object object2) {
+ if( extractor1.isNullValue( workingMemory, object1 ) ) {
+ return false;
+ }
+ return extractor1.getCharValue( workingMemory, object1 ) > extractor2.getCharValue( workingMemory, object2 );
+ }
+
+ public String toString() {
+ return "Character >";
+ }
+ }
+
+ static class CharacterGreaterOrEqualEvaluator extends BaseEvaluator {
+ /**
+ *
+ */
+ private static final long serialVersionUID = 400L;
+ private final static Evaluator INSTANCE = new CharacterGreaterOrEqualEvaluator();
+
+ private CharacterGreaterOrEqualEvaluator() {
+ super( ValueType.PCHAR_TYPE,
+ Operator.GREATER_OR_EQUAL );
+ }
+
+ public boolean evaluate(InternalWorkingMemory workingMemory,
+ final Extractor extractor,
+ final Object object1, final FieldValue object2) {
+ if( extractor.isNullValue( workingMemory, object1 ) ) {
+ return false;
+ }
+ return extractor.getCharValue( workingMemory, object1 ) >= object2.getCharValue();
+ }
+
+ public boolean evaluateCachedRight(InternalWorkingMemory workingMemory,
+ final VariableContextEntry context, final Object left) {
+ if( context.rightNull ) {
+ return false;
+ }
+ return ((CharVariableContextEntry) context).right >= context.declaration.getExtractor().getCharValue( workingMemory, left );
+ }
+
+ public boolean evaluateCachedLeft(InternalWorkingMemory workingMemory,
+ final VariableContextEntry context, final Object right) {
+ if( context.extractor.isNullValue( workingMemory, right ) ) {
+ return false;
+ }
+ return context.extractor.getCharValue( workingMemory, right ) >= ((CharVariableContextEntry) context).left;
+ }
+
+ public boolean evaluate(InternalWorkingMemory workingMemory,
+ final Extractor extractor1,
+ final Object object1,
+ final Extractor extractor2, final Object object2) {
+ if( extractor1.isNullValue( workingMemory, object1 ) ) {
+ return false;
+ }
+ return extractor1.getCharValue( workingMemory, object1 ) >= extractor2.getCharValue( workingMemory, object2 );
+ }
+
+ public String toString() {
+ return "Character >=";
+ }
+ }
+
+ static class DateLessEvaluator extends BaseEvaluator {
+ /**
+ *
+ */
+ private static final long serialVersionUID = 400L;
+ public final static Evaluator INSTANCE = new DateLessEvaluator();
+
+ private DateLessEvaluator() {
+ super( ValueType.DATE_TYPE,
+ Operator.LESS );
+ }
+
+ public boolean evaluate(InternalWorkingMemory workingMemory,
+ final Extractor extractor,
+ final Object object1, final FieldValue object2) {
+ if( extractor.isNullValue( workingMemory, object1 ) ) {
+ return false;
+ }
+ final Date value1 = (Date) extractor.getValue( workingMemory, object1 );
+ final Object value2 = object2.getValue();
+ return value1.compareTo( DateUtils.getRightDate( value2 ) ) < 0;
+ }
+
+ public boolean evaluateCachedRight(InternalWorkingMemory workingMemory,
+ final VariableContextEntry context, final Object left) {
+ if( context.rightNull ) {
+ return false;
+ }
+ final Date value1 = (Date) context.declaration.getExtractor().getValue( workingMemory, left );
+ final Object value2 = ((ObjectVariableContextEntry) context).right;
+ return DateUtils.getRightDate( value2 ).compareTo( value1 ) < 0;
+ }
+
+ public boolean evaluateCachedLeft(InternalWorkingMemory workingMemory,
+ final VariableContextEntry context, final Object right) {
+ if( context.extractor.isNullValue( workingMemory, right ) ) {
+ return false;
+ }
+ final Date value1 = (Date) ((ObjectVariableContextEntry) context).left;
+ final Object value2 = context.extractor.getValue( workingMemory, right );
+ return DateUtils.getRightDate( value2 ).compareTo( value1 ) < 0;
+ }
+
+ public boolean evaluate(InternalWorkingMemory workingMemory,
+ final Extractor extractor1,
+ final Object object1,
+ final Extractor extractor2, final Object object2) {
+ if( extractor1.isNullValue( workingMemory, object1 ) ) {
+ return false;
+ }
+ final Date value1 = (Date) extractor1.getValue( workingMemory, object1 );
+ final Date value2 = (Date) extractor2.getValue( workingMemory, object2 );
+ return value1.compareTo( value2 ) < 0;
+ }
+
+ public String toString() {
+ return "Date <";
+ }
+ }
+
+ static class DateLessOrEqualEvaluator extends BaseEvaluator {
+ /**
+ *
+ */
+ private static final long serialVersionUID = 400L;
+ public final static Evaluator INSTANCE = new DateLessOrEqualEvaluator();
+
+ private DateLessOrEqualEvaluator() {
+ super( ValueType.DATE_TYPE,
+ Operator.LESS_OR_EQUAL );
+ }
+
+ public boolean evaluate(InternalWorkingMemory workingMemory,
+ final Extractor extractor,
+ final Object object1, final FieldValue object2) {
+ if( extractor.isNullValue( workingMemory, object1 ) ) {
+ return false;
+ }
+ final Date value1 = (Date) extractor.getValue( workingMemory, object1 );
+ final Object value2 = object2.getValue();
+ return value1.compareTo( DateUtils.getRightDate( value2 ) ) <= 0;
+ }
+
+ public boolean evaluateCachedRight(InternalWorkingMemory workingMemory,
+ final VariableContextEntry context, final Object left) {
+ if( context.rightNull ) {
+ return false;
+ }
+ final Date value1 = (Date) context.declaration.getExtractor().getValue( workingMemory, left );
+ final Object value2 = ((ObjectVariableContextEntry) context).right;
+ return DateUtils.getRightDate( value2 ).compareTo( value1 ) <= 0;
+ }
+
+ public boolean evaluateCachedLeft(InternalWorkingMemory workingMemory,
+ final VariableContextEntry context, final Object right) {
+ if( context.extractor.isNullValue( workingMemory, right ) ) {
+ return false;
+ }
+ final Date value1 = (Date) ((ObjectVariableContextEntry) context).left;
+ final Object value2 = context.extractor.getValue( workingMemory, right );
+ return DateUtils.getRightDate( value2 ).compareTo( value1 ) <= 0;
+ }
+
+ public boolean evaluate(InternalWorkingMemory workingMemory,
+ final Extractor extractor1,
+ final Object object1,
+ final Extractor extractor2, final Object object2) {
+ if( extractor1.isNullValue( workingMemory, object1 ) ) {
+ return false;
+ }
+ final Date value1 = (Date) extractor1.getValue( workingMemory, object1 );
+ final Date value2 = (Date) extractor2.getValue( workingMemory, object2 );
+ return value1.compareTo( value2 ) <= 0;
+ }
+
+ public String toString() {
+ return "Date <=";
+ }
+ }
+
+ static class DateGreaterEvaluator extends BaseEvaluator {
+ /**
+ *
+ */
+ private static final long serialVersionUID = 400L;
+ public final static Evaluator INSTANCE = new DateGreaterEvaluator();
+
+ private DateGreaterEvaluator() {
+ super( ValueType.DATE_TYPE,
+ Operator.GREATER );
+ }
+
+ public boolean evaluate(InternalWorkingMemory workingMemory,
+ final Extractor extractor,
+ final Object object1, final FieldValue object2) {
+ if( extractor.isNullValue( workingMemory, object1 ) ) {
+ return false;
+ }
+ final Date value1 = (Date) extractor.getValue( workingMemory, object1 );
+ final Object value2 = object2.getValue();
+ return value1.compareTo( DateUtils.getRightDate( value2 ) ) > 0;
+ }
+
+ public boolean evaluateCachedRight(InternalWorkingMemory workingMemory,
+ final VariableContextEntry context, final Object left) {
+ if( context.rightNull ) {
+ return false;
+ }
+ final Date value1 = (Date) context.declaration.getExtractor().getValue( workingMemory, left );
+ final Object value2 = ((ObjectVariableContextEntry) context).right;
+ return DateUtils.getRightDate( value2 ).compareTo( value1 ) > 0;
+ }
+
+ public boolean evaluateCachedLeft(InternalWorkingMemory workingMemory,
+ final VariableContextEntry context, final Object right) {
+ if( context.extractor.isNullValue( workingMemory, right ) ) {
+ return false;
+ }
+ final Date value1 = (Date) ((ObjectVariableContextEntry) context).left;
+ final Object value2 = context.extractor.getValue( workingMemory, right );
+ return DateUtils.getRightDate( value2 ).compareTo( value1 ) > 0;
+ }
+
+ public boolean evaluate(InternalWorkingMemory workingMemory,
+ final Extractor extractor1,
+ final Object object1,
+ final Extractor extractor2, final Object object2) {
+ if( extractor1.isNullValue( workingMemory, object1 ) ) {
+ return false;
+ }
+ final Date value1 = (Date) extractor1.getValue( workingMemory, object1 );
+ final Date value2 = (Date) extractor2.getValue( workingMemory, object2 );
+ return value1.compareTo( value2 ) > 0;
+ }
+
+ public String toString() {
+ return "Date >";
+ }
+ }
+
+ static class DateGreaterOrEqualEvaluator extends BaseEvaluator {
+ /**
+ *
+ */
+ private static final long serialVersionUID = 400L;
+ private final static Evaluator INSTANCE = new DateGreaterOrEqualEvaluator();
+
+ private DateGreaterOrEqualEvaluator() {
+ super( ValueType.DATE_TYPE,
+ Operator.GREATER_OR_EQUAL );
+ }
+
+ public boolean evaluate(InternalWorkingMemory workingMemory,
+ final Extractor extractor,
+ final Object object1, final FieldValue object2) {
+ if( extractor.isNullValue( workingMemory, object1 ) ) {
+ return false;
+ }
+ final Date value1 = (Date) extractor.getValue( workingMemory, object1 );
+ final Object value2 = object2.getValue();
+ return value1.compareTo( DateUtils.getRightDate( value2 ) ) >= 0;
+ }
+
+ public boolean evaluateCachedRight(InternalWorkingMemory workingMemory,
+ final VariableContextEntry context, final Object left) {
+ if( context.rightNull ) {
+ return false;
+ }
+ final Date value1 = (Date) context.declaration.getExtractor().getValue( workingMemory, left );
+ final Object value2 = ((ObjectVariableContextEntry) context).right;
+ return DateUtils.getRightDate( value2 ).compareTo( value1 ) >= 0;
+ }
+
+ public boolean evaluateCachedLeft(InternalWorkingMemory workingMemory,
+ final VariableContextEntry context, final Object right) {
+ if( context.extractor.isNullValue( workingMemory, right ) ) {
+ return false;
+ }
+ final Date value1 = (Date) ((ObjectVariableContextEntry) context).left;
+ final Object value2 = context.extractor.getValue( workingMemory, right );
+ return DateUtils.getRightDate( value2 ).compareTo( value1 ) >= 0;
+ }
+
+ public boolean evaluate(InternalWorkingMemory workingMemory,
+ final Extractor extractor1,
+ final Object object1,
+ final Extractor extractor2, final Object object2) {
+ if( extractor1.isNullValue( workingMemory, object1 ) ) {
+ return false;
+ }
+ final Date value1 = (Date) extractor1.getValue( workingMemory, object1 );
+ final Date value2 = (Date) extractor2.getValue( workingMemory, object2 );
+ return value1.compareTo( value2 ) >= 0;
+ }
+
+ public String toString() {
+ return "Date >=";
+ }
+ }
+
+ static class DoubleLessEvaluator extends BaseEvaluator {
+ /**
+ *
+ */
+ private static final long serialVersionUID = 400L;
+ public final static Evaluator INSTANCE = new DoubleLessEvaluator();
+
+ private DoubleLessEvaluator() {
+ super( ValueType.PDOUBLE_TYPE,
+ Operator.LESS );
+ }
+
+ public boolean evaluate(InternalWorkingMemory workingMemory,
+ final Extractor extractor,
+ final Object object1, final FieldValue object2) {
+ if( extractor.isNullValue( workingMemory, object1 ) ) {
+ return false;
+ }
+ // TODO: we are not handling delta right now... maybe we should
+ return extractor.getDoubleValue( workingMemory, object1 ) < object2.getDoubleValue();
+ }
+
+ public boolean evaluateCachedRight(InternalWorkingMemory workingMemory,
+ final VariableContextEntry context, final Object left) {
+ if( context.rightNull ) {
+ return false;
+ }
+ // TODO: we are not handling delta right now... maybe we should
+ return ((DoubleVariableContextEntry) context).right < context.declaration.getExtractor().getDoubleValue( workingMemory, left );
+ }
+
+ public boolean evaluateCachedLeft(InternalWorkingMemory workingMemory,
+ final VariableContextEntry context, final Object right) {
+ if( context.extractor.isNullValue( workingMemory, right ) ) {
+ return false;
+ }
+ // TODO: we are not handling delta right now... maybe we should
+ return context.extractor.getDoubleValue( workingMemory, right ) < ((DoubleVariableContextEntry) context).left;
+ }
+
+ public boolean evaluate(InternalWorkingMemory workingMemory,
+ final Extractor extractor1,
+ final Object object1,
+ final Extractor extractor2, final Object object2) {
+ if( extractor1.isNullValue( workingMemory, object1 ) ) {
+ return false;
+ }
+ // TODO: we are not handling delta right now... maybe we should
+ return extractor1.getDoubleValue( workingMemory, object1 ) < extractor2.getDoubleValue( workingMemory, object2 );
+ }
+
+ public String toString() {
+ return "Double <";
+ }
+ }
+
+ static class DoubleLessOrEqualEvaluator extends BaseEvaluator {
+ /**
+ *
+ */
+ private static final long serialVersionUID = 400L;
+ public final static Evaluator INSTANCE = new DoubleLessOrEqualEvaluator();
+
+ private DoubleLessOrEqualEvaluator() {
+ super( ValueType.PDOUBLE_TYPE,
+ Operator.LESS_OR_EQUAL );
+ }
+
+ public boolean evaluate(InternalWorkingMemory workingMemory,
+ final Extractor extractor,
+ final Object object1, final FieldValue object2) {
+ if( extractor.isNullValue( workingMemory, object1 ) ) {
+ return false;
+ }
+ // TODO: we are not handling delta right now... maybe we should
+ return extractor.getDoubleValue( workingMemory, object1 ) <= object2.getDoubleValue();
+ }
+
+ public boolean evaluateCachedRight(InternalWorkingMemory workingMemory,
+ final VariableContextEntry context, final Object left) {
+ if( context.rightNull ) {
+ return false;
+ }
+ // TODO: we are not handling delta right now... maybe we should
+ return ((DoubleVariableContextEntry) context).right <= context.declaration.getExtractor().getDoubleValue( workingMemory, left );
+ }
+
+ public boolean evaluateCachedLeft(InternalWorkingMemory workingMemory,
+ final VariableContextEntry context, final Object right) {
+ if( context.extractor.isNullValue( workingMemory, right ) ) {
+ return false;
+ }
+ // TODO: we are not handling delta right now... maybe we should
+ return context.extractor.getDoubleValue( workingMemory, right ) <= ((DoubleVariableContextEntry) context).left;
+ }
+
+ public boolean evaluate(InternalWorkingMemory workingMemory,
+ final Extractor extractor1,
+ final Object object1,
+ final Extractor extractor2, final Object object2) {
+ if( extractor1.isNullValue( workingMemory, object1 ) ) {
+ return false;
+ }
+ // TODO: we are not handling delta right now... maybe we should
+ return extractor1.getDoubleValue( workingMemory, object1 ) <= extractor2.getDoubleValue( workingMemory, object2 );
+ }
+
+ public String toString() {
+ return "Double <=";
+ }
+ }
+
+ static class DoubleGreaterEvaluator extends BaseEvaluator {
+ /**
+ *
+ */
+ private static final long serialVersionUID = 400L;
+ public final static Evaluator INSTANCE = new DoubleGreaterEvaluator();
+
+ private DoubleGreaterEvaluator() {
+ super( ValueType.PDOUBLE_TYPE,
+ Operator.GREATER );
+ }
+
+ public boolean evaluate(InternalWorkingMemory workingMemory,
+ final Extractor extractor,
+ final Object object1, final FieldValue object2) {
+ if( extractor.isNullValue( workingMemory, object1 ) ) {
+ return false;
+ }
+ // TODO: we are not handling delta right now... maybe we should
+ return extractor.getDoubleValue( workingMemory, object1 ) > object2.getDoubleValue();
+ }
+
+ public boolean evaluateCachedRight(InternalWorkingMemory workingMemory,
+ final VariableContextEntry context, final Object left) {
+ if( context.rightNull ) {
+ return false;
+ }
+ // TODO: we are not handling delta right now... maybe we should
+ return ((DoubleVariableContextEntry) context).right > context.declaration.getExtractor().getDoubleValue( workingMemory, left );
+ }
+
+ public boolean evaluateCachedLeft(InternalWorkingMemory workingMemory,
+ final VariableContextEntry context, final Object right) {
+ if( context.extractor.isNullValue( workingMemory, right ) ) {
+ return false;
+ }
+ // TODO: we are not handling delta right now... maybe we should
+ return context.extractor.getDoubleValue( workingMemory, right ) > ((DoubleVariableContextEntry) context).left;
+ }
+
+ public boolean evaluate(InternalWorkingMemory workingMemory,
+ final Extractor extractor1,
+ final Object object1,
+ final Extractor extractor2, final Object object2) {
+ if( extractor1.isNullValue( workingMemory, object1 ) ) {
+ return false;
+ }
+ // TODO: we are not handling delta right now... maybe we should
+ return extractor1.getDoubleValue( workingMemory, object1 ) > extractor2.getDoubleValue( workingMemory, object2 );
+ }
+
+ public String toString() {
+ return "Double >";
+ }
+ }
+
+ static class DoubleGreaterOrEqualEvaluator extends BaseEvaluator {
+ /**
+ *
+ */
+ private static final long serialVersionUID = 400L;
+ private final static Evaluator INSTANCE = new DoubleGreaterOrEqualEvaluator();
+
+ private DoubleGreaterOrEqualEvaluator() {
+ super( ValueType.PDOUBLE_TYPE,
+ Operator.GREATER_OR_EQUAL );
+ }
+
+ public boolean evaluate(InternalWorkingMemory workingMemory,
+ final Extractor extractor,
+ final Object object1, final FieldValue object2) {
+ if( extractor.isNullValue( workingMemory, object1 ) ) {
+ return false;
+ }
+ // TODO: we are not handling delta right now... maybe we should
+ return extractor.getDoubleValue( workingMemory, object1 ) >= object2.getDoubleValue();
+ }
+
+ public boolean evaluateCachedRight(InternalWorkingMemory workingMemory,
+ final VariableContextEntry context, final Object left) {
+ if( context.rightNull ) {
+ return false;
+ }
+ // TODO: we are not handling delta right now... maybe we should
+ return ((DoubleVariableContextEntry) context).right >= context.declaration.getExtractor().getDoubleValue( workingMemory, left );
+ }
+
+ public boolean evaluateCachedLeft(InternalWorkingMemory workingMemory,
+ final VariableContextEntry context, final Object right) {
+ if( context.extractor.isNullValue( workingMemory, right ) ) {
+ return false;
+ }
+ // TODO: we are not handling delta right now... maybe we should
+ return context.extractor.getDoubleValue( workingMemory, right ) >= ((DoubleVariableContextEntry) context).left;
+ }
+
+ public boolean evaluate(InternalWorkingMemory workingMemory,
+ final Extractor extractor1,
+ final Object object1,
+ final Extractor extractor2, final Object object2) {
+ if( extractor1.isNullValue( workingMemory, object1 ) ) {
+ return false;
+ }
+ // TODO: we are not handling delta right now... maybe we should
+ return extractor1.getDoubleValue( workingMemory, object1 ) >= extractor2.getDoubleValue( workingMemory, object2 );
+ }
+
+ public String toString() {
+ return "Double >=";
+ }
+ }
+
+ static class FloatLessEvaluator extends BaseEvaluator {
+ /**
+ *
+ */
+ private static final long serialVersionUID = 400L;
+ public final static Evaluator INSTANCE = new FloatLessEvaluator();
+
+ private FloatLessEvaluator() {
+ super( ValueType.PFLOAT_TYPE,
+ Operator.LESS );
+ }
+
+ public boolean evaluate(InternalWorkingMemory workingMemory,
+ final Extractor extractor,
+ final Object object1, final FieldValue object2) {
+ if( extractor.isNullValue( workingMemory, object1 ) ) {
+ return false;
+ }
+ // TODO: we are not handling delta right now... maybe we should
+ return extractor.getFloatValue( workingMemory, object1 ) < object2.getFloatValue();
+ }
+
+ public boolean evaluateCachedRight(InternalWorkingMemory workingMemory,
+ final VariableContextEntry context, final Object left) {
+ if( context.rightNull ) {
+ return false;
+ }
+ // TODO: we are not handling delta right now... maybe we should
+ return ((DoubleVariableContextEntry) context).right < context.declaration.getExtractor().getFloatValue( workingMemory, left );
+ }
+
+ public boolean evaluateCachedLeft(InternalWorkingMemory workingMemory,
+ final VariableContextEntry context, final Object right) {
+ if( context.extractor.isNullValue( workingMemory, right ) ) {
+ return false;
+ }
+ // TODO: we are not handling delta right now... maybe we should
+ return context.extractor.getFloatValue( workingMemory, right ) < ((DoubleVariableContextEntry) context).left;
+ }
+
+ public boolean evaluate(InternalWorkingMemory workingMemory,
+ final Extractor extractor1,
+ final Object object1,
+ final Extractor extractor2, final Object object2) {
+ if( extractor1.isNullValue( workingMemory, object1 ) ) {
+ return false;
+ }
+ // TODO: we are not handling delta right now... maybe we should
+ return extractor1.getFloatValue( workingMemory, object1 ) < extractor2.getFloatValue( workingMemory, object2 );
+ }
+
+ public String toString() {
+ return "Float <";
+ }
+ }
+
+ static class FloatLessOrEqualEvaluator extends BaseEvaluator {
+ /**
+ *
+ */
+ private static final long serialVersionUID = 400L;
+ public final static Evaluator INSTANCE = new FloatLessOrEqualEvaluator();
+
+ private FloatLessOrEqualEvaluator() {
+ super( ValueType.PFLOAT_TYPE,
+ Operator.LESS_OR_EQUAL );
+ }
+
+ public boolean evaluate(InternalWorkingMemory workingMemory,
+ final Extractor extractor,
+ final Object object1, final FieldValue object2) {
+ if( extractor.isNullValue( workingMemory, object1 ) ) {
+ return false;
+ }
+ // TODO: we are not handling delta right now... maybe we should
+ return extractor.getFloatValue( workingMemory, object1 ) <= object2.getFloatValue();
+ }
+
+ public boolean evaluateCachedRight(InternalWorkingMemory workingMemory,
+ final VariableContextEntry context, final Object left) {
+ if( context.rightNull ) {
+ return false;
+ }
+ // TODO: we are not handling delta right now... maybe we should
+ return ((DoubleVariableContextEntry) context).right <= context.declaration.getExtractor().getFloatValue( workingMemory, left );
+ }
+
+ public boolean evaluateCachedLeft(InternalWorkingMemory workingMemory,
+ final VariableContextEntry context, final Object right) {
+ if( context.extractor.isNullValue( workingMemory, right ) ) {
+ return false;
+ }
+ // TODO: we are not handling delta right now... maybe we should
+ return context.extractor.getFloatValue( workingMemory, right ) <= ((DoubleVariableContextEntry) context).left;
+ }
+
+ public boolean evaluate(InternalWorkingMemory workingMemory,
+ final Extractor extractor1,
+ final Object object1,
+ final Extractor extractor2, final Object object2) {
+ if( extractor1.isNullValue( workingMemory, object1 ) ) {
+ return false;
+ }
+ // TODO: we are not handling delta right now... maybe we should
+ return extractor1.getFloatValue( workingMemory, object1 ) <= extractor2.getFloatValue( workingMemory, object2 );
+ }
+
+ public String toString() {
+ return "Float <=";
+ }
+ }
+
+ static class FloatGreaterEvaluator extends BaseEvaluator {
+ /**
+ *
+ */
+ private static final long serialVersionUID = 400L;
+ public final static Evaluator INSTANCE = new FloatGreaterEvaluator();
+
+ private FloatGreaterEvaluator() {
+ super( ValueType.PFLOAT_TYPE,
+ Operator.GREATER );
+ }
+
+ public boolean evaluate(InternalWorkingMemory workingMemory,
+ final Extractor extractor,
+ final Object object1, final FieldValue object2) {
+ if( extractor.isNullValue( workingMemory, object1 ) ) {
+ return false;
+ }
+ // TODO: we are not handling delta right now... maybe we should
+ return extractor.getFloatValue( workingMemory, object1 ) > object2.getFloatValue();
+ }
+
+ public boolean evaluateCachedRight(InternalWorkingMemory workingMemory,
+ final VariableContextEntry context, final Object left) {
+ if( context.rightNull ) {
+ return false;
+ }
+ // TODO: we are not handling delta right now... maybe we should
+ return ((DoubleVariableContextEntry) context).right > context.declaration.getExtractor().getFloatValue( workingMemory, left );
+ }
+
+ public boolean evaluateCachedLeft(InternalWorkingMemory workingMemory,
+ final VariableContextEntry context, final Object right) {
+ if( context.extractor.isNullValue( workingMemory, right ) ) {
+ return false;
+ }
+ // TODO: we are not handling delta right now... maybe we should
+ return context.extractor.getFloatValue( workingMemory, right ) > ((DoubleVariableContextEntry) context).left;
+ }
+
+ public boolean evaluate(InternalWorkingMemory workingMemory,
+ final Extractor extractor1,
+ final Object object1,
+ final Extractor extractor2, final Object object2) {
+ if( extractor1.isNullValue( workingMemory, object1 ) ) {
+ return false;
+ }
+ // TODO: we are not handling delta right now... maybe we should
+ return extractor1.getFloatValue( workingMemory, object1 ) > extractor2.getFloatValue( workingMemory, object2 );
+ }
+
+ public String toString() {
+ return "Float >";
+ }
+ }
+
+ static class FloatGreaterOrEqualEvaluator extends BaseEvaluator {
+ /**
+ *
+ */
+ private static final long serialVersionUID = 400L;
+ private final static Evaluator INSTANCE = new FloatGreaterOrEqualEvaluator();
+
+ private FloatGreaterOrEqualEvaluator() {
+ super( ValueType.PFLOAT_TYPE,
+ Operator.GREATER_OR_EQUAL );
+ }
+
+ public boolean evaluate(InternalWorkingMemory workingMemory,
+ final Extractor extractor,
+ final Object object1, final FieldValue object2) {
+ if( extractor.isNullValue( workingMemory, object1 ) ) {
+ return false;
+ }
+ // TODO: we are not handling delta right now... maybe we should
+ return extractor.getFloatValue( workingMemory, object1 ) >= object2.getFloatValue();
+ }
+
+ public boolean evaluateCachedRight(InternalWorkingMemory workingMemory,
+ final VariableContextEntry context, final Object left) {
+ if( context.rightNull ) {
+ return false;
+ }
+ // TODO: we are not handling delta right now... maybe we should
+ return ((DoubleVariableContextEntry) context).right >= context.declaration.getExtractor().getFloatValue( workingMemory, left );
+ }
+
+ public boolean evaluateCachedLeft(InternalWorkingMemory workingMemory,
+ final VariableContextEntry context, final Object right) {
+ if( context.extractor.isNullValue( workingMemory, right ) ) {
+ return false;
+ }
+ // TODO: we are not handling delta right now... maybe we should
+ return context.extractor.getFloatValue( workingMemory, right ) >= ((DoubleVariableContextEntry) context).left;
+ }
+
+ public boolean evaluate(InternalWorkingMemory workingMemory,
+ final Extractor extractor1,
+ final Object object1,
+ final Extractor extractor2, final Object object2) {
+ if( extractor1.isNullValue( workingMemory, object1 ) ) {
+ return false;
+ }
+ // TODO: we are not handling delta right now... maybe we should
+ return extractor1.getFloatValue( workingMemory, object1 ) >= extractor2.getFloatValue( workingMemory, object2 );
+ }
+
+ public String toString() {
+ return "Float >=";
+ }
+ }
+
+ static class IntegerLessEvaluator extends BaseEvaluator {
+ /**
+ *
+ */
+ private static final long serialVersionUID = 400L;
+ public final static Evaluator INSTANCE = new IntegerLessEvaluator();
+
+ private IntegerLessEvaluator() {
+ super( ValueType.PINTEGER_TYPE,
+ Operator.LESS );
+ }
+
+ public boolean evaluate(InternalWorkingMemory workingMemory,
+ final Extractor extractor,
+ final Object object1, final FieldValue object2) {
+ if( extractor.isNullValue( workingMemory, object1 ) ) {
+ return false;
+ }
+ return extractor.getIntValue( workingMemory, object1 ) < object2.getIntValue();
+ }
+
+ public boolean evaluateCachedRight(InternalWorkingMemory workingMemory,
+ final VariableContextEntry context, final Object left) {
+ if( context.rightNull ) {
+ return false;
+ }
+ return ((LongVariableContextEntry) context).right < context.declaration.getExtractor().getIntValue( workingMemory, left );
+ }
+
+ public boolean evaluateCachedLeft(InternalWorkingMemory workingMemory,
+ final VariableContextEntry context, final Object right) {
+ if( context.extractor.isNullValue( workingMemory, right ) ) {
+ return false;
+ }
+ return context.extractor.getIntValue( workingMemory, right ) < ((LongVariableContextEntry) context).left;
+ }
+
+ public boolean evaluate(InternalWorkingMemory workingMemory,
+ final Extractor extractor1,
+ final Object object1,
+ final Extractor extractor2, final Object object2) {
+ if( extractor1.isNullValue( workingMemory, object1 ) ) {
+ return false;
+ }
+ return extractor1.getIntValue( workingMemory, object1 ) < extractor2.getIntValue( workingMemory, object2 );
+ }
+
+ public String toString() {
+ return "Integer <";
+ }
+ }
+
+ static class IntegerLessOrEqualEvaluator extends BaseEvaluator {
+ /**
+ *
+ */
+ private static final long serialVersionUID = 400L;
+ public final static Evaluator INSTANCE = new IntegerLessOrEqualEvaluator();
+
+ private IntegerLessOrEqualEvaluator() {
+ super( ValueType.PINTEGER_TYPE,
+ Operator.LESS_OR_EQUAL );
+ }
+
+ public boolean evaluate(InternalWorkingMemory workingMemory,
+ final Extractor extractor,
+ final Object object1, final FieldValue object2) {
+ if( extractor.isNullValue( workingMemory, object1 ) ) {
+ return false;
+ }
+ return extractor.getIntValue( workingMemory, object1 ) <= object2.getIntValue();
+ }
+
+ public boolean evaluateCachedRight(InternalWorkingMemory workingMemory,
+ final VariableContextEntry context, final Object left) {
+ if( context.rightNull ) {
+ return false;
+ }
+ return ((LongVariableContextEntry) context).right <= context.declaration.getExtractor().getIntValue( workingMemory, left );
+ }
+
+ public boolean evaluateCachedLeft(InternalWorkingMemory workingMemory,
+ final VariableContextEntry context, final Object right) {
+ if( context.extractor.isNullValue( workingMemory, right ) ) {
+ return false;
+ }
+ return context.extractor.getIntValue( workingMemory, right ) <= ((LongVariableContextEntry) context).left;
+ }
+
+ public boolean evaluate(InternalWorkingMemory workingMemory,
+ final Extractor extractor1,
+ final Object object1,
+ final Extractor extractor2, final Object object2) {
+ if( extractor1.isNullValue( workingMemory, object1 ) ) {
+ return false;
+ }
+ return extractor1.getIntValue( workingMemory, object1 ) <= extractor2.getIntValue( workingMemory, object2 );
+ }
+
+ public String toString() {
+ return "Integer <=";
+ }
+ }
+
+ static class IntegerGreaterEvaluator extends BaseEvaluator {
+ /**
+ *
+ */
+ private static final long serialVersionUID = 400L;
+ public final static Evaluator INSTANCE = new IntegerGreaterEvaluator();
+
+ private IntegerGreaterEvaluator() {
+ super( ValueType.PINTEGER_TYPE,
+ Operator.GREATER );
+ }
+
+ public boolean evaluate(InternalWorkingMemory workingMemory,
+ final Extractor extractor,
+ final Object object1, final FieldValue object2) {
+ if( extractor.isNullValue( workingMemory, object1 ) ) {
+ return false;
+ }
+ return extractor.getIntValue( workingMemory, object1 ) > object2.getIntValue();
+ }
+
+ public boolean evaluateCachedRight(InternalWorkingMemory workingMemory,
+ final VariableContextEntry context, final Object left) {
+ if( context.rightNull ) {
+ return false;
+ }
+ return ((LongVariableContextEntry) context).right > context.declaration.getExtractor().getIntValue( workingMemory, left );
+ }
+
+ public boolean evaluateCachedLeft(InternalWorkingMemory workingMemory,
+ final VariableContextEntry context, final Object right) {
+ if( context.extractor.isNullValue( workingMemory, right ) ) {
+ return false;
+ }
+ return context.extractor.getIntValue( workingMemory, right ) > ((LongVariableContextEntry) context).left;
+ }
+
+ public boolean evaluate(InternalWorkingMemory workingMemory,
+ final Extractor extractor1,
+ final Object object1,
+ final Extractor extractor2, final Object object2) {
+ if( extractor1.isNullValue( workingMemory, object1 ) ) {
+ return false;
+ }
+ return extractor1.getIntValue( workingMemory, object1 ) > extractor2.getIntValue( workingMemory, object2 );
+ }
+
+ public String toString() {
+ return "Integer >";
+ }
+ }
+
+ static class IntegerGreaterOrEqualEvaluator extends BaseEvaluator {
+ /**
+ *
+ */
+ private static final long serialVersionUID = 400L;
+ private final static Evaluator INSTANCE = new IntegerGreaterOrEqualEvaluator();
+
+ private IntegerGreaterOrEqualEvaluator() {
+ super( ValueType.PINTEGER_TYPE,
+ Operator.GREATER_OR_EQUAL );
+ }
+
+ public boolean evaluate(InternalWorkingMemory workingMemory,
+ final Extractor extractor,
+ final Object object1, final FieldValue object2) {
+ if( extractor.isNullValue( workingMemory, object1 ) ) {
+ return false;
+ }
+ return extractor.getIntValue( workingMemory, object1 ) >= object2.getIntValue();
+ }
+
+ public boolean evaluateCachedRight(InternalWorkingMemory workingMemory,
+ final VariableContextEntry context, final Object left) {
+ if( context.rightNull ) {
+ return false;
+ }
+ return ((LongVariableContextEntry) context).right >= context.declaration.getExtractor().getIntValue( workingMemory, left );
+ }
+
+ public boolean evaluateCachedLeft(InternalWorkingMemory workingMemory,
+ final VariableContextEntry context, final Object right) {
+ if( context.extractor.isNullValue( workingMemory, right ) ) {
+ return false;
+ }
+ return context.extractor.getIntValue( workingMemory, right ) >= ((LongVariableContextEntry) context).left;
+ }
+
+ public boolean evaluate(InternalWorkingMemory workingMemory,
+ final Extractor extractor1,
+ final Object object1,
+ final Extractor extractor2, final Object object2) {
+ if( extractor1.isNullValue( workingMemory, object1 ) ) {
+ return false;
+ }
+ return extractor1.getIntValue( workingMemory, object1 ) >= extractor2.getIntValue( workingMemory, object2 );
+ }
+
+ public String toString() {
+ return "Integer >=";
+ }
+ }
+
+ static class LongLessEvaluator extends BaseEvaluator {
+ /**
+ *
+ */
+ private static final long serialVersionUID = 400L;
+ public final static Evaluator INSTANCE = new LongLessEvaluator();
+
+ private LongLessEvaluator() {
+ super( ValueType.PLONG_TYPE,
+ Operator.LESS );
+ }
+
+ public boolean evaluate(InternalWorkingMemory workingMemory,
+ final Extractor extractor,
+ final Object object1, final FieldValue object2) {
+ if( extractor.isNullValue( workingMemory, object1 ) ) {
+ return false;
+ }
+ return extractor.getLongValue( workingMemory, object1 ) < object2.getLongValue();
+ }
+
+ public boolean evaluateCachedRight(InternalWorkingMemory workingMemory,
+ final VariableContextEntry context, final Object left) {
+ if( context.rightNull ) {
+ return false;
+ }
+ return ((LongVariableContextEntry) context).right < context.declaration.getExtractor().getLongValue( workingMemory, left );
+ }
+
+ public boolean evaluateCachedLeft(InternalWorkingMemory workingMemory,
+ final VariableContextEntry context, final Object right) {
+ if( context.extractor.isNullValue( workingMemory, right ) ) {
+ return false;
+ }
+ return context.extractor.getLongValue( workingMemory, right ) < ((LongVariableContextEntry) context).left;
+ }
+
+ public boolean evaluate(InternalWorkingMemory workingMemory,
+ final Extractor extractor1,
+ final Object object1,
+ final Extractor extractor2, final Object object2) {
+ if( extractor1.isNullValue( workingMemory, object1 ) ) {
+ return false;
+ }
+ return extractor1.getLongValue( workingMemory, object1 ) < extractor2.getLongValue( workingMemory, object2 );
+ }
+
+ public String toString() {
+ return "Long <";
+ }
+ }
+
+ static class LongLessOrEqualEvaluator extends BaseEvaluator {
+ /**
+ *
+ */
+ private static final long serialVersionUID = 400L;
+ public final static Evaluator INSTANCE = new LongLessOrEqualEvaluator();
+
+ private LongLessOrEqualEvaluator() {
+ super( ValueType.PLONG_TYPE,
+ Operator.LESS_OR_EQUAL );
+ }
+
+ public boolean evaluate(InternalWorkingMemory workingMemory,
+ final Extractor extractor,
+ final Object object1, final FieldValue object2) {
+ if( extractor.isNullValue( workingMemory, object1 ) ) {
+ return false;
+ }
+ return extractor.getLongValue( workingMemory, object1 ) <= object2.getLongValue();
+ }
+
+ public boolean evaluateCachedRight(InternalWorkingMemory workingMemory,
+ final VariableContextEntry context, final Object left) {
+ if( context.rightNull ) {
+ return false;
+ }
+ return ((LongVariableContextEntry) context).right <= context.declaration.getExtractor().getLongValue( workingMemory, left );
+ }
+
+ public boolean evaluateCachedLeft(InternalWorkingMemory workingMemory,
+ final VariableContextEntry context, final Object right) {
+ if( context.extractor.isNullValue( workingMemory, right ) ) {
+ return false;
+ }
+ return context.extractor.getLongValue( workingMemory, right ) <= ((LongVariableContextEntry) context).left;
+ }
+
+ public boolean evaluate(InternalWorkingMemory workingMemory,
+ final Extractor extractor1,
+ final Object object1,
+ final Extractor extractor2, final Object object2) {
+ if( extractor1.isNullValue( workingMemory, object1 ) ) {
+ return false;
+ }
+ return extractor1.getLongValue( workingMemory, object1 ) <= extractor2.getLongValue( workingMemory, object2 );
+ }
+
+ public String toString() {
+ return "Long <=";
+ }
+ }
+
+ static class LongGreaterEvaluator extends BaseEvaluator {
+ /**
+ *
+ */
+ private static final long serialVersionUID = 400L;
+ public final static Evaluator INSTANCE = new LongGreaterEvaluator();
+
+ private LongGreaterEvaluator() {
+ super( ValueType.PLONG_TYPE,
+ Operator.GREATER );
+ }
+
+ public boolean evaluate(InternalWorkingMemory workingMemory,
+ final Extractor extractor,
+ final Object object1, final FieldValue object2) {
+ if( extractor.isNullValue( workingMemory, object1 ) ) {
+ return false;
+ }
+ return extractor.getLongValue( workingMemory, object1 ) > object2.getLongValue();
+ }
+
+ public boolean evaluateCachedRight(InternalWorkingMemory workingMemory,
+ final VariableContextEntry context, final Object left) {
+ if( context.rightNull ) {
+ return false;
+ }
+ return ((LongVariableContextEntry) context).right > context.declaration.getExtractor().getLongValue( workingMemory, left );
+ }
+
+ public boolean evaluateCachedLeft(InternalWorkingMemory workingMemory,
+ final VariableContextEntry context, final Object right) {
+ if( context.extractor.isNullValue( workingMemory, right ) ) {
+ return false;
+ }
+ return context.extractor.getLongValue( workingMemory, right ) > ((LongVariableContextEntry) context).left;
+ }
+
+ public boolean evaluate(InternalWorkingMemory workingMemory,
+ final Extractor extractor1,
+ final Object object1,
+ final Extractor extractor2, final Object object2) {
+ if( extractor1.isNullValue( workingMemory, object1 ) ) {
+ return false;
+ }
+ return extractor1.getLongValue( workingMemory, object1 ) > extractor2.getLongValue( workingMemory, object2 );
+ }
+
+ public String toString() {
+ return "Long >";
+ }
+ }
+
+ static class LongGreaterOrEqualEvaluator extends BaseEvaluator {
+ /**
+ *
+ */
+ private static final long serialVersionUID = 400L;
+ private final static Evaluator INSTANCE = new LongGreaterOrEqualEvaluator();
+
+ private LongGreaterOrEqualEvaluator() {
+ super( ValueType.PLONG_TYPE,
+ Operator.GREATER_OR_EQUAL );
+ }
+
+ public boolean evaluate(InternalWorkingMemory workingMemory,
+ final Extractor extractor,
+ final Object object1, final FieldValue object2) {
+ if( extractor.isNullValue( workingMemory, object1 ) ) {
+ return false;
+ }
+ return extractor.getLongValue( workingMemory, object1 ) >= object2.getLongValue();
+ }
+
+ public boolean evaluateCachedRight(InternalWorkingMemory workingMemory,
+ final VariableContextEntry context, final Object left) {
+ if( context.rightNull ) {
+ return false;
+ }
+ return ((LongVariableContextEntry) context).right >= context.declaration.getExtractor().getLongValue( workingMemory, left );
+ }
+
+ public boolean evaluateCachedLeft(InternalWorkingMemory workingMemory,
+ final VariableContextEntry context, final Object right) {
+ if( context.extractor.isNullValue( workingMemory, right ) ) {
+ return false;
+ }
+ return context.extractor.getLongValue( workingMemory, right ) >= ((LongVariableContextEntry) context).left;
+ }
+
+ public boolean evaluate(InternalWorkingMemory workingMemory,
+ final Extractor extractor1,
+ final Object object1,
+ final Extractor extractor2, final Object object2) {
+ if( extractor1.isNullValue( workingMemory, object1 ) ) {
+ return false;
+ }
+ return extractor1.getLongValue( workingMemory, object1 ) >= extractor2.getLongValue( workingMemory, object2 );
+ }
+
+ public String toString() {
+ return "Long >=";
+ }
+ }
+
+ static class ObjectLessEvaluator extends BaseEvaluator {
+ private static final long serialVersionUID = 400L;
+ public final static Evaluator INSTANCE = new ObjectLessEvaluator();
+
+ private ObjectLessEvaluator() {
+ super( ValueType.OBJECT_TYPE,
+ Operator.LESS );
+ }
+
+ public boolean evaluate(InternalWorkingMemory workingMemory,
+ final Extractor extractor,
+ final Object object1, final FieldValue object2) {
+ if( extractor.isNullValue( workingMemory, object1 ) ) {
+ return false;
+ }
+ final Comparable comp = (Comparable) extractor.getValue( workingMemory, object1 );
+ return comp.compareTo( object2.getValue() ) < 0;
+ }
+
+ public boolean evaluateCachedRight(InternalWorkingMemory workingMemory,
+ final VariableContextEntry context, final Object left) {
+ if( context.rightNull ) {
+ return false;
+ }
+ final Comparable comp = (Comparable) ((ObjectVariableContextEntry) context).right;
+ return comp.compareTo( context.declaration.getExtractor().getValue( workingMemory, left ) ) < 0;
+ }
+
+ public boolean evaluateCachedLeft(InternalWorkingMemory workingMemory,
+ final VariableContextEntry context, final Object right) {
+ if( context.extractor.isNullValue( workingMemory, right ) ) {
+ return false;
+ }
+ final Comparable comp = (Comparable) context.extractor.getValue( workingMemory, right );
+ return comp.compareTo( ((ObjectVariableContextEntry) context).left ) < 0;
+ }
+
+ public boolean evaluate(InternalWorkingMemory workingMemory,
+ final Extractor extractor1,
+ final Object object1,
+ final Extractor extractor2, final Object object2) {
+ if( extractor1.isNullValue( workingMemory, object1 ) ) {
+ return false;
+ }
+ final Comparable comp = (Comparable) extractor1.getValue( workingMemory, object1 );
+ return comp.compareTo( extractor2.getValue( workingMemory, object2 ) ) < 0;
+ }
+
+ public String toString() {
+ return "Object <";
+ }
+ }
+
+ static class ObjectLessOrEqualEvaluator extends BaseEvaluator {
+ /**
+ *
+ */
+ private static final long serialVersionUID = 400L;
+ public final static Evaluator INSTANCE = new ObjectLessOrEqualEvaluator();
+
+ private ObjectLessOrEqualEvaluator() {
+ super( ValueType.OBJECT_TYPE,
+ Operator.LESS_OR_EQUAL );
+ }
+
+ public boolean evaluate(InternalWorkingMemory workingMemory,
+ final Extractor extractor,
+ final Object object1, final FieldValue object2) {
+ if( extractor.isNullValue( workingMemory, object1 ) ) {
+ return false;
+ }
+ final Comparable comp = (Comparable) extractor.getValue( workingMemory, object1 );
+ return comp.compareTo( object2.getValue() ) <= 0;
+ }
+
+ public boolean evaluateCachedRight(InternalWorkingMemory workingMemory,
+ final VariableContextEntry context, final Object left) {
+ if( context.rightNull ) {
+ return false;
+ }
+ final Comparable comp = (Comparable) ((ObjectVariableContextEntry) context).right;
+ return comp.compareTo( context.declaration.getExtractor().getValue( workingMemory, left ) ) <= 0;
+ }
+
+ public boolean evaluateCachedLeft(InternalWorkingMemory workingMemory,
+ final VariableContextEntry context, final Object right) {
+ if( context.extractor.isNullValue( workingMemory, right ) ) {
+ return false;
+ }
+ final Comparable comp = (Comparable) context.extractor.getValue( workingMemory, right );
+ return comp.compareTo( ((ObjectVariableContextEntry) context).left ) <= 0;
+ }
+
+ public boolean evaluate(InternalWorkingMemory workingMemory,
+ final Extractor extractor1,
+ final Object object1,
+ final Extractor extractor2, final Object object2) {
+ if( extractor1.isNullValue( workingMemory, object1 ) ) {
+ return false;
+ }
+ final Comparable comp = (Comparable) extractor1.getValue( workingMemory, object1 );
+ return comp.compareTo( extractor2.getValue( workingMemory, object2 ) ) <= 0;
+ }
+
+ public String toString() {
+ return "Object <=";
+ }
+ }
+
+ static class ObjectGreaterEvaluator extends BaseEvaluator {
+ /**
+ *
+ */
+ private static final long serialVersionUID = 400L;
+ public final static Evaluator INSTANCE = new ObjectGreaterEvaluator();
+
+ private ObjectGreaterEvaluator() {
+ super( ValueType.OBJECT_TYPE,
+ Operator.GREATER );
+ }
+
+ public boolean evaluate(InternalWorkingMemory workingMemory,
+ final Extractor extractor,
+ final Object object1, final FieldValue object2) {
+ if( extractor.isNullValue( workingMemory, object1 ) ) {
+ return false;
+ }
+ final Comparable comp = (Comparable) extractor.getValue( workingMemory, object1 );
+ return comp.compareTo( object2.getValue() ) > 0;
+ }
+
+ public boolean evaluateCachedRight(InternalWorkingMemory workingMemory,
+ final VariableContextEntry context, final Object left) {
+ if( context.rightNull ) {
+ return false;
+ }
+ final Comparable comp = (Comparable) ((ObjectVariableContextEntry) context).right;
+ return comp.compareTo( context.declaration.getExtractor().getValue( workingMemory, left ) ) > 0;
+ }
+
+ public boolean evaluateCachedLeft(InternalWorkingMemory workingMemory,
+ final VariableContextEntry context, final Object right) {
+ if( context.extractor.isNullValue( workingMemory, right ) ) {
+ return false;
+ }
+ final Comparable comp = (Comparable) context.extractor.getValue( workingMemory, right );
+ return comp.compareTo( ((ObjectVariableContextEntry) context).left ) > 0;
+ }
+
+ public boolean evaluate(InternalWorkingMemory workingMemory,
+ final Extractor extractor1,
+ final Object object1,
+ final Extractor extractor2, final Object object2) {
+ if( extractor1.isNullValue( workingMemory, object1 ) ) {
+ return false;
+ }
+ final Comparable comp = (Comparable) extractor1.getValue( workingMemory, object1 );
+ return comp.compareTo( extractor2.getValue( workingMemory, object2 ) ) > 0;
+ }
+
+ public String toString() {
+ return "Object >";
+ }
+ }
+
+ static class ObjectGreaterOrEqualEvaluator extends BaseEvaluator {
+ /**
+ *
+ */
+ private static final long serialVersionUID = 400L;
+ public final static Evaluator INSTANCE = new ObjectGreaterOrEqualEvaluator();
+
+ private ObjectGreaterOrEqualEvaluator() {
+ super( ValueType.OBJECT_TYPE,
+ Operator.GREATER_OR_EQUAL );
+ }
+
+ public boolean evaluate(InternalWorkingMemory workingMemory,
+ final Extractor extractor,
+ final Object object1, final FieldValue object2) {
+ if( extractor.isNullValue( workingMemory, object1 ) ) {
+ return false;
+ }
+ final Comparable comp = (Comparable) extractor.getValue( workingMemory, object1 );
+ return comp.compareTo( object2.getValue() ) >= 0;
+ }
+
+ public boolean evaluateCachedRight(InternalWorkingMemory workingMemory,
+ final VariableContextEntry context, final Object left) {
+ if( context.rightNull ) {
+ return false;
+ }
+ final Comparable comp = (Comparable) ((ObjectVariableContextEntry) context).right;
+ return comp.compareTo( context.declaration.getExtractor().getValue( workingMemory, left ) ) >= 0;
+ }
+
+ public boolean evaluateCachedLeft(InternalWorkingMemory workingMemory,
+ final VariableContextEntry context, final Object right) {
+ if( context.extractor.isNullValue( workingMemory, right ) ) {
+ return false;
+ }
+ final Comparable comp = (Comparable) context.extractor.getValue( workingMemory, right );
+ return comp.compareTo( ((ObjectVariableContextEntry) context).left ) >= 0;
+ }
+
+ public boolean evaluate(InternalWorkingMemory workingMemory,
+ final Extractor extractor1,
+ final Object object1,
+ final Extractor extractor2, final Object object2) {
+ if( extractor1.isNullValue( workingMemory, object1 ) ) {
+ return false;
+ }
+ final Comparable comp = (Comparable) extractor1.getValue( workingMemory, object1 );
+ return comp.compareTo( extractor2.getValue( workingMemory, object2 ) ) >= 0;
+ }
+
+ public String toString() {
+ return "Object >=";
+ }
+ }
+
+ static class ShortLessEvaluator extends BaseEvaluator {
+ /**
+ *
+ */
+ private static final long serialVersionUID = 400L;
+ private static final Evaluator INSTANCE = new ShortLessEvaluator();
+
+ private ShortLessEvaluator() {
+ super( ValueType.PSHORT_TYPE,
+ Operator.LESS );
+ }
+
+ public boolean evaluate(InternalWorkingMemory workingMemory,
+ final Extractor extractor,
+ final Object object1, final FieldValue object2) {
+ if( extractor.isNullValue( workingMemory, object1 ) ) {
+ return false;
+ }
+ return extractor.getShortValue( workingMemory, object1 ) < object2.getShortValue();
+ }
+
+ public boolean evaluateCachedRight(InternalWorkingMemory workingMemory,
+ final VariableContextEntry context, final Object left) {
+ if( context.rightNull ) {
+ return false;
+ }
+ return ((LongVariableContextEntry) context).right < context.declaration.getExtractor().getShortValue( workingMemory, left );
+ }
+
+ public boolean evaluateCachedLeft(InternalWorkingMemory workingMemory,
+ final VariableContextEntry context, final Object right) {
+ if( context.extractor.isNullValue( workingMemory, right ) ) {
+ return false;
+ }
+ return context.extractor.getShortValue( workingMemory, right ) < ((LongVariableContextEntry) context).left;
+ }
+
+ public boolean evaluate(InternalWorkingMemory workingMemory,
+ final Extractor extractor1,
+ final Object object1,
+ final Extractor extractor2, final Object object2) {
+ if( extractor1.isNullValue( workingMemory, object1 ) ) {
+ return false;
+ }
+ return extractor1.getShortValue( workingMemory, object1 ) < extractor2.getShortValue( workingMemory, object2 );
+ }
+
+ public String toString() {
+ return "Short <";
+ }
+ }
+
+ static class ShortLessOrEqualEvaluator extends BaseEvaluator {
+ /**
+ *
+ */
+ private static final long serialVersionUID = 400L;
+ private static final Evaluator INSTANCE = new ShortLessOrEqualEvaluator();
+
+ private ShortLessOrEqualEvaluator() {
+ super( ValueType.PSHORT_TYPE,
+ Operator.LESS_OR_EQUAL );
+ }
+
+ public boolean evaluate(InternalWorkingMemory workingMemory,
+ final Extractor extractor,
+ final Object object1, final FieldValue object2) {
+ if( extractor.isNullValue( workingMemory, object1 ) ) {
+ return false;
+ }
+ return extractor.getShortValue( workingMemory, object1 ) <= object2.getShortValue();
+ }
+
+ public boolean evaluateCachedRight(InternalWorkingMemory workingMemory,
+ final VariableContextEntry context, final Object left) {
+ if( context.rightNull ) {
+ return false;
+ }
+ return ((LongVariableContextEntry) context).right <= context.declaration.getExtractor().getShortValue( workingMemory, left );
+ }
+
+ public boolean evaluateCachedLeft(InternalWorkingMemory workingMemory,
+ final VariableContextEntry context, final Object right) {
+ if( context.extractor.isNullValue( workingMemory, right ) ) {
+ return false;
+ }
+ return context.extractor.getShortValue( workingMemory, right ) <= ((LongVariableContextEntry) context).left;
+ }
+
+ public boolean evaluate(InternalWorkingMemory workingMemory,
+ final Extractor extractor1,
+ final Object object1,
+ final Extractor extractor2, final Object object2) {
+ if( extractor1.isNullValue( workingMemory, object1 ) ) {
+ return false;
+ }
+ return extractor1.getShortValue( workingMemory, object1 ) <= extractor2.getShortValue( workingMemory, object2 );
+ }
+
+ public String toString() {
+ return "Boolean <=";
+ }
+ }
+
+ static class ShortGreaterEvaluator extends BaseEvaluator {
+ /**
+ *
+ */
+ private static final long serialVersionUID = 400L;
+ private static final Evaluator INSTANCE = new ShortGreaterEvaluator();
+
+ private ShortGreaterEvaluator() {
+ super( ValueType.PSHORT_TYPE,
+ Operator.GREATER );
+ }
+
+ public boolean evaluate(InternalWorkingMemory workingMemory,
+ final Extractor extractor,
+ final Object object1, final FieldValue object2) {
+ if( extractor.isNullValue( workingMemory, object1 ) ) {
+ return false;
+ }
+ return extractor.getShortValue( workingMemory, object1 ) > object2.getShortValue();
+ }
+
+ public boolean evaluateCachedRight(InternalWorkingMemory workingMemory,
+ final VariableContextEntry context, final Object left) {
+ if( context.rightNull ) {
+ return false;
+ }
+ return ((LongVariableContextEntry) context).right > context.declaration.getExtractor().getShortValue( workingMemory, left );
+ }
+
+ public boolean evaluateCachedLeft(InternalWorkingMemory workingMemory,
+ final VariableContextEntry context, final Object right) {
+ if( context.extractor.isNullValue( workingMemory, right ) ) {
+ return false;
+ }
+ return context.extractor.getShortValue( workingMemory, right ) > ((LongVariableContextEntry) context).left;
+ }
+
+ public boolean evaluate(InternalWorkingMemory workingMemory,
+ final Extractor extractor1,
+ final Object object1,
+ final Extractor extractor2, final Object object2) {
+ if( extractor1.isNullValue( workingMemory, object1 ) ) {
+ return false;
+ }
+ return extractor1.getShortValue( workingMemory, object1 ) > extractor2.getShortValue( workingMemory, object2 );
+ }
+
+ public String toString() {
+ return "Short >";
+ }
+ }
+
+ static class ShortGreaterOrEqualEvaluator extends BaseEvaluator {
+ /**
+ *
+ */
+ private static final long serialVersionUID = 400L;
+ private static final Evaluator INSTANCE = new ShortGreaterOrEqualEvaluator();
+
+ private ShortGreaterOrEqualEvaluator() {
+ super( ValueType.PSHORT_TYPE,
+ Operator.GREATER_OR_EQUAL );
+ }
+
+ public boolean evaluate(InternalWorkingMemory workingMemory,
+ final Extractor extractor,
+ final Object object1, final FieldValue object2) {
+ if( extractor.isNullValue( workingMemory, object1 ) ) {
+ return false;
+ }
+ return extractor.getShortValue( workingMemory, object1 ) >= object2.getShortValue();
+ }
+
+ public boolean evaluateCachedRight(InternalWorkingMemory workingMemory,
+ final VariableContextEntry context, final Object left) {
+ if( context.rightNull ) {
+ return false;
+ }
+ return ((LongVariableContextEntry) context).right >= context.declaration.getExtractor().getShortValue( workingMemory, left );
+ }
+
+ public boolean evaluateCachedLeft(InternalWorkingMemory workingMemory,
+ final VariableContextEntry context, final Object right) {
+ if( context.extractor.isNullValue( workingMemory, right ) ) {
+ return false;
+ }
+ return context.extractor.getShortValue( workingMemory, right ) >= ((LongVariableContextEntry) context).left;
+ }
+
+ public boolean evaluate(InternalWorkingMemory workingMemory,
+ final Extractor extractor1,
+ final Object object1,
+ final Extractor extractor2, final Object object2) {
+ if( extractor1.isNullValue( workingMemory, object1 ) ) {
+ return false;
+ }
+ return extractor1.getShortValue( workingMemory, object1 ) >= extractor2.getShortValue( workingMemory, object2 );
+ }
+
+ public String toString() {
+ return "Short >=";
+ }
+ }
+
+
+}
Deleted: labs/jbossrules/branches/temporal_rete/drools-core/src/main/java/org/drools/base/evaluators/DateFactory.java
===================================================================
--- labs/jbossrules/branches/temporal_rete/drools-core/src/main/java/org/drools/base/evaluators/DateFactory.java 2007-12-07 13:39:06 UTC (rev 17088)
+++ labs/jbossrules/branches/temporal_rete/drools-core/src/main/java/org/drools/base/evaluators/DateFactory.java 2007-12-07 14:10:27 UTC (rev 17089)
@@ -1,535 +0,0 @@
-package org.drools.base.evaluators;
-
-/*
- * Copyright 2005 JBoss Inc
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-import java.text.ParseException;
-import java.text.SimpleDateFormat;
-import java.util.Date;
-
-import org.drools.base.BaseEvaluator;
-import org.drools.base.ValueType;
-import org.drools.common.InternalWorkingMemory;
-import org.drools.rule.VariableRestriction.ObjectVariableContextEntry;
-import org.drools.rule.VariableRestriction.VariableContextEntry;
-import org.drools.spi.Evaluator;
-import org.drools.spi.Extractor;
-import org.drools.spi.FieldValue;
-
-/**
- * This will generate evaluators that handle dates.
- * This will also parse strings into dates, according to
- * DEFAULT_FORMAT_MASK, unless it is overridden by the drools.dateformat system property.
- *
- * When parsing dates from a string, no time is included.
- *
- * So you can do expressions like
- * <code>Person(birthday <= "10-Jul-1974")</code> etc.
- *
- * @author Michael Neale
- */
-public class DateFactory
- implements
- EvaluatorFactory {
-
- private static final long serialVersionUID = 400L;
- private static final String DEFAULT_FORMAT_MASK = "dd-MMM-yyyy";
- private static final String DATE_FORMAT_MASK = getDateFormatMask();
-
- private static EvaluatorFactory INSTANCE = new DateFactory();
- private static SimpleDateFormat df;
-
- private DateFactory() {
- df = new SimpleDateFormat( DateFactory.DATE_FORMAT_MASK );
- }
-
- public static EvaluatorFactory getInstance() {
- if ( DateFactory.INSTANCE == null ) {
- DateFactory.INSTANCE = new DateFactory();
- }
- return DateFactory.INSTANCE;
- }
-
- public Evaluator getEvaluator(final Operator operator) {
- if ( operator == Operator.EQUAL ) {
- return DateEqualEvaluator.INSTANCE;
- } else if ( operator == Operator.NOT_EQUAL ) {
- return DateNotEqualEvaluator.INSTANCE;
- } else if ( operator == Operator.LESS ) {
- return DateLessEvaluator.INSTANCE;
- } else if ( operator == Operator.LESS_OR_EQUAL ) {
- return DateLessOrEqualEvaluator.INSTANCE;
- } else if ( operator == Operator.GREATER ) {
- return DateGreaterEvaluator.INSTANCE;
- } else if ( operator == Operator.GREATER_OR_EQUAL ) {
- return DateGreaterOrEqualEvaluator.INSTANCE;
- } else if ( operator == Operator.MEMBEROF ) {
- return DateMemberOfEvaluator.INSTANCE;
- } else if ( operator == Operator.NOTMEMBEROF ) {
- return DateNotMemberOfEvaluator.INSTANCE;
- } else {
- throw new RuntimeException( "Operator '" + operator + "' does not exist for DateEvaluator" );
- }
- }
-
- static class DateEqualEvaluator extends BaseEvaluator {
- /**
- *
- */
- private static final long serialVersionUID = 400L;
- public final static Evaluator INSTANCE = new DateEqualEvaluator();
-
- private DateEqualEvaluator() {
- super( ValueType.DATE_TYPE,
- Operator.EQUAL );
- }
-
- public boolean evaluate(InternalWorkingMemory workingMemory,
- final Extractor extractor,
- final Object object1, final FieldValue object2) {
- final Date value1 = (Date) extractor.getValue( workingMemory, object1 );
- final Object value2 = object2.getValue();
- if ( value1 == null ) {
- return value2 == null;
- }
- if ( value2 == null ) {
- return false;
- }
- return value1.compareTo( getRightDate( value2 ) ) == 0;
- }
-
- public boolean evaluateCachedRight(InternalWorkingMemory workingMemory,
- final VariableContextEntry context, final Object left) {
- final Date value1 = (Date) context.declaration.getExtractor().getValue( workingMemory, left );
- final Object value2 = ((ObjectVariableContextEntry) context).right;
- if ( value1 == null ) {
- return value2 == null;
- }
- if ( value2 == null ) {
- return false;
- }
- return value1.compareTo( getRightDate( value2 ) ) == 0;
- }
-
- public boolean evaluateCachedLeft(InternalWorkingMemory workingMemory,
- final VariableContextEntry context, final Object right) {
- final Date value1 = (Date) ((ObjectVariableContextEntry) context).left;
- final Object value2 = context.extractor.getValue( workingMemory, right );
- if ( value1 == null ) {
- return value2 == null;
- }
- if ( value2 == null ) {
- return false;
- }
- return value1.compareTo( getRightDate( value2 ) ) == 0;
- }
-
- public boolean evaluate(InternalWorkingMemory workingMemory,
- final Extractor extractor1,
- final Object object1,
- final Extractor extractor2, final Object object2) {
- final Date value1 = (Date) extractor1.getValue( workingMemory, object1 );
- final Date value2 = (Date) extractor2.getValue( workingMemory, object2 );
- if ( value1 == null ) {
- return value2 == null;
- }
- if ( value2 == null ) {
- return false;
- }
- return value1.compareTo( value2 ) == 0;
- }
-
- public String toString() {
- return "Date ==";
- }
-
- }
-
- static class DateNotEqualEvaluator extends BaseEvaluator {
- /**
- *
- */
- private static final long serialVersionUID = 400L;
- public final static Evaluator INSTANCE = new DateNotEqualEvaluator();
-
- private DateNotEqualEvaluator() {
- super( ValueType.DATE_TYPE,
- Operator.NOT_EQUAL );
- }
-
- public boolean evaluate(InternalWorkingMemory workingMemory,
- final Extractor extractor,
- final Object object1, final FieldValue object2) {
- final Date value1 = (Date) extractor.getValue( workingMemory, object1 );
- final Object value2 = object2.getValue();
- if ( value1 == null ) {
- return value2 != null;
- }
- if ( value2 == null ) {
- return true;
- }
- return value1.compareTo( getRightDate( value2 ) ) != 0;
- }
-
- public boolean evaluateCachedRight(InternalWorkingMemory workingMemory,
- final VariableContextEntry context, final Object left) {
- final Date value1 = (Date) context.declaration.getExtractor().getValue( workingMemory, left );
- final Object value2 = ((ObjectVariableContextEntry) context).right;
- if ( value1 == null ) {
- return value2 != null;
- }
- if ( value2 == null ) {
- return true;
- }
- return value1.compareTo( getRightDate( value2 ) ) != 0;
- }
-
- public boolean evaluateCachedLeft(InternalWorkingMemory workingMemory,
- final VariableContextEntry context, final Object right) {
- final Date value1 = (Date) ((ObjectVariableContextEntry) context).left;
- final Object value2 = context.extractor.getValue( workingMemory, right );
- if ( value1 == null ) {
- return value2 != null;
- }
- if ( value2 == null ) {
- return true;
- }
- return value1.compareTo( getRightDate( value2 ) ) != 0;
- }
-
- public boolean evaluate(InternalWorkingMemory workingMemory,
- final Extractor extractor1,
- final Object object1,
- final Extractor extractor2, final Object object2) {
- final Date value1 = (Date) extractor1.getValue( workingMemory, object1 );
- final Date value2 = (Date) extractor2.getValue( workingMemory, object2 );
- if ( value1 == null ) {
- return value2 != null;
- }
- if ( value2 == null ) {
- return true;
- }
- return value1.compareTo( value2 ) != 0;
- }
-
- public String toString() {
- return "Date !=";
- }
- }
-
- static class DateLessEvaluator extends BaseEvaluator {
- /**
- *
- */
- private static final long serialVersionUID = 400L;
- public final static Evaluator INSTANCE = new DateLessEvaluator();
-
- private DateLessEvaluator() {
- super( ValueType.DATE_TYPE,
- Operator.LESS );
- }
-
- public boolean evaluate(InternalWorkingMemory workingMemory,
- final Extractor extractor,
- final Object object1, final FieldValue object2) {
- if( extractor.isNullValue( workingMemory, object1 ) ) {
- return false;
- }
- final Date value1 = (Date) extractor.getValue( workingMemory, object1 );
- final Object value2 = object2.getValue();
- return value1.compareTo( getRightDate( value2 ) ) < 0;
- }
-
- public boolean evaluateCachedRight(InternalWorkingMemory workingMemory,
- final VariableContextEntry context, final Object left) {
- if( context.rightNull ) {
- return false;
- }
- final Date value1 = (Date) context.declaration.getExtractor().getValue( workingMemory, left );
- final Object value2 = ((ObjectVariableContextEntry) context).right;
- return getRightDate( value2 ).compareTo( value1 ) < 0;
- }
-
- public boolean evaluateCachedLeft(InternalWorkingMemory workingMemory,
- final VariableContextEntry context, final Object right) {
- if( context.extractor.isNullValue( workingMemory, right ) ) {
- return false;
- }
- final Date value1 = (Date) ((ObjectVariableContextEntry) context).left;
- final Object value2 = context.extractor.getValue( workingMemory, right );
- return getRightDate( value2 ).compareTo( value1 ) < 0;
- }
-
- public boolean evaluate(InternalWorkingMemory workingMemory,
- final Extractor extractor1,
- final Object object1,
- final Extractor extractor2, final Object object2) {
- if( extractor1.isNullValue( workingMemory, object1 ) ) {
- return false;
- }
- final Date value1 = (Date) extractor1.getValue( workingMemory, object1 );
- final Date value2 = (Date) extractor2.getValue( workingMemory, object2 );
- return value1.compareTo( value2 ) < 0;
- }
-
- public String toString() {
- return "Date <";
- }
- }
-
- static class DateLessOrEqualEvaluator extends BaseEvaluator {
- /**
- *
- */
- private static final long serialVersionUID = 400L;
- public final static Evaluator INSTANCE = new DateLessOrEqualEvaluator();
-
- private DateLessOrEqualEvaluator() {
- super( ValueType.DATE_TYPE,
- Operator.LESS_OR_EQUAL );
- }
-
- public boolean evaluate(InternalWorkingMemory workingMemory,
- final Extractor extractor,
- final Object object1, final FieldValue object2) {
- if( extractor.isNullValue( workingMemory, object1 ) ) {
- return false;
- }
- final Date value1 = (Date) extractor.getValue( workingMemory, object1 );
- final Object value2 = object2.getValue();
- return value1.compareTo( getRightDate( value2 ) ) <= 0;
- }
-
- public boolean evaluateCachedRight(InternalWorkingMemory workingMemory,
- final VariableContextEntry context, final Object left) {
- if( context.rightNull ) {
- return false;
- }
- final Date value1 = (Date) context.declaration.getExtractor().getValue( workingMemory, left );
- final Object value2 = ((ObjectVariableContextEntry) context).right;
- return getRightDate( value2 ).compareTo( value1 ) <= 0;
- }
-
- public boolean evaluateCachedLeft(InternalWorkingMemory workingMemory,
- final VariableContextEntry context, final Object right) {
- if( context.extractor.isNullValue( workingMemory, right ) ) {
- return false;
- }
- final Date value1 = (Date) ((ObjectVariableContextEntry) context).left;
- final Object value2 = context.extractor.getValue( workingMemory, right );
- return getRightDate( value2 ).compareTo( value1 ) <= 0;
- }
-
- public boolean evaluate(InternalWorkingMemory workingMemory,
- final Extractor extractor1,
- final Object object1,
- final Extractor extractor2, final Object object2) {
- if( extractor1.isNullValue( workingMemory, object1 ) ) {
- return false;
- }
- final Date value1 = (Date) extractor1.getValue( workingMemory, object1 );
- final Date value2 = (Date) extractor2.getValue( workingMemory, object2 );
- return value1.compareTo( value2 ) <= 0;
- }
-
- public String toString() {
- return "Date <=";
- }
- }
-
- static class DateGreaterEvaluator extends BaseEvaluator {
- /**
- *
- */
- private static final long serialVersionUID = 400L;
- public final static Evaluator INSTANCE = new DateGreaterEvaluator();
-
- private DateGreaterEvaluator() {
- super( ValueType.DATE_TYPE,
- Operator.GREATER );
- }
-
- public boolean evaluate(InternalWorkingMemory workingMemory,
- final Extractor extractor,
- final Object object1, final FieldValue object2) {
- if( extractor.isNullValue( workingMemory, object1 ) ) {
- return false;
- }
- final Date value1 = (Date) extractor.getValue( workingMemory, object1 );
- final Object value2 = object2.getValue();
- return value1.compareTo( getRightDate( value2 ) ) > 0;
- }
-
- public boolean evaluateCachedRight(InternalWorkingMemory workingMemory,
- final VariableContextEntry context, final Object left) {
- if( context.rightNull ) {
- return false;
- }
- final Date value1 = (Date) context.declaration.getExtractor().getValue( workingMemory, left );
- final Object value2 = ((ObjectVariableContextEntry) context).right;
- return getRightDate( value2 ).compareTo( value1 ) > 0;
- }
-
- public boolean evaluateCachedLeft(InternalWorkingMemory workingMemory,
- final VariableContextEntry context, final Object right) {
- if( context.extractor.isNullValue( workingMemory, right ) ) {
- return false;
- }
- final Date value1 = (Date) ((ObjectVariableContextEntry) context).left;
- final Object value2 = context.extractor.getValue( workingMemory, right );
- return getRightDate( value2 ).compareTo( value1 ) > 0;
- }
-
- public boolean evaluate(InternalWorkingMemory workingMemory,
- final Extractor extractor1,
- final Object object1,
- final Extractor extractor2, final Object object2) {
- if( extractor1.isNullValue( workingMemory, object1 ) ) {
- return false;
- }
- final Date value1 = (Date) extractor1.getValue( workingMemory, object1 );
- final Date value2 = (Date) extractor2.getValue( workingMemory, object2 );
- return value1.compareTo( value2 ) > 0;
- }
-
- public String toString() {
- return "Date >";
- }
- }
-
- static class DateGreaterOrEqualEvaluator extends BaseEvaluator {
- /**
- *
- */
- private static final long serialVersionUID = 400L;
- private final static Evaluator INSTANCE = new DateGreaterOrEqualEvaluator();
-
- private DateGreaterOrEqualEvaluator() {
- super( ValueType.DATE_TYPE,
- Operator.GREATER_OR_EQUAL );
- }
-
- public boolean evaluate(InternalWorkingMemory workingMemory,
- final Extractor extractor,
- final Object object1, final FieldValue object2) {
- if( extractor.isNullValue( workingMemory, object1 ) ) {
- return false;
- }
- final Date value1 = (Date) extractor.getValue( workingMemory, object1 );
- final Object value2 = object2.getValue();
- return value1.compareTo( getRightDate( value2 ) ) >= 0;
- }
-
- public boolean evaluateCachedRight(InternalWorkingMemory workingMemory,
- final VariableContextEntry context, final Object left) {
- if( context.rightNull ) {
- return false;
- }
- final Date value1 = (Date) context.declaration.getExtractor().getValue( workingMemory, left );
- final Object value2 = ((ObjectVariableContextEntry) context).right;
- return getRightDate( value2 ).compareTo( value1 ) >= 0;
- }
-
- public boolean evaluateCachedLeft(InternalWorkingMemory workingMemory,
- final VariableContextEntry context, final Object right) {
- if( context.extractor.isNullValue( workingMemory, right ) ) {
- return false;
- }
- final Date value1 = (Date) ((ObjectVariableContextEntry) context).left;
- final Object value2 = context.extractor.getValue( workingMemory, right );
- return getRightDate( value2 ).compareTo( value1 ) >= 0;
- }
-
- public boolean evaluate(InternalWorkingMemory workingMemory,
- final Extractor extractor1,
- final Object object1,
- final Extractor extractor2, final Object object2) {
- if( extractor1.isNullValue( workingMemory, object1 ) ) {
- return false;
- }
- final Date value1 = (Date) extractor1.getValue( workingMemory, object1 );
- final Date value2 = (Date) extractor2.getValue( workingMemory, object2 );
- return value1.compareTo( value2 ) >= 0;
- }
-
- public String toString() {
- return "Date >=";
- }
- }
-
- static class DateMemberOfEvaluator extends BaseMemberOfEvaluator {
-
- private static final long serialVersionUID = 400L;
- public final static Evaluator INSTANCE = new DateMemberOfEvaluator();
-
- private DateMemberOfEvaluator() {
- super( ValueType.DATE_TYPE,
- Operator.MEMBEROF );
- }
-
- public String toString() {
- return "Date memberOf";
- }
- }
-
- static class DateNotMemberOfEvaluator extends BaseNotMemberOfEvaluator {
-
- private static final long serialVersionUID = 400L;
- public final static Evaluator INSTANCE = new DateNotMemberOfEvaluator();
-
- private DateNotMemberOfEvaluator() {
- super( ValueType.DATE_TYPE,
- Operator.NOTMEMBEROF );
- }
-
- public String toString() {
- return "Date not memberOf";
- }
- }
-
- /** Use the simple date formatter to read the date from a string */
- public static Date parseDate(final String input) {
- try {
- return df.parse( input );
- } catch ( final ParseException e ) {
- throw new IllegalArgumentException( "Invalid date input format: [" + input + "] it should follow: [" + DateFactory.DATE_FORMAT_MASK + "]" );
- }
- }
-
- /** Converts the right hand side date as appropriate */
- private static Date getRightDate(final Object object2) {
- if ( object2 == null ) {
- return null;
- }
- if ( object2 instanceof String ) {
- return parseDate( (String) object2 );
- } else if ( object2 instanceof Date ) {
- return (Date) object2;
- } else {
- throw new IllegalArgumentException( "Unable to convert " + object2.getClass() + " to a Date." );
- }
- }
-
- /** Check for the system property override, if it exists */
- private static String getDateFormatMask() {
- String fmt = System.getProperty( "drools.dateformat" );
- if ( fmt == null ) {
- fmt = DateFactory.DEFAULT_FORMAT_MASK;
- }
- return fmt;
- }
-
-}
\ No newline at end of file
Deleted: labs/jbossrules/branches/temporal_rete/drools-core/src/main/java/org/drools/base/evaluators/DoubleFactory.java
===================================================================
--- labs/jbossrules/branches/temporal_rete/drools-core/src/main/java/org/drools/base/evaluators/DoubleFactory.java 2007-12-07 13:39:06 UTC (rev 17088)
+++ labs/jbossrules/branches/temporal_rete/drools-core/src/main/java/org/drools/base/evaluators/DoubleFactory.java 2007-12-07 14:10:27 UTC (rev 17089)
@@ -1,456 +0,0 @@
-package org.drools.base.evaluators;
-
-/*
- * Copyright 2005 JBoss Inc
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-import org.drools.base.BaseEvaluator;
-import org.drools.base.ValueType;
-import org.drools.common.InternalWorkingMemory;
-import org.drools.rule.VariableRestriction.DoubleVariableContextEntry;
-import org.drools.rule.VariableRestriction.VariableContextEntry;
-import org.drools.spi.Evaluator;
-import org.drools.spi.Extractor;
-import org.drools.spi.FieldValue;
-
-public class DoubleFactory
- implements
- EvaluatorFactory {
-
- private static final long serialVersionUID = 400L;
- private static EvaluatorFactory INSTANCE = new DoubleFactory();
-
- private DoubleFactory() {
-
- }
-
- public static EvaluatorFactory getInstance() {
- if ( DoubleFactory.INSTANCE == null ) {
- DoubleFactory.INSTANCE = new DoubleFactory();
- }
- return DoubleFactory.INSTANCE;
- }
-
- public Evaluator getEvaluator(final Operator operator) {
- if ( operator == Operator.EQUAL ) {
- return DoubleEqualEvaluator.INSTANCE;
- } else if ( operator == Operator.NOT_EQUAL ) {
- return DoubleNotEqualEvaluator.INSTANCE;
- } else if ( operator == Operator.LESS ) {
- return DoubleLessEvaluator.INSTANCE;
- } else if ( operator == Operator.LESS_OR_EQUAL ) {
- return DoubleLessOrEqualEvaluator.INSTANCE;
- } else if ( operator == Operator.GREATER ) {
- return DoubleGreaterEvaluator.INSTANCE;
- } else if ( operator == Operator.GREATER_OR_EQUAL ) {
- return DoubleGreaterOrEqualEvaluator.INSTANCE;
- } else if ( operator == Operator.MEMBEROF ) {
- return DoubleMemberOfEvaluator.INSTANCE;
- } else if ( operator == Operator.NOTMEMBEROF ) {
- return DoubleNotMemberOfEvaluator.INSTANCE;
- } else {
- throw new RuntimeException( "Operator '" + operator + "' does not exist for DoubleEvaluator" );
- }
- }
-
- static class DoubleEqualEvaluator extends BaseEvaluator {
- /**
- *
- */
- private static final long serialVersionUID = 400L;
- public final static Evaluator INSTANCE = new DoubleEqualEvaluator();
-
- private DoubleEqualEvaluator() {
- super( ValueType.PDOUBLE_TYPE,
- Operator.EQUAL );
- }
-
- public boolean evaluate(InternalWorkingMemory workingMemory,
- final Extractor extractor,
- final Object object1, final FieldValue object2) {
- if ( extractor.isNullValue( workingMemory, object1 ) ) {
- return object2.isNull();
- } else if ( object2.isNull() ) {
- return false;
- }
- // TODO: we are not handling delta right now... maybe we should
- return extractor.getDoubleValue( workingMemory, object1 ) == object2.getDoubleValue();
- }
-
- public boolean evaluateCachedRight(InternalWorkingMemory workingMemory,
- final VariableContextEntry context, final Object left) {
- if ( context.declaration.getExtractor().isNullValue( workingMemory, left ) ) {
- return context.isRightNull();
- } else if ( context.isRightNull() ) {
- return false;
- }
- // TODO: we are not handling delta right now... maybe we should
- return context.declaration.getExtractor().getDoubleValue( workingMemory, left ) == ((DoubleVariableContextEntry) context).right;
- }
-
- public boolean evaluateCachedLeft(InternalWorkingMemory workingMemory,
- final VariableContextEntry context, final Object right) {
- if ( context.extractor.isNullValue( workingMemory, right )) {
- return context.isLeftNull();
- } else if ( context.isLeftNull() ) {
- return false;
- }
-
- // TODO: we are not handling delta right now... maybe we should
- return ((DoubleVariableContextEntry) context).left == context.extractor.getDoubleValue( workingMemory, right );
- }
-
- public boolean evaluate(InternalWorkingMemory workingMemory,
- final Extractor extractor1,
- final Object object1,
- final Extractor extractor2, final Object object2) {
- if (extractor1.isNullValue( workingMemory, object1 )) {
- return extractor2.isNullValue( workingMemory, object2 );
- } else if (extractor2.isNullValue( workingMemory, object2 )) {
- return false;
- }
-
- // TODO: we are not handling delta right now... maybe we should
- return extractor1.getDoubleValue( workingMemory, object1 ) == extractor2.getDoubleValue( workingMemory, object2 );
- }
-
- public String toString() {
- return "Double ==";
- }
- }
-
- static class DoubleNotEqualEvaluator extends BaseEvaluator {
- /**
- *
- */
- private static final long serialVersionUID = 400L;
- public final static Evaluator INSTANCE = new DoubleNotEqualEvaluator();
-
- private DoubleNotEqualEvaluator() {
- super( ValueType.PDOUBLE_TYPE,
- Operator.NOT_EQUAL );
- }
-
- public boolean evaluate(InternalWorkingMemory workingMemory,
- final Extractor extractor,
- final Object object1, final FieldValue object2) {
- if ( extractor.isNullValue( workingMemory, object1 ) ) {
- return !object2.isNull();
- } else if ( object2.isNull() ) {
- return true;
- }
-
- // TODO: we are not handling delta right now... maybe we should
- return extractor.getDoubleValue( workingMemory, object1 ) != object2.getDoubleValue();
- }
-
- public boolean evaluateCachedRight(InternalWorkingMemory workingMemory,
- final VariableContextEntry context, final Object left) {
- if ( context.declaration.getExtractor().isNullValue( workingMemory, left ) ) {
- return !context.isRightNull();
- } else if ( context.isRightNull() ) {
- return true;
- }
-
- // TODO: we are not handling delta right now... maybe we should
- return context.declaration.getExtractor().getDoubleValue( workingMemory, left ) != ((DoubleVariableContextEntry) context).right;
- }
-
- public boolean evaluateCachedLeft(InternalWorkingMemory workingMemory,
- final VariableContextEntry context, final Object right) {
- if ( context.extractor.isNullValue( workingMemory, right )) {
- return !context.isLeftNull();
- } else if ( context.isLeftNull() ) {
- return true;
- }
-
- // TODO: we are not handling delta right now... maybe we should
- return ((DoubleVariableContextEntry) context).left != context.extractor.getDoubleValue( workingMemory, right );
- }
-
- public boolean evaluate(InternalWorkingMemory workingMemory,
- final Extractor extractor1,
- final Object object1,
- final Extractor extractor2, final Object object2) {
- if (extractor1.isNullValue( workingMemory, object1 )) {
- return !extractor2.isNullValue( workingMemory, object2 );
- } else if (extractor2.isNullValue( workingMemory, object2 )) {
- return true;
- }
-
- // TODO: we are not handling delta right now... maybe we should
- return extractor1.getDoubleValue( workingMemory, object1 ) != extractor2.getDoubleValue( workingMemory, object2 );
- }
-
- public String toString() {
- return "Double !=";
- }
- }
-
- static class DoubleLessEvaluator extends BaseEvaluator {
- /**
- *
- */
- private static final long serialVersionUID = 400L;
- public final static Evaluator INSTANCE = new DoubleLessEvaluator();
-
- private DoubleLessEvaluator() {
- super( ValueType.PDOUBLE_TYPE,
- Operator.LESS );
- }
-
- public boolean evaluate(InternalWorkingMemory workingMemory,
- final Extractor extractor,
- final Object object1, final FieldValue object2) {
- if( extractor.isNullValue( workingMemory, object1 ) ) {
- return false;
- }
- // TODO: we are not handling delta right now... maybe we should
- return extractor.getDoubleValue( workingMemory, object1 ) < object2.getDoubleValue();
- }
-
- public boolean evaluateCachedRight(InternalWorkingMemory workingMemory,
- final VariableContextEntry context, final Object left) {
- if( context.rightNull ) {
- return false;
- }
- // TODO: we are not handling delta right now... maybe we should
- return ((DoubleVariableContextEntry) context).right < context.declaration.getExtractor().getDoubleValue( workingMemory, left );
- }
-
- public boolean evaluateCachedLeft(InternalWorkingMemory workingMemory,
- final VariableContextEntry context, final Object right) {
- if( context.extractor.isNullValue( workingMemory, right ) ) {
- return false;
- }
- // TODO: we are not handling delta right now... maybe we should
- return context.extractor.getDoubleValue( workingMemory, right ) < ((DoubleVariableContextEntry) context).left;
- }
-
- public boolean evaluate(InternalWorkingMemory workingMemory,
- final Extractor extractor1,
- final Object object1,
- final Extractor extractor2, final Object object2) {
- if( extractor1.isNullValue( workingMemory, object1 ) ) {
- return false;
- }
- // TODO: we are not handling delta right now... maybe we should
- return extractor1.getDoubleValue( workingMemory, object1 ) < extractor2.getDoubleValue( workingMemory, object2 );
- }
-
- public String toString() {
- return "Double <";
- }
- }
-
- static class DoubleLessOrEqualEvaluator extends BaseEvaluator {
- /**
- *
- */
- private static final long serialVersionUID = 400L;
- public final static Evaluator INSTANCE = new DoubleLessOrEqualEvaluator();
-
- private DoubleLessOrEqualEvaluator() {
- super( ValueType.PDOUBLE_TYPE,
- Operator.LESS_OR_EQUAL );
- }
-
- public boolean evaluate(InternalWorkingMemory workingMemory,
- final Extractor extractor,
- final Object object1, final FieldValue object2) {
- if( extractor.isNullValue( workingMemory, object1 ) ) {
- return false;
- }
- // TODO: we are not handling delta right now... maybe we should
- return extractor.getDoubleValue( workingMemory, object1 ) <= object2.getDoubleValue();
- }
-
- public boolean evaluateCachedRight(InternalWorkingMemory workingMemory,
- final VariableContextEntry context, final Object left) {
- if( context.rightNull ) {
- return false;
- }
- // TODO: we are not handling delta right now... maybe we should
- return ((DoubleVariableContextEntry) context).right <= context.declaration.getExtractor().getDoubleValue( workingMemory, left );
- }
-
- public boolean evaluateCachedLeft(InternalWorkingMemory workingMemory,
- final VariableContextEntry context, final Object right) {
- if( context.extractor.isNullValue( workingMemory, right ) ) {
- return false;
- }
- // TODO: we are not handling delta right now... maybe we should
- return context.extractor.getDoubleValue( workingMemory, right ) <= ((DoubleVariableContextEntry) context).left;
- }
-
- public boolean evaluate(InternalWorkingMemory workingMemory,
- final Extractor extractor1,
- final Object object1,
- final Extractor extractor2, final Object object2) {
- if( extractor1.isNullValue( workingMemory, object1 ) ) {
- return false;
- }
- // TODO: we are not handling delta right now... maybe we should
- return extractor1.getDoubleValue( workingMemory, object1 ) <= extractor2.getDoubleValue( workingMemory, object2 );
- }
-
- public String toString() {
- return "Double <=";
- }
- }
-
- static class DoubleGreaterEvaluator extends BaseEvaluator {
- /**
- *
- */
- private static final long serialVersionUID = 400L;
- public final static Evaluator INSTANCE = new DoubleGreaterEvaluator();
-
- private DoubleGreaterEvaluator() {
- super( ValueType.PDOUBLE_TYPE,
- Operator.GREATER );
- }
-
- public boolean evaluate(InternalWorkingMemory workingMemory,
- final Extractor extractor,
- final Object object1, final FieldValue object2) {
- if( extractor.isNullValue( workingMemory, object1 ) ) {
- return false;
- }
- // TODO: we are not handling delta right now... maybe we should
- return extractor.getDoubleValue( workingMemory, object1 ) > object2.getDoubleValue();
- }
-
- public boolean evaluateCachedRight(InternalWorkingMemory workingMemory,
- final VariableContextEntry context, final Object left) {
- if( context.rightNull ) {
- return false;
- }
- // TODO: we are not handling delta right now... maybe we should
- return ((DoubleVariableContextEntry) context).right > context.declaration.getExtractor().getDoubleValue( workingMemory, left );
- }
-
- public boolean evaluateCachedLeft(InternalWorkingMemory workingMemory,
- final VariableContextEntry context, final Object right) {
- if( context.extractor.isNullValue( workingMemory, right ) ) {
- return false;
- }
- // TODO: we are not handling delta right now... maybe we should
- return context.extractor.getDoubleValue( workingMemory, right ) > ((DoubleVariableContextEntry) context).left;
- }
-
- public boolean evaluate(InternalWorkingMemory workingMemory,
- final Extractor extractor1,
- final Object object1,
- final Extractor extractor2, final Object object2) {
- if( extractor1.isNullValue( workingMemory, object1 ) ) {
- return false;
- }
- // TODO: we are not handling delta right now... maybe we should
- return extractor1.getDoubleValue( workingMemory, object1 ) > extractor2.getDoubleValue( workingMemory, object2 );
- }
-
- public String toString() {
- return "Double >";
- }
- }
-
- static class DoubleGreaterOrEqualEvaluator extends BaseEvaluator {
- /**
- *
- */
- private static final long serialVersionUID = 400L;
- private final static Evaluator INSTANCE = new DoubleGreaterOrEqualEvaluator();
-
- private DoubleGreaterOrEqualEvaluator() {
- super( ValueType.PDOUBLE_TYPE,
- Operator.GREATER_OR_EQUAL );
- }
-
- public boolean evaluate(InternalWorkingMemory workingMemory,
- final Extractor extractor,
- final Object object1, final FieldValue object2) {
- if( extractor.isNullValue( workingMemory, object1 ) ) {
- return false;
- }
- // TODO: we are not handling delta right now... maybe we should
- return extractor.getDoubleValue( workingMemory, object1 ) >= object2.getDoubleValue();
- }
-
- public boolean evaluateCachedRight(InternalWorkingMemory workingMemory,
- final VariableContextEntry context, final Object left) {
- if( context.rightNull ) {
- return false;
- }
- // TODO: we are not handling delta right now... maybe we should
- return ((DoubleVariableContextEntry) context).right >= context.declaration.getExtractor().getDoubleValue( workingMemory, left );
- }
-
- public boolean evaluateCachedLeft(InternalWorkingMemory workingMemory,
- final VariableContextEntry context, final Object right) {
- if( context.extractor.isNullValue( workingMemory, right ) ) {
- return false;
- }
- // TODO: we are not handling delta right now... maybe we should
- return context.extractor.getDoubleValue( workingMemory, right ) >= ((DoubleVariableContextEntry) context).left;
- }
-
- public boolean evaluate(InternalWorkingMemory workingMemory,
- final Extractor extractor1,
- final Object object1,
- final Extractor extractor2, final Object object2) {
- if( extractor1.isNullValue( workingMemory, object1 ) ) {
- return false;
- }
- // TODO: we are not handling delta right now... maybe we should
- return extractor1.getDoubleValue( workingMemory, object1 ) >= extractor2.getDoubleValue( workingMemory, object2 );
- }
-
- public String toString() {
- return "Double >=";
- }
- }
-
- static class DoubleMemberOfEvaluator extends BaseMemberOfEvaluator {
-
- private static final long serialVersionUID = 400L;
- public final static Evaluator INSTANCE = new DoubleMemberOfEvaluator();
-
- private DoubleMemberOfEvaluator() {
- super( ValueType.PDOUBLE_TYPE,
- Operator.MEMBEROF );
- }
-
- public String toString() {
- return "Double memberOf";
- }
- }
-
- static class DoubleNotMemberOfEvaluator extends BaseNotMemberOfEvaluator {
-
- private static final long serialVersionUID = 400L;
- public final static Evaluator INSTANCE = new DoubleNotMemberOfEvaluator();
-
- private DoubleNotMemberOfEvaluator() {
- super( ValueType.PDOUBLE_TYPE,
- Operator.NOTMEMBEROF );
- }
-
- public String toString() {
- return "Double not memberOf";
- }
- }
-
-}
\ No newline at end of file
Added: labs/jbossrules/branches/temporal_rete/drools-core/src/main/java/org/drools/base/evaluators/EqualityEvaluatorsDefinition.java
===================================================================
--- labs/jbossrules/branches/temporal_rete/drools-core/src/main/java/org/drools/base/evaluators/EqualityEvaluatorsDefinition.java (rev 0)
+++ labs/jbossrules/branches/temporal_rete/drools-core/src/main/java/org/drools/base/evaluators/EqualityEvaluatorsDefinition.java 2007-12-07 14:10:27 UTC (rev 17089)
@@ -0,0 +1,2069 @@
+/*
+ * Copyright 2007 JBoss Inc
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ * Created on Dec 6, 2007
+ */
+package org.drools.base.evaluators;
+
+import java.util.Date;
+
+import org.drools.base.BaseEvaluator;
+import org.drools.base.ShadowProxy;
+import org.drools.base.ValueType;
+import org.drools.common.InternalWorkingMemory;
+import org.drools.rule.VariableRestriction.BooleanVariableContextEntry;
+import org.drools.rule.VariableRestriction.CharVariableContextEntry;
+import org.drools.rule.VariableRestriction.DoubleVariableContextEntry;
+import org.drools.rule.VariableRestriction.LongVariableContextEntry;
+import org.drools.rule.VariableRestriction.ObjectVariableContextEntry;
+import org.drools.rule.VariableRestriction.VariableContextEntry;
+import org.drools.spi.Evaluator;
+import org.drools.spi.Extractor;
+import org.drools.spi.FieldValue;
+import org.drools.util.DateUtils;
+
+/**
+ * This class defines the default built in equality
+ * evaluators == and !=
+ *
+ * @author etirelli
+ */
+public class EqualityEvaluatorsDefinition implements EvaluatorDefinition {
+
+ private static final String[] SUPPORTED_IDS = { Operator.EQUAL.getOperatorString(), Operator.NOT_EQUAL.getOperatorString() };
+ private EvaluatorRegistry evaluators = new EvaluatorRegistry() {
+ private static final long serialVersionUID = 4782368623L;
+ {
+ addEvaluator( ValueType.ARRAY_TYPE, Operator.EQUAL, ArrayEqualEvaluator.INSTANCE );
+ addEvaluator( ValueType.ARRAY_TYPE, Operator.NOT_EQUAL, ArrayNotEqualEvaluator.INSTANCE );
+ addEvaluator( ValueType.BIG_DECIMAL_TYPE, Operator.EQUAL, BigDecimalEqualEvaluator.INSTANCE );
+ addEvaluator( ValueType.BIG_DECIMAL_TYPE, Operator.NOT_EQUAL, BigDecimalNotEqualEvaluator.INSTANCE );
+ addEvaluator( ValueType.BIG_INTEGER_TYPE, Operator.EQUAL, BigIntegerEqualEvaluator.INSTANCE );
+ addEvaluator( ValueType.BIG_INTEGER_TYPE, Operator.NOT_EQUAL, BigIntegerNotEqualEvaluator.INSTANCE );
+ addEvaluator( ValueType.BOOLEAN_TYPE, Operator.EQUAL, BooleanEqualEvaluator.INSTANCE );
+ addEvaluator( ValueType.BOOLEAN_TYPE, Operator.NOT_EQUAL, BooleanNotEqualEvaluator.INSTANCE );
+ addEvaluator( ValueType.PBOOLEAN_TYPE, Operator.EQUAL, BooleanEqualEvaluator.INSTANCE );
+ addEvaluator( ValueType.PBOOLEAN_TYPE, Operator.NOT_EQUAL, BooleanNotEqualEvaluator.INSTANCE );
+ addEvaluator( ValueType.BYTE_TYPE, Operator.EQUAL, ByteEqualEvaluator.INSTANCE );
+ addEvaluator( ValueType.BYTE_TYPE, Operator.NOT_EQUAL, ByteNotEqualEvaluator.INSTANCE );
+ addEvaluator( ValueType.PBYTE_TYPE, Operator.EQUAL, ByteEqualEvaluator.INSTANCE );
+ addEvaluator( ValueType.PBYTE_TYPE, Operator.NOT_EQUAL, ByteNotEqualEvaluator.INSTANCE );
+ addEvaluator( ValueType.CHAR_TYPE, Operator.EQUAL, CharacterEqualEvaluator.INSTANCE );
+ addEvaluator( ValueType.CHAR_TYPE, Operator.NOT_EQUAL, CharacterNotEqualEvaluator.INSTANCE );
+ addEvaluator( ValueType.PCHAR_TYPE, Operator.EQUAL, CharacterEqualEvaluator.INSTANCE );
+ addEvaluator( ValueType.PCHAR_TYPE, Operator.NOT_EQUAL, CharacterNotEqualEvaluator.INSTANCE );
+ addEvaluator( ValueType.DATE_TYPE, Operator.EQUAL, DateEqualEvaluator.INSTANCE );
+ addEvaluator( ValueType.DATE_TYPE, Operator.NOT_EQUAL, DateNotEqualEvaluator.INSTANCE );
+ addEvaluator( ValueType.DOUBLE_TYPE, Operator.EQUAL, DoubleEqualEvaluator.INSTANCE );
+ addEvaluator( ValueType.DOUBLE_TYPE, Operator.NOT_EQUAL, DoubleNotEqualEvaluator.INSTANCE );
+ addEvaluator( ValueType.PDOUBLE_TYPE, Operator.EQUAL, DoubleEqualEvaluator.INSTANCE );
+ addEvaluator( ValueType.PDOUBLE_TYPE, Operator.NOT_EQUAL, DoubleNotEqualEvaluator.INSTANCE );
+ addEvaluator( ValueType.FACTTEMPLATE_TYPE, Operator.EQUAL, FactTemplateEqualEvaluator.INSTANCE );
+ addEvaluator( ValueType.FACTTEMPLATE_TYPE, Operator.NOT_EQUAL, FactTemplateNotEqualEvaluator.INSTANCE );
+ addEvaluator( ValueType.FLOAT_TYPE, Operator.EQUAL, FloatEqualEvaluator.INSTANCE );
+ addEvaluator( ValueType.FLOAT_TYPE, Operator.NOT_EQUAL, FloatNotEqualEvaluator.INSTANCE );
+ addEvaluator( ValueType.PFLOAT_TYPE, Operator.EQUAL, FloatEqualEvaluator.INSTANCE );
+ addEvaluator( ValueType.PFLOAT_TYPE, Operator.NOT_EQUAL, FloatNotEqualEvaluator.INSTANCE );
+ addEvaluator( ValueType.INTEGER_TYPE, Operator.EQUAL, IntegerEqualEvaluator.INSTANCE );
+ addEvaluator( ValueType.INTEGER_TYPE, Operator.NOT_EQUAL, IntegerNotEqualEvaluator.INSTANCE );
+ addEvaluator( ValueType.PINTEGER_TYPE, Operator.EQUAL, IntegerEqualEvaluator.INSTANCE );
+ addEvaluator( ValueType.PINTEGER_TYPE, Operator.NOT_EQUAL, IntegerNotEqualEvaluator.INSTANCE );
+ addEvaluator( ValueType.LONG_TYPE, Operator.EQUAL, LongEqualEvaluator.INSTANCE );
+ addEvaluator( ValueType.LONG_TYPE, Operator.NOT_EQUAL, LongNotEqualEvaluator.INSTANCE );
+ addEvaluator( ValueType.PLONG_TYPE, Operator.EQUAL, LongEqualEvaluator.INSTANCE );
+ addEvaluator( ValueType.PLONG_TYPE, Operator.NOT_EQUAL, LongNotEqualEvaluator.INSTANCE );
+ addEvaluator( ValueType.OBJECT_TYPE, Operator.EQUAL, ObjectEqualEvaluator.INSTANCE );
+ addEvaluator( ValueType.OBJECT_TYPE, Operator.NOT_EQUAL, ObjectNotEqualEvaluator.INSTANCE );
+ addEvaluator( ValueType.SHORT_TYPE, Operator.EQUAL, ShortEqualEvaluator.INSTANCE );
+ addEvaluator( ValueType.SHORT_TYPE, Operator.NOT_EQUAL, ShortNotEqualEvaluator.INSTANCE );
+ addEvaluator( ValueType.PSHORT_TYPE, Operator.EQUAL, ShortEqualEvaluator.INSTANCE );
+ addEvaluator( ValueType.PSHORT_TYPE, Operator.NOT_EQUAL, ShortNotEqualEvaluator.INSTANCE );
+ addEvaluator( ValueType.STRING_TYPE, Operator.EQUAL, StringEqualEvaluator.INSTANCE );
+ addEvaluator( ValueType.STRING_TYPE, Operator.NOT_EQUAL, StringNotEqualEvaluator.INSTANCE );
+ }
+ };
+
+ /**
+ * @inheridDoc
+ */
+ public Evaluator getEvaluator(ValueType type,
+ Operator operator) {
+ return this.evaluators.getEvaluator( type,
+ operator );
+ }
+
+ /**
+ * @inheridDoc
+ */
+ public Evaluator getEvaluator(ValueType type,
+ Operator operator,
+ String parameterText) {
+ return this.evaluators.getEvaluator( type,
+ operator );
+ }
+
+
+ public Evaluator getEvaluator(final ValueType type,
+ final String operatorId,
+ final boolean isNegated,
+ final String parameterText) {
+ return this.evaluators.getEvaluator( type, Operator.determineOperator( operatorId, isNegated ) );
+ }
+
+ public String[] getEvaluatorIds() {
+ return SUPPORTED_IDS;
+ }
+
+ public boolean isNegatable() {
+ return false;
+ }
+
+ public boolean operatesOnFactHandles() {
+ return false;
+ }
+
+ public boolean supportsType(ValueType type) {
+ return this.evaluators.supportsType( type );
+ }
+
+ /* *********************************************************
+ * Evaluator Implementations
+ * *********************************************************
+ */
+
+ static class ArrayEqualEvaluator extends BaseEvaluator {
+
+ private static final long serialVersionUID = 400L;
+ public final static Evaluator INSTANCE = new ArrayEqualEvaluator();
+
+ private ArrayEqualEvaluator() {
+ super( ValueType.ARRAY_TYPE,
+ Operator.EQUAL );
+ }
+
+ public boolean evaluate(InternalWorkingMemory workingMemory,
+ final Extractor extractor,
+ final Object object1,
+ final FieldValue object2) {
+ final Object value1 = extractor.getValue( workingMemory,
+ object1 );
+ final Object value2 = object2.getValue();
+ if ( value1 == null ) {
+ return value2 == null;
+ }
+ return value1.equals( value2 );
+ }
+
+ public boolean evaluateCachedRight(InternalWorkingMemory workingMemory,
+ final VariableContextEntry context,
+ final Object left) {
+ final Object value = context.declaration.getExtractor().getValue( workingMemory,
+ left );
+ if ( value == null ) {
+ return ((ObjectVariableContextEntry) context).right == null;
+ }
+ return value.equals( ((ObjectVariableContextEntry) context).right );
+ }
+
+ public boolean evaluateCachedLeft(InternalWorkingMemory workingMemory,
+ final VariableContextEntry context,
+ final Object right) {
+ final Object value = context.extractor.getValue( workingMemory,
+ right );
+ if ( ((ObjectVariableContextEntry) context).left == null ) {
+ return value == null;
+ }
+ return ((ObjectVariableContextEntry) context).left.equals( value );
+ }
+
+ public boolean evaluate(InternalWorkingMemory workingMemory,
+ final Extractor extractor1,
+ final Object object1,
+ final Extractor extractor2,
+ final Object object2) {
+ final Object value1 = extractor1.getValue( workingMemory,
+ object1 );
+ final Object value2 = extractor2.getValue( workingMemory,
+ object2 );
+ if ( value1 == null ) {
+ return value2 == null;
+ }
+ return value1.equals( value2 );
+ }
+
+ public String toString() {
+ return "Array ==";
+ }
+
+ }
+
+ static class ArrayNotEqualEvaluator extends BaseEvaluator {
+ /**
+ *
+ */
+ private static final long serialVersionUID = 400L;
+ public final static Evaluator INSTANCE = new ArrayNotEqualEvaluator();
+
+ private ArrayNotEqualEvaluator() {
+ super( ValueType.ARRAY_TYPE,
+ Operator.NOT_EQUAL );
+ }
+
+ public boolean evaluate(InternalWorkingMemory workingMemory,
+ final Extractor extractor,
+ final Object object1,
+ final FieldValue object2) {
+ final Object value1 = extractor.getValue( workingMemory,
+ object1 );
+ final Object value2 = object2.getValue();
+ if ( value1 == null ) {
+ return value2 != null;
+ }
+ return !value1.equals( value2 );
+ }
+
+ public boolean evaluateCachedRight(InternalWorkingMemory workingMemory,
+ final VariableContextEntry context,
+ final Object left) {
+ final Object value = context.declaration.getExtractor().getValue( workingMemory,
+ left );
+ if ( value == null ) {
+ return ((ObjectVariableContextEntry) context).right != null;
+ }
+ return !value.equals( ((ObjectVariableContextEntry) context).right );
+ }
+
+ public boolean evaluateCachedLeft(InternalWorkingMemory workingMemory,
+ final VariableContextEntry context,
+ final Object right) {
+ final Object value = context.extractor.getValue( workingMemory,
+ right );
+ if ( ((ObjectVariableContextEntry) context).left == null ) {
+ return value != null;
+ }
+ return !((ObjectVariableContextEntry) context).left.equals( value );
+ }
+
+ public boolean evaluate(InternalWorkingMemory workingMemory,
+ final Extractor extractor1,
+ final Object object1,
+ final Extractor extractor2,
+ final Object object2) {
+ final Object value1 = extractor1.getValue( workingMemory,
+ object1 );
+ final Object value2 = extractor2.getValue( workingMemory,
+ object2 );
+ if ( value1 == null ) {
+ return value2 != null;
+ }
+ return !value1.equals( value2 );
+ }
+
+ public String toString() {
+ return "Array !=";
+ }
+ }
+
+ static class BigDecimalEqualEvaluator extends BaseEvaluator {
+ /**
+ *
+ */
+ private static final long serialVersionUID = 400L;
+ public final static Evaluator INSTANCE = new BigDecimalEqualEvaluator();
+
+ private BigDecimalEqualEvaluator() {
+ super( ValueType.BIG_DECIMAL_TYPE,
+ Operator.EQUAL );
+ }
+
+ public boolean evaluate(InternalWorkingMemory workingMemory,
+ final Extractor extractor,
+ final Object object1, final FieldValue object2) {
+ final Object value1 = extractor.getValue( workingMemory, object1 );
+ final Object value2 = object2.getValue();
+ if ( value1 == null ) {
+ return value2 == null;
+ }
+ return value1.equals( value2 );
+ }
+
+ public boolean evaluateCachedRight(InternalWorkingMemory workingMemory,
+ final VariableContextEntry context, final Object left) {
+ final Object value = context.declaration.getExtractor().getValue( workingMemory, left );
+ if ( value == null ) {
+ return ((ObjectVariableContextEntry) context).right == null;
+ }
+ return value.equals( ((ObjectVariableContextEntry) context).right );
+ }
+
+ public boolean evaluateCachedLeft(InternalWorkingMemory workingMemory,
+ final VariableContextEntry context, final Object right) {
+ final Object value = context.extractor.getValue( workingMemory, right );
+ if ( ((ObjectVariableContextEntry) context).left == null ) {
+ return value == null;
+ }
+ return ((ObjectVariableContextEntry) context).left.equals( value );
+ }
+
+ public boolean evaluate(InternalWorkingMemory workingMemory,
+ final Extractor extractor1,
+ final Object object1,
+ final Extractor extractor2, final Object object2) {
+ final Object value1 = extractor1.getValue( workingMemory, object1 );
+ final Object value2 = extractor2.getValue( workingMemory, object2 );
+ if ( value1 == null ) {
+ return value2 == null;
+ }
+ return value1.equals( value2 );
+ }
+
+ public String toString() {
+ return "BigDecimal ==";
+ }
+
+ }
+
+ static class BigDecimalNotEqualEvaluator extends BaseEvaluator {
+ /**
+ *
+ */
+ private static final long serialVersionUID = 400L;
+ public final static Evaluator INSTANCE = new BigDecimalNotEqualEvaluator();
+
+ private BigDecimalNotEqualEvaluator() {
+ super( ValueType.BIG_DECIMAL_TYPE,
+ Operator.NOT_EQUAL );
+ }
+
+ public boolean evaluate(InternalWorkingMemory workingMemory,
+ final Extractor extractor,
+ final Object object1, final FieldValue object2) {
+ final Object value1 = extractor.getValue( workingMemory, object1 );
+ final Object value2 = object2.getValue();
+ if ( value1 == null ) {
+ return value2 != null;
+ }
+ return !value1.equals( value2 );
+ }
+
+ public boolean evaluateCachedRight(InternalWorkingMemory workingMemory,
+ final VariableContextEntry context, final Object left) {
+ final Object value = context.declaration.getExtractor().getValue( workingMemory, left );
+ if ( value == null ) {
+ return ((ObjectVariableContextEntry) context).right != null;
+ }
+ return !value.equals( ((ObjectVariableContextEntry) context).right );
+ }
+
+ public boolean evaluateCachedLeft(InternalWorkingMemory workingMemory,
+ final VariableContextEntry context, final Object right) {
+ final Object value = context.extractor.getValue( workingMemory, right );
+ if ( ((ObjectVariableContextEntry) context).left == null ) {
+ return value != null;
+ }
+ return !((ObjectVariableContextEntry) context).left.equals( value );
+ }
+
+ public boolean evaluate(InternalWorkingMemory workingMemory,
+ final Extractor extractor1,
+ final Object object1,
+ final Extractor extractor2, final Object object2) {
+ final Object value1 = extractor1.getValue( workingMemory, object1 );
+ final Object value2 = extractor2.getValue( workingMemory, object2 );
+ if ( value1 == null ) {
+ return value2 != null;
+ }
+ return !value1.equals( value2 );
+ }
+
+ public String toString() {
+ return "BigDecimal !=";
+ }
+ }
+
+ static class BigIntegerEqualEvaluator extends BaseEvaluator {
+ /**
+ *
+ */
+ private static final long serialVersionUID = 400L;
+ public final static Evaluator INSTANCE = new BigIntegerEqualEvaluator();
+
+ private BigIntegerEqualEvaluator() {
+ super( ValueType.BIG_INTEGER_TYPE,
+ Operator.EQUAL );
+ }
+
+ public boolean evaluate(InternalWorkingMemory workingMemory,
+ final Extractor extractor,
+ final Object object1, final FieldValue object2) {
+ final Object value1 = extractor.getValue( workingMemory, object1 );
+ final Object value2 = object2.getValue();
+ if ( value1 == null ) {
+ return value2 == null;
+ }
+ return value1.equals( value2 );
+ }
+
+ public boolean evaluateCachedRight(InternalWorkingMemory workingMemory,
+ final VariableContextEntry context, final Object left) {
+ final Object value = context.declaration.getExtractor().getValue( workingMemory, left );
+ if ( value == null ) {
+ return ((ObjectVariableContextEntry) context).right == null;
+ }
+ return value.equals( ((ObjectVariableContextEntry) context).right );
+ }
+
+ public boolean evaluateCachedLeft(InternalWorkingMemory workingMemory,
+ final VariableContextEntry context, final Object right) {
+ final Object value = context.extractor.getValue( workingMemory, right );
+ if ( ((ObjectVariableContextEntry) context).left == null ) {
+ return value == null;
+ }
+ return ((ObjectVariableContextEntry) context).left.equals( value );
+ }
+
+ public boolean evaluate(InternalWorkingMemory workingMemory,
+ final Extractor extractor1,
+ final Object object1,
+ final Extractor extractor2, final Object object2) {
+ final Object value1 = extractor1.getValue( workingMemory, object1 );
+ final Object value2 = extractor2.getValue( workingMemory, object2 );
+ if ( value1 == null ) {
+ return value2 == null;
+ }
+ return value1.equals( value2 );
+ }
+
+ public String toString() {
+ return "BigInteger ==";
+ }
+ }
+
+ static class BigIntegerNotEqualEvaluator extends BaseEvaluator {
+ /**
+ *
+ */
+ private static final long serialVersionUID = 400L;
+ public final static Evaluator INSTANCE = new BigIntegerNotEqualEvaluator();
+
+ private BigIntegerNotEqualEvaluator() {
+ super( ValueType.BIG_INTEGER_TYPE,
+ Operator.NOT_EQUAL );
+ }
+
+ public boolean evaluate(InternalWorkingMemory workingMemory,
+ final Extractor extractor,
+ final Object object1, final FieldValue object2) {
+ final Object value1 = extractor.getValue( workingMemory, object1 );
+ final Object value2 = object2.getValue();
+ if ( value1 == null ) {
+ return value2 != null;
+ }
+ return !value1.equals( value2 );
+ }
+
+ public boolean evaluateCachedRight(InternalWorkingMemory workingMemory,
+ final VariableContextEntry context, final Object left) {
+ final Object value = context.declaration.getExtractor().getValue( workingMemory, left );
+ if ( value == null ) {
+ return ((ObjectVariableContextEntry) context).right != null;
+ }
+ return !value.equals( ((ObjectVariableContextEntry) context).right );
+ }
+
+ public boolean evaluateCachedLeft(InternalWorkingMemory workingMemory,
+ final VariableContextEntry context, final Object right) {
+ final Object value = context.extractor.getValue( workingMemory, right );
+ if ( ((ObjectVariableContextEntry) context).left == null ) {
+ return value != null;
+ }
+ return !((ObjectVariableContextEntry) context).left.equals( value );
+ }
+
+ public boolean evaluate(InternalWorkingMemory workingMemory,
+ final Extractor extractor1,
+ final Object object1,
+ final Extractor extractor2, final Object object2) {
+ final Object value1 = extractor1.getValue( workingMemory, object1 );
+ final Object value2 = extractor2.getValue( workingMemory, object2 );
+ if ( value1 == null ) {
+ return value2 != null;
+ }
+ return !value1.equals( value2 );
+ }
+
+ public String toString() {
+ return "BigInteger !=";
+ }
+ }
+
+ static class BooleanEqualEvaluator extends BaseEvaluator {
+
+ private static final long serialVersionUID = 400L;
+ private final static Evaluator INSTANCE = new BooleanEqualEvaluator();
+
+ private BooleanEqualEvaluator() {
+ super( ValueType.PBOOLEAN_TYPE,
+ Operator.EQUAL );
+ }
+
+ public boolean evaluate(InternalWorkingMemory workingMemory,
+ final Extractor extractor,
+ final Object object1, final FieldValue object2) {
+ if ( extractor.isNullValue( workingMemory, object1 ) ) {
+ return object2.isNull();
+ } else if ( object2.isNull() ) {
+ return false;
+ }
+
+ return extractor.getBooleanValue( workingMemory, object1 ) == object2.getBooleanValue();
+ }
+
+ public boolean evaluateCachedRight(InternalWorkingMemory workingMemory,
+ final VariableContextEntry context, final Object left) {
+ if ( context.declaration.getExtractor().isNullValue( workingMemory, left ) ) {
+ return context.isRightNull();
+ } else if ( context.isRightNull() ) {
+ return false;
+ }
+
+ return context.declaration.getExtractor().getBooleanValue( workingMemory, left ) == ((BooleanVariableContextEntry) context).right;
+ }
+
+ public boolean evaluateCachedLeft(InternalWorkingMemory workingMemory,
+ final VariableContextEntry context, final Object object2) {
+ if ( context.extractor.isNullValue( workingMemory, object2 )) {
+ return context.isLeftNull();
+ } else if ( context.isLeftNull() ) {
+ return false;
+ }
+
+ return context.extractor.getBooleanValue( workingMemory, object2 ) == ((BooleanVariableContextEntry) context).left;
+ }
+
+ public boolean evaluate(InternalWorkingMemory workingMemory,
+ final Extractor extractor1,
+ final Object object1,
+ final Extractor extractor2, final Object object2) {
+ if (extractor1.isNullValue( workingMemory, object1 )) {
+ return extractor2.isNullValue( workingMemory, object2 );
+ } else if (extractor2.isNullValue( workingMemory, object2 )) {
+ return false;
+ }
+
+ return extractor1.getBooleanValue( workingMemory, object1 ) == extractor2.getBooleanValue( workingMemory, object2 );
+ }
+
+ public String toString() {
+ return "Boolean ==";
+ }
+
+ }
+
+ static class BooleanNotEqualEvaluator extends BaseEvaluator {
+ /**
+ *
+ */
+ private static final long serialVersionUID = 400L;
+ public final static Evaluator INSTANCE = new BooleanNotEqualEvaluator();
+
+ private BooleanNotEqualEvaluator() {
+ super( ValueType.PBOOLEAN_TYPE,
+ Operator.NOT_EQUAL );
+ }
+
+ public boolean evaluate(InternalWorkingMemory workingMemory,
+ final Extractor extractor,
+ final Object object1, final FieldValue object2) {
+ if ( extractor.isNullValue( workingMemory, object1 ) ) {
+ return !object2.isNull();
+ } else if ( object2.isNull() ) {
+ return true;
+ }
+
+ return extractor.getBooleanValue( workingMemory, object1 ) != object2.getBooleanValue();
+ }
+
+ public boolean evaluateCachedRight(InternalWorkingMemory workingMemory,
+ final VariableContextEntry context, final Object left) {
+ if ( context.declaration.getExtractor().isNullValue( workingMemory, left ) ) {
+ return !context.isRightNull();
+ } else if ( context.isRightNull() ) {
+ return true;
+ }
+ return context.declaration.getExtractor().getBooleanValue( workingMemory, left ) != ((BooleanVariableContextEntry) context).right;
+ }
+
+ public boolean evaluateCachedLeft(InternalWorkingMemory workingMemory,
+ final VariableContextEntry context, final Object object2) {
+ if ( context.extractor.isNullValue( workingMemory, object2 )) {
+ return !context.isLeftNull();
+ } else if ( context.isLeftNull() ) {
+ return true;
+ }
+
+ return context.extractor.getBooleanValue( workingMemory, object2 ) != ((BooleanVariableContextEntry) context).left;
+ }
+
+ public boolean evaluate(InternalWorkingMemory workingMemory,
+ final Extractor extractor1,
+ final Object object1,
+ final Extractor extractor2, final Object object2) {
+ if (extractor1.isNullValue( workingMemory, object1 )) {
+ return !extractor2.isNullValue( workingMemory, object2 );
+ } else if (extractor2.isNullValue( workingMemory, object2 )) {
+ return true;
+ }
+
+ return extractor1.getBooleanValue( workingMemory, object1 ) != extractor1.getBooleanValue( workingMemory, object2 );
+ }
+
+ public String toString() {
+ return "Boolean !=";
+ }
+ }
+
+ static class ByteEqualEvaluator extends BaseEvaluator {
+ /**
+ *
+ */
+ private static final long serialVersionUID = 400L;
+ public final static Evaluator INSTANCE = new ByteEqualEvaluator();
+
+ private ByteEqualEvaluator() {
+ super( ValueType.PBYTE_TYPE,
+ Operator.EQUAL );
+ }
+
+ public boolean evaluate(InternalWorkingMemory workingMemory,
+ final Extractor extractor,
+ final Object object1, final FieldValue object2) {
+ if ( extractor.isNullValue( workingMemory, object1 ) ) {
+ return object2.isNull();
+ } else if ( object2.isNull() ) {
+ return false;
+ }
+
+ return extractor.getByteValue( workingMemory, object1 ) == object2.getByteValue();
+ }
+
+ public boolean evaluateCachedRight(InternalWorkingMemory workingMemory,
+ final VariableContextEntry context, final Object left) {
+ if ( context.declaration.getExtractor().isNullValue( workingMemory, left ) ) {
+ return context.isRightNull();
+ } else if ( context.isRightNull() ) {
+ return false;
+ }
+
+ return context.declaration.getExtractor().getByteValue( workingMemory, left ) == ((LongVariableContextEntry) context).right;
+ }
+
+ public boolean evaluateCachedLeft(InternalWorkingMemory workingMemory,
+ final VariableContextEntry context, final Object right) {
+ if ( context.extractor.isNullValue( workingMemory, right )) {
+ return context.isLeftNull();
+ } else if ( context.isLeftNull() ) {
+ return false;
+ }
+
+ return ((LongVariableContextEntry) context).left == context.extractor.getByteValue( workingMemory, right );
+ }
+
+ public boolean evaluate(InternalWorkingMemory workingMemory,
+ final Extractor extractor1,
+ final Object object1,
+ final Extractor extractor2, final Object object2) {
+ if (extractor1.isNullValue( workingMemory, object1 )) {
+ return extractor2.isNullValue( workingMemory, object2 );
+ } else if (extractor2.isNullValue( workingMemory, object2 )) {
+ return false;
+ }
+
+ return extractor1.getByteValue( workingMemory, object1 ) == extractor2.getByteValue( workingMemory, object2 );
+ }
+
+ public String toString() {
+ return "Byte ==";
+ }
+
+ }
+
+ static class ByteNotEqualEvaluator extends BaseEvaluator {
+ /**
+ *
+ */
+ private static final long serialVersionUID = 400L;
+ public final static Evaluator INSTANCE = new ByteNotEqualEvaluator();
+
+ private ByteNotEqualEvaluator() {
+ super( ValueType.PBYTE_TYPE,
+ Operator.NOT_EQUAL );
+ }
+
+ public boolean evaluate(InternalWorkingMemory workingMemory,
+ final Extractor extractor,
+ final Object object1, final FieldValue object2) {
+ if ( extractor.isNullValue( workingMemory, object1 ) ) {
+ return !object2.isNull();
+ } else if ( object2.isNull() ) {
+ return true;
+ }
+
+ return extractor.getByteValue( workingMemory, object1 ) != object2.getByteValue();
+ }
+
+ public boolean evaluateCachedRight(InternalWorkingMemory workingMemory,
+ final VariableContextEntry context, final Object left) {
+ if ( context.declaration.getExtractor().isNullValue( workingMemory, left ) ) {
+ return !context.isRightNull();
+ } else if ( context.isRightNull() ) {
+ return true;
+ }
+
+ return context.declaration.getExtractor().getByteValue( workingMemory, left ) != ((LongVariableContextEntry) context).right;
+ }
+
+ public boolean evaluateCachedLeft(InternalWorkingMemory workingMemory,
+ final VariableContextEntry context, final Object object2) {
+ if ( context.extractor.isNullValue( workingMemory, object2 ) ) {
+ return !context.isLeftNull();
+ } else if ( context.isLeftNull() ) {
+ return true;
+ }
+
+ return ((LongVariableContextEntry) context).left != context.extractor.getByteValue( workingMemory, object2 );
+ }
+
+ public boolean evaluate(InternalWorkingMemory workingMemory,
+ final Extractor extractor1,
+ final Object object1,
+ final Extractor extractor2, final Object object2) {
+ if (extractor1.isNullValue( workingMemory, object1 )) {
+ return !extractor2.isNullValue( workingMemory, object2 );
+ } else if (extractor2.isNullValue( workingMemory, object2 )) {
+ return true;
+ }
+
+ return extractor1.getByteValue( workingMemory, object1 ) != extractor2.getByteValue( workingMemory, object2 );
+ }
+
+ public String toString() {
+ return "Byte !=";
+ }
+ }
+
+ static class CharacterEqualEvaluator extends BaseEvaluator {
+ /**
+ *
+ */
+ private static final long serialVersionUID = 400L;
+ public final static Evaluator INSTANCE = new CharacterEqualEvaluator();
+
+ private CharacterEqualEvaluator() {
+ super( ValueType.PCHAR_TYPE,
+ Operator.EQUAL );
+ }
+
+ public boolean evaluate(InternalWorkingMemory workingMemory,
+ final Extractor extractor,
+ final Object object1, final FieldValue object2) {
+ if ( extractor.isNullValue( workingMemory, object1 ) ) {
+ return object2.isNull();
+ } else if ( object2.isNull() ) {
+ return false;
+ }
+
+ return extractor.getCharValue( workingMemory, object1 ) == object2.getCharValue();
+ }
+
+ public boolean evaluateCachedRight(InternalWorkingMemory workingMemory,
+ final VariableContextEntry context, final Object left) {
+ if ( context.declaration.getExtractor().isNullValue( workingMemory, left ) ) {
+ return context.isRightNull();
+ } else if ( context.isRightNull() ) {
+ return false;
+ }
+
+ return context.declaration.getExtractor().getCharValue( workingMemory, left ) == ((CharVariableContextEntry) context).right;
+ }
+
+ public boolean evaluateCachedLeft(InternalWorkingMemory workingMemory,
+ final VariableContextEntry context, final Object right) {
+ if ( context.extractor.isNullValue( workingMemory, right )) {
+ return context.isLeftNull();
+ } else if ( context.isLeftNull() ) {
+ return false;
+ }
+
+ return ((CharVariableContextEntry) context).left == context.extractor.getCharValue( workingMemory, right );
+ }
+
+ public boolean evaluate(InternalWorkingMemory workingMemory,
+ final Extractor extractor1,
+ final Object object1,
+ final Extractor extractor2, final Object object2) {
+ if (extractor1.isNullValue( workingMemory, object1 )) {
+ return extractor2.isNullValue( workingMemory, object2 );
+ } else if (extractor2.isNullValue( workingMemory, object2 )) {
+ return false;
+ }
+
+ return extractor1.getCharValue( workingMemory, object1 ) == extractor2.getCharValue( workingMemory, object2 );
+ }
+
+ public String toString() {
+ return "Character ==";
+ }
+ }
+
+ static class CharacterNotEqualEvaluator extends BaseEvaluator {
+ /**
+ *
+ */
+ private static final long serialVersionUID = 400L;
+ public final static Evaluator INSTANCE = new CharacterNotEqualEvaluator();
+
+ private CharacterNotEqualEvaluator() {
+ super( ValueType.PCHAR_TYPE,
+ Operator.NOT_EQUAL );
+ }
+
+ public boolean evaluate(InternalWorkingMemory workingMemory,
+ final Extractor extractor,
+ final Object object1, final FieldValue object2) {
+ if ( extractor.isNullValue( workingMemory, object1 ) ) {
+ return !object2.isNull();
+ } else if ( object2.isNull() ) {
+ return true;
+ }
+
+ return extractor.getCharValue( workingMemory, object1 ) != object2.getCharValue();
+ }
+
+ public boolean evaluateCachedRight(InternalWorkingMemory workingMemory,
+ final VariableContextEntry context, final Object left) {
+ if ( context.declaration.getExtractor().isNullValue( workingMemory, left ) ) {
+ return !context.isRightNull();
+ } else if ( context.isRightNull() ) {
+ return true;
+ }
+
+ return context.declaration.getExtractor().getCharValue( workingMemory, left ) != ((CharVariableContextEntry) context).right;
+ }
+
+ public boolean evaluateCachedLeft(InternalWorkingMemory workingMemory,
+ final VariableContextEntry context, final Object right) {
+ if ( context.extractor.isNullValue( workingMemory, right ) ) {
+ return !context.isLeftNull();
+ } else if ( context.isLeftNull() ) {
+ return true;
+ }
+
+ return ((CharVariableContextEntry) context).left != context.extractor.getCharValue( workingMemory, right );
+ }
+
+ public boolean evaluate(InternalWorkingMemory workingMemory,
+ final Extractor extractor1,
+ final Object object1,
+ final Extractor extractor2, final Object object2) {
+ if (extractor1.isNullValue( workingMemory, object1 )) {
+ return !extractor2.isNullValue( workingMemory, object2 );
+ } else if (extractor2.isNullValue( workingMemory, object2 )) {
+ return true;
+ }
+
+ return extractor1.getCharValue( workingMemory, object1 ) != extractor2.getCharValue( workingMemory, object2 );
+ }
+
+ public String toString() {
+ return "Character !=";
+ }
+ }
+
+ static class DateEqualEvaluator extends BaseEvaluator {
+ /**
+ *
+ */
+ private static final long serialVersionUID = 400L;
+ public final static Evaluator INSTANCE = new DateEqualEvaluator();
+
+ private DateEqualEvaluator() {
+ super( ValueType.DATE_TYPE,
+ Operator.EQUAL );
+ }
+
+ public boolean evaluate(InternalWorkingMemory workingMemory,
+ final Extractor extractor,
+ final Object object1, final FieldValue object2) {
+ final Date value1 = (Date) extractor.getValue( workingMemory, object1 );
+ final Object value2 = object2.getValue();
+ if ( value1 == null ) {
+ return value2 == null;
+ }
+ if ( value2 == null ) {
+ return false;
+ }
+ return value1.compareTo( DateUtils.getRightDate( value2 ) ) == 0;
+ }
+
+ public boolean evaluateCachedRight(InternalWorkingMemory workingMemory,
+ final VariableContextEntry context, final Object left) {
+ final Date value1 = (Date) context.declaration.getExtractor().getValue( workingMemory, left );
+ final Object value2 = ((ObjectVariableContextEntry) context).right;
+ if ( value1 == null ) {
+ return value2 == null;
+ }
+ if ( value2 == null ) {
+ return false;
+ }
+ return value1.compareTo( DateUtils.getRightDate( value2 ) ) == 0;
+ }
+
+ public boolean evaluateCachedLeft(InternalWorkingMemory workingMemory,
+ final VariableContextEntry context, final Object right) {
+ final Date value1 = (Date) ((ObjectVariableContextEntry) context).left;
+ final Object value2 = context.extractor.getValue( workingMemory, right );
+ if ( value1 == null ) {
+ return value2 == null;
+ }
+ if ( value2 == null ) {
+ return false;
+ }
+ return value1.compareTo( DateUtils.getRightDate( value2 ) ) == 0;
+ }
+
+ public boolean evaluate(InternalWorkingMemory workingMemory,
+ final Extractor extractor1,
+ final Object object1,
+ final Extractor extractor2, final Object object2) {
+ final Date value1 = (Date) extractor1.getValue( workingMemory, object1 );
+ final Date value2 = (Date) extractor2.getValue( workingMemory, object2 );
+ if ( value1 == null ) {
+ return value2 == null;
+ }
+ if ( value2 == null ) {
+ return false;
+ }
+ return value1.compareTo( value2 ) == 0;
+ }
+
+ public String toString() {
+ return "Date ==";
+ }
+
+ }
+
+ static class DateNotEqualEvaluator extends BaseEvaluator {
+ /**
+ *
+ */
+ private static final long serialVersionUID = 400L;
+ public final static Evaluator INSTANCE = new DateNotEqualEvaluator();
+
+ private DateNotEqualEvaluator() {
+ super( ValueType.DATE_TYPE,
+ Operator.NOT_EQUAL );
+ }
+
+ public boolean evaluate(InternalWorkingMemory workingMemory,
+ final Extractor extractor,
+ final Object object1, final FieldValue object2) {
+ final Date value1 = (Date) extractor.getValue( workingMemory, object1 );
+ final Object value2 = object2.getValue();
+ if ( value1 == null ) {
+ return value2 != null;
+ }
+ if ( value2 == null ) {
+ return true;
+ }
+ return value1.compareTo( DateUtils.getRightDate( value2 ) ) != 0;
+ }
+
+ public boolean evaluateCachedRight(InternalWorkingMemory workingMemory,
+ final VariableContextEntry context, final Object left) {
+ final Date value1 = (Date) context.declaration.getExtractor().getValue( workingMemory, left );
+ final Object value2 = ((ObjectVariableContextEntry) context).right;
+ if ( value1 == null ) {
+ return value2 != null;
+ }
+ if ( value2 == null ) {
+ return true;
+ }
+ return value1.compareTo( DateUtils.getRightDate( value2 ) ) != 0;
+ }
+
+ public boolean evaluateCachedLeft(InternalWorkingMemory workingMemory,
+ final VariableContextEntry context, final Object right) {
+ final Date value1 = (Date) ((ObjectVariableContextEntry) context).left;
+ final Object value2 = context.extractor.getValue( workingMemory, right );
+ if ( value1 == null ) {
+ return value2 != null;
+ }
+ if ( value2 == null ) {
+ return true;
+ }
+ return value1.compareTo( DateUtils.getRightDate( value2 ) ) != 0;
+ }
+
+ public boolean evaluate(InternalWorkingMemory workingMemory,
+ final Extractor extractor1,
+ final Object object1,
+ final Extractor extractor2, final Object object2) {
+ final Date value1 = (Date) extractor1.getValue( workingMemory, object1 );
+ final Date value2 = (Date) extractor2.getValue( workingMemory, object2 );
+ if ( value1 == null ) {
+ return value2 != null;
+ }
+ if ( value2 == null ) {
+ return true;
+ }
+ return value1.compareTo( value2 ) != 0;
+ }
+
+ public String toString() {
+ return "Date !=";
+ }
+ }
+
+ static class DoubleEqualEvaluator extends BaseEvaluator {
+ /**
+ *
+ */
+ private static final long serialVersionUID = 400L;
+ public final static Evaluator INSTANCE = new DoubleEqualEvaluator();
+
+ private DoubleEqualEvaluator() {
+ super( ValueType.PDOUBLE_TYPE,
+ Operator.EQUAL );
+ }
+
+ public boolean evaluate(InternalWorkingMemory workingMemory,
+ final Extractor extractor,
+ final Object object1, final FieldValue object2) {
+ if ( extractor.isNullValue( workingMemory, object1 ) ) {
+ return object2.isNull();
+ } else if ( object2.isNull() ) {
+ return false;
+ }
+ // TODO: we are not handling delta right now... maybe we should
+ return extractor.getDoubleValue( workingMemory, object1 ) == object2.getDoubleValue();
+ }
+
+ public boolean evaluateCachedRight(InternalWorkingMemory workingMemory,
+ final VariableContextEntry context, final Object left) {
+ if ( context.declaration.getExtractor().isNullValue( workingMemory, left ) ) {
+ return context.isRightNull();
+ } else if ( context.isRightNull() ) {
+ return false;
+ }
+ // TODO: we are not handling delta right now... maybe we should
+ return context.declaration.getExtractor().getDoubleValue( workingMemory, left ) == ((DoubleVariableContextEntry) context).right;
+ }
+
+ public boolean evaluateCachedLeft(InternalWorkingMemory workingMemory,
+ final VariableContextEntry context, final Object right) {
+ if ( context.extractor.isNullValue( workingMemory, right )) {
+ return context.isLeftNull();
+ } else if ( context.isLeftNull() ) {
+ return false;
+ }
+
+ // TODO: we are not handling delta right now... maybe we should
+ return ((DoubleVariableContextEntry) context).left == context.extractor.getDoubleValue( workingMemory, right );
+ }
+
+ public boolean evaluate(InternalWorkingMemory workingMemory,
+ final Extractor extractor1,
+ final Object object1,
+ final Extractor extractor2, final Object object2) {
+ if (extractor1.isNullValue( workingMemory, object1 )) {
+ return extractor2.isNullValue( workingMemory, object2 );
+ } else if (extractor2.isNullValue( workingMemory, object2 )) {
+ return false;
+ }
+
+ // TODO: we are not handling delta right now... maybe we should
+ return extractor1.getDoubleValue( workingMemory, object1 ) == extractor2.getDoubleValue( workingMemory, object2 );
+ }
+
+ public String toString() {
+ return "Double ==";
+ }
+ }
+
+ static class DoubleNotEqualEvaluator extends BaseEvaluator {
+ /**
+ *
+ */
+ private static final long serialVersionUID = 400L;
+ public final static Evaluator INSTANCE = new DoubleNotEqualEvaluator();
+
+ private DoubleNotEqualEvaluator() {
+ super( ValueType.PDOUBLE_TYPE,
+ Operator.NOT_EQUAL );
+ }
+
+ public boolean evaluate(InternalWorkingMemory workingMemory,
+ final Extractor extractor,
+ final Object object1, final FieldValue object2) {
+ if ( extractor.isNullValue( workingMemory, object1 ) ) {
+ return !object2.isNull();
+ } else if ( object2.isNull() ) {
+ return true;
+ }
+
+ // TODO: we are not handling delta right now... maybe we should
+ return extractor.getDoubleValue( workingMemory, object1 ) != object2.getDoubleValue();
+ }
+
+ public boolean evaluateCachedRight(InternalWorkingMemory workingMemory,
+ final VariableContextEntry context, final Object left) {
+ if ( context.declaration.getExtractor().isNullValue( workingMemory, left ) ) {
+ return !context.isRightNull();
+ } else if ( context.isRightNull() ) {
+ return true;
+ }
+
+ // TODO: we are not handling delta right now... maybe we should
+ return context.declaration.getExtractor().getDoubleValue( workingMemory, left ) != ((DoubleVariableContextEntry) context).right;
+ }
+
+ public boolean evaluateCachedLeft(InternalWorkingMemory workingMemory,
+ final VariableContextEntry context, final Object right) {
+ if ( context.extractor.isNullValue( workingMemory, right )) {
+ return !context.isLeftNull();
+ } else if ( context.isLeftNull() ) {
+ return true;
+ }
+
+ // TODO: we are not handling delta right now... maybe we should
+ return ((DoubleVariableContextEntry) context).left != context.extractor.getDoubleValue( workingMemory, right );
+ }
+
+ public boolean evaluate(InternalWorkingMemory workingMemory,
+ final Extractor extractor1,
+ final Object object1,
+ final Extractor extractor2, final Object object2) {
+ if (extractor1.isNullValue( workingMemory, object1 )) {
+ return !extractor2.isNullValue( workingMemory, object2 );
+ } else if (extractor2.isNullValue( workingMemory, object2 )) {
+ return true;
+ }
+
+ // TODO: we are not handling delta right now... maybe we should
+ return extractor1.getDoubleValue( workingMemory, object1 ) != extractor2.getDoubleValue( workingMemory, object2 );
+ }
+
+ public String toString() {
+ return "Double !=";
+ }
+ }
+
+ static class FactTemplateEqualEvaluator extends BaseEvaluator {
+ /**
+ *
+ */
+ private static final long serialVersionUID = 400L;
+ public final static Evaluator INSTANCE = new FactTemplateEqualEvaluator();
+
+ private FactTemplateEqualEvaluator() {
+ super( ValueType.FACTTEMPLATE_TYPE,
+ Operator.EQUAL );
+ }
+
+ public boolean evaluate(InternalWorkingMemory workingMemory,
+ final Extractor extractor,
+ final Object object1, final FieldValue object2) {
+ final Object value1 = extractor.getValue( workingMemory, object1 );
+ final Object value2 = object2.getValue();
+ if ( value1 == null ) {
+ return value2 == null;
+ }
+ return value1.equals( value2 );
+ }
+
+ public boolean evaluateCachedRight(InternalWorkingMemory workingMemory,
+ final VariableContextEntry context, final Object left) {
+ final Object value = context.declaration.getExtractor().getValue( workingMemory, left );
+ if ( value == null ) {
+ return ((ObjectVariableContextEntry) context).right == null;
+ }
+ return value.equals( ((ObjectVariableContextEntry) context).right );
+ }
+
+ public boolean evaluateCachedLeft(InternalWorkingMemory workingMemory,
+ final VariableContextEntry context, final Object right) {
+ final Object value = context.extractor.getValue( workingMemory, right );
+ if ( ((ObjectVariableContextEntry) context).left == null ) {
+ return value == null;
+ }
+ return ((ObjectVariableContextEntry) context).left.equals( value );
+ }
+
+ public boolean evaluate(InternalWorkingMemory workingMemory,
+ final Extractor extractor1,
+ final Object object1,
+ final Extractor extractor2, final Object object2) {
+ final Object value1 = extractor1.getValue( workingMemory, object1 );
+ final Object value2 = extractor2.getValue( workingMemory, object2 );
+ if ( value1 == null ) {
+ return value2 == null;
+ }
+ return value1.equals( value2 );
+ }
+
+ public String toString() {
+ return "FactTemplate ==";
+ }
+
+ }
+
+ static class FactTemplateNotEqualEvaluator extends BaseEvaluator {
+ /**
+ *
+ */
+ private static final long serialVersionUID = 400L;
+ public final static Evaluator INSTANCE = new FactTemplateNotEqualEvaluator();
+
+ private FactTemplateNotEqualEvaluator() {
+ super( ValueType.FACTTEMPLATE_TYPE,
+ Operator.NOT_EQUAL );
+ }
+
+ public boolean evaluate(InternalWorkingMemory workingMemory,
+ final Extractor extractor,
+ final Object object1, final FieldValue object2) {
+ final Object value1 = extractor.getValue( workingMemory, object1 );
+ final Object value2 = object2.getValue();
+ if ( value1 == null ) {
+ return value2 != null;
+ }
+ return !value1.equals( value2 );
+ }
+
+ public boolean evaluateCachedRight(InternalWorkingMemory workingMemory,
+ final VariableContextEntry context, final Object left) {
+ final Object value = context.declaration.getExtractor().getValue( workingMemory, left );
+ if ( value == null ) {
+ return ((ObjectVariableContextEntry) context).right != null;
+ }
+ return !value.equals( ((ObjectVariableContextEntry) context).right );
+ }
+
+ public boolean evaluateCachedLeft(InternalWorkingMemory workingMemory,
+ final VariableContextEntry context, final Object right) {
+ final Object value = context.extractor.getValue( workingMemory, right );
+ if ( ((ObjectVariableContextEntry) context).left == null ) {
+ return value != null;
+ }
+ return !((ObjectVariableContextEntry) context).left.equals( value );
+ }
+
+ public boolean evaluate(InternalWorkingMemory workingMemory,
+ final Extractor extractor1,
+ final Object object1,
+ final Extractor extractor2, final Object object2) {
+ final Object value1 = extractor1.getValue( workingMemory, object1 );
+ final Object value2 = extractor2.getValue( workingMemory, object2 );
+ if ( value1 == null ) {
+ return value2 != null;
+ }
+ return !value1.equals( value2 );
+ }
+
+ public String toString() {
+ return "FactTemplate !=";
+ }
+ }
+
+ static class FloatEqualEvaluator extends BaseEvaluator {
+
+ private static final long serialVersionUID = 400L;
+ public final static Evaluator INSTANCE = new FloatEqualEvaluator();
+
+ private FloatEqualEvaluator() {
+ super( ValueType.PFLOAT_TYPE,
+ Operator.EQUAL );
+ }
+
+ public boolean evaluate(InternalWorkingMemory workingMemory,
+ final Extractor extractor,
+ final Object object1, final FieldValue object2) {
+ if ( extractor.isNullValue( workingMemory, object1 ) ) {
+ return object2.isNull();
+ } else if ( object2.isNull() ) {
+ return false;
+ }
+
+ // TODO: we are not handling delta right now... maybe we should
+ return extractor.getFloatValue( workingMemory, object1 ) == object2.getFloatValue();
+ }
+
+ public boolean evaluateCachedRight(InternalWorkingMemory workingMemory,
+ final VariableContextEntry context, final Object left) {
+ if ( context.declaration.getExtractor().isNullValue( workingMemory, left ) ) {
+ return context.isRightNull();
+ } else if ( context.isRightNull() ) {
+ return false;
+ }
+
+ // TODO: we are not handling delta right now... maybe we should
+ return context.declaration.getExtractor().getFloatValue( workingMemory, left ) == ((DoubleVariableContextEntry) context).right;
+ }
+
+ public boolean evaluateCachedLeft(InternalWorkingMemory workingMemory,
+ final VariableContextEntry context, final Object right) {
+ if ( context.extractor.isNullValue( workingMemory, right )) {
+ return context.isLeftNull();
+ } else if ( context.isLeftNull() ) {
+ return false;
+ }
+
+ // TODO: we are not handling delta right now... maybe we should
+ return ((DoubleVariableContextEntry) context).left == context.extractor.getFloatValue( workingMemory, right );
+ }
+
+ public boolean evaluate(InternalWorkingMemory workingMemory,
+ final Extractor extractor1,
+ final Object object1,
+ final Extractor extractor2, final Object object2) {
+ if (extractor1.isNullValue( workingMemory, object1 )) {
+ return extractor2.isNullValue( workingMemory, object2 );
+ } else if (extractor2.isNullValue( workingMemory, object2 )) {
+ return false;
+ }
+
+ // TODO: we are not handling delta right now... maybe we should
+ return extractor1.getFloatValue( workingMemory, object1 ) == extractor2.getFloatValue( workingMemory, object2 );
+ }
+
+ public String toString() {
+ return "Float ==";
+ }
+ }
+
+ static class FloatNotEqualEvaluator extends BaseEvaluator {
+ /**
+ *
+ */
+ private static final long serialVersionUID = 400L;
+ public final static Evaluator INSTANCE = new FloatNotEqualEvaluator();
+
+ private FloatNotEqualEvaluator() {
+ super( ValueType.PFLOAT_TYPE,
+ Operator.NOT_EQUAL );
+ }
+
+ public boolean evaluate(InternalWorkingMemory workingMemory,
+ final Extractor extractor,
+ final Object object1, final FieldValue object2) {
+ if ( extractor.isNullValue( workingMemory, object1 ) ) {
+ return !object2.isNull();
+ } else if ( object2.isNull() ) {
+ return true;
+ }
+
+ // TODO: we are not handling delta right now... maybe we should
+ return extractor.getFloatValue( workingMemory, object1 ) != object2.getFloatValue();
+ }
+
+ public boolean evaluateCachedRight(InternalWorkingMemory workingMemory,
+ final VariableContextEntry context, final Object left) {
+ if ( context.declaration.getExtractor().isNullValue( workingMemory, left ) ) {
+ return !context.isRightNull();
+ } else if ( context.isRightNull() ) {
+ return true;
+ }
+
+ // TODO: we are not handling delta right now... maybe we should
+ return context.declaration.getExtractor().getFloatValue( workingMemory, left ) != ((DoubleVariableContextEntry) context).right;
+ }
+
+ public boolean evaluateCachedLeft(InternalWorkingMemory workingMemory,
+ final VariableContextEntry context, final Object right) {
+ if ( context.extractor.isNullValue( workingMemory, right ) ) {
+ return !context.isLeftNull();
+ } else if ( context.isLeftNull() ) {
+ return true;
+ }
+
+ // TODO: we are not handling delta right now... maybe we should
+ return ((DoubleVariableContextEntry) context).left != context.extractor.getFloatValue( workingMemory, right );
+ }
+
+ public boolean evaluate(InternalWorkingMemory workingMemory,
+ final Extractor extractor1,
+ final Object object1,
+ final Extractor extractor2, final Object object2) {
+ if (extractor1.isNullValue( workingMemory, object1 )) {
+ return !extractor2.isNullValue( workingMemory, object2 );
+ } else if (extractor2.isNullValue( workingMemory, object2 )) {
+ return true;
+ }
+
+ // TODO: we are not handling delta right now... maybe we should
+ return extractor1.getFloatValue( workingMemory, object1 ) != extractor2.getFloatValue( workingMemory, object2 );
+ }
+
+ public String toString() {
+ return "Float !=";
+ }
+ }
+
+ static class IntegerEqualEvaluator extends BaseEvaluator {
+ /**
+ *
+ */
+ private static final long serialVersionUID = 400L;
+ public final static Evaluator INSTANCE = new IntegerEqualEvaluator();
+
+ private IntegerEqualEvaluator() {
+ super( ValueType.PINTEGER_TYPE,
+ Operator.EQUAL );
+ }
+
+ public boolean evaluate(InternalWorkingMemory workingMemory,
+ final Extractor extractor,
+ final Object object1, final FieldValue object2) {
+ if ( extractor.isNullValue( workingMemory, object1 ) ) {
+ return object2.isNull();
+ } else if ( object2.isNull() ) {
+ return false;
+ }
+
+ return extractor.getIntValue( workingMemory, object1 ) == object2.getIntValue();
+ }
+
+ public boolean evaluateCachedRight(InternalWorkingMemory workingMemory,
+ final VariableContextEntry context, final Object left) {
+ if ( context.declaration.getExtractor().isNullValue( workingMemory, left ) ) {
+ return context.isRightNull();
+ } else if ( context.isRightNull() ) {
+ return false;
+ }
+
+ return context.declaration.getExtractor().getIntValue( workingMemory, left ) == ((LongVariableContextEntry) context).right;
+ }
+
+ public boolean evaluateCachedLeft(InternalWorkingMemory workingMemory,
+ final VariableContextEntry context, final Object object2) {
+ if ( context.extractor.isNullValue( workingMemory, object2 )) {
+ return context.isLeftNull();
+ } else if ( context.isLeftNull() ) {
+ return false;
+ }
+
+ return context.extractor.getIntValue( workingMemory, object2 ) == ((LongVariableContextEntry) context).left;
+ }
+
+ public boolean evaluate(InternalWorkingMemory workingMemory,
+ final Extractor extractor1,
+ final Object object1,
+ final Extractor extractor2, final Object object2) {
+ if (extractor1.isNullValue( workingMemory, object1 )) {
+ return extractor2.isNullValue( workingMemory, object2 );
+ } else if (extractor2.isNullValue( workingMemory, object2 )) {
+ return false;
+ }
+
+ return extractor1.getIntValue( workingMemory, object1 ) == extractor2.getIntValue( workingMemory, object2 );
+ }
+
+ public String toString() {
+ return "Integer ==";
+ }
+
+ }
+
+ static class IntegerNotEqualEvaluator extends BaseEvaluator {
+ /**
+ *
+ */
+ private static final long serialVersionUID = 400L;
+ public final static Evaluator INSTANCE = new IntegerNotEqualEvaluator();
+
+ private IntegerNotEqualEvaluator() {
+ super( ValueType.PINTEGER_TYPE,
+ Operator.NOT_EQUAL );
+ }
+
+ public boolean evaluate(InternalWorkingMemory workingMemory,
+ final Extractor extractor,
+ final Object object1, final FieldValue object2) {
+ if ( extractor.isNullValue( workingMemory, object1 ) ) {
+ return !object2.isNull();
+ } else if ( object2.isNull() ) {
+ return true;
+ }
+
+ return extractor.getIntValue( workingMemory, object1 ) != object2.getIntValue();
+ }
+
+ public boolean evaluateCachedRight(InternalWorkingMemory workingMemory,
+ final VariableContextEntry context, final Object left) {
+ if ( context.declaration.getExtractor().isNullValue( workingMemory, left ) ) {
+ return !context.isRightNull();
+ } else if ( context.isRightNull() ) {
+ return true;
+ }
+
+ return context.declaration.getExtractor().getIntValue( workingMemory, left ) != ((LongVariableContextEntry) context).right;
+ }
+
+ public boolean evaluateCachedLeft(InternalWorkingMemory workingMemory,
+ final VariableContextEntry context, final Object object2) {
+ if ( context.extractor.isNullValue( workingMemory, object2 ) ) {
+ return !context.isLeftNull();
+ } else if ( context.isLeftNull() ) {
+ return true;
+ }
+
+ return context.extractor.getIntValue( workingMemory, object2 ) != ((LongVariableContextEntry) context).left;
+ }
+
+ public boolean evaluate(InternalWorkingMemory workingMemory,
+ final Extractor extractor1,
+ final Object object1,
+ final Extractor extractor2, final Object object2) {
+ if (extractor1.isNullValue( workingMemory, object1 )) {
+ return !extractor2.isNullValue( workingMemory, object2 );
+ } else if (extractor2.isNullValue( workingMemory, object2 )) {
+ return true;
+ }
+
+ return extractor1.getIntValue( workingMemory, object1 ) != extractor2.getIntValue( workingMemory, object2 );
+ }
+
+ public String toString() {
+ return "Integer !=";
+ }
+ }
+
+ static class LongEqualEvaluator extends BaseEvaluator {
+ /**
+ *
+ */
+ private static final long serialVersionUID = 400L;
+ public final static Evaluator INSTANCE = new LongEqualEvaluator();
+
+ private LongEqualEvaluator() {
+ super( ValueType.PLONG_TYPE,
+ Operator.EQUAL );
+ }
+
+ public boolean evaluate(InternalWorkingMemory workingMemory,
+ final Extractor extractor,
+ final Object object1, final FieldValue object2) {
+ if ( extractor.isNullValue( workingMemory, object1 ) ) {
+ return object2.isNull();
+ } else if ( object2.isNull() ) {
+ return false;
+ }
+
+ return extractor.getLongValue( workingMemory, object1 ) == object2.getLongValue();
+ }
+
+ public boolean evaluateCachedRight(InternalWorkingMemory workingMemory,
+ final VariableContextEntry context, final Object left) {
+ if ( context.declaration.getExtractor().isNullValue( workingMemory, left ) ) {
+ return context.isRightNull();
+ } else if ( context.isRightNull() ) {
+ return false;
+ }
+
+ return context.declaration.getExtractor().getLongValue( workingMemory, left ) == ((LongVariableContextEntry) context).right;
+ }
+
+ public boolean evaluateCachedLeft(InternalWorkingMemory workingMemory,
+ final VariableContextEntry context, final Object right) {
+ if ( context.extractor.isNullValue( workingMemory, right )) {
+ return context.isLeftNull();
+ } else if ( context.isLeftNull() ) {
+ return false;
+ }
+
+ return ((LongVariableContextEntry) context).left == context.extractor.getLongValue( workingMemory, right );
+ }
+
+ public boolean evaluate(InternalWorkingMemory workingMemory,
+ final Extractor extractor1,
+ final Object object1,
+ final Extractor extractor2, final Object object2) {
+ if (extractor1.isNullValue( workingMemory, object1 )) {
+ return extractor2.isNullValue( workingMemory, object2 );
+ } else if (extractor2.isNullValue( workingMemory, object2 )) {
+ return false;
+ }
+
+ return extractor1.getLongValue( workingMemory, object1 ) == extractor2.getLongValue( workingMemory, object2 );
+ }
+
+ public String toString() {
+ return "Long ==";
+ }
+ }
+
+ static class LongNotEqualEvaluator extends BaseEvaluator {
+ /**
+ *
+ */
+ private static final long serialVersionUID = 400L;
+ public final static Evaluator INSTANCE = new LongNotEqualEvaluator();
+
+ private LongNotEqualEvaluator() {
+ super( ValueType.PLONG_TYPE,
+ Operator.NOT_EQUAL );
+ }
+
+ public boolean evaluate(InternalWorkingMemory workingMemory,
+ final Extractor extractor,
+ final Object object1, final FieldValue object2) {
+ if ( extractor.isNullValue( workingMemory, object1 ) ) {
+ return !object2.isNull();
+ } else if ( object2.isNull() ) {
+ return true;
+ }
+
+ return extractor.getLongValue( workingMemory, object1 ) != object2.getLongValue();
+ }
+
+ public boolean evaluateCachedRight(InternalWorkingMemory workingMemory,
+ final VariableContextEntry context, final Object left) {
+ if ( context.declaration.getExtractor().isNullValue( workingMemory, left ) ) {
+ return !context.isRightNull();
+ } else if ( context.isRightNull() ) {
+ return true;
+ }
+
+ return context.declaration.getExtractor().getLongValue( workingMemory, left ) != ((LongVariableContextEntry) context).right;
+ }
+
+ public boolean evaluateCachedLeft(InternalWorkingMemory workingMemory,
+ final VariableContextEntry context, final Object right) {
+ if ( context.extractor.isNullValue( workingMemory, right ) ) {
+ return !context.isLeftNull();
+ } else if ( context.isLeftNull() ) {
+ return true;
+ }
+
+ return ((LongVariableContextEntry) context).left != context.extractor.getLongValue( workingMemory, right );
+ }
+
+ public boolean evaluate(InternalWorkingMemory workingMemory,
+ final Extractor extractor1,
+ final Object object1,
+ final Extractor extractor2, final Object object2) {
+ if (extractor1.isNullValue( workingMemory, object1 )) {
+ return !extractor2.isNullValue( workingMemory, object2 );
+ } else if (extractor2.isNullValue( workingMemory, object2 )) {
+ return true;
+ }
+
+ return extractor1.getLongValue( workingMemory, object1 ) != extractor2.getLongValue( workingMemory, object2 );
+ }
+
+ public String toString() {
+ return "Long !=";
+ }
+ }
+
+ static class ObjectEqualEvaluator extends BaseEvaluator {
+ /**
+ *
+ */
+ private static final long serialVersionUID = 400L;
+ public final static Evaluator INSTANCE = new ObjectEqualEvaluator();
+
+ private ObjectEqualEvaluator() {
+ super( ValueType.OBJECT_TYPE,
+ Operator.EQUAL );
+ }
+
+ public boolean evaluate(InternalWorkingMemory workingMemory,
+ final Extractor extractor,
+ final Object object1, final FieldValue object2) {
+ final Object value1 = extractor.getValue( workingMemory, object1 );
+ final Object value2 = object2.getValue();
+ if ( value1 == null ) {
+ return value2 == null;
+ }
+ if( value2 != null && value2 instanceof ShadowProxy ) {
+ return value2.equals( value1 );
+ }
+ return value1.equals( value2 );
+ }
+
+ public boolean evaluateCachedRight(InternalWorkingMemory workingMemory,
+ final VariableContextEntry context, final Object left) {
+ final Object value = context.declaration.getExtractor().getValue( workingMemory, left );
+ if ( value == null ) {
+ return ((ObjectVariableContextEntry) context).right == null;
+ }
+ if( ((ObjectVariableContextEntry) context).right != null && ((ObjectVariableContextEntry) context).right instanceof ShadowProxy ) {
+ return ((ObjectVariableContextEntry) context).right.equals( value );
+ }
+ return value.equals( ((ObjectVariableContextEntry) context).right );
+ }
+
+ public boolean evaluateCachedLeft(InternalWorkingMemory workingMemory,
+ final VariableContextEntry context, final Object right) {
+ final Object value = context.extractor.getValue( workingMemory, right );
+ if ( ((ObjectVariableContextEntry) context).left == null ) {
+ return value == null;
+ }
+ if( value != null && value instanceof ShadowProxy ) {
+ return value.equals( ((ObjectVariableContextEntry) context).left );
+ }
+ return ((ObjectVariableContextEntry) context).left.equals( value );
+ }
+
+ public boolean evaluate(InternalWorkingMemory workingMemory,
+ final Extractor extractor1,
+ final Object object1,
+ final Extractor extractor2, final Object object2) {
+ final Object value1 = extractor1.getValue( workingMemory, object1 );
+ final Object value2 = extractor2.getValue( workingMemory, object2 );
+ if ( value1 == null ) {
+ return value2 == null;
+ }
+ if( value2 != null && value2 instanceof ShadowProxy ) {
+ return value2.equals( value1 );
+ }
+ return value1.equals( value2 );
+ }
+
+ public String toString() {
+ return "Object ==";
+ }
+
+ }
+
+ static class ObjectNotEqualEvaluator extends BaseEvaluator {
+ /**
+ *
+ */
+ private static final long serialVersionUID = 400L;
+ public final static Evaluator INSTANCE = new ObjectNotEqualEvaluator();
+
+ private ObjectNotEqualEvaluator() {
+ super( ValueType.OBJECT_TYPE,
+ Operator.NOT_EQUAL );
+ }
+
+ public boolean evaluate(InternalWorkingMemory workingMemory,
+ final Extractor extractor,
+ final Object object1, final FieldValue object2) {
+ final Object value1 = extractor.getValue( workingMemory, object1 );
+ final Object value2 = object2.getValue();
+ if ( value1 == null ) {
+ return value2 != null;
+ }
+ if( value2 != null && value2 instanceof ShadowProxy ) {
+ return !value2.equals( value1 );
+ }
+ return !value1.equals( value2 );
+ }
+
+ public boolean evaluateCachedRight(InternalWorkingMemory workingMemory,
+ final VariableContextEntry context, final Object left) {
+ final Object value = context.declaration.getExtractor().getValue( workingMemory, left );
+ if ( value == null ) {
+ return ((ObjectVariableContextEntry) context).right != null;
+ }
+ if( ((ObjectVariableContextEntry) context).right != null && ((ObjectVariableContextEntry) context).right instanceof ShadowProxy ) {
+ return !((ObjectVariableContextEntry) context).right.equals( value );
+ }
+ return !value.equals( ((ObjectVariableContextEntry) context).right );
+ }
+
+ public boolean evaluateCachedLeft(InternalWorkingMemory workingMemory,
+ final VariableContextEntry context, final Object right) {
+ final Object value = context.extractor.getValue( workingMemory, right );
+ if ( ((ObjectVariableContextEntry) context).left == null ) {
+ return value != null;
+ }
+ if( value != null && value instanceof ShadowProxy ) {
+ return !value.equals( ((ObjectVariableContextEntry) context).left );
+ }
+ return !((ObjectVariableContextEntry) context).left.equals( value );
+ }
+
+ public boolean evaluate(InternalWorkingMemory workingMemory,
+ final Extractor extractor1,
+ final Object object1,
+ final Extractor extractor2, final Object object2) {
+ final Object value1 = extractor1.getValue( workingMemory, object1 );
+ final Object value2 = extractor2.getValue( workingMemory, object2 );
+ if ( value1 == null ) {
+ return value2 != null;
+ }
+ if( value2 != null && value2 instanceof ShadowProxy ) {
+ return !value2.equals( value1 );
+ }
+ return !value1.equals( value2 );
+ }
+
+ public String toString() {
+ return "Object !=";
+ }
+ }
+
+ static class ShortEqualEvaluator extends BaseEvaluator {
+ /**
+ *
+ */
+ private static final long serialVersionUID = 400L;
+ private static final Evaluator INSTANCE = new ShortEqualEvaluator();
+
+ private ShortEqualEvaluator() {
+ super( ValueType.PSHORT_TYPE,
+ Operator.EQUAL );
+ }
+
+ public boolean evaluate(InternalWorkingMemory workingMemory,
+ final Extractor extractor,
+ final Object object1, final FieldValue object2) {
+ if ( extractor.isNullValue( workingMemory, object1 ) ) {
+ return object2.isNull();
+ } else if ( object2.isNull() ) {
+ return false;
+ }
+
+ return extractor.getShortValue( workingMemory, object1 ) == object2.getShortValue();
+ }
+
+ public boolean evaluateCachedRight(InternalWorkingMemory workingMemory,
+ final VariableContextEntry context, final Object left) {
+ if ( context.declaration.getExtractor().isNullValue( workingMemory, left ) ) {
+ return context.isRightNull();
+ } else if ( context.isRightNull() ) {
+ return false;
+ }
+
+ return context.declaration.getExtractor().getShortValue( workingMemory, left ) == ((LongVariableContextEntry) context).right;
+ }
+
+ public boolean evaluateCachedLeft(InternalWorkingMemory workingMemory,
+ final VariableContextEntry context, final Object right) {
+ if ( context.extractor.isNullValue( workingMemory, right )) {
+ return context.isLeftNull();
+ } else if ( context.isLeftNull() ) {
+ return false;
+ }
+
+ return ((LongVariableContextEntry) context).left == context.extractor.getShortValue( workingMemory, right );
+ }
+
+ public boolean evaluate(InternalWorkingMemory workingMemory,
+ final Extractor extractor1,
+ final Object object1,
+ final Extractor extractor2, final Object object2) {
+ if (extractor1.isNullValue( workingMemory, object1 )) {
+ return extractor2.isNullValue( workingMemory, object2 );
+ } else if (extractor2.isNullValue( workingMemory, object2 )) {
+ return false;
+ }
+
+ return extractor1.getShortValue( workingMemory, object1 ) == extractor2.getShortValue( workingMemory, object2 );
+ }
+
+ public String toString() {
+ return "Short ==";
+ }
+ }
+
+ static class ShortNotEqualEvaluator extends BaseEvaluator {
+ /**
+ *
+ */
+ private static final long serialVersionUID = 400L;
+ private static final Evaluator INSTANCE = new ShortNotEqualEvaluator();
+
+ private ShortNotEqualEvaluator() {
+ super( ValueType.PSHORT_TYPE,
+ Operator.NOT_EQUAL );
+ }
+
+ public boolean evaluate(InternalWorkingMemory workingMemory,
+ final Extractor extractor,
+ final Object object1, final FieldValue object2) {
+ if ( extractor.isNullValue( workingMemory, object1 ) ) {
+ return !object2.isNull();
+ } else if ( object2.isNull() ) {
+ return true;
+ }
+
+ return extractor.getShortValue( workingMemory, object1 ) != object2.getShortValue();
+ }
+
+ public boolean evaluateCachedRight(InternalWorkingMemory workingMemory,
+ final VariableContextEntry context, final Object left) {
+ if ( context.declaration.getExtractor().isNullValue( workingMemory, left ) ) {
+ return !context.isRightNull();
+ } else if ( context.isRightNull() ) {
+ return true;
+ }
+
+ return context.declaration.getExtractor().getShortValue( workingMemory, left ) != ((LongVariableContextEntry) context).right;
+ }
+
+ public boolean evaluateCachedLeft(InternalWorkingMemory workingMemory,
+ final VariableContextEntry context, final Object right) {
+ if ( context.extractor.isNullValue( workingMemory, right ) ) {
+ return !context.isLeftNull();
+ } else if ( context.isLeftNull() ) {
+ return true;
+ }
+
+ return ((LongVariableContextEntry) context).left != context.extractor.getShortValue( workingMemory, right );
+ }
+
+ public boolean evaluate(InternalWorkingMemory workingMemory,
+ final Extractor extractor1,
+ final Object object1,
+ final Extractor extractor2, final Object object2) {
+ if (extractor1.isNullValue( workingMemory, object1 )) {
+ return !extractor2.isNullValue( workingMemory, object2 );
+ } else if (extractor2.isNullValue( workingMemory, object2 )) {
+ return true;
+ }
+
+ return extractor1.getShortValue( workingMemory, object1 ) != extractor2.getShortValue( workingMemory, object2 );
+ }
+
+ public String toString() {
+ return "Short !=";
+ }
+ }
+
+ static class StringEqualEvaluator extends BaseEvaluator {
+ /**
+ *
+ */
+ private static final long serialVersionUID = 400L;
+ public final static Evaluator INSTANCE = new StringEqualEvaluator();
+
+ private StringEqualEvaluator() {
+ super( ValueType.STRING_TYPE,
+ Operator.EQUAL );
+ }
+
+ public boolean evaluate(InternalWorkingMemory workingMemory,
+ final Extractor extractor,
+ final Object object1, final FieldValue object2) {
+ final Object value1 = extractor.getValue( workingMemory, object1 );
+ final Object value2 = object2.getValue();
+ if ( value1 == null ) {
+ return value2 == null;
+ }
+ return value1.equals( value2 );
+ }
+
+ public boolean evaluateCachedRight(InternalWorkingMemory workingMemory,
+ final VariableContextEntry context, final Object left) {
+ final Object value = context.declaration.getExtractor().getValue( workingMemory, left );
+ if ( value == null ) {
+ return ((ObjectVariableContextEntry) context).right == null;
+ }
+ return value.equals( ((ObjectVariableContextEntry) context).right );
+ }
+
+ public boolean evaluateCachedLeft(InternalWorkingMemory workingMemory,
+ final VariableContextEntry context, final Object right) {
+ final Object value = context.extractor.getValue( workingMemory, right );
+ if ( ((ObjectVariableContextEntry) context).left == null ) {
+ return value == null;
+ }
+ return ((ObjectVariableContextEntry) context).left.equals( value );
+ }
+
+ public boolean evaluate(InternalWorkingMemory workingMemory,
+ final Extractor extractor1,
+ final Object object1,
+ final Extractor extractor2, final Object object2) {
+ final Object value1 = extractor1.getValue( workingMemory, object1 );
+ final Object value2 = extractor2.getValue( workingMemory, object2 );
+ if ( value1 == null ) {
+ return value2 == null;
+ }
+ return value1.equals( value2 );
+ }
+
+ public String toString() {
+ return "String ==";
+ }
+
+ }
+
+ static class StringNotEqualEvaluator extends BaseEvaluator {
+ /**
+ *
+ */
+ private static final long serialVersionUID = 400L;
+ public final static Evaluator INSTANCE = new StringNotEqualEvaluator();
+
+ private StringNotEqualEvaluator() {
+ super( ValueType.STRING_TYPE,
+ Operator.NOT_EQUAL );
+ }
+
+ public boolean evaluate(InternalWorkingMemory workingMemory,
+ final Extractor extractor,
+ final Object object1, final FieldValue object2) {
+ final Object value1 = extractor.getValue( workingMemory, object1 );
+ final Object value2 = object2.getValue();
+ if ( value1 == null ) {
+ return value2 != null;
+ }
+ return !value1.equals( value2 );
+ }
+
+ public boolean evaluateCachedRight(InternalWorkingMemory workingMemory,
+ final VariableContextEntry context, final Object left) {
+ final Object value = context.declaration.getExtractor().getValue( workingMemory, left );
+ if ( value == null ) {
+ return ((ObjectVariableContextEntry) context).right != null;
+ }
+ return !value.equals( ((ObjectVariableContextEntry) context).right );
+ }
+
+ public boolean evaluateCachedLeft(InternalWorkingMemory workingMemory,
+ final VariableContextEntry context, final Object right) {
+ final Object value = context.extractor.getValue( workingMemory, right );
+ if ( ((ObjectVariableContextEntry) context).left == null ) {
+ return value != null;
+ }
+ return !((ObjectVariableContextEntry) context).left.equals( value );
+ }
+
+ public boolean evaluate(InternalWorkingMemory workingMemory,
+ final Extractor extractor1,
+ final Object object1,
+ final Extractor extractor2, final Object object2) {
+ final Object value1 = extractor1.getValue( workingMemory, object1 );
+ final Object value2 = extractor2.getValue( workingMemory, object2 );
+ if ( value1 == null ) {
+ return value2 != null;
+ }
+ return !value1.equals( value2 );
+ }
+
+ public String toString() {
+ return "String !=";
+ }
+ }
+
+
+}
Added: labs/jbossrules/branches/temporal_rete/drools-core/src/main/java/org/drools/base/evaluators/EvaluatorDefinition.java
===================================================================
--- labs/jbossrules/branches/temporal_rete/drools-core/src/main/java/org/drools/base/evaluators/EvaluatorDefinition.java (rev 0)
+++ labs/jbossrules/branches/temporal_rete/drools-core/src/main/java/org/drools/base/evaluators/EvaluatorDefinition.java 2007-12-07 14:10:27 UTC (rev 17089)
@@ -0,0 +1,143 @@
+/*
+ * Copyright 2007 JBoss Inc
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ * Created on Dec 6, 2007
+ */
+package org.drools.base.evaluators;
+
+import org.drools.base.ValueType;
+import org.drools.spi.Evaluator;
+
+/**
+ * An evaluator definition interface that allows for pluggable
+ * evaluator implementation.
+ *
+ * This interface is the registry entry point for all available
+ * evaluators and describes all evaluator capabilities
+ *
+ * @author etirelli
+ */
+public interface EvaluatorDefinition {
+
+ /**
+ * Returns the list of identifies this
+ * evaluator implementation supports
+ *
+ * @return
+ */
+ public String[] getEvaluatorIds();
+
+ /**
+ * My appologies to english speakers if the word "negatable" does not
+ * exists. :)
+ *
+ * This method returns true if this evaluator supports negation. Example:
+ *
+ * the "matches" operator supports "not matches" and so is "negatable" (!?)
+ *
+ * @return
+ */
+ public boolean isNegatable();
+
+ /**
+ * Returns the evaluator instance for the given type and the
+ * defined parameterText
+ *
+ * @param type the type of the attributes this evaluator will
+ * operate on. This is important because the evaluator
+ * may do optimizations and type coercion based on the
+ * types it is evaluating. It is also possible that
+ * this evaluator does not support a given type.
+ *
+ * @param operatorId the string identifier of the evaluator
+ *
+ * @param isNegated true if the evaluator instance to be returned is
+ * the negated version of the evaluator.
+ *
+ * @param parameterText some evaluators support parameters and these
+ * parameters are defined as a String that is
+ * parsed by the evaluator itself.
+ *
+ * @return an Evaluator instance capable of evaluating expressions
+ * between values of the given type, or null in case the type
+ * is not supported.
+ */
+ public Evaluator getEvaluator(ValueType type,
+ String operatorId,
+ boolean isNegated,
+ String parameterText);
+
+ /**
+ * Returns the evaluator instance for the given type and the
+ * defined parameterText
+ *
+ * @param type the type of the attributes this evaluator will
+ * operate on. This is important because the evaluator
+ * may do optimizations and type coercion based on the
+ * types it is evaluating. It is also possible that
+ * this evaluator does not support a given type.
+ *
+ * @param operator the operator implemented by the evaluator
+ *
+ * @param parameterText some evaluators support parameters and these
+ * parameters are defined as a String that is
+ * parsed by the evaluator itself.
+ *
+ * @return an Evaluator instance capable of evaluating expressions
+ * between values of the given type, or null in case the type
+ * is not supported.
+ */
+ public Evaluator getEvaluator(ValueType type,
+ Operator operator,
+ String parameterText);
+
+ /**
+ * Returns the evaluator instance for the given type and the
+ * defined parameterText
+ *
+ * @param type the type of the attributes this evaluator will
+ * operate on. This is important because the evaluator
+ * may do optimizations and type coercion based on the
+ * types it is evaluating. It is also possible that
+ * this evaluator does not support a given type.
+ *
+ * @param operator the operator implemented by the evaluator
+ *
+ * @return an Evaluator instance capable of evaluating expressions
+ * between values of the given type, or null in case the type
+ * is not supported.
+ */
+ public Evaluator getEvaluator(ValueType type,
+ Operator operator);
+
+ /**
+ * Returns true in case this evaluator supports operations over values
+ * of that specific type.
+ *
+ * @param type
+ * @return
+ */
+ public boolean supportsType(ValueType type);
+
+ /**
+ * There are evaluators that operate on *fact handle* attributes and
+ * evaluators that operate on *fact* attributes.
+ *
+ * @return true if this evaluator operates on fact handle attributes
+ * and false if it operates on fact attributes
+ */
+ public boolean operatesOnFactHandles();
+
+}
Added: labs/jbossrules/branches/temporal_rete/drools-core/src/main/java/org/drools/base/evaluators/EvaluatorDefinitionRegistry.java
===================================================================
--- labs/jbossrules/branches/temporal_rete/drools-core/src/main/java/org/drools/base/evaluators/EvaluatorDefinitionRegistry.java (rev 0)
+++ labs/jbossrules/branches/temporal_rete/drools-core/src/main/java/org/drools/base/evaluators/EvaluatorDefinitionRegistry.java 2007-12-07 14:10:27 UTC (rev 17089)
@@ -0,0 +1,218 @@
+/*
+ * Copyright 2007 JBoss Inc
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ * Created on Dec 6, 2007
+ */
+package org.drools.base.evaluators;
+
+import java.io.Serializable;
+import java.util.HashMap;
+import java.util.Map;
+
+import org.drools.RuntimeDroolsException;
+import org.drools.base.ValueType;
+import org.drools.spi.Evaluator;
+
+/**
+ * A registry class for all available evaluators
+ *
+ * @author etirelli
+ */
+public class EvaluatorDefinitionRegistry
+ implements
+ Serializable {
+
+ private static final long serialVersionUID = -3047718531857258033L;
+
+ private Map<String, EvaluatorDefinition> evaluators;
+ private ClassLoader classloader;
+
+ /**
+ * Default constructor. The registry will use the context classloader (if available)
+ * to load the evaluator definition classes or this class classloader if it is
+ * not available.
+ */
+ public EvaluatorDefinitionRegistry() {
+ this( null );
+ }
+
+ /**
+ * Creates a new EvaluatorRegistry using the given classloader to load
+ * the evaluator definition classes.
+ *
+ * @param classloader the classloader to use to load evaluator definition
+ * classes. If it is null, try to obtain the context
+ * classloader. If it is also null, uses the same classloader
+ * that loaded this class.
+ *
+ */
+ public EvaluatorDefinitionRegistry(ClassLoader classloader) {
+ this.evaluators = new HashMap<String, EvaluatorDefinition>();
+ if ( classloader != null ) {
+ this.classloader = classloader;
+ } else {
+ this.classloader = Thread.currentThread().getContextClassLoader() != null ? Thread.currentThread().getContextClassLoader() : this.getClass().getClassLoader();
+ }
+ }
+
+ /**
+ * Adds an evaluator definition class to the registry using the
+ * evaluator class name. The class will be loaded and the corresponting
+ * evaluator ID will be added to the registry. In case there exists
+ * an implementation for that ID already, the new implementation will
+ * replace the previous one.
+ *
+ * @param className the name of the class for the implementation definition.
+ * The class must implement the EvaluatorDefinition interface.
+ *
+ * @return true if the new class implementation is replacing an old
+ * implementation for the same evaluator ID. False otherwise.
+ */
+ public void addEvaluatorDefinition(String className) {
+ try {
+ Class<EvaluatorDefinition> defClass = (Class<EvaluatorDefinition>) this.classloader.loadClass( className );
+ EvaluatorDefinition def = defClass.newInstance();
+ addEvaluatorDefinition( def );
+ } catch ( ClassNotFoundException e ) {
+ throw new RuntimeDroolsException( "Class not found for evaluator definition: " + className,
+ e );
+ } catch ( InstantiationException e ) {
+ throw new RuntimeDroolsException( "Error instantiating class for evaluator definition: " + className,
+ e );
+ } catch ( IllegalAccessException e ) {
+ throw new RuntimeDroolsException( "Illegal access instantiating class for evaluator definition: " + className,
+ e );
+ }
+ }
+
+ /**
+ * Adds an evaluator definition class to the registry. In case there exists
+ * an implementation for that evaluator ID already, the new implementation will
+ * replace the previous one.
+ *
+ * @param def the evaluator definition to be added.
+ */
+ public void addEvaluatorDefinition(EvaluatorDefinition def) {
+ for ( String id : def.getEvaluatorIds() ) {
+ this.evaluators.put( id,
+ def );
+ }
+ }
+
+ /**
+ * Returns the evaluator definition for the given evaluator ID
+ * or null if no one was found
+ *
+ * @param evaluatorId
+ * @return
+ */
+ public EvaluatorDefinition getEvaluatorDefinition(String evaluatorId) {
+ return this.evaluators.get( evaluatorId );
+ }
+
+ /**
+ * Returns the evaluator definition for the given operator
+ * or null if no one was found
+ *
+ * @param operator the operator implemented by the evaluator definition
+ * @return
+ */
+ public EvaluatorDefinition getEvaluatorDefinition(Operator operator) {
+ return this.evaluators.get( operator.getOperatorString() );
+ }
+
+ /**
+ * Returns the evaluator instance for the given type and the
+ * defined parameterText
+ *
+ * @param type the type of the attributes this evaluator will
+ * operate on. This is important because the evaluator
+ * may do optimizations and type coercion based on the
+ * types it is evaluating. It is also possible that
+ * this evaluator does not support a given type.
+ *
+ * @param operatorId the string identifier of the evaluator
+ *
+ * @param isNegated true if the evaluator instance to be returned is
+ * the negated version of the evaluator.
+ *
+ * @param parameterText some evaluators support parameters and these
+ * parameters are defined as a String that is
+ * parsed by the evaluator itself.
+ *
+ * @return an Evaluator instance capable of evaluating expressions
+ * between values of the given type, or null in case the type
+ * is not supported.
+ */
+ public Evaluator getEvaluator(ValueType type,
+ String operatorId,
+ boolean isNegated,
+ String parameterText) {
+ return this.getEvaluatorDefinition( operatorId ).getEvaluator( type,
+ operatorId,
+ isNegated,
+ parameterText );
+ }
+
+ /**
+ * Returns the evaluator instance for the given type and the
+ * defined parameterText
+ *
+ * @param type the type of the attributes this evaluator will
+ * operate on. This is important because the evaluator
+ * may do optimizations and type coercion based on the
+ * types it is evaluating. It is also possible that
+ * this evaluator does not support a given type.
+ *
+ * @param operator the operator that evaluator implements
+ *
+ * @param parameterText some evaluators support parameters and these
+ * parameters are defined as a String that is
+ * parsed by the evaluator itself.
+ *
+ * @return an Evaluator instance capable of evaluating expressions
+ * between values of the given type, or null in case the type
+ * is not supported.
+ */
+ public Evaluator getEvaluator(ValueType type,
+ Operator operator,
+ String parameterText) {
+ return this.getEvaluatorDefinition( operator ).getEvaluator( type,
+ operator,
+ parameterText );
+ }
+
+ /**
+ * Returns the evaluator instance for the given type and the
+ * defined parameterText
+ *
+ * @param type the type of the attributes this evaluator will
+ * operate on. This is important because the evaluator
+ * may do optimizations and type coercion based on the
+ * types it is evaluating. It is also possible that
+ * this evaluator does not support a given type.
+ *
+ * @param operator the operator that evaluator implements
+ *
+ * @return an Evaluator instance capable of evaluating expressions
+ * between values of the given type, or null in case the type
+ * is not supported.
+ */
+ public Evaluator getEvaluator(ValueType type,
+ Operator operator) {
+ return this.getEvaluatorDefinition( operator ).getEvaluator( type,
+ operator );
+ }
+}
Deleted: labs/jbossrules/branches/temporal_rete/drools-core/src/main/java/org/drools/base/evaluators/EvaluatorFactory.java
===================================================================
--- labs/jbossrules/branches/temporal_rete/drools-core/src/main/java/org/drools/base/evaluators/EvaluatorFactory.java 2007-12-07 13:39:06 UTC (rev 17088)
+++ labs/jbossrules/branches/temporal_rete/drools-core/src/main/java/org/drools/base/evaluators/EvaluatorFactory.java 2007-12-07 14:10:27 UTC (rev 17089)
@@ -1,11 +0,0 @@
-package org.drools.base.evaluators;
-
-import java.io.Serializable;
-
-import org.drools.spi.Evaluator;
-
-public interface EvaluatorFactory
- extends
- Serializable {
- public Evaluator getEvaluator(Operator operator);
-}
Added: labs/jbossrules/branches/temporal_rete/drools-core/src/main/java/org/drools/base/evaluators/EvaluatorRegistry.java
===================================================================
--- labs/jbossrules/branches/temporal_rete/drools-core/src/main/java/org/drools/base/evaluators/EvaluatorRegistry.java (rev 0)
+++ labs/jbossrules/branches/temporal_rete/drools-core/src/main/java/org/drools/base/evaluators/EvaluatorRegistry.java 2007-12-07 14:10:27 UTC (rev 17089)
@@ -0,0 +1,61 @@
+/*
+ * Copyright 2007 JBoss Inc
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ * Created on Dec 6, 2007
+ */
+package org.drools.base.evaluators;
+
+import java.io.Serializable;
+import java.util.HashMap;
+import java.util.Map;
+
+import org.drools.RuntimeDroolsException;
+import org.drools.base.ValueType;
+import org.drools.spi.Evaluator;
+
+/**
+ * A simple helper class to store Evaluators for a given set of
+ * value types and operators
+ *
+ * @author etirelli
+ */
+public class EvaluatorRegistry implements Serializable {
+
+
+ private static final long serialVersionUID = 5643974484372543392L;
+ private Map<ValueType, Map<Operator, Evaluator>> evaluators = new HashMap<ValueType, Map<Operator, Evaluator>>();
+
+ public EvaluatorRegistry() {
+ }
+
+ public void addEvaluator( final ValueType type, final Operator operator, final Evaluator evaluator ) {
+ Map<Operator, Evaluator> opEvalMap = this.evaluators.get( type );
+ if( opEvalMap == null ) {
+ opEvalMap = new HashMap<Operator, Evaluator>();
+ this.evaluators.put( type, opEvalMap );
+ }
+ opEvalMap.put( operator, evaluator );
+ }
+
+ public Evaluator getEvaluator( final ValueType type, final Operator operator ) {
+ Map<Operator, Evaluator> opEvalMap = this.evaluators.get( type );
+ return opEvalMap != null ? opEvalMap.get( operator ) : null;
+ }
+
+ public boolean supportsType(ValueType type) {
+ return this.evaluators.containsKey( type );
+ }
+
+}
Deleted: labs/jbossrules/branches/temporal_rete/drools-core/src/main/java/org/drools/base/evaluators/FactTemplateFactory.java
===================================================================
--- labs/jbossrules/branches/temporal_rete/drools-core/src/main/java/org/drools/base/evaluators/FactTemplateFactory.java 2007-12-07 13:39:06 UTC (rev 17088)
+++ labs/jbossrules/branches/temporal_rete/drools-core/src/main/java/org/drools/base/evaluators/FactTemplateFactory.java 2007-12-07 14:10:27 UTC (rev 17089)
@@ -1,179 +0,0 @@
-package org.drools.base.evaluators;
-
-/*
- * Copyright 2005 JBoss Inc
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-import org.drools.base.BaseEvaluator;
-import org.drools.base.ValueType;
-import org.drools.common.InternalWorkingMemory;
-import org.drools.rule.VariableRestriction.ObjectVariableContextEntry;
-import org.drools.rule.VariableRestriction.VariableContextEntry;
-import org.drools.spi.Evaluator;
-import org.drools.spi.Extractor;
-import org.drools.spi.FieldValue;
-
-/**
- * This is the misc "bucket" evaluator factory for objects.
- * It is fairly limited in operations,
- * and what operations are available are dependent on the exact type.
- *
- * @author Michael Neale
- */
-public class FactTemplateFactory
- implements
- EvaluatorFactory {
-
- private static final long serialVersionUID = 400L;
- private static EvaluatorFactory INSTANCE = new FactTemplateFactory();
-
- private FactTemplateFactory() {
-
- }
-
- public static EvaluatorFactory getInstance() {
- if ( FactTemplateFactory.INSTANCE == null ) {
- FactTemplateFactory.INSTANCE = new FactTemplateFactory();
- }
- return FactTemplateFactory.INSTANCE;
- }
-
- public Evaluator getEvaluator(final Operator operator) {
- if ( operator == Operator.EQUAL ) {
- return FactTemplateEqualEvaluator.INSTANCE;
- } else if ( operator == Operator.NOT_EQUAL ) {
- return FactTemplateNotEqualEvaluator.INSTANCE;
- } else {
- throw new RuntimeException( "Operator '" + operator + "' does not exist for FactTemplateEvaluator" );
- }
- }
-
- static class FactTemplateEqualEvaluator extends BaseEvaluator {
- /**
- *
- */
- private static final long serialVersionUID = 400L;
- public final static Evaluator INSTANCE = new FactTemplateEqualEvaluator();
-
- private FactTemplateEqualEvaluator() {
- super( ValueType.FACTTEMPLATE_TYPE,
- Operator.EQUAL );
- }
-
- public boolean evaluate(InternalWorkingMemory workingMemory,
- final Extractor extractor,
- final Object object1, final FieldValue object2) {
- final Object value1 = extractor.getValue( workingMemory, object1 );
- final Object value2 = object2.getValue();
- if ( value1 == null ) {
- return value2 == null;
- }
- return value1.equals( value2 );
- }
-
- public boolean evaluateCachedRight(InternalWorkingMemory workingMemory,
- final VariableContextEntry context, final Object left) {
- final Object value = context.declaration.getExtractor().getValue( workingMemory, left );
- if ( value == null ) {
- return ((ObjectVariableContextEntry) context).right == null;
- }
- return value.equals( ((ObjectVariableContextEntry) context).right );
- }
-
- public boolean evaluateCachedLeft(InternalWorkingMemory workingMemory,
- final VariableContextEntry context, final Object right) {
- final Object value = context.extractor.getValue( workingMemory, right );
- if ( ((ObjectVariableContextEntry) context).left == null ) {
- return value == null;
- }
- return ((ObjectVariableContextEntry) context).left.equals( value );
- }
-
- public boolean evaluate(InternalWorkingMemory workingMemory,
- final Extractor extractor1,
- final Object object1,
- final Extractor extractor2, final Object object2) {
- final Object value1 = extractor1.getValue( workingMemory, object1 );
- final Object value2 = extractor2.getValue( workingMemory, object2 );
- if ( value1 == null ) {
- return value2 == null;
- }
- return value1.equals( value2 );
- }
-
- public String toString() {
- return "FactTemplate ==";
- }
-
- }
-
- static class FactTemplateNotEqualEvaluator extends BaseEvaluator {
- /**
- *
- */
- private static final long serialVersionUID = 400L;
- public final static Evaluator INSTANCE = new FactTemplateNotEqualEvaluator();
-
- private FactTemplateNotEqualEvaluator() {
- super( ValueType.FACTTEMPLATE_TYPE,
- Operator.NOT_EQUAL );
- }
-
- public boolean evaluate(InternalWorkingMemory workingMemory,
- final Extractor extractor,
- final Object object1, final FieldValue object2) {
- final Object value1 = extractor.getValue( workingMemory, object1 );
- final Object value2 = object2.getValue();
- if ( value1 == null ) {
- return value2 != null;
- }
- return !value1.equals( value2 );
- }
-
- public boolean evaluateCachedRight(InternalWorkingMemory workingMemory,
- final VariableContextEntry context, final Object left) {
- final Object value = context.declaration.getExtractor().getValue( workingMemory, left );
- if ( value == null ) {
- return ((ObjectVariableContextEntry) context).right != null;
- }
- return !value.equals( ((ObjectVariableContextEntry) context).right );
- }
-
- public boolean evaluateCachedLeft(InternalWorkingMemory workingMemory,
- final VariableContextEntry context, final Object right) {
- final Object value = context.extractor.getValue( workingMemory, right );
- if ( ((ObjectVariableContextEntry) context).left == null ) {
- return value != null;
- }
- return !((ObjectVariableContextEntry) context).left.equals( value );
- }
-
- public boolean evaluate(InternalWorkingMemory workingMemory,
- final Extractor extractor1,
- final Object object1,
- final Extractor extractor2, final Object object2) {
- final Object value1 = extractor1.getValue( workingMemory, object1 );
- final Object value2 = extractor2.getValue( workingMemory, object2 );
- if ( value1 == null ) {
- return value2 != null;
- }
- return !value1.equals( value2 );
- }
-
- public String toString() {
- return "FactTemplate !=";
- }
- }
-}
\ No newline at end of file
Deleted: labs/jbossrules/branches/temporal_rete/drools-core/src/main/java/org/drools/base/evaluators/FloatFactory.java
===================================================================
--- labs/jbossrules/branches/temporal_rete/drools-core/src/main/java/org/drools/base/evaluators/FloatFactory.java 2007-12-07 13:39:06 UTC (rev 17088)
+++ labs/jbossrules/branches/temporal_rete/drools-core/src/main/java/org/drools/base/evaluators/FloatFactory.java 2007-12-07 14:10:27 UTC (rev 17089)
@@ -1,456 +0,0 @@
-package org.drools.base.evaluators;
-
-/*
- * Copyright 2005 JBoss Inc
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-import org.drools.base.BaseEvaluator;
-import org.drools.base.ValueType;
-import org.drools.common.InternalWorkingMemory;
-import org.drools.rule.VariableRestriction.DoubleVariableContextEntry;
-import org.drools.rule.VariableRestriction.VariableContextEntry;
-import org.drools.spi.Evaluator;
-import org.drools.spi.Extractor;
-import org.drools.spi.FieldValue;
-
-public class FloatFactory
- implements
- EvaluatorFactory {
-
- private static final long serialVersionUID = 400L;
- private static EvaluatorFactory INSTANCE = new FloatFactory();
-
- private FloatFactory() {
-
- }
-
- public static EvaluatorFactory getInstance() {
- if ( FloatFactory.INSTANCE == null ) {
- FloatFactory.INSTANCE = new FloatFactory();
- }
- return FloatFactory.INSTANCE;
- }
-
- public Evaluator getEvaluator(final Operator operator) {
- if ( operator == Operator.EQUAL ) {
- return FloatEqualEvaluator.INSTANCE;
- } else if ( operator == Operator.NOT_EQUAL ) {
- return FloatNotEqualEvaluator.INSTANCE;
- } else if ( operator == Operator.LESS ) {
- return FloatLessEvaluator.INSTANCE;
- } else if ( operator == Operator.LESS_OR_EQUAL ) {
- return FloatLessOrEqualEvaluator.INSTANCE;
- } else if ( operator == Operator.GREATER ) {
- return FloatGreaterEvaluator.INSTANCE;
- } else if ( operator == Operator.GREATER_OR_EQUAL ) {
- return FloatGreaterOrEqualEvaluator.INSTANCE;
- } else if ( operator == Operator.MEMBEROF ) {
- return FloatMemberOfEvaluator.INSTANCE;
- } else if ( operator == Operator.NOTMEMBEROF ) {
- return FloatNotMemberOfEvaluator.INSTANCE;
- } else {
- throw new RuntimeException( "Operator '" + operator + "' does not exist for FloatEvaluator" );
- }
- }
-
- static class FloatEqualEvaluator extends BaseEvaluator {
-
- private static final long serialVersionUID = 400L;
- public final static Evaluator INSTANCE = new FloatEqualEvaluator();
-
- private FloatEqualEvaluator() {
- super( ValueType.PFLOAT_TYPE,
- Operator.EQUAL );
- }
-
- public boolean evaluate(InternalWorkingMemory workingMemory,
- final Extractor extractor,
- final Object object1, final FieldValue object2) {
- if ( extractor.isNullValue( workingMemory, object1 ) ) {
- return object2.isNull();
- } else if ( object2.isNull() ) {
- return false;
- }
-
- // TODO: we are not handling delta right now... maybe we should
- return extractor.getFloatValue( workingMemory, object1 ) == object2.getFloatValue();
- }
-
- public boolean evaluateCachedRight(InternalWorkingMemory workingMemory,
- final VariableContextEntry context, final Object left) {
- if ( context.declaration.getExtractor().isNullValue( workingMemory, left ) ) {
- return context.isRightNull();
- } else if ( context.isRightNull() ) {
- return false;
- }
-
- // TODO: we are not handling delta right now... maybe we should
- return context.declaration.getExtractor().getFloatValue( workingMemory, left ) == ((DoubleVariableContextEntry) context).right;
- }
-
- public boolean evaluateCachedLeft(InternalWorkingMemory workingMemory,
- final VariableContextEntry context, final Object right) {
- if ( context.extractor.isNullValue( workingMemory, right )) {
- return context.isLeftNull();
- } else if ( context.isLeftNull() ) {
- return false;
- }
-
- // TODO: we are not handling delta right now... maybe we should
- return ((DoubleVariableContextEntry) context).left == context.extractor.getFloatValue( workingMemory, right );
- }
-
- public boolean evaluate(InternalWorkingMemory workingMemory,
- final Extractor extractor1,
- final Object object1,
- final Extractor extractor2, final Object object2) {
- if (extractor1.isNullValue( workingMemory, object1 )) {
- return extractor2.isNullValue( workingMemory, object2 );
- } else if (extractor2.isNullValue( workingMemory, object2 )) {
- return false;
- }
-
- // TODO: we are not handling delta right now... maybe we should
- return extractor1.getFloatValue( workingMemory, object1 ) == extractor2.getFloatValue( workingMemory, object2 );
- }
-
- public String toString() {
- return "Float ==";
- }
- }
-
- static class FloatNotEqualEvaluator extends BaseEvaluator {
- /**
- *
- */
- private static final long serialVersionUID = 400L;
- public final static Evaluator INSTANCE = new FloatNotEqualEvaluator();
-
- private FloatNotEqualEvaluator() {
- super( ValueType.PFLOAT_TYPE,
- Operator.NOT_EQUAL );
- }
-
- public boolean evaluate(InternalWorkingMemory workingMemory,
- final Extractor extractor,
- final Object object1, final FieldValue object2) {
- if ( extractor.isNullValue( workingMemory, object1 ) ) {
- return !object2.isNull();
- } else if ( object2.isNull() ) {
- return true;
- }
-
- // TODO: we are not handling delta right now... maybe we should
- return extractor.getFloatValue( workingMemory, object1 ) != object2.getFloatValue();
- }
-
- public boolean evaluateCachedRight(InternalWorkingMemory workingMemory,
- final VariableContextEntry context, final Object left) {
- if ( context.declaration.getExtractor().isNullValue( workingMemory, left ) ) {
- return !context.isRightNull();
- } else if ( context.isRightNull() ) {
- return true;
- }
-
- // TODO: we are not handling delta right now... maybe we should
- return context.declaration.getExtractor().getFloatValue( workingMemory, left ) != ((DoubleVariableContextEntry) context).right;
- }
-
- public boolean evaluateCachedLeft(InternalWorkingMemory workingMemory,
- final VariableContextEntry context, final Object right) {
- if ( context.extractor.isNullValue( workingMemory, right ) ) {
- return !context.isLeftNull();
- } else if ( context.isLeftNull() ) {
- return true;
- }
-
- // TODO: we are not handling delta right now... maybe we should
- return ((DoubleVariableContextEntry) context).left != context.extractor.getFloatValue( workingMemory, right );
- }
-
- public boolean evaluate(InternalWorkingMemory workingMemory,
- final Extractor extractor1,
- final Object object1,
- final Extractor extractor2, final Object object2) {
- if (extractor1.isNullValue( workingMemory, object1 )) {
- return !extractor2.isNullValue( workingMemory, object2 );
- } else if (extractor2.isNullValue( workingMemory, object2 )) {
- return true;
- }
-
- // TODO: we are not handling delta right now... maybe we should
- return extractor1.getFloatValue( workingMemory, object1 ) != extractor2.getFloatValue( workingMemory, object2 );
- }
-
- public String toString() {
- return "Float !=";
- }
- }
-
- static class FloatLessEvaluator extends BaseEvaluator {
- /**
- *
- */
- private static final long serialVersionUID = 400L;
- public final static Evaluator INSTANCE = new FloatLessEvaluator();
-
- private FloatLessEvaluator() {
- super( ValueType.PFLOAT_TYPE,
- Operator.LESS );
- }
-
- public boolean evaluate(InternalWorkingMemory workingMemory,
- final Extractor extractor,
- final Object object1, final FieldValue object2) {
- if( extractor.isNullValue( workingMemory, object1 ) ) {
- return false;
- }
- // TODO: we are not handling delta right now... maybe we should
- return extractor.getFloatValue( workingMemory, object1 ) < object2.getFloatValue();
- }
-
- public boolean evaluateCachedRight(InternalWorkingMemory workingMemory,
- final VariableContextEntry context, final Object left) {
- if( context.rightNull ) {
- return false;
- }
- // TODO: we are not handling delta right now... maybe we should
- return ((DoubleVariableContextEntry) context).right < context.declaration.getExtractor().getFloatValue( workingMemory, left );
- }
-
- public boolean evaluateCachedLeft(InternalWorkingMemory workingMemory,
- final VariableContextEntry context, final Object right) {
- if( context.extractor.isNullValue( workingMemory, right ) ) {
- return false;
- }
- // TODO: we are not handling delta right now... maybe we should
- return context.extractor.getFloatValue( workingMemory, right ) < ((DoubleVariableContextEntry) context).left;
- }
-
- public boolean evaluate(InternalWorkingMemory workingMemory,
- final Extractor extractor1,
- final Object object1,
- final Extractor extractor2, final Object object2) {
- if( extractor1.isNullValue( workingMemory, object1 ) ) {
- return false;
- }
- // TODO: we are not handling delta right now... maybe we should
- return extractor1.getFloatValue( workingMemory, object1 ) < extractor2.getFloatValue( workingMemory, object2 );
- }
-
- public String toString() {
- return "Float <";
- }
- }
-
- static class FloatLessOrEqualEvaluator extends BaseEvaluator {
- /**
- *
- */
- private static final long serialVersionUID = 400L;
- public final static Evaluator INSTANCE = new FloatLessOrEqualEvaluator();
-
- private FloatLessOrEqualEvaluator() {
- super( ValueType.PFLOAT_TYPE,
- Operator.LESS_OR_EQUAL );
- }
-
- public boolean evaluate(InternalWorkingMemory workingMemory,
- final Extractor extractor,
- final Object object1, final FieldValue object2) {
- if( extractor.isNullValue( workingMemory, object1 ) ) {
- return false;
- }
- // TODO: we are not handling delta right now... maybe we should
- return extractor.getFloatValue( workingMemory, object1 ) <= object2.getFloatValue();
- }
-
- public boolean evaluateCachedRight(InternalWorkingMemory workingMemory,
- final VariableContextEntry context, final Object left) {
- if( context.rightNull ) {
- return false;
- }
- // TODO: we are not handling delta right now... maybe we should
- return ((DoubleVariableContextEntry) context).right <= context.declaration.getExtractor().getFloatValue( workingMemory, left );
- }
-
- public boolean evaluateCachedLeft(InternalWorkingMemory workingMemory,
- final VariableContextEntry context, final Object right) {
- if( context.extractor.isNullValue( workingMemory, right ) ) {
- return false;
- }
- // TODO: we are not handling delta right now... maybe we should
- return context.extractor.getFloatValue( workingMemory, right ) <= ((DoubleVariableContextEntry) context).left;
- }
-
- public boolean evaluate(InternalWorkingMemory workingMemory,
- final Extractor extractor1,
- final Object object1,
- final Extractor extractor2, final Object object2) {
- if( extractor1.isNullValue( workingMemory, object1 ) ) {
- return false;
- }
- // TODO: we are not handling delta right now... maybe we should
- return extractor1.getFloatValue( workingMemory, object1 ) <= extractor2.getFloatValue( workingMemory, object2 );
- }
-
- public String toString() {
- return "Float <=";
- }
- }
-
- static class FloatGreaterEvaluator extends BaseEvaluator {
- /**
- *
- */
- private static final long serialVersionUID = 400L;
- public final static Evaluator INSTANCE = new FloatGreaterEvaluator();
-
- private FloatGreaterEvaluator() {
- super( ValueType.PFLOAT_TYPE,
- Operator.GREATER );
- }
-
- public boolean evaluate(InternalWorkingMemory workingMemory,
- final Extractor extractor,
- final Object object1, final FieldValue object2) {
- if( extractor.isNullValue( workingMemory, object1 ) ) {
- return false;
- }
- // TODO: we are not handling delta right now... maybe we should
- return extractor.getFloatValue( workingMemory, object1 ) > object2.getFloatValue();
- }
-
- public boolean evaluateCachedRight(InternalWorkingMemory workingMemory,
- final VariableContextEntry context, final Object left) {
- if( context.rightNull ) {
- return false;
- }
- // TODO: we are not handling delta right now... maybe we should
- return ((DoubleVariableContextEntry) context).right > context.declaration.getExtractor().getFloatValue( workingMemory, left );
- }
-
- public boolean evaluateCachedLeft(InternalWorkingMemory workingMemory,
- final VariableContextEntry context, final Object right) {
- if( context.extractor.isNullValue( workingMemory, right ) ) {
- return false;
- }
- // TODO: we are not handling delta right now... maybe we should
- return context.extractor.getFloatValue( workingMemory, right ) > ((DoubleVariableContextEntry) context).left;
- }
-
- public boolean evaluate(InternalWorkingMemory workingMemory,
- final Extractor extractor1,
- final Object object1,
- final Extractor extractor2, final Object object2) {
- if( extractor1.isNullValue( workingMemory, object1 ) ) {
- return false;
- }
- // TODO: we are not handling delta right now... maybe we should
- return extractor1.getFloatValue( workingMemory, object1 ) > extractor2.getFloatValue( workingMemory, object2 );
- }
-
- public String toString() {
- return "Float >";
- }
- }
-
- static class FloatGreaterOrEqualEvaluator extends BaseEvaluator {
- /**
- *
- */
- private static final long serialVersionUID = 400L;
- private final static Evaluator INSTANCE = new FloatGreaterOrEqualEvaluator();
-
- private FloatGreaterOrEqualEvaluator() {
- super( ValueType.PFLOAT_TYPE,
- Operator.GREATER_OR_EQUAL );
- }
-
- public boolean evaluate(InternalWorkingMemory workingMemory,
- final Extractor extractor,
- final Object object1, final FieldValue object2) {
- if( extractor.isNullValue( workingMemory, object1 ) ) {
- return false;
- }
- // TODO: we are not handling delta right now... maybe we should
- return extractor.getFloatValue( workingMemory, object1 ) >= object2.getFloatValue();
- }
-
- public boolean evaluateCachedRight(InternalWorkingMemory workingMemory,
- final VariableContextEntry context, final Object left) {
- if( context.rightNull ) {
- return false;
- }
- // TODO: we are not handling delta right now... maybe we should
- return ((DoubleVariableContextEntry) context).right >= context.declaration.getExtractor().getFloatValue( workingMemory, left );
- }
-
- public boolean evaluateCachedLeft(InternalWorkingMemory workingMemory,
- final VariableContextEntry context, final Object right) {
- if( context.extractor.isNullValue( workingMemory, right ) ) {
- return false;
- }
- // TODO: we are not handling delta right now... maybe we should
- return context.extractor.getFloatValue( workingMemory, right ) >= ((DoubleVariableContextEntry) context).left;
- }
-
- public boolean evaluate(InternalWorkingMemory workingMemory,
- final Extractor extractor1,
- final Object object1,
- final Extractor extractor2, final Object object2) {
- if( extractor1.isNullValue( workingMemory, object1 ) ) {
- return false;
- }
- // TODO: we are not handling delta right now... maybe we should
- return extractor1.getFloatValue( workingMemory, object1 ) >= extractor2.getFloatValue( workingMemory, object2 );
- }
-
- public String toString() {
- return "Float >=";
- }
- }
-
- static class FloatMemberOfEvaluator extends BaseMemberOfEvaluator {
-
- private static final long serialVersionUID = 400L;
- public final static Evaluator INSTANCE = new FloatMemberOfEvaluator();
-
- private FloatMemberOfEvaluator() {
- super( ValueType.PFLOAT_TYPE,
- Operator.MEMBEROF );
- }
-
- public String toString() {
- return "Float memberOf";
- }
- }
-
- static class FloatNotMemberOfEvaluator extends BaseNotMemberOfEvaluator {
-
- private static final long serialVersionUID = 400L;
- public final static Evaluator INSTANCE = new FloatNotMemberOfEvaluator();
-
- private FloatNotMemberOfEvaluator() {
- super( ValueType.PFLOAT_TYPE,
- Operator.NOTMEMBEROF );
- }
-
- public String toString() {
- return "Float not memberOf";
- }
- }
-
-}
\ No newline at end of file
Deleted: labs/jbossrules/branches/temporal_rete/drools-core/src/main/java/org/drools/base/evaluators/IntegerFactory.java
===================================================================
--- labs/jbossrules/branches/temporal_rete/drools-core/src/main/java/org/drools/base/evaluators/IntegerFactory.java 2007-12-07 13:39:06 UTC (rev 17088)
+++ labs/jbossrules/branches/temporal_rete/drools-core/src/main/java/org/drools/base/evaluators/IntegerFactory.java 2007-12-07 14:10:27 UTC (rev 17089)
@@ -1,436 +0,0 @@
-package org.drools.base.evaluators;
-
-/*
- * Copyright 2005 JBoss Inc
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-import org.drools.base.BaseEvaluator;
-import org.drools.base.ValueType;
-import org.drools.common.InternalWorkingMemory;
-import org.drools.rule.VariableRestriction.LongVariableContextEntry;
-import org.drools.rule.VariableRestriction.VariableContextEntry;
-import org.drools.spi.Evaluator;
-import org.drools.spi.Extractor;
-import org.drools.spi.FieldValue;
-
-public class IntegerFactory
- implements
- EvaluatorFactory {
-
- private static final long serialVersionUID = 400L;
- private static EvaluatorFactory INSTANCE = new IntegerFactory();
-
- private IntegerFactory() {
-
- }
-
- public static EvaluatorFactory getInstance() {
- if ( IntegerFactory.INSTANCE == null ) {
- IntegerFactory.INSTANCE = new IntegerFactory();
- }
- return IntegerFactory.INSTANCE;
- }
-
- public Evaluator getEvaluator(final Operator operator) {
- if ( operator == Operator.EQUAL ) {
- return IntegerEqualEvaluator.INSTANCE;
- } else if ( operator == Operator.NOT_EQUAL ) {
- return IntegerNotEqualEvaluator.INSTANCE;
- } else if ( operator == Operator.LESS ) {
- return IntegerLessEvaluator.INSTANCE;
- } else if ( operator == Operator.LESS_OR_EQUAL ) {
- return IntegerLessOrEqualEvaluator.INSTANCE;
- } else if ( operator == Operator.GREATER ) {
- return IntegerGreaterEvaluator.INSTANCE;
- } else if ( operator == Operator.GREATER_OR_EQUAL ) {
- return IntegerGreaterOrEqualEvaluator.INSTANCE;
- } else if ( operator == Operator.MEMBEROF ) {
- return IntegerMemberOfEvaluator.INSTANCE;
- } else if ( operator == Operator.NOTMEMBEROF ) {
- return IntegerNotMemberOfEvaluator.INSTANCE;
- } else {
- throw new RuntimeException( "Operator '" + operator + "' does not exist for IntegerEvaluator" );
- }
- }
-
- static class IntegerEqualEvaluator extends BaseEvaluator {
- /**
- *
- */
- private static final long serialVersionUID = 400L;
- public final static Evaluator INSTANCE = new IntegerEqualEvaluator();
-
- private IntegerEqualEvaluator() {
- super( ValueType.PINTEGER_TYPE,
- Operator.EQUAL );
- }
-
- public boolean evaluate(InternalWorkingMemory workingMemory,
- final Extractor extractor,
- final Object object1, final FieldValue object2) {
- if ( extractor.isNullValue( workingMemory, object1 ) ) {
- return object2.isNull();
- } else if ( object2.isNull() ) {
- return false;
- }
-
- return extractor.getIntValue( workingMemory, object1 ) == object2.getIntValue();
- }
-
- public boolean evaluateCachedRight(InternalWorkingMemory workingMemory,
- final VariableContextEntry context, final Object left) {
- if ( context.declaration.getExtractor().isNullValue( workingMemory, left ) ) {
- return context.isRightNull();
- } else if ( context.isRightNull() ) {
- return false;
- }
-
- return context.declaration.getExtractor().getIntValue( workingMemory, left ) == ((LongVariableContextEntry) context).right;
- }
-
- public boolean evaluateCachedLeft(InternalWorkingMemory workingMemory,
- final VariableContextEntry context, final Object object2) {
- if ( context.extractor.isNullValue( workingMemory, object2 )) {
- return context.isLeftNull();
- } else if ( context.isLeftNull() ) {
- return false;
- }
-
- return context.extractor.getIntValue( workingMemory, object2 ) == ((LongVariableContextEntry) context).left;
- }
-
- public boolean evaluate(InternalWorkingMemory workingMemory,
- final Extractor extractor1,
- final Object object1,
- final Extractor extractor2, final Object object2) {
- if (extractor1.isNullValue( workingMemory, object1 )) {
- return extractor2.isNullValue( workingMemory, object2 );
- } else if (extractor2.isNullValue( workingMemory, object2 )) {
- return false;
- }
-
- return extractor1.getIntValue( workingMemory, object1 ) == extractor2.getIntValue( workingMemory, object2 );
- }
-
- public String toString() {
- return "Integer ==";
- }
-
- }
-
- static class IntegerNotEqualEvaluator extends BaseEvaluator {
- /**
- *
- */
- private static final long serialVersionUID = 400L;
- public final static Evaluator INSTANCE = new IntegerNotEqualEvaluator();
-
- private IntegerNotEqualEvaluator() {
- super( ValueType.PINTEGER_TYPE,
- Operator.NOT_EQUAL );
- }
-
- public boolean evaluate(InternalWorkingMemory workingMemory,
- final Extractor extractor,
- final Object object1, final FieldValue object2) {
- if ( extractor.isNullValue( workingMemory, object1 ) ) {
- return !object2.isNull();
- } else if ( object2.isNull() ) {
- return true;
- }
-
- return extractor.getIntValue( workingMemory, object1 ) != object2.getIntValue();
- }
-
- public boolean evaluateCachedRight(InternalWorkingMemory workingMemory,
- final VariableContextEntry context, final Object left) {
- if ( context.declaration.getExtractor().isNullValue( workingMemory, left ) ) {
- return !context.isRightNull();
- } else if ( context.isRightNull() ) {
- return true;
- }
-
- return context.declaration.getExtractor().getIntValue( workingMemory, left ) != ((LongVariableContextEntry) context).right;
- }
-
- public boolean evaluateCachedLeft(InternalWorkingMemory workingMemory,
- final VariableContextEntry context, final Object object2) {
- if ( context.extractor.isNullValue( workingMemory, object2 ) ) {
- return !context.isLeftNull();
- } else if ( context.isLeftNull() ) {
- return true;
- }
-
- return context.extractor.getIntValue( workingMemory, object2 ) != ((LongVariableContextEntry) context).left;
- }
-
- public boolean evaluate(InternalWorkingMemory workingMemory,
- final Extractor extractor1,
- final Object object1,
- final Extractor extractor2, final Object object2) {
- if (extractor1.isNullValue( workingMemory, object1 )) {
- return !extractor2.isNullValue( workingMemory, object2 );
- } else if (extractor2.isNullValue( workingMemory, object2 )) {
- return true;
- }
-
- return extractor1.getIntValue( workingMemory, object1 ) != extractor2.getIntValue( workingMemory, object2 );
- }
-
- public String toString() {
- return "Integer !=";
- }
- }
-
- static class IntegerLessEvaluator extends BaseEvaluator {
- /**
- *
- */
- private static final long serialVersionUID = 400L;
- public final static Evaluator INSTANCE = new IntegerLessEvaluator();
-
- private IntegerLessEvaluator() {
- super( ValueType.PINTEGER_TYPE,
- Operator.LESS );
- }
-
- public boolean evaluate(InternalWorkingMemory workingMemory,
- final Extractor extractor,
- final Object object1, final FieldValue object2) {
- if( extractor.isNullValue( workingMemory, object1 ) ) {
- return false;
- }
- return extractor.getIntValue( workingMemory, object1 ) < object2.getIntValue();
- }
-
- public boolean evaluateCachedRight(InternalWorkingMemory workingMemory,
- final VariableContextEntry context, final Object left) {
- if( context.rightNull ) {
- return false;
- }
- return ((LongVariableContextEntry) context).right < context.declaration.getExtractor().getIntValue( workingMemory, left );
- }
-
- public boolean evaluateCachedLeft(InternalWorkingMemory workingMemory,
- final VariableContextEntry context, final Object right) {
- if( context.extractor.isNullValue( workingMemory, right ) ) {
- return false;
- }
- return context.extractor.getIntValue( workingMemory, right ) < ((LongVariableContextEntry) context).left;
- }
-
- public boolean evaluate(InternalWorkingMemory workingMemory,
- final Extractor extractor1,
- final Object object1,
- final Extractor extractor2, final Object object2) {
- if( extractor1.isNullValue( workingMemory, object1 ) ) {
- return false;
- }
- return extractor1.getIntValue( workingMemory, object1 ) < extractor2.getIntValue( workingMemory, object2 );
- }
-
- public String toString() {
- return "Integer <";
- }
- }
-
- static class IntegerLessOrEqualEvaluator extends BaseEvaluator {
- /**
- *
- */
- private static final long serialVersionUID = 400L;
- public final static Evaluator INSTANCE = new IntegerLessOrEqualEvaluator();
-
- private IntegerLessOrEqualEvaluator() {
- super( ValueType.PINTEGER_TYPE,
- Operator.LESS_OR_EQUAL );
- }
-
- public boolean evaluate(InternalWorkingMemory workingMemory,
- final Extractor extractor,
- final Object object1, final FieldValue object2) {
- if( extractor.isNullValue( workingMemory, object1 ) ) {
- return false;
- }
- return extractor.getIntValue( workingMemory, object1 ) <= object2.getIntValue();
- }
-
- public boolean evaluateCachedRight(InternalWorkingMemory workingMemory,
- final VariableContextEntry context, final Object left) {
- if( context.rightNull ) {
- return false;
- }
- return ((LongVariableContextEntry) context).right <= context.declaration.getExtractor().getIntValue( workingMemory, left );
- }
-
- public boolean evaluateCachedLeft(InternalWorkingMemory workingMemory,
- final VariableContextEntry context, final Object right) {
- if( context.extractor.isNullValue( workingMemory, right ) ) {
- return false;
- }
- return context.extractor.getIntValue( workingMemory, right ) <= ((LongVariableContextEntry) context).left;
- }
-
- public boolean evaluate(InternalWorkingMemory workingMemory,
- final Extractor extractor1,
- final Object object1,
- final Extractor extractor2, final Object object2) {
- if( extractor1.isNullValue( workingMemory, object1 ) ) {
- return false;
- }
- return extractor1.getIntValue( workingMemory, object1 ) <= extractor2.getIntValue( workingMemory, object2 );
- }
-
- public String toString() {
- return "Integer <=";
- }
- }
-
- static class IntegerGreaterEvaluator extends BaseEvaluator {
- /**
- *
- */
- private static final long serialVersionUID = 400L;
- public final static Evaluator INSTANCE = new IntegerGreaterEvaluator();
-
- private IntegerGreaterEvaluator() {
- super( ValueType.PINTEGER_TYPE,
- Operator.GREATER );
- }
-
- public boolean evaluate(InternalWorkingMemory workingMemory,
- final Extractor extractor,
- final Object object1, final FieldValue object2) {
- if( extractor.isNullValue( workingMemory, object1 ) ) {
- return false;
- }
- return extractor.getIntValue( workingMemory, object1 ) > object2.getIntValue();
- }
-
- public boolean evaluateCachedRight(InternalWorkingMemory workingMemory,
- final VariableContextEntry context, final Object left) {
- if( context.rightNull ) {
- return false;
- }
- return ((LongVariableContextEntry) context).right > context.declaration.getExtractor().getIntValue( workingMemory, left );
- }
-
- public boolean evaluateCachedLeft(InternalWorkingMemory workingMemory,
- final VariableContextEntry context, final Object right) {
- if( context.extractor.isNullValue( workingMemory, right ) ) {
- return false;
- }
- return context.extractor.getIntValue( workingMemory, right ) > ((LongVariableContextEntry) context).left;
- }
-
- public boolean evaluate(InternalWorkingMemory workingMemory,
- final Extractor extractor1,
- final Object object1,
- final Extractor extractor2, final Object object2) {
- if( extractor1.isNullValue( workingMemory, object1 ) ) {
- return false;
- }
- return extractor1.getIntValue( workingMemory, object1 ) > extractor2.getIntValue( workingMemory, object2 );
- }
-
- public String toString() {
- return "Integer >";
- }
- }
-
- static class IntegerGreaterOrEqualEvaluator extends BaseEvaluator {
- /**
- *
- */
- private static final long serialVersionUID = 400L;
- private final static Evaluator INSTANCE = new IntegerGreaterOrEqualEvaluator();
-
- private IntegerGreaterOrEqualEvaluator() {
- super( ValueType.PINTEGER_TYPE,
- Operator.GREATER_OR_EQUAL );
- }
-
- public boolean evaluate(InternalWorkingMemory workingMemory,
- final Extractor extractor,
- final Object object1, final FieldValue object2) {
- if( extractor.isNullValue( workingMemory, object1 ) ) {
- return false;
- }
- return extractor.getIntValue( workingMemory, object1 ) >= object2.getIntValue();
- }
-
- public boolean evaluateCachedRight(InternalWorkingMemory workingMemory,
- final VariableContextEntry context, final Object left) {
- if( context.rightNull ) {
- return false;
- }
- return ((LongVariableContextEntry) context).right >= context.declaration.getExtractor().getIntValue( workingMemory, left );
- }
-
- public boolean evaluateCachedLeft(InternalWorkingMemory workingMemory,
- final VariableContextEntry context, final Object right) {
- if( context.extractor.isNullValue( workingMemory, right ) ) {
- return false;
- }
- return context.extractor.getIntValue( workingMemory, right ) >= ((LongVariableContextEntry) context).left;
- }
-
- public boolean evaluate(InternalWorkingMemory workingMemory,
- final Extractor extractor1,
- final Object object1,
- final Extractor extractor2, final Object object2) {
- if( extractor1.isNullValue( workingMemory, object1 ) ) {
- return false;
- }
- return extractor1.getIntValue( workingMemory, object1 ) >= extractor2.getIntValue( workingMemory, object2 );
- }
-
- public String toString() {
- return "Integer >=";
- }
- }
-
- static class IntegerMemberOfEvaluator extends BaseMemberOfEvaluator {
-
- private static final long serialVersionUID = 400L;
- public final static Evaluator INSTANCE = new IntegerMemberOfEvaluator();
-
- private IntegerMemberOfEvaluator() {
- super( ValueType.PINTEGER_TYPE,
- Operator.MEMBEROF );
- }
-
- public String toString() {
- return "Integer memberOf";
- }
- }
-
- static class IntegerNotMemberOfEvaluator extends BaseNotMemberOfEvaluator {
-
- private static final long serialVersionUID = 400L;
- public final static Evaluator INSTANCE = new IntegerNotMemberOfEvaluator();
-
- private IntegerNotMemberOfEvaluator() {
- super( ValueType.PINTEGER_TYPE,
- Operator.NOTMEMBEROF );
- }
-
- public String toString() {
- return "Integer not memberOf";
- }
- }
-
-
-}
\ No newline at end of file
Deleted: labs/jbossrules/branches/temporal_rete/drools-core/src/main/java/org/drools/base/evaluators/LongFactory.java
===================================================================
--- labs/jbossrules/branches/temporal_rete/drools-core/src/main/java/org/drools/base/evaluators/LongFactory.java 2007-12-07 13:39:06 UTC (rev 17088)
+++ labs/jbossrules/branches/temporal_rete/drools-core/src/main/java/org/drools/base/evaluators/LongFactory.java 2007-12-07 14:10:27 UTC (rev 17089)
@@ -1,434 +0,0 @@
-package org.drools.base.evaluators;
-
-/*
- * Copyright 2005 JBoss Inc
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-import org.drools.base.BaseEvaluator;
-import org.drools.base.ValueType;
-import org.drools.common.InternalWorkingMemory;
-import org.drools.rule.VariableRestriction.LongVariableContextEntry;
-import org.drools.rule.VariableRestriction.VariableContextEntry;
-import org.drools.spi.Evaluator;
-import org.drools.spi.Extractor;
-import org.drools.spi.FieldValue;
-
-public class LongFactory
- implements
- EvaluatorFactory {
-
- private static final long serialVersionUID = 400L;
- private static EvaluatorFactory INSTANCE = new LongFactory();
-
- private LongFactory() {
-
- }
-
- public static EvaluatorFactory getInstance() {
- if ( LongFactory.INSTANCE == null ) {
- LongFactory.INSTANCE = new LongFactory();
- }
- return LongFactory.INSTANCE;
- }
-
- public Evaluator getEvaluator(final Operator operator) {
- if ( operator == Operator.EQUAL ) {
- return LongEqualEvaluator.INSTANCE;
- } else if ( operator == Operator.NOT_EQUAL ) {
- return LongNotEqualEvaluator.INSTANCE;
- } else if ( operator == Operator.LESS ) {
- return LongLessEvaluator.INSTANCE;
- } else if ( operator == Operator.LESS_OR_EQUAL ) {
- return LongLessOrEqualEvaluator.INSTANCE;
- } else if ( operator == Operator.GREATER ) {
- return LongGreaterEvaluator.INSTANCE;
- } else if ( operator == Operator.GREATER_OR_EQUAL ) {
- return LongGreaterOrEqualEvaluator.INSTANCE;
- } else if ( operator == Operator.MEMBEROF ) {
- return LongMemberOfEvaluator.INSTANCE;
- } else if ( operator == Operator.NOTMEMBEROF ) {
- return LongNotMemberOfEvaluator.INSTANCE;
- } else {
- throw new RuntimeException( "Operator '" + operator + "' does not exist for LongEvaluator" );
- }
- }
-
- static class LongEqualEvaluator extends BaseEvaluator {
- /**
- *
- */
- private static final long serialVersionUID = 400L;
- public final static Evaluator INSTANCE = new LongEqualEvaluator();
-
- private LongEqualEvaluator() {
- super( ValueType.PLONG_TYPE,
- Operator.EQUAL );
- }
-
- public boolean evaluate(InternalWorkingMemory workingMemory,
- final Extractor extractor,
- final Object object1, final FieldValue object2) {
- if ( extractor.isNullValue( workingMemory, object1 ) ) {
- return object2.isNull();
- } else if ( object2.isNull() ) {
- return false;
- }
-
- return extractor.getLongValue( workingMemory, object1 ) == object2.getLongValue();
- }
-
- public boolean evaluateCachedRight(InternalWorkingMemory workingMemory,
- final VariableContextEntry context, final Object left) {
- if ( context.declaration.getExtractor().isNullValue( workingMemory, left ) ) {
- return context.isRightNull();
- } else if ( context.isRightNull() ) {
- return false;
- }
-
- return context.declaration.getExtractor().getLongValue( workingMemory, left ) == ((LongVariableContextEntry) context).right;
- }
-
- public boolean evaluateCachedLeft(InternalWorkingMemory workingMemory,
- final VariableContextEntry context, final Object right) {
- if ( context.extractor.isNullValue( workingMemory, right )) {
- return context.isLeftNull();
- } else if ( context.isLeftNull() ) {
- return false;
- }
-
- return ((LongVariableContextEntry) context).left == context.extractor.getLongValue( workingMemory, right );
- }
-
- public boolean evaluate(InternalWorkingMemory workingMemory,
- final Extractor extractor1,
- final Object object1,
- final Extractor extractor2, final Object object2) {
- if (extractor1.isNullValue( workingMemory, object1 )) {
- return extractor2.isNullValue( workingMemory, object2 );
- } else if (extractor2.isNullValue( workingMemory, object2 )) {
- return false;
- }
-
- return extractor1.getLongValue( workingMemory, object1 ) == extractor2.getLongValue( workingMemory, object2 );
- }
-
- public String toString() {
- return "Long ==";
- }
- }
-
- static class LongNotEqualEvaluator extends BaseEvaluator {
- /**
- *
- */
- private static final long serialVersionUID = 400L;
- public final static Evaluator INSTANCE = new LongNotEqualEvaluator();
-
- private LongNotEqualEvaluator() {
- super( ValueType.PLONG_TYPE,
- Operator.NOT_EQUAL );
- }
-
- public boolean evaluate(InternalWorkingMemory workingMemory,
- final Extractor extractor,
- final Object object1, final FieldValue object2) {
- if ( extractor.isNullValue( workingMemory, object1 ) ) {
- return !object2.isNull();
- } else if ( object2.isNull() ) {
- return true;
- }
-
- return extractor.getLongValue( workingMemory, object1 ) != object2.getLongValue();
- }
-
- public boolean evaluateCachedRight(InternalWorkingMemory workingMemory,
- final VariableContextEntry context, final Object left) {
- if ( context.declaration.getExtractor().isNullValue( workingMemory, left ) ) {
- return !context.isRightNull();
- } else if ( context.isRightNull() ) {
- return true;
- }
-
- return context.declaration.getExtractor().getLongValue( workingMemory, left ) != ((LongVariableContextEntry) context).right;
- }
-
- public boolean evaluateCachedLeft(InternalWorkingMemory workingMemory,
- final VariableContextEntry context, final Object right) {
- if ( context.extractor.isNullValue( workingMemory, right ) ) {
- return !context.isLeftNull();
- } else if ( context.isLeftNull() ) {
- return true;
- }
-
- return ((LongVariableContextEntry) context).left != context.extractor.getLongValue( workingMemory, right );
- }
-
- public boolean evaluate(InternalWorkingMemory workingMemory,
- final Extractor extractor1,
- final Object object1,
- final Extractor extractor2, final Object object2) {
- if (extractor1.isNullValue( workingMemory, object1 )) {
- return !extractor2.isNullValue( workingMemory, object2 );
- } else if (extractor2.isNullValue( workingMemory, object2 )) {
- return true;
- }
-
- return extractor1.getLongValue( workingMemory, object1 ) != extractor2.getLongValue( workingMemory, object2 );
- }
-
- public String toString() {
- return "Long !=";
- }
- }
-
- static class LongLessEvaluator extends BaseEvaluator {
- /**
- *
- */
- private static final long serialVersionUID = 400L;
- public final static Evaluator INSTANCE = new LongLessEvaluator();
-
- private LongLessEvaluator() {
- super( ValueType.PLONG_TYPE,
- Operator.LESS );
- }
-
- public boolean evaluate(InternalWorkingMemory workingMemory,
- final Extractor extractor,
- final Object object1, final FieldValue object2) {
- if( extractor.isNullValue( workingMemory, object1 ) ) {
- return false;
- }
- return extractor.getLongValue( workingMemory, object1 ) < object2.getLongValue();
- }
-
- public boolean evaluateCachedRight(InternalWorkingMemory workingMemory,
- final VariableContextEntry context, final Object left) {
- if( context.rightNull ) {
- return false;
- }
- return ((LongVariableContextEntry) context).right < context.declaration.getExtractor().getLongValue( workingMemory, left );
- }
-
- public boolean evaluateCachedLeft(InternalWorkingMemory workingMemory,
- final VariableContextEntry context, final Object right) {
- if( context.extractor.isNullValue( workingMemory, right ) ) {
- return false;
- }
- return context.extractor.getLongValue( workingMemory, right ) < ((LongVariableContextEntry) context).left;
- }
-
- public boolean evaluate(InternalWorkingMemory workingMemory,
- final Extractor extractor1,
- final Object object1,
- final Extractor extractor2, final Object object2) {
- if( extractor1.isNullValue( workingMemory, object1 ) ) {
- return false;
- }
- return extractor1.getLongValue( workingMemory, object1 ) < extractor2.getLongValue( workingMemory, object2 );
- }
-
- public String toString() {
- return "Long <";
- }
- }
-
- static class LongLessOrEqualEvaluator extends BaseEvaluator {
- /**
- *
- */
- private static final long serialVersionUID = 400L;
- public final static Evaluator INSTANCE = new LongLessOrEqualEvaluator();
-
- private LongLessOrEqualEvaluator() {
- super( ValueType.PLONG_TYPE,
- Operator.LESS_OR_EQUAL );
- }
-
- public boolean evaluate(InternalWorkingMemory workingMemory,
- final Extractor extractor,
- final Object object1, final FieldValue object2) {
- if( extractor.isNullValue( workingMemory, object1 ) ) {
- return false;
- }
- return extractor.getLongValue( workingMemory, object1 ) <= object2.getLongValue();
- }
-
- public boolean evaluateCachedRight(InternalWorkingMemory workingMemory,
- final VariableContextEntry context, final Object left) {
- if( context.rightNull ) {
- return false;
- }
- return ((LongVariableContextEntry) context).right <= context.declaration.getExtractor().getLongValue( workingMemory, left );
- }
-
- public boolean evaluateCachedLeft(InternalWorkingMemory workingMemory,
- final VariableContextEntry context, final Object right) {
- if( context.extractor.isNullValue( workingMemory, right ) ) {
- return false;
- }
- return context.extractor.getLongValue( workingMemory, right ) <= ((LongVariableContextEntry) context).left;
- }
-
- public boolean evaluate(InternalWorkingMemory workingMemory,
- final Extractor extractor1,
- final Object object1,
- final Extractor extractor2, final Object object2) {
- if( extractor1.isNullValue( workingMemory, object1 ) ) {
- return false;
- }
- return extractor1.getLongValue( workingMemory, object1 ) <= extractor2.getLongValue( workingMemory, object2 );
- }
-
- public String toString() {
- return "Long <=";
- }
- }
-
- static class LongGreaterEvaluator extends BaseEvaluator {
- /**
- *
- */
- private static final long serialVersionUID = 400L;
- public final static Evaluator INSTANCE = new LongGreaterEvaluator();
-
- private LongGreaterEvaluator() {
- super( ValueType.PLONG_TYPE,
- Operator.GREATER );
- }
-
- public boolean evaluate(InternalWorkingMemory workingMemory,
- final Extractor extractor,
- final Object object1, final FieldValue object2) {
- if( extractor.isNullValue( workingMemory, object1 ) ) {
- return false;
- }
- return extractor.getLongValue( workingMemory, object1 ) > object2.getLongValue();
- }
-
- public boolean evaluateCachedRight(InternalWorkingMemory workingMemory,
- final VariableContextEntry context, final Object left) {
- if( context.rightNull ) {
- return false;
- }
- return ((LongVariableContextEntry) context).right > context.declaration.getExtractor().getLongValue( workingMemory, left );
- }
-
- public boolean evaluateCachedLeft(InternalWorkingMemory workingMemory,
- final VariableContextEntry context, final Object right) {
- if( context.extractor.isNullValue( workingMemory, right ) ) {
- return false;
- }
- return context.extractor.getLongValue( workingMemory, right ) > ((LongVariableContextEntry) context).left;
- }
-
- public boolean evaluate(InternalWorkingMemory workingMemory,
- final Extractor extractor1,
- final Object object1,
- final Extractor extractor2, final Object object2) {
- if( extractor1.isNullValue( workingMemory, object1 ) ) {
- return false;
- }
- return extractor1.getLongValue( workingMemory, object1 ) > extractor2.getLongValue( workingMemory, object2 );
- }
-
- public String toString() {
- return "Long >";
- }
- }
-
- static class LongGreaterOrEqualEvaluator extends BaseEvaluator {
- /**
- *
- */
- private static final long serialVersionUID = 400L;
- private final static Evaluator INSTANCE = new LongGreaterOrEqualEvaluator();
-
- private LongGreaterOrEqualEvaluator() {
- super( ValueType.PLONG_TYPE,
- Operator.GREATER_OR_EQUAL );
- }
-
- public boolean evaluate(InternalWorkingMemory workingMemory,
- final Extractor extractor,
- final Object object1, final FieldValue object2) {
- if( extractor.isNullValue( workingMemory, object1 ) ) {
- return false;
- }
- return extractor.getLongValue( workingMemory, object1 ) >= object2.getLongValue();
- }
-
- public boolean evaluateCachedRight(InternalWorkingMemory workingMemory,
- final VariableContextEntry context, final Object left) {
- if( context.rightNull ) {
- return false;
- }
- return ((LongVariableContextEntry) context).right >= context.declaration.getExtractor().getLongValue( workingMemory, left );
- }
-
- public boolean evaluateCachedLeft(InternalWorkingMemory workingMemory,
- final VariableContextEntry context, final Object right) {
- if( context.extractor.isNullValue( workingMemory, right ) ) {
- return false;
- }
- return context.extractor.getLongValue( workingMemory, right ) >= ((LongVariableContextEntry) context).left;
- }
-
- public boolean evaluate(InternalWorkingMemory workingMemory,
- final Extractor extractor1,
- final Object object1,
- final Extractor extractor2, final Object object2) {
- if( extractor1.isNullValue( workingMemory, object1 ) ) {
- return false;
- }
- return extractor1.getLongValue( workingMemory, object1 ) >= extractor2.getLongValue( workingMemory, object2 );
- }
-
- public String toString() {
- return "Long >=";
- }
- }
-
- static class LongMemberOfEvaluator extends BaseMemberOfEvaluator {
-
- private static final long serialVersionUID = 400L;
- public final static Evaluator INSTANCE = new LongMemberOfEvaluator();
-
- private LongMemberOfEvaluator() {
- super( ValueType.PLONG_TYPE,
- Operator.MEMBEROF );
- }
-
- public String toString() {
- return "Long memberOf";
- }
- }
-
- static class LongNotMemberOfEvaluator extends BaseNotMemberOfEvaluator {
-
- private static final long serialVersionUID = 400L;
- public final static Evaluator INSTANCE = new LongNotMemberOfEvaluator();
-
- private LongNotMemberOfEvaluator() {
- super( ValueType.PLONG_TYPE,
- Operator.NOTMEMBEROF );
- }
-
- public String toString() {
- return "Long not memberOf";
- }
- }
-
-}
\ No newline at end of file
Added: labs/jbossrules/branches/temporal_rete/drools-core/src/main/java/org/drools/base/evaluators/MatchesEvaluatorsDefinition.java
===================================================================
--- labs/jbossrules/branches/temporal_rete/drools-core/src/main/java/org/drools/base/evaluators/MatchesEvaluatorsDefinition.java (rev 0)
+++ labs/jbossrules/branches/temporal_rete/drools-core/src/main/java/org/drools/base/evaluators/MatchesEvaluatorsDefinition.java 2007-12-07 14:10:27 UTC (rev 17089)
@@ -0,0 +1,213 @@
+/*
+ * Copyright 2007 JBoss Inc
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ * Created on Dec 6, 2007
+ */
+package org.drools.base.evaluators;
+
+import org.drools.base.BaseEvaluator;
+import org.drools.base.ValueType;
+import org.drools.common.InternalWorkingMemory;
+import org.drools.rule.VariableRestriction.ObjectVariableContextEntry;
+import org.drools.rule.VariableRestriction.VariableContextEntry;
+import org.drools.spi.Evaluator;
+import org.drools.spi.Extractor;
+import org.drools.spi.FieldValue;
+
+/**
+ * This class defines the matches evaluator
+ *
+ * @author etirelli
+ */
+public class MatchesEvaluatorsDefinition implements EvaluatorDefinition {
+
+ public static final Operator MATCHES = Operator.addOperatorToRegistry( "matches",
+ false );
+ public static final Operator NOT_MATCHES = Operator.addOperatorToRegistry( "matches",
+ true );
+
+ private static final String[] SUPPORTED_IDS = { MATCHES.getOperatorString() };
+ private EvaluatorRegistry evaluators = new EvaluatorRegistry() {
+ private static final long serialVersionUID = 4782368623L;
+ {
+ addEvaluator( ValueType.STRING_TYPE, MATCHES, StringMatchesEvaluator.INSTANCE );
+ addEvaluator( ValueType.STRING_TYPE, NOT_MATCHES, StringNotMatchesEvaluator.INSTANCE );
+ }
+ };
+
+ /**
+ * @inheridDoc
+ */
+ public Evaluator getEvaluator(ValueType type,
+ Operator operator) {
+ return this.evaluators.getEvaluator( type,
+ operator );
+ }
+
+ /**
+ * @inheridDoc
+ */
+ public Evaluator getEvaluator(ValueType type,
+ Operator operator,
+ String parameterText) {
+ return this.evaluators.getEvaluator( type,
+ operator );
+ }
+
+
+ public Evaluator getEvaluator(final ValueType type,
+ final String operatorId,
+ final boolean isNegated,
+ final String parameterText) {
+ return this.evaluators.getEvaluator( type, Operator.determineOperator( operatorId, isNegated ) );
+ }
+
+ public String[] getEvaluatorIds() {
+ return SUPPORTED_IDS;
+ }
+
+ public boolean isNegatable() {
+ return true;
+ }
+
+ public boolean operatesOnFactHandles() {
+ return false;
+ }
+
+ public boolean supportsType(ValueType type) {
+ return this.evaluators.supportsType( type );
+ }
+
+ /* *********************************************************
+ * Evaluator Implementations
+ * *********************************************************
+ */
+ static class StringMatchesEvaluator extends BaseEvaluator {
+ /**
+ *
+ */
+ private static final long serialVersionUID = 400L;
+ public final static Evaluator INSTANCE = new StringMatchesEvaluator();
+
+ private StringMatchesEvaluator() {
+ super( ValueType.STRING_TYPE,
+ MATCHES );
+ }
+
+ public boolean evaluate(InternalWorkingMemory workingMemory,
+ final Extractor extractor,
+ final Object object1, final FieldValue object2) {
+ final String value1 = (String) extractor.getValue( workingMemory, object1 );
+ final String value2 = (String) object2.getValue();
+ if ( value1 == null ) {
+ return false;
+ }
+ return value1.matches( value2 );
+ }
+
+ public boolean evaluateCachedRight(InternalWorkingMemory workingMemory,
+ final VariableContextEntry context, final Object left) {
+ final String value = (String) ((ObjectVariableContextEntry) context).right;
+ if ( value == null ) {
+ return false;
+ }
+ return value.matches( (String) context.declaration.getExtractor().getValue( workingMemory, left ) );
+ }
+
+ public boolean evaluateCachedLeft(InternalWorkingMemory workingMemory,
+ final VariableContextEntry context, final Object right) {
+ final String value = (String) context.extractor.getValue( workingMemory, right );
+ if ( value == null ) {
+ return false;
+ }
+ return value.matches( (String) ((ObjectVariableContextEntry) context).left );
+ }
+
+ public boolean evaluate(InternalWorkingMemory workingMemory,
+ final Extractor extractor1,
+ final Object object1,
+ final Extractor extractor2, final Object object2) {
+ final Object value1 = extractor1.getValue( workingMemory, object1 );
+ final Object value2 = extractor2.getValue( workingMemory, object2 );
+ if ( value1 == null ) {
+ return false;
+ }
+ return ((String) value1).matches( (String) value2 );
+ }
+
+ public String toString() {
+ return "String matches";
+ }
+ }
+
+ static class StringNotMatchesEvaluator extends BaseEvaluator {
+ /**
+ *
+ */
+ private static final long serialVersionUID = 400L;
+ public final static Evaluator INSTANCE = new StringNotMatchesEvaluator();
+
+ private StringNotMatchesEvaluator() {
+ super( ValueType.STRING_TYPE,
+ NOT_MATCHES );
+ }
+
+ public boolean evaluate(InternalWorkingMemory workingMemory,
+ final Extractor extractor,
+ final Object object1, final FieldValue object2) {
+ final String value1 = (String) extractor.getValue( workingMemory, object1 );
+ final String value2 = (String) object2.getValue();
+ if ( value1 == null ) {
+ return false;
+ }
+ return ! value1.matches( value2 );
+ }
+
+ public boolean evaluateCachedRight(InternalWorkingMemory workingMemory,
+ final VariableContextEntry context, final Object left) {
+ final String value = (String) ((ObjectVariableContextEntry) context).right;
+ if ( value == null ) {
+ return false;
+ }
+ return ! value.matches( (String) context.declaration.getExtractor().getValue( workingMemory, left ) );
+ }
+
+ public boolean evaluateCachedLeft(InternalWorkingMemory workingMemory,
+ final VariableContextEntry context, final Object right) {
+ final String value = (String) context.extractor.getValue( workingMemory, right );
+ if ( value == null ) {
+ return false;
+ }
+ return ! value.matches( (String) ((ObjectVariableContextEntry) context).left );
+ }
+
+ public boolean evaluate(InternalWorkingMemory workingMemory,
+ final Extractor extractor1,
+ final Object object1,
+ final Extractor extractor2, final Object object2) {
+ final Object value1 = extractor1.getValue( workingMemory, object1 );
+ final Object value2 = extractor2.getValue( workingMemory, object2 );
+ if ( value1 == null ) {
+ return false;
+ }
+ return ! ((String) value1).matches( (String) value2 );
+ }
+
+ public String toString() {
+ return "String not matches";
+ }
+ }
+
+}
Deleted: labs/jbossrules/branches/temporal_rete/drools-core/src/main/java/org/drools/base/evaluators/ObjectFactory.java
===================================================================
--- labs/jbossrules/branches/temporal_rete/drools-core/src/main/java/org/drools/base/evaluators/ObjectFactory.java 2007-12-07 13:39:06 UTC (rev 17088)
+++ labs/jbossrules/branches/temporal_rete/drools-core/src/main/java/org/drools/base/evaluators/ObjectFactory.java 2007-12-07 14:10:27 UTC (rev 17089)
@@ -1,578 +0,0 @@
-package org.drools.base.evaluators;
-
-/*
- * Copyright 2005 JBoss Inc
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-import java.util.Collection;
-
-import org.drools.base.BaseEvaluator;
-import org.drools.base.ShadowProxy;
-import org.drools.base.ValueType;
-import org.drools.common.InternalWorkingMemory;
-import org.drools.rule.VariableRestriction.ObjectVariableContextEntry;
-import org.drools.rule.VariableRestriction.VariableContextEntry;
-import org.drools.spi.Evaluator;
-import org.drools.spi.Extractor;
-import org.drools.spi.FieldValue;
-import org.drools.util.ShadowProxyUtils;
-
-/**
- * This is the misc "bucket" evaluator factory for objects.
- * It is fairly limited in operations,
- * and what operations are available are dependent on the exact type.
- *
- * This supports "<" and ">" etc by requiring objects to implement the comparable interface.
- * Of course, literals will not work with comparator, as it has no way
- * of converting from literal to the appropriate type.
- *
- * @author Michael Neale
- */
-public class ObjectFactory
- implements
- EvaluatorFactory {
-
- private static final long serialVersionUID = 400L;
- private static EvaluatorFactory INSTANCE = new ObjectFactory();
-
- private ObjectFactory() {
-
- }
-
- public static EvaluatorFactory getInstance() {
- if ( ObjectFactory.INSTANCE == null ) {
- ObjectFactory.INSTANCE = new ObjectFactory();
- }
- return ObjectFactory.INSTANCE;
- }
-
- public Evaluator getEvaluator(final Operator operator) {
- if ( operator == Operator.EQUAL ) {
- return ObjectEqualEvaluator.INSTANCE;
- } else if ( operator == Operator.NOT_EQUAL ) {
- return ObjectNotEqualEvaluator.INSTANCE;
- } else if ( operator == Operator.LESS ) {
- return ObjectLessEvaluator.INSTANCE;
- } else if ( operator == Operator.LESS_OR_EQUAL ) {
- return ObjectLessOrEqualEvaluator.INSTANCE;
- } else if ( operator == Operator.GREATER ) {
- return ObjectGreaterEvaluator.INSTANCE;
- } else if ( operator == Operator.GREATER_OR_EQUAL ) {
- return ObjectGreaterOrEqualEvaluator.INSTANCE;
- } else if ( operator == Operator.CONTAINS ) {
- return ObjectContainsEvaluator.INSTANCE;
- } else if ( operator == Operator.EXCLUDES ) {
- return ObjectExcludesEvaluator.INSTANCE;
- } else if ( operator == Operator.NOT_CONTAINS) {
- return ObjectExcludesEvaluator.INSTANCE; // 'not contains' and 'excludes' are synonyms
- } else if ( operator == Operator.MEMBEROF ) {
- return ObjectMemberOfEvaluator.INSTANCE;
- } else if ( operator == Operator.NOTMEMBEROF ) {
- return ObjectNotMemberOfEvaluator.INSTANCE;
- } else {
- throw new RuntimeException( "Operator '" + operator + "' does not exist for ObjectEvaluator" );
- }
- }
-
- static class ObjectEqualEvaluator extends BaseEvaluator {
- /**
- *
- */
- private static final long serialVersionUID = 400L;
- public final static Evaluator INSTANCE = new ObjectEqualEvaluator();
-
- private ObjectEqualEvaluator() {
- super( ValueType.OBJECT_TYPE,
- Operator.EQUAL );
- }
-
- public boolean evaluate(InternalWorkingMemory workingMemory,
- final Extractor extractor,
- final Object object1, final FieldValue object2) {
- final Object value1 = extractor.getValue( workingMemory, object1 );
- final Object value2 = object2.getValue();
- if ( value1 == null ) {
- return value2 == null;
- }
- if( value2 != null && value2 instanceof ShadowProxy ) {
- return value2.equals( value1 );
- }
- return value1.equals( value2 );
- }
-
- public boolean evaluateCachedRight(InternalWorkingMemory workingMemory,
- final VariableContextEntry context, final Object left) {
- final Object value = context.declaration.getExtractor().getValue( workingMemory, left );
- if ( value == null ) {
- return ((ObjectVariableContextEntry) context).right == null;
- }
- if( ((ObjectVariableContextEntry) context).right != null && ((ObjectVariableContextEntry) context).right instanceof ShadowProxy ) {
- return ((ObjectVariableContextEntry) context).right.equals( value );
- }
- return value.equals( ((ObjectVariableContextEntry) context).right );
- }
-
- public boolean evaluateCachedLeft(InternalWorkingMemory workingMemory,
- final VariableContextEntry context, final Object right) {
- final Object value = context.extractor.getValue( workingMemory, right );
- if ( ((ObjectVariableContextEntry) context).left == null ) {
- return value == null;
- }
- if( value != null && value instanceof ShadowProxy ) {
- return value.equals( ((ObjectVariableContextEntry) context).left );
- }
- return ((ObjectVariableContextEntry) context).left.equals( value );
- }
-
- public boolean evaluate(InternalWorkingMemory workingMemory,
- final Extractor extractor1,
- final Object object1,
- final Extractor extractor2, final Object object2) {
- final Object value1 = extractor1.getValue( workingMemory, object1 );
- final Object value2 = extractor2.getValue( workingMemory, object2 );
- if ( value1 == null ) {
- return value2 == null;
- }
- if( value2 != null && value2 instanceof ShadowProxy ) {
- return value2.equals( value1 );
- }
- return value1.equals( value2 );
- }
-
- public String toString() {
- return "Object ==";
- }
-
- }
-
- static class ObjectNotEqualEvaluator extends BaseEvaluator {
- /**
- *
- */
- private static final long serialVersionUID = 400L;
- public final static Evaluator INSTANCE = new ObjectNotEqualEvaluator();
-
- private ObjectNotEqualEvaluator() {
- super( ValueType.OBJECT_TYPE,
- Operator.NOT_EQUAL );
- }
-
- public boolean evaluate(InternalWorkingMemory workingMemory,
- final Extractor extractor,
- final Object object1, final FieldValue object2) {
- final Object value1 = extractor.getValue( workingMemory, object1 );
- final Object value2 = object2.getValue();
- if ( value1 == null ) {
- return value2 != null;
- }
- if( value2 != null && value2 instanceof ShadowProxy ) {
- return !value2.equals( value1 );
- }
- return !value1.equals( value2 );
- }
-
- public boolean evaluateCachedRight(InternalWorkingMemory workingMemory,
- final VariableContextEntry context, final Object left) {
- final Object value = context.declaration.getExtractor().getValue( workingMemory, left );
- if ( value == null ) {
- return ((ObjectVariableContextEntry) context).right != null;
- }
- if( ((ObjectVariableContextEntry) context).right != null && ((ObjectVariableContextEntry) context).right instanceof ShadowProxy ) {
- return !((ObjectVariableContextEntry) context).right.equals( value );
- }
- return !value.equals( ((ObjectVariableContextEntry) context).right );
- }
-
- public boolean evaluateCachedLeft(InternalWorkingMemory workingMemory,
- final VariableContextEntry context, final Object right) {
- final Object value = context.extractor.getValue( workingMemory, right );
- if ( ((ObjectVariableContextEntry) context).left == null ) {
- return value != null;
- }
- if( value != null && value instanceof ShadowProxy ) {
- return !value.equals( ((ObjectVariableContextEntry) context).left );
- }
- return !((ObjectVariableContextEntry) context).left.equals( value );
- }
-
- public boolean evaluate(InternalWorkingMemory workingMemory,
- final Extractor extractor1,
- final Object object1,
- final Extractor extractor2, final Object object2) {
- final Object value1 = extractor1.getValue( workingMemory, object1 );
- final Object value2 = extractor2.getValue( workingMemory, object2 );
- if ( value1 == null ) {
- return value2 != null;
- }
- if( value2 != null && value2 instanceof ShadowProxy ) {
- return !value2.equals( value1 );
- }
- return !value1.equals( value2 );
- }
-
- public String toString() {
- return "Object !=";
- }
- }
-
- static class ObjectLessEvaluator extends BaseEvaluator {
- private static final long serialVersionUID = 400L;
- public final static Evaluator INSTANCE = new ObjectLessEvaluator();
-
- private ObjectLessEvaluator() {
- super( ValueType.OBJECT_TYPE,
- Operator.LESS );
- }
-
- public boolean evaluate(InternalWorkingMemory workingMemory,
- final Extractor extractor,
- final Object object1, final FieldValue object2) {
- if( extractor.isNullValue( workingMemory, object1 ) ) {
- return false;
- }
- final Comparable comp = (Comparable) extractor.getValue( workingMemory, object1 );
- return comp.compareTo( object2.getValue() ) < 0;
- }
-
- public boolean evaluateCachedRight(InternalWorkingMemory workingMemory,
- final VariableContextEntry context, final Object left) {
- if( context.rightNull ) {
- return false;
- }
- final Comparable comp = (Comparable) ((ObjectVariableContextEntry) context).right;
- return comp.compareTo( context.declaration.getExtractor().getValue( workingMemory, left ) ) < 0;
- }
-
- public boolean evaluateCachedLeft(InternalWorkingMemory workingMemory,
- final VariableContextEntry context, final Object right) {
- if( context.extractor.isNullValue( workingMemory, right ) ) {
- return false;
- }
- final Comparable comp = (Comparable) context.extractor.getValue( workingMemory, right );
- return comp.compareTo( ((ObjectVariableContextEntry) context).left ) < 0;
- }
-
- public boolean evaluate(InternalWorkingMemory workingMemory,
- final Extractor extractor1,
- final Object object1,
- final Extractor extractor2, final Object object2) {
- if( extractor1.isNullValue( workingMemory, object1 ) ) {
- return false;
- }
- final Comparable comp = (Comparable) extractor1.getValue( workingMemory, object1 );
- return comp.compareTo( extractor2.getValue( workingMemory, object2 ) ) < 0;
- }
-
- public String toString() {
- return "Object <";
- }
- }
-
- static class ObjectLessOrEqualEvaluator extends BaseEvaluator {
- /**
- *
- */
- private static final long serialVersionUID = 400L;
- public final static Evaluator INSTANCE = new ObjectLessOrEqualEvaluator();
-
- private ObjectLessOrEqualEvaluator() {
- super( ValueType.OBJECT_TYPE,
- Operator.LESS_OR_EQUAL );
- }
-
- public boolean evaluate(InternalWorkingMemory workingMemory,
- final Extractor extractor,
- final Object object1, final FieldValue object2) {
- if( extractor.isNullValue( workingMemory, object1 ) ) {
- return false;
- }
- final Comparable comp = (Comparable) extractor.getValue( workingMemory, object1 );
- return comp.compareTo( object2.getValue() ) <= 0;
- }
-
- public boolean evaluateCachedRight(InternalWorkingMemory workingMemory,
- final VariableContextEntry context, final Object left) {
- if( context.rightNull ) {
- return false;
- }
- final Comparable comp = (Comparable) ((ObjectVariableContextEntry) context).right;
- return comp.compareTo( context.declaration.getExtractor().getValue( workingMemory, left ) ) <= 0;
- }
-
- public boolean evaluateCachedLeft(InternalWorkingMemory workingMemory,
- final VariableContextEntry context, final Object right) {
- if( context.extractor.isNullValue( workingMemory, right ) ) {
- return false;
- }
- final Comparable comp = (Comparable) context.extractor.getValue( workingMemory, right );
- return comp.compareTo( ((ObjectVariableContextEntry) context).left ) <= 0;
- }
-
- public boolean evaluate(InternalWorkingMemory workingMemory,
- final Extractor extractor1,
- final Object object1,
- final Extractor extractor2, final Object object2) {
- if( extractor1.isNullValue( workingMemory, object1 ) ) {
- return false;
- }
- final Comparable comp = (Comparable) extractor1.getValue( workingMemory, object1 );
- return comp.compareTo( extractor2.getValue( workingMemory, object2 ) ) <= 0;
- }
-
- public String toString() {
- return "Object <=";
- }
- }
-
- static class ObjectGreaterEvaluator extends BaseEvaluator {
- /**
- *
- */
- private static final long serialVersionUID = 400L;
- public final static Evaluator INSTANCE = new ObjectGreaterEvaluator();
-
- private ObjectGreaterEvaluator() {
- super( ValueType.OBJECT_TYPE,
- Operator.GREATER );
- }
-
- public boolean evaluate(InternalWorkingMemory workingMemory,
- final Extractor extractor,
- final Object object1, final FieldValue object2) {
- if( extractor.isNullValue( workingMemory, object1 ) ) {
- return false;
- }
- final Comparable comp = (Comparable) extractor.getValue( workingMemory, object1 );
- return comp.compareTo( object2.getValue() ) > 0;
- }
-
- public boolean evaluateCachedRight(InternalWorkingMemory workingMemory,
- final VariableContextEntry context, final Object left) {
- if( context.rightNull ) {
- return false;
- }
- final Comparable comp = (Comparable) ((ObjectVariableContextEntry) context).right;
- return comp.compareTo( context.declaration.getExtractor().getValue( workingMemory, left ) ) > 0;
- }
-
- public boolean evaluateCachedLeft(InternalWorkingMemory workingMemory,
- final VariableContextEntry context, final Object right) {
- if( context.extractor.isNullValue( workingMemory, right ) ) {
- return false;
- }
- final Comparable comp = (Comparable) context.extractor.getValue( workingMemory, right );
- return comp.compareTo( ((ObjectVariableContextEntry) context).left ) > 0;
- }
-
- public boolean evaluate(InternalWorkingMemory workingMemory,
- final Extractor extractor1,
- final Object object1,
- final Extractor extractor2, final Object object2) {
- if( extractor1.isNullValue( workingMemory, object1 ) ) {
- return false;
- }
- final Comparable comp = (Comparable) extractor1.getValue( workingMemory, object1 );
- return comp.compareTo( extractor2.getValue( workingMemory, object2 ) ) > 0;
- }
-
- public String toString() {
- return "Object >";
- }
- }
-
- static class ObjectGreaterOrEqualEvaluator extends BaseEvaluator {
- /**
- *
- */
- private static final long serialVersionUID = 400L;
- public final static Evaluator INSTANCE = new ObjectGreaterOrEqualEvaluator();
-
- private ObjectGreaterOrEqualEvaluator() {
- super( ValueType.OBJECT_TYPE,
- Operator.GREATER_OR_EQUAL );
- }
-
- public boolean evaluate(InternalWorkingMemory workingMemory,
- final Extractor extractor,
- final Object object1, final FieldValue object2) {
- if( extractor.isNullValue( workingMemory, object1 ) ) {
- return false;
- }
- final Comparable comp = (Comparable) extractor.getValue( workingMemory, object1 );
- return comp.compareTo( object2.getValue() ) >= 0;
- }
-
- public boolean evaluateCachedRight(InternalWorkingMemory workingMemory,
- final VariableContextEntry context, final Object left) {
- if( context.rightNull ) {
- return false;
- }
- final Comparable comp = (Comparable) ((ObjectVariableContextEntry) context).right;
- return comp.compareTo( context.declaration.getExtractor().getValue( workingMemory, left ) ) >= 0;
- }
-
- public boolean evaluateCachedLeft(InternalWorkingMemory workingMemory,
- final VariableContextEntry context, final Object right) {
- if( context.extractor.isNullValue( workingMemory, right ) ) {
- return false;
- }
- final Comparable comp = (Comparable) context.extractor.getValue( workingMemory, right );
- return comp.compareTo( ((ObjectVariableContextEntry) context).left ) >= 0;
- }
-
- public boolean evaluate(InternalWorkingMemory workingMemory,
- final Extractor extractor1,
- final Object object1,
- final Extractor extractor2, final Object object2) {
- if( extractor1.isNullValue( workingMemory, object1 ) ) {
- return false;
- }
- final Comparable comp = (Comparable) extractor1.getValue( workingMemory, object1 );
- return comp.compareTo( extractor2.getValue( workingMemory, object2 ) ) >= 0;
- }
-
- public String toString() {
- return "Object >=";
- }
- }
-
- static class ObjectContainsEvaluator extends BaseEvaluator {
- /**
- *
- */
- private static final long serialVersionUID = 400L;
- public final static Evaluator INSTANCE = new ObjectContainsEvaluator();
-
- private ObjectContainsEvaluator() {
- super( ValueType.OBJECT_TYPE,
- Operator.CONTAINS );
- }
-
- public boolean evaluate(InternalWorkingMemory workingMemory,
- final Extractor extractor,
- final Object object1, final FieldValue object2) {
- final Object value = object2.getValue();
- final Collection col = (Collection) extractor.getValue( workingMemory, object1 );
- return ( col == null ) ? false : ShadowProxyUtils.contains( col, value );
- }
-
- public boolean evaluateCachedRight(InternalWorkingMemory workingMemory,
- final VariableContextEntry context, final Object left) {
- final Object value = context.declaration.getExtractor().getValue( workingMemory, left );
- final Collection col = (Collection) ((ObjectVariableContextEntry) context).right;
- return ( col == null ) ? false : ShadowProxyUtils.contains( col, value );
- }
-
- public boolean evaluateCachedLeft(InternalWorkingMemory workingMemory,
- final VariableContextEntry context, final Object right) {
- final Object value = ((ObjectVariableContextEntry) context).left;
- final Collection col = (Collection) context.extractor.getValue( workingMemory, right );
- return ( col == null ) ? false : ShadowProxyUtils.contains( col, value );
- }
-
- public boolean evaluate(InternalWorkingMemory workingMemory,
- final Extractor extractor1,
- final Object object1,
- final Extractor extractor2, final Object object2) {
- final Object value = extractor2.getValue( workingMemory, object2 );
- final Collection col = (Collection) extractor1.getValue( workingMemory, object1 );
- return ( col == null ) ? false : ShadowProxyUtils.contains( col, value );
- }
-
- public String toString() {
- return "Object contains";
- }
- }
-
- static class ObjectExcludesEvaluator extends BaseEvaluator {
- /**
- *
- */
- private static final long serialVersionUID = 400L;
- public final static Evaluator INSTANCE = new ObjectExcludesEvaluator();
-
- private ObjectExcludesEvaluator() {
- super( ValueType.OBJECT_TYPE,
- Operator.EXCLUDES );
- }
-
- public boolean evaluate(InternalWorkingMemory workingMemory,
- final Extractor extractor,
- final Object object1, final FieldValue object2) {
- final Object value = object2.getValue();
- final Collection col = (Collection) extractor.getValue( workingMemory, object1 );
- return ( col == null ) ? true : !ShadowProxyUtils.contains( col, value );
- }
-
- public boolean evaluateCachedRight(InternalWorkingMemory workingMemory,
- final VariableContextEntry context, final Object left) {
- final Object value = context.declaration.getExtractor().getValue( workingMemory, left );
- final Collection col = (Collection) ((ObjectVariableContextEntry) context).right;
- return ( col == null ) ? true : !ShadowProxyUtils.contains( col, value );
- }
-
- public boolean evaluateCachedLeft(InternalWorkingMemory workingMemory,
- final VariableContextEntry context, final Object right) {
- final Object value = ((ObjectVariableContextEntry) context).left;
- final Collection col = (Collection) context.extractor.getValue( workingMemory, right );
- return ( col == null ) ? true : !ShadowProxyUtils.contains( col, value );
- }
-
- public boolean evaluate(InternalWorkingMemory workingMemory,
- final Extractor extractor1,
- final Object object1,
- final Extractor extractor2, final Object object2) {
- final Object value = extractor2.getValue( workingMemory, object2 );
- final Collection col = (Collection) extractor1.getValue( workingMemory, object1 );
- return ( col == null ) ? true : !ShadowProxyUtils.contains( col, value );
- }
-
- public String toString() {
- return "Object excludes";
- }
- }
-
- static class ObjectMemberOfEvaluator extends BaseMemberOfEvaluator {
-
- private static final long serialVersionUID = 400L;
- public final static Evaluator INSTANCE = new ObjectMemberOfEvaluator();
-
- private ObjectMemberOfEvaluator() {
- super( ValueType.OBJECT_TYPE,
- Operator.MEMBEROF );
- }
-
- public String toString() {
- return "Object memberOf";
- }
- }
-
- static class ObjectNotMemberOfEvaluator extends BaseNotMemberOfEvaluator {
-
- private static final long serialVersionUID = 400L;
- public final static Evaluator INSTANCE = new ObjectNotMemberOfEvaluator();
-
- private ObjectNotMemberOfEvaluator() {
- super( ValueType.OBJECT_TYPE,
- Operator.NOTMEMBEROF );
- }
-
- public String toString() {
- return "Object not memberOf";
- }
- }
-
-
-}
\ No newline at end of file
Modified: labs/jbossrules/branches/temporal_rete/drools-core/src/main/java/org/drools/base/evaluators/Operator.java
===================================================================
--- labs/jbossrules/branches/temporal_rete/drools-core/src/main/java/org/drools/base/evaluators/Operator.java 2007-12-07 13:39:06 UTC (rev 17088)
+++ labs/jbossrules/branches/temporal_rete/drools-core/src/main/java/org/drools/base/evaluators/Operator.java 2007-12-07 14:10:27 UTC (rev 17089)
@@ -1,6 +1,9 @@
package org.drools.base.evaluators;
import java.io.Serializable;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.Map;
import org.drools.RuntimeDroolsException;
@@ -8,69 +11,85 @@
implements
Serializable {
- private static final long serialVersionUID = 400L;
+ private static final long serialVersionUID = 400L;
- public static final Operator EQUAL = new Operator( "==", false );
- public static final Operator NOT_EQUAL = new Operator( "!=", false );
- public static final Operator LESS = new Operator( "<", false );
- public static final Operator LESS_OR_EQUAL = new Operator( "<=", false );
- public static final Operator GREATER = new Operator( ">", false );
- public static final Operator GREATER_OR_EQUAL = new Operator( ">=", false );
- public static final Operator CONTAINS = new Operator( "contains", false );
- public static final Operator EXCLUDES = new Operator( "excludes", false );
- public static final Operator NOT_CONTAINS = new Operator( "contains", true );
- public static final Operator MATCHES = new Operator( "matches", false );
- public static final Operator NOT_MATCHES = new Operator( "matches", true );
- public static final Operator MEMBEROF = new Operator( "memberOf", false );
- public static final Operator NOTMEMBEROF = new Operator( "memberOf", true );
+ // a static private cache so that pluggable operator can register their implementations
+ // it is automatically initialized with common operator implementations
+ private static final Map<String, Operator> CACHE = Collections.synchronizedMap( new HashMap<String, Operator>() );
- public static final Operator SOUNDSLIKE = new Operator("soundslike", false);
+ // these static operator constants are kept here just to make it easier for the engine
+ // to reference common used operators. The addition of new constants here is not
+ // advisable though.
+ public static final Operator EQUAL = addOperatorToRegistry( "==",
+ false );
+ public static final Operator NOT_EQUAL = addOperatorToRegistry( "!=",
+ false );
+ public static final Operator LESS = addOperatorToRegistry( "<",
+ false );
+ public static final Operator LESS_OR_EQUAL = addOperatorToRegistry( "<=",
+ false );
+ public static final Operator GREATER = addOperatorToRegistry( ">",
+ false );
+ public static final Operator GREATER_OR_EQUAL = addOperatorToRegistry( ">=",
+ false );
- private String operator;
- private boolean isNegated;
+ /**
+ * Creates a new Operator instance for the given parameters,
+ * adds it to the registry and return it
+ *
+ * @param operatorId the identification symbol of the operator
+ * @param isNegated true if it is negated
+ *
+ * @return the newly created operator
+ */
+ public static Operator addOperatorToRegistry(final String operatorId,
+ final boolean isNegated) {
+ Operator op = new Operator( operatorId,
+ isNegated );
+ CACHE.put( getKey( operatorId,
+ isNegated ),
+ op );
+ return op;
+ }
- private Operator(final String operator, final boolean isNegated) {
+ /**
+ * Returns the operator instance for the given parameters
+ *
+ * @param operatorId the identification symbol of the operator
+ * @param isNegated true if it is negated
+ *
+ * @return the operator in case it exists
+ */
+ public static Operator determineOperator(final String operatorId,
+ final boolean isNegated) {
+ Operator op = CACHE.get( getKey( operatorId,
+ isNegated ) );
+ if ( op == null ) {
+ throw new RuntimeDroolsException( "unable to determine operator for symbol [" + (isNegated ? "not " : "") + operatorId + "]" );
+ }
+ return op;
+ }
+
+ private static String getKey(final String string,
+ final boolean isNegated) {
+ return isNegated + ":" + string;
+ }
+
+ // This class attributes
+ private String operator;
+ private boolean isNegated;
+
+ private Operator(final String operator,
+ final boolean isNegated) {
this.operator = operator;
this.isNegated = isNegated;
}
private Object readResolve() throws java.io.ObjectStreamException {
- return determineOperator( this.operator, this.isNegated );
+ return determineOperator( this.operator,
+ this.isNegated );
}
- public static Operator determineOperator(final String string, final boolean isNegated) {
- if ( string.equals( "==" ) ) {
- return Operator.EQUAL;
- } else if ( string.equals( "!=" ) ) {
- return Operator.NOT_EQUAL;
- } else if ( string.equals( "<" ) ) {
- return Operator.LESS;
- } else if ( string.equals( "<=" ) ) {
- return Operator.LESS_OR_EQUAL;
- } else if ( string.equals( ">" ) ) {
- return Operator.GREATER;
- } else if ( string.equals( ">=" ) ) {
- return Operator.GREATER_OR_EQUAL;
- } else if ( string.equals( "contains" ) && !isNegated ) {
- return Operator.CONTAINS;
- } else if ( string.equals( "contains" ) && isNegated ) {
- return Operator.NOT_CONTAINS;
- } else if ( string.equals( "matches" ) && !isNegated ) {
- return Operator.MATCHES;
- } else if ( string.equals( "matches" ) && isNegated ) {
- return Operator.NOT_MATCHES;
- } else if ( string.equals( "excludes" ) ) {
- return Operator.EXCLUDES;
- } else if ( string.equals( "memberOf" ) && !isNegated ) {
- return Operator.MEMBEROF;
- } else if ( string.equals( "memberOf" ) && isNegated ) {
- return Operator.NOTMEMBEROF;
- } else if ( string.equals( "soundslike" ) ) {
- return Operator.SOUNDSLIKE;
- }
- throw new RuntimeDroolsException( "unable to determine operator for String [" + string + "]" );
- }
-
public String toString() {
return "Operator = '" + this.operator + "'";
}
@@ -78,16 +97,31 @@
public String getOperatorString() {
return this.operator;
}
+
+ public boolean isNegated() {
+ return this.isNegated;
+ }
+ @Override
public int hashCode() {
- return this.operator.hashCode();
+ final int PRIME = 31;
+ int result = super.hashCode();
+ result = PRIME * result + (isNegated ? 1231 : 1237);
+ result = PRIME * result + ((operator == null) ? 0 : operator.hashCode());
+ return result;
}
- public boolean equals(final Object object) {
- if ( object == this ) {
- return true;
- }
+ @Override
+ public boolean equals(Object obj) {
+ if ( this == obj ) return true;
+ if ( obj == null ) return false;
+ if ( getClass() != obj.getClass() ) return false;
+ final Operator other = (Operator) obj;
+ if ( isNegated != other.isNegated ) return false;
+ if ( operator == null ) {
+ if ( other.operator != null ) return false;
+ } else if ( !operator.equals( other.operator ) ) return false;
+ return true;
+ }
- return false;
- }
}
Added: labs/jbossrules/branches/temporal_rete/drools-core/src/main/java/org/drools/base/evaluators/SetEvaluatorsDefinition.java
===================================================================
--- labs/jbossrules/branches/temporal_rete/drools-core/src/main/java/org/drools/base/evaluators/SetEvaluatorsDefinition.java (rev 0)
+++ labs/jbossrules/branches/temporal_rete/drools-core/src/main/java/org/drools/base/evaluators/SetEvaluatorsDefinition.java 2007-12-07 14:10:27 UTC (rev 17089)
@@ -0,0 +1,1098 @@
+/*
+ * Copyright 2007 JBoss Inc
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ * Created on Dec 6, 2007
+ */
+package org.drools.base.evaluators;
+
+import java.util.Collection;
+
+import org.drools.base.BaseEvaluator;
+import org.drools.base.ValueType;
+import org.drools.common.InternalWorkingMemory;
+import org.drools.rule.VariableRestriction.ObjectVariableContextEntry;
+import org.drools.rule.VariableRestriction.VariableContextEntry;
+import org.drools.spi.Evaluator;
+import org.drools.spi.Extractor;
+import org.drools.spi.FieldValue;
+import org.drools.util.ShadowProxyUtils;
+
+/**
+ * This class defines all the set built in
+ * evaluators like contains, memberOf, etc.
+ *
+ * @author etirelli
+ */
+public class SetEvaluatorsDefinition
+ implements
+ EvaluatorDefinition {
+
+ public static final Operator CONTAINS = Operator.addOperatorToRegistry( "contains",
+ false );
+ public static final Operator NOT_CONTAINS = Operator.addOperatorToRegistry( "contains",
+ true );
+ public static final Operator EXCLUDES = Operator.addOperatorToRegistry( "excludes",
+ false );
+ public static final Operator NOT_EXCLUDES = Operator.addOperatorToRegistry( "excludes",
+ true );
+ public static final Operator MEMBEROF = Operator.addOperatorToRegistry( "memberOf",
+ false );
+ public static final Operator NOT_MEMBEROF = Operator.addOperatorToRegistry( "memberOf",
+ true );
+
+ private static final String[] SUPPORTED_IDS = {CONTAINS.getOperatorString(), EXCLUDES.getOperatorString(), MEMBEROF.getOperatorString()};
+ private EvaluatorRegistry evaluators = new EvaluatorRegistry() {
+ private static final long serialVersionUID = 4782368623L;
+ {
+ addEvaluator( ValueType.ARRAY_TYPE, CONTAINS, ArrayContainsEvaluator.INSTANCE );
+ addEvaluator( ValueType.ARRAY_TYPE, NOT_CONTAINS, ArrayExcludesEvaluator.INSTANCE );
+ addEvaluator( ValueType.ARRAY_TYPE, EXCLUDES, ArrayExcludesEvaluator.INSTANCE );
+ addEvaluator( ValueType.ARRAY_TYPE, NOT_EXCLUDES, ArrayContainsEvaluator.INSTANCE );
+ addEvaluator( ValueType.ARRAY_TYPE, MEMBEROF, ArrayMemberOfEvaluator.INSTANCE );
+ addEvaluator( ValueType.ARRAY_TYPE, NOT_MEMBEROF, ArrayNotMemberOfEvaluator.INSTANCE );
+ addEvaluator( ValueType.BIG_DECIMAL_TYPE, MEMBEROF, BigDecimalMemberOfEvaluator.INSTANCE );
+ addEvaluator( ValueType.BIG_DECIMAL_TYPE, NOT_MEMBEROF, BigDecimalNotMemberOfEvaluator.INSTANCE );
+ addEvaluator( ValueType.BIG_INTEGER_TYPE, MEMBEROF, BigIntegerMemberOfEvaluator.INSTANCE );
+ addEvaluator( ValueType.BIG_INTEGER_TYPE, NOT_MEMBEROF, BigIntegerNotMemberOfEvaluator.INSTANCE );
+ addEvaluator( ValueType.BOOLEAN_TYPE, MEMBEROF, BooleanMemberOfEvaluator.INSTANCE );
+ addEvaluator( ValueType.BOOLEAN_TYPE, NOT_MEMBEROF, BooleanNotMemberOfEvaluator.INSTANCE );
+ addEvaluator( ValueType.PBOOLEAN_TYPE, MEMBEROF, BooleanMemberOfEvaluator.INSTANCE );
+ addEvaluator( ValueType.PBOOLEAN_TYPE, NOT_MEMBEROF, BooleanNotMemberOfEvaluator.INSTANCE );
+ addEvaluator( ValueType.BYTE_TYPE, MEMBEROF, ByteMemberOfEvaluator.INSTANCE );
+ addEvaluator( ValueType.BYTE_TYPE, NOT_MEMBEROF, ByteNotMemberOfEvaluator.INSTANCE );
+ addEvaluator( ValueType.PBYTE_TYPE, MEMBEROF, ByteMemberOfEvaluator.INSTANCE );
+ addEvaluator( ValueType.PBYTE_TYPE, NOT_MEMBEROF, ByteNotMemberOfEvaluator.INSTANCE );
+ addEvaluator( ValueType.CHAR_TYPE, MEMBEROF, CharacterMemberOfEvaluator.INSTANCE );
+ addEvaluator( ValueType.CHAR_TYPE, NOT_MEMBEROF, CharacterNotMemberOfEvaluator.INSTANCE );
+ addEvaluator( ValueType.PCHAR_TYPE, MEMBEROF, CharacterMemberOfEvaluator.INSTANCE );
+ addEvaluator( ValueType.PCHAR_TYPE, NOT_MEMBEROF, CharacterNotMemberOfEvaluator.INSTANCE );
+ addEvaluator( ValueType.DATE_TYPE, MEMBEROF, DateMemberOfEvaluator.INSTANCE );
+ addEvaluator( ValueType.DATE_TYPE, NOT_MEMBEROF, DateNotMemberOfEvaluator.INSTANCE );
+ addEvaluator( ValueType.DOUBLE_TYPE, MEMBEROF, DoubleMemberOfEvaluator.INSTANCE );
+ addEvaluator( ValueType.DOUBLE_TYPE, NOT_MEMBEROF, DoubleNotMemberOfEvaluator.INSTANCE );
+ addEvaluator( ValueType.PDOUBLE_TYPE, MEMBEROF, DoubleMemberOfEvaluator.INSTANCE );
+ addEvaluator( ValueType.PDOUBLE_TYPE, NOT_MEMBEROF, DoubleNotMemberOfEvaluator.INSTANCE );
+ addEvaluator( ValueType.FLOAT_TYPE, MEMBEROF, FloatMemberOfEvaluator.INSTANCE );
+ addEvaluator( ValueType.FLOAT_TYPE, NOT_MEMBEROF, FloatNotMemberOfEvaluator.INSTANCE );
+ addEvaluator( ValueType.PFLOAT_TYPE, MEMBEROF, FloatMemberOfEvaluator.INSTANCE );
+ addEvaluator( ValueType.PFLOAT_TYPE, NOT_MEMBEROF, FloatNotMemberOfEvaluator.INSTANCE );
+ addEvaluator( ValueType.INTEGER_TYPE, MEMBEROF, IntegerMemberOfEvaluator.INSTANCE );
+ addEvaluator( ValueType.INTEGER_TYPE, NOT_MEMBEROF, IntegerNotMemberOfEvaluator.INSTANCE );
+ addEvaluator( ValueType.PINTEGER_TYPE, MEMBEROF, IntegerMemberOfEvaluator.INSTANCE );
+ addEvaluator( ValueType.PINTEGER_TYPE, NOT_MEMBEROF, IntegerNotMemberOfEvaluator.INSTANCE );
+ addEvaluator( ValueType.LONG_TYPE, MEMBEROF, LongMemberOfEvaluator.INSTANCE );
+ addEvaluator( ValueType.LONG_TYPE, NOT_MEMBEROF, LongNotMemberOfEvaluator.INSTANCE );
+ addEvaluator( ValueType.PLONG_TYPE, MEMBEROF, LongMemberOfEvaluator.INSTANCE );
+ addEvaluator( ValueType.PLONG_TYPE, NOT_MEMBEROF, LongNotMemberOfEvaluator.INSTANCE );
+ addEvaluator( ValueType.OBJECT_TYPE, CONTAINS, ObjectContainsEvaluator.INSTANCE );
+ addEvaluator( ValueType.OBJECT_TYPE, NOT_CONTAINS, ObjectExcludesEvaluator.INSTANCE );
+ addEvaluator( ValueType.OBJECT_TYPE, EXCLUDES, ObjectExcludesEvaluator.INSTANCE );
+ addEvaluator( ValueType.OBJECT_TYPE, NOT_EXCLUDES, ObjectContainsEvaluator.INSTANCE );
+ addEvaluator( ValueType.OBJECT_TYPE, MEMBEROF, ObjectMemberOfEvaluator.INSTANCE );
+ addEvaluator( ValueType.OBJECT_TYPE, NOT_MEMBEROF, ObjectNotMemberOfEvaluator.INSTANCE );
+ addEvaluator( ValueType.SHORT_TYPE, MEMBEROF, ShortMemberOfEvaluator.INSTANCE );
+ addEvaluator( ValueType.SHORT_TYPE, NOT_MEMBEROF, ShortNotMemberOfEvaluator.INSTANCE );
+ addEvaluator( ValueType.PSHORT_TYPE, MEMBEROF, ShortMemberOfEvaluator.INSTANCE );
+ addEvaluator( ValueType.PSHORT_TYPE, NOT_MEMBEROF, ShortNotMemberOfEvaluator.INSTANCE );
+ addEvaluator( ValueType.STRING_TYPE, MEMBEROF, StringMemberOfEvaluator.INSTANCE );
+ addEvaluator( ValueType.STRING_TYPE, NOT_MEMBEROF, StringNotMemberOfEvaluator.INSTANCE );
+ }
+ };
+
+ /**
+ * @inheridDoc
+ */
+ public Evaluator getEvaluator(ValueType type,
+ Operator operator) {
+ return this.evaluators.getEvaluator( type,
+ operator );
+ }
+
+ /**
+ * @inheridDoc
+ */
+ public Evaluator getEvaluator(ValueType type,
+ Operator operator,
+ String parameterText) {
+ return this.evaluators.getEvaluator( type,
+ operator );
+ }
+
+ public Evaluator getEvaluator(final ValueType type,
+ final String operatorId,
+ final boolean isNegated,
+ final String parameterText) {
+ return this.evaluators.getEvaluator( type,
+ Operator.determineOperator( operatorId,
+ isNegated ) );
+ }
+
+ public String[] getEvaluatorIds() {
+ return SUPPORTED_IDS;
+ }
+
+ public boolean isNegatable() {
+ return true;
+ }
+
+ public boolean operatesOnFactHandles() {
+ return false;
+ }
+
+ public boolean supportsType(ValueType type) {
+ return this.evaluators.supportsType( type );
+ }
+
+ /* *********************************************************
+ * Evaluator Implementations
+ * *********************************************************
+ */
+ static class ArrayContainsEvaluator extends BaseEvaluator {
+
+ private static final long serialVersionUID = 400L;
+ public final static Evaluator INSTANCE = new ArrayContainsEvaluator();
+
+ private ArrayContainsEvaluator() {
+ super( ValueType.ARRAY_TYPE,
+ CONTAINS );
+ }
+
+ public boolean evaluate(InternalWorkingMemory workingMemory,
+ final Extractor extractor,
+ final Object object1,
+ final FieldValue object2) {
+ final Object value = object2.getValue();
+ final Object[] array = (Object[]) extractor.getValue( workingMemory,
+ object1 );
+ if ( array == null ) return false;
+ return ShadowProxyUtils.contains( array,
+ value );
+ }
+
+ public boolean evaluateCachedRight(InternalWorkingMemory workingMemory,
+ final VariableContextEntry context,
+ final Object left) {
+ final Object value = context.declaration.getExtractor().getValue( workingMemory,
+ left );
+ final Object[] array = (Object[]) ((ObjectVariableContextEntry) context).right;
+ if ( array == null ) return false;
+ return ShadowProxyUtils.contains( array,
+ value );
+ }
+
+ public boolean evaluateCachedLeft(InternalWorkingMemory workingMemory,
+ final VariableContextEntry context,
+ final Object right) {
+ final Object value = ((ObjectVariableContextEntry) context).left;
+ final Object[] array = (Object[]) context.extractor.getValue( workingMemory,
+ right );
+ if ( array == null ) return false;
+ return ShadowProxyUtils.contains( array,
+ value );
+ }
+
+ public boolean evaluate(InternalWorkingMemory workingMemory,
+ final Extractor extractor1,
+ final Object object1,
+ final Extractor extractor2,
+ final Object object2) {
+ final Object value = extractor2.getValue( workingMemory,
+ object2 );
+ final Object[] array = (Object[]) extractor1.getValue( workingMemory,
+ object1 );
+
+ if ( array == null ) return false;
+ return ShadowProxyUtils.contains( array,
+ value );
+ }
+
+ public String toString() {
+ return "Array contains";
+ }
+ }
+
+ static class ArrayExcludesEvaluator extends BaseEvaluator {
+ /**
+ *
+ */
+ private static final long serialVersionUID = 400L;
+ public final static Evaluator INSTANCE = new ArrayExcludesEvaluator();
+
+ private ArrayExcludesEvaluator() {
+ super( ValueType.ARRAY_TYPE,
+ EXCLUDES );
+ }
+
+ public boolean evaluate(InternalWorkingMemory workingMemory,
+ final Extractor extractor,
+ final Object object1,
+ final FieldValue object2) {
+ final Object value = object2.getValue();
+ final Object[] array = (Object[]) extractor.getValue( workingMemory,
+ object1 );
+ if ( array == null ) return true;
+ return !ShadowProxyUtils.contains( array,
+ value );
+ }
+
+ public boolean evaluateCachedRight(InternalWorkingMemory workingMemory,
+ final VariableContextEntry context,
+ final Object left) {
+ final Object value = context.declaration.getExtractor().getValue( workingMemory,
+ left );
+ final Object[] array = (Object[]) ((ObjectVariableContextEntry) context).right;
+ if ( array == null ) return true;
+ return !ShadowProxyUtils.contains( array,
+ value );
+ }
+
+ public boolean evaluateCachedLeft(InternalWorkingMemory workingMemory,
+ final VariableContextEntry context,
+ final Object right) {
+ final Object value = ((ObjectVariableContextEntry) context).left;
+ final Object[] array = (Object[]) context.extractor.getValue( workingMemory,
+ right );
+ if ( array == null ) return true;
+ return !ShadowProxyUtils.contains( array,
+ value );
+ }
+
+ public boolean evaluate(InternalWorkingMemory workingMemory,
+ final Extractor extractor1,
+ final Object object1,
+ final Extractor extractor2,
+ final Object object2) {
+ final Object value = extractor2.getValue( workingMemory,
+ object2 );
+ final Object[] array = (Object[]) extractor1.getValue( workingMemory,
+ object1 );
+
+ if ( array == null ) return true;
+ return !ShadowProxyUtils.contains( array,
+ value );
+ }
+
+ public String toString() {
+ return "Array excludes";
+ }
+ }
+
+ static class ArrayMemberOfEvaluator extends BaseEvaluator {
+ /**
+ *
+ */
+ private static final long serialVersionUID = 400L;
+ public final static Evaluator INSTANCE = new ArrayMemberOfEvaluator();
+
+ private ArrayMemberOfEvaluator() {
+ super( ValueType.ARRAY_TYPE,
+ MEMBEROF );
+ }
+
+ public boolean evaluate(InternalWorkingMemory workingMemory,
+ final Extractor extractor,
+ final Object object1,
+ final FieldValue object2) {
+ final Object[] array = (Object[]) object2.getValue();
+ final Object value = extractor.getValue( workingMemory,
+ object1 );
+ if ( array == null ) return false;
+ return ShadowProxyUtils.contains( array,
+ value );
+ }
+
+ public boolean evaluateCachedRight(InternalWorkingMemory workingMemory,
+ final VariableContextEntry context,
+ final Object left) {
+ final Object[] array = (Object[]) context.declaration.getExtractor().getValue( workingMemory,
+ left );
+ final Object value = ((ObjectVariableContextEntry) context).right;
+ if ( array == null ) return false;
+ return ShadowProxyUtils.contains( array,
+ value );
+ }
+
+ public boolean evaluateCachedLeft(InternalWorkingMemory workingMemory,
+ final VariableContextEntry context,
+ final Object right) {
+ final Object[] array = (Object[]) ((ObjectVariableContextEntry) context).left;
+ final Object value = context.extractor.getValue( workingMemory,
+ right );
+ if ( array == null ) return false;
+ return ShadowProxyUtils.contains( array,
+ value );
+ }
+
+ public boolean evaluate(InternalWorkingMemory workingMemory,
+ final Extractor extractor1,
+ final Object object1,
+ final Extractor extractor2,
+ final Object object2) {
+ final Object[] array = (Object[]) extractor2.getValue( workingMemory,
+ object2 );
+ final Object value = extractor1.getValue( workingMemory,
+ object1 );
+
+ if ( array == null ) return false;
+ return ShadowProxyUtils.contains( array,
+ value );
+ }
+
+ public String toString() {
+ return "Array memberOf";
+ }
+ }
+
+ static class ArrayNotMemberOfEvaluator extends BaseEvaluator {
+ /**
+ *
+ */
+ private static final long serialVersionUID = 400L;
+ public final static Evaluator INSTANCE = new ArrayNotMemberOfEvaluator();
+
+ private ArrayNotMemberOfEvaluator() {
+ super( ValueType.ARRAY_TYPE,
+ NOT_MEMBEROF );
+ }
+
+ public boolean evaluate(InternalWorkingMemory workingMemory,
+ final Extractor extractor,
+ final Object object1,
+ final FieldValue object2) {
+ final Object[] array = (Object[]) object2.getValue();
+ final Object value = extractor.getValue( workingMemory,
+ object1 );
+ if ( array == null ) return true;
+ return !ShadowProxyUtils.contains( array,
+ value );
+ }
+
+ public boolean evaluateCachedRight(InternalWorkingMemory workingMemory,
+ final VariableContextEntry context,
+ final Object left) {
+ final Object[] array = (Object[]) context.declaration.getExtractor().getValue( workingMemory,
+ left );
+ final Object value = ((ObjectVariableContextEntry) context).right;
+ if ( array == null ) return true;
+ return !ShadowProxyUtils.contains( array,
+ value );
+ }
+
+ public boolean evaluateCachedLeft(InternalWorkingMemory workingMemory,
+ final VariableContextEntry context,
+ final Object right) {
+ final Object[] array = (Object[]) ((ObjectVariableContextEntry) context).left;
+ final Object value = context.extractor.getValue( workingMemory,
+ right );
+ if ( array == null ) return true;
+ return !ShadowProxyUtils.contains( array,
+ value );
+ }
+
+ public boolean evaluate(InternalWorkingMemory workingMemory,
+ final Extractor extractor1,
+ final Object object1,
+ final Extractor extractor2,
+ final Object object2) {
+ final Object[] array = (Object[]) extractor2.getValue( workingMemory,
+ object2 );
+ final Object value = extractor1.getValue( workingMemory,
+ object1 );
+
+ if ( array == null ) return true;
+ return !ShadowProxyUtils.contains( array,
+ value );
+ }
+
+ public String toString() {
+ return "Array not memberOf";
+ }
+ }
+
+ static abstract class BaseMemberOfEvaluator extends BaseEvaluator {
+
+ private static final long serialVersionUID = 2017803222427893249L;
+
+ public BaseMemberOfEvaluator(ValueType type,
+ Operator operator) {
+ super( type,
+ operator );
+ }
+
+ public boolean evaluate(InternalWorkingMemory workingMemory,
+ final Extractor extractor,
+ final Object object1,
+ final FieldValue object2) {
+ if ( object2.isNull() ) {
+ return false;
+ } else if ( !object2.isCollectionField() ) {
+ throw new ClassCastException( "Can't check if an attribute is member of an object of class " + object2.getValue().getClass() );
+ }
+ final Collection col = (Collection) object2.getValue();
+ final Object value = extractor.getValue( workingMemory,
+ object1 );
+ return ShadowProxyUtils.contains( col,
+ value );
+ }
+
+ public boolean evaluateCachedRight(InternalWorkingMemory workingMemory,
+ final VariableContextEntry context,
+ final Object left) {
+ final Object object = context.declaration.getExtractor().getValue( workingMemory,
+ left );
+ if ( object == null ) {
+ return false;
+ } else if ( !(object instanceof Collection) ) {
+ throw new ClassCastException( "Can't check if an attribute is member of an object of class " + object.getClass() );
+ }
+ final Collection col = (Collection) object;
+ final Object value = ((ObjectVariableContextEntry) context).right;
+ return ShadowProxyUtils.contains( col,
+ value );
+ }
+
+ public boolean evaluateCachedLeft(InternalWorkingMemory workingMemory,
+ final VariableContextEntry context,
+ final Object right) {
+ final Object object = ((ObjectVariableContextEntry) context).left;
+ if ( object == null ) {
+ return false;
+ } else if ( !(object instanceof Collection) ) {
+ throw new ClassCastException( "Can't check if an attribute is member of an object of class " + object.getClass() );
+ }
+ final Collection col = (Collection) object;
+ final Object value = context.extractor.getValue( workingMemory,
+ right );
+ return ShadowProxyUtils.contains( col,
+ value );
+ }
+
+ public boolean evaluate(InternalWorkingMemory workingMemory,
+ final Extractor extractor1,
+ final Object object1,
+ final Extractor extractor2,
+ final Object object2) {
+ final Object object = extractor2.getValue( workingMemory,
+ object2 );
+ if ( object == null ) {
+ return false;
+ } else if ( !(object instanceof Collection) ) {
+ throw new ClassCastException( "Can't check if an attribute is member of an object of class " + object.getClass() );
+ }
+ final Collection col = (Collection) object;
+ final Object value = extractor1.getValue( workingMemory,
+ object1 );
+ return ShadowProxyUtils.contains( col,
+ value );
+ }
+
+ public abstract String toString();
+
+ }
+
+ static abstract class BaseNotMemberOfEvaluator extends BaseEvaluator {
+
+ private static final long serialVersionUID = -8730331781980886901L;
+
+ public BaseNotMemberOfEvaluator(ValueType type,
+ Operator operator) {
+ super( type,
+ operator );
+ }
+
+ public boolean evaluate(InternalWorkingMemory workingMemory,
+ final Extractor extractor,
+ final Object object1,
+ final FieldValue object2) {
+ if ( object2.isNull() ) {
+ return false;
+ } else if ( !object2.isCollectionField() ) {
+ throw new ClassCastException( "Can't check if an attribute is not member of an object of class " + object2.getValue().getClass() );
+ }
+ final Collection col = (Collection) object2.getValue();
+ final Object value = extractor.getValue( workingMemory,
+ object1 );
+ return !ShadowProxyUtils.contains( col,
+ value );
+ }
+
+ public boolean evaluateCachedRight(InternalWorkingMemory workingMemory,
+ final VariableContextEntry context,
+ final Object left) {
+ final Object object = context.declaration.getExtractor().getValue( workingMemory,
+ left );
+ if ( object == null ) {
+ return false;
+ } else if ( !(object instanceof Collection) ) {
+ throw new ClassCastException( "Can't check if an attribute is not member of an object of class " + object.getClass() );
+ }
+ final Collection col = (Collection) object;
+ final Object value = ((ObjectVariableContextEntry) context).right;
+ return !ShadowProxyUtils.contains( col,
+ value );
+ }
+
+ public boolean evaluateCachedLeft(InternalWorkingMemory workingMemory,
+ final VariableContextEntry context,
+ final Object right) {
+ final Object object = ((ObjectVariableContextEntry) context).left;
+ if ( object == null ) {
+ return false;
+ } else if ( !(object instanceof Collection) ) {
+ throw new ClassCastException( "Can't check if an attribute is not member of an object of class " + object.getClass() );
+ }
+ final Collection col = (Collection) object;
+ final Object value = context.extractor.getValue( workingMemory,
+ right );
+ return !ShadowProxyUtils.contains( col,
+ value );
+ }
+
+ public boolean evaluate(InternalWorkingMemory workingMemory,
+ final Extractor extractor1,
+ final Object object1,
+ final Extractor extractor2,
+ final Object object2) {
+ final Object object = extractor2.getValue( workingMemory,
+ object2 );
+ if ( object == null ) {
+ return false;
+ } else if ( !(object instanceof Collection) ) {
+ throw new ClassCastException( "Can't check if an attribute is not member of an object of class " + object.getClass() );
+ }
+ final Collection col = (Collection) object;
+ final Object value = extractor1.getValue( workingMemory,
+ object1 );
+ return !ShadowProxyUtils.contains( col,
+ value );
+ }
+
+ public abstract String toString();
+ }
+
+ static class BigDecimalMemberOfEvaluator extends BaseMemberOfEvaluator {
+
+ private static final long serialVersionUID = 400L;
+ public final static Evaluator INSTANCE = new BigDecimalMemberOfEvaluator();
+
+ private BigDecimalMemberOfEvaluator() {
+ super( ValueType.BIG_DECIMAL_TYPE,
+ MEMBEROF );
+ }
+
+ public String toString() {
+ return "BigDecimal memberOf";
+ }
+ }
+
+ static class BigDecimalNotMemberOfEvaluator extends BaseNotMemberOfEvaluator {
+
+ private static final long serialVersionUID = 400L;
+ public final static Evaluator INSTANCE = new BigDecimalNotMemberOfEvaluator();
+
+ private BigDecimalNotMemberOfEvaluator() {
+ super( ValueType.BIG_DECIMAL_TYPE,
+ NOT_MEMBEROF );
+ }
+
+ public String toString() {
+ return "BigDecimal not memberOf";
+ }
+ }
+
+ static class BigIntegerMemberOfEvaluator extends BaseMemberOfEvaluator {
+
+ private static final long serialVersionUID = 400L;
+ public final static Evaluator INSTANCE = new BigIntegerMemberOfEvaluator();
+
+ private BigIntegerMemberOfEvaluator() {
+ super( ValueType.BIG_INTEGER_TYPE,
+ MEMBEROF );
+ }
+
+ public String toString() {
+ return "BigInteger memberOf";
+ }
+ }
+
+ static class BigIntegerNotMemberOfEvaluator extends BaseNotMemberOfEvaluator {
+ /**
+ *
+ */
+ private static final long serialVersionUID = 400L;
+ public final static Evaluator INSTANCE = new BigIntegerNotMemberOfEvaluator();
+
+ private BigIntegerNotMemberOfEvaluator() {
+ super( ValueType.BIG_INTEGER_TYPE,
+ NOT_MEMBEROF );
+ }
+
+ public String toString() {
+ return "BigInteger not memberOf";
+ }
+ }
+
+ static class BooleanMemberOfEvaluator extends BaseMemberOfEvaluator {
+
+ private static final long serialVersionUID = 400L;
+ public final static Evaluator INSTANCE = new BooleanMemberOfEvaluator();
+
+ private BooleanMemberOfEvaluator() {
+ super( ValueType.PBOOLEAN_TYPE,
+ MEMBEROF );
+ }
+
+ public String toString() {
+ return "Boolean memberOf";
+ }
+ }
+
+ static class BooleanNotMemberOfEvaluator extends BaseNotMemberOfEvaluator {
+
+ private static final long serialVersionUID = 400L;
+ public final static Evaluator INSTANCE = new BooleanNotMemberOfEvaluator();
+
+ private BooleanNotMemberOfEvaluator() {
+ super( ValueType.PBOOLEAN_TYPE,
+ NOT_MEMBEROF );
+ }
+
+ public String toString() {
+ return "Boolean not memberOf";
+ }
+ }
+
+ static class ByteMemberOfEvaluator extends BaseMemberOfEvaluator {
+
+ private static final long serialVersionUID = 400L;
+ public final static Evaluator INSTANCE = new ByteMemberOfEvaluator();
+
+ private ByteMemberOfEvaluator() {
+ super( ValueType.PBYTE_TYPE,
+ MEMBEROF );
+ }
+
+ public String toString() {
+ return "Byte memberOf";
+ }
+ }
+
+ static class ByteNotMemberOfEvaluator extends BaseNotMemberOfEvaluator {
+
+ private static final long serialVersionUID = 400L;
+ public final static Evaluator INSTANCE = new ByteNotMemberOfEvaluator();
+
+ private ByteNotMemberOfEvaluator() {
+ super( ValueType.PBYTE_TYPE,
+ NOT_MEMBEROF );
+ }
+
+ public String toString() {
+ return "Byte not memberOf";
+ }
+ }
+
+ static class CharacterMemberOfEvaluator extends BaseMemberOfEvaluator {
+
+ private static final long serialVersionUID = 400L;
+ public final static Evaluator INSTANCE = new CharacterMemberOfEvaluator();
+
+ private CharacterMemberOfEvaluator() {
+ super( ValueType.PCHAR_TYPE,
+ MEMBEROF );
+ }
+
+ public String toString() {
+ return "Character memberOf";
+ }
+ }
+
+ static class CharacterNotMemberOfEvaluator extends BaseNotMemberOfEvaluator {
+
+ private static final long serialVersionUID = 400L;
+ public final static Evaluator INSTANCE = new CharacterNotMemberOfEvaluator();
+
+ private CharacterNotMemberOfEvaluator() {
+ super( ValueType.PCHAR_TYPE,
+ NOT_MEMBEROF );
+ }
+
+ public String toString() {
+ return "Character not memberOf";
+ }
+ }
+
+ static class DateMemberOfEvaluator extends BaseMemberOfEvaluator {
+
+ private static final long serialVersionUID = 400L;
+ public final static Evaluator INSTANCE = new DateMemberOfEvaluator();
+
+ private DateMemberOfEvaluator() {
+ super( ValueType.DATE_TYPE,
+ MEMBEROF );
+ }
+
+ public String toString() {
+ return "Date memberOf";
+ }
+ }
+
+ static class DateNotMemberOfEvaluator extends BaseNotMemberOfEvaluator {
+
+ private static final long serialVersionUID = 400L;
+ public final static Evaluator INSTANCE = new DateNotMemberOfEvaluator();
+
+ private DateNotMemberOfEvaluator() {
+ super( ValueType.DATE_TYPE,
+ NOT_MEMBEROF );
+ }
+
+ public String toString() {
+ return "Date not memberOf";
+ }
+ }
+
+ static class DoubleMemberOfEvaluator extends BaseMemberOfEvaluator {
+
+ private static final long serialVersionUID = 400L;
+ public final static Evaluator INSTANCE = new DoubleMemberOfEvaluator();
+
+ private DoubleMemberOfEvaluator() {
+ super( ValueType.PDOUBLE_TYPE,
+ MEMBEROF );
+ }
+
+ public String toString() {
+ return "Double memberOf";
+ }
+ }
+
+ static class DoubleNotMemberOfEvaluator extends BaseNotMemberOfEvaluator {
+
+ private static final long serialVersionUID = 400L;
+ public final static Evaluator INSTANCE = new DoubleNotMemberOfEvaluator();
+
+ private DoubleNotMemberOfEvaluator() {
+ super( ValueType.PDOUBLE_TYPE,
+ NOT_MEMBEROF );
+ }
+
+ public String toString() {
+ return "Double not memberOf";
+ }
+ }
+
+ static class FloatMemberOfEvaluator extends BaseMemberOfEvaluator {
+
+ private static final long serialVersionUID = 400L;
+ public final static Evaluator INSTANCE = new FloatMemberOfEvaluator();
+
+ private FloatMemberOfEvaluator() {
+ super( ValueType.PFLOAT_TYPE,
+ MEMBEROF );
+ }
+
+ public String toString() {
+ return "Float memberOf";
+ }
+ }
+
+ static class FloatNotMemberOfEvaluator extends BaseNotMemberOfEvaluator {
+
+ private static final long serialVersionUID = 400L;
+ public final static Evaluator INSTANCE = new FloatNotMemberOfEvaluator();
+
+ private FloatNotMemberOfEvaluator() {
+ super( ValueType.PFLOAT_TYPE,
+ NOT_MEMBEROF );
+ }
+
+ public String toString() {
+ return "Float not memberOf";
+ }
+ }
+
+ static class IntegerMemberOfEvaluator extends BaseMemberOfEvaluator {
+
+ private static final long serialVersionUID = 400L;
+ public final static Evaluator INSTANCE = new IntegerMemberOfEvaluator();
+
+ private IntegerMemberOfEvaluator() {
+ super( ValueType.PINTEGER_TYPE,
+ MEMBEROF );
+ }
+
+ public String toString() {
+ return "Integer memberOf";
+ }
+ }
+
+ static class IntegerNotMemberOfEvaluator extends BaseNotMemberOfEvaluator {
+
+ private static final long serialVersionUID = 400L;
+ public final static Evaluator INSTANCE = new IntegerNotMemberOfEvaluator();
+
+ private IntegerNotMemberOfEvaluator() {
+ super( ValueType.PINTEGER_TYPE,
+ NOT_MEMBEROF );
+ }
+
+ public String toString() {
+ return "Integer not memberOf";
+ }
+ }
+
+ static class LongMemberOfEvaluator extends BaseMemberOfEvaluator {
+
+ private static final long serialVersionUID = 400L;
+ public final static Evaluator INSTANCE = new LongMemberOfEvaluator();
+
+ private LongMemberOfEvaluator() {
+ super( ValueType.PLONG_TYPE,
+ MEMBEROF );
+ }
+
+ public String toString() {
+ return "Long memberOf";
+ }
+ }
+
+ static class LongNotMemberOfEvaluator extends BaseNotMemberOfEvaluator {
+
+ private static final long serialVersionUID = 400L;
+ public final static Evaluator INSTANCE = new LongNotMemberOfEvaluator();
+
+ private LongNotMemberOfEvaluator() {
+ super( ValueType.PLONG_TYPE,
+ NOT_MEMBEROF );
+ }
+
+ public String toString() {
+ return "Long not memberOf";
+ }
+ }
+
+ static class ObjectContainsEvaluator extends BaseEvaluator {
+ /**
+ *
+ */
+ private static final long serialVersionUID = 400L;
+ public final static Evaluator INSTANCE = new ObjectContainsEvaluator();
+
+ private ObjectContainsEvaluator() {
+ super( ValueType.OBJECT_TYPE,
+ CONTAINS );
+ }
+
+ public boolean evaluate(InternalWorkingMemory workingMemory,
+ final Extractor extractor,
+ final Object object1,
+ final FieldValue object2) {
+ final Object value = object2.getValue();
+ final Collection col = (Collection) extractor.getValue( workingMemory,
+ object1 );
+ return (col == null) ? false : ShadowProxyUtils.contains( col,
+ value );
+ }
+
+ public boolean evaluateCachedRight(InternalWorkingMemory workingMemory,
+ final VariableContextEntry context,
+ final Object left) {
+ final Object value = context.declaration.getExtractor().getValue( workingMemory,
+ left );
+ final Collection col = (Collection) ((ObjectVariableContextEntry) context).right;
+ return (col == null) ? false : ShadowProxyUtils.contains( col,
+ value );
+ }
+
+ public boolean evaluateCachedLeft(InternalWorkingMemory workingMemory,
+ final VariableContextEntry context,
+ final Object right) {
+ final Object value = ((ObjectVariableContextEntry) context).left;
+ final Collection col = (Collection) context.extractor.getValue( workingMemory,
+ right );
+ return (col == null) ? false : ShadowProxyUtils.contains( col,
+ value );
+ }
+
+ public boolean evaluate(InternalWorkingMemory workingMemory,
+ final Extractor extractor1,
+ final Object object1,
+ final Extractor extractor2,
+ final Object object2) {
+ final Object value = extractor2.getValue( workingMemory,
+ object2 );
+ final Collection col = (Collection) extractor1.getValue( workingMemory,
+ object1 );
+ return (col == null) ? false : ShadowProxyUtils.contains( col,
+ value );
+ }
+
+ public String toString() {
+ return "Object contains";
+ }
+ }
+
+ static class ObjectExcludesEvaluator extends BaseEvaluator {
+ /**
+ *
+ */
+ private static final long serialVersionUID = 400L;
+ public final static Evaluator INSTANCE = new ObjectExcludesEvaluator();
+
+ private ObjectExcludesEvaluator() {
+ super( ValueType.OBJECT_TYPE,
+ EXCLUDES );
+ }
+
+ public boolean evaluate(InternalWorkingMemory workingMemory,
+ final Extractor extractor,
+ final Object object1,
+ final FieldValue object2) {
+ final Object value = object2.getValue();
+ final Collection col = (Collection) extractor.getValue( workingMemory,
+ object1 );
+ return (col == null) ? true : !ShadowProxyUtils.contains( col,
+ value );
+ }
+
+ public boolean evaluateCachedRight(InternalWorkingMemory workingMemory,
+ final VariableContextEntry context,
+ final Object left) {
+ final Object value = context.declaration.getExtractor().getValue( workingMemory,
+ left );
+ final Collection col = (Collection) ((ObjectVariableContextEntry) context).right;
+ return (col == null) ? true : !ShadowProxyUtils.contains( col,
+ value );
+ }
+
+ public boolean evaluateCachedLeft(InternalWorkingMemory workingMemory,
+ final VariableContextEntry context,
+ final Object right) {
+ final Object value = ((ObjectVariableContextEntry) context).left;
+ final Collection col = (Collection) context.extractor.getValue( workingMemory,
+ right );
+ return (col == null) ? true : !ShadowProxyUtils.contains( col,
+ value );
+ }
+
+ public boolean evaluate(InternalWorkingMemory workingMemory,
+ final Extractor extractor1,
+ final Object object1,
+ final Extractor extractor2,
+ final Object object2) {
+ final Object value = extractor2.getValue( workingMemory,
+ object2 );
+ final Collection col = (Collection) extractor1.getValue( workingMemory,
+ object1 );
+ return (col == null) ? true : !ShadowProxyUtils.contains( col,
+ value );
+ }
+
+ public String toString() {
+ return "Object excludes";
+ }
+ }
+
+ static class ObjectMemberOfEvaluator extends BaseMemberOfEvaluator {
+
+ private static final long serialVersionUID = 400L;
+ public final static Evaluator INSTANCE = new ObjectMemberOfEvaluator();
+
+ private ObjectMemberOfEvaluator() {
+ super( ValueType.OBJECT_TYPE,
+ MEMBEROF );
+ }
+
+ public String toString() {
+ return "Object memberOf";
+ }
+ }
+
+ static class ObjectNotMemberOfEvaluator extends BaseNotMemberOfEvaluator {
+
+ private static final long serialVersionUID = 400L;
+ public final static Evaluator INSTANCE = new ObjectNotMemberOfEvaluator();
+
+ private ObjectNotMemberOfEvaluator() {
+ super( ValueType.OBJECT_TYPE,
+ NOT_MEMBEROF );
+ }
+
+ public String toString() {
+ return "Object not memberOf";
+ }
+ }
+
+ static class ShortMemberOfEvaluator extends BaseMemberOfEvaluator {
+
+ private static final long serialVersionUID = 400L;
+ public final static Evaluator INSTANCE = new ShortMemberOfEvaluator();
+
+ private ShortMemberOfEvaluator() {
+ super( ValueType.PSHORT_TYPE,
+ MEMBEROF );
+ }
+
+ public String toString() {
+ return "Short memberOf";
+ }
+ }
+
+ static class ShortNotMemberOfEvaluator extends BaseNotMemberOfEvaluator {
+
+ private static final long serialVersionUID = 400L;
+ public final static Evaluator INSTANCE = new ShortNotMemberOfEvaluator();
+
+ private ShortNotMemberOfEvaluator() {
+ super( ValueType.PSHORT_TYPE,
+ NOT_MEMBEROF );
+ }
+
+ public String toString() {
+ return "Short not memberOf";
+ }
+ }
+
+ static class StringMemberOfEvaluator extends BaseMemberOfEvaluator {
+
+ private static final long serialVersionUID = 400L;
+ public final static Evaluator INSTANCE = new StringMemberOfEvaluator();
+
+ private StringMemberOfEvaluator() {
+ super( ValueType.STRING_TYPE,
+ MEMBEROF );
+ }
+
+ public String toString() {
+ return "String memberOf";
+ }
+ }
+
+ static class StringNotMemberOfEvaluator extends BaseNotMemberOfEvaluator {
+
+ private static final long serialVersionUID = 400L;
+ public final static Evaluator INSTANCE = new StringNotMemberOfEvaluator();
+
+ private StringNotMemberOfEvaluator() {
+ super( ValueType.STRING_TYPE,
+ NOT_MEMBEROF );
+ }
+
+ public String toString() {
+ return "String not memberOf";
+ }
+ }
+}
Deleted: labs/jbossrules/branches/temporal_rete/drools-core/src/main/java/org/drools/base/evaluators/ShortFactory.java
===================================================================
--- labs/jbossrules/branches/temporal_rete/drools-core/src/main/java/org/drools/base/evaluators/ShortFactory.java 2007-12-07 13:39:06 UTC (rev 17088)
+++ labs/jbossrules/branches/temporal_rete/drools-core/src/main/java/org/drools/base/evaluators/ShortFactory.java 2007-12-07 14:10:27 UTC (rev 17089)
@@ -1,434 +0,0 @@
-package org.drools.base.evaluators;
-
-/*
- * Copyright 2005 JBoss Inc
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-import org.drools.base.BaseEvaluator;
-import org.drools.base.ValueType;
-import org.drools.common.InternalWorkingMemory;
-import org.drools.rule.VariableRestriction.LongVariableContextEntry;
-import org.drools.rule.VariableRestriction.VariableContextEntry;
-import org.drools.spi.Evaluator;
-import org.drools.spi.Extractor;
-import org.drools.spi.FieldValue;
-
-public class ShortFactory
- implements
- EvaluatorFactory {
-
- private static final long serialVersionUID = 400L;
- private static EvaluatorFactory INSTANCE = new ShortFactory();
-
- private ShortFactory() {
-
- }
-
- public static EvaluatorFactory getInstance() {
- if ( ShortFactory.INSTANCE == null ) {
- ShortFactory.INSTANCE = new ShortFactory();
- }
- return ShortFactory.INSTANCE;
- }
-
- public Evaluator getEvaluator(final Operator operator) {
- if ( operator == Operator.EQUAL ) {
- return ShortEqualEvaluator.INSTANCE;
- } else if ( operator == Operator.NOT_EQUAL ) {
- return ShortNotEqualEvaluator.INSTANCE;
- } else if ( operator == Operator.LESS ) {
- return ShortLessEvaluator.INSTANCE;
- } else if ( operator == Operator.LESS_OR_EQUAL ) {
- return ShortLessOrEqualEvaluator.INSTANCE;
- } else if ( operator == Operator.GREATER ) {
- return ShortGreaterEvaluator.INSTANCE;
- } else if ( operator == Operator.GREATER_OR_EQUAL ) {
- return ShortGreaterOrEqualEvaluator.INSTANCE;
- } else if ( operator == Operator.MEMBEROF ) {
- return ShortMemberOfEvaluator.INSTANCE;
- } else if ( operator == Operator.NOTMEMBEROF ) {
- return ShortNotMemberOfEvaluator.INSTANCE;
- } else {
- throw new RuntimeException( "Operator '" + operator + "' does not exist for ShortEvaluator" );
- }
- }
-
- static class ShortEqualEvaluator extends BaseEvaluator {
- /**
- *
- */
- private static final long serialVersionUID = 400L;
- private static final Evaluator INSTANCE = new ShortEqualEvaluator();
-
- private ShortEqualEvaluator() {
- super( ValueType.PSHORT_TYPE,
- Operator.EQUAL );
- }
-
- public boolean evaluate(InternalWorkingMemory workingMemory,
- final Extractor extractor,
- final Object object1, final FieldValue object2) {
- if ( extractor.isNullValue( workingMemory, object1 ) ) {
- return object2.isNull();
- } else if ( object2.isNull() ) {
- return false;
- }
-
- return extractor.getShortValue( workingMemory, object1 ) == object2.getShortValue();
- }
-
- public boolean evaluateCachedRight(InternalWorkingMemory workingMemory,
- final VariableContextEntry context, final Object left) {
- if ( context.declaration.getExtractor().isNullValue( workingMemory, left ) ) {
- return context.isRightNull();
- } else if ( context.isRightNull() ) {
- return false;
- }
-
- return context.declaration.getExtractor().getShortValue( workingMemory, left ) == ((LongVariableContextEntry) context).right;
- }
-
- public boolean evaluateCachedLeft(InternalWorkingMemory workingMemory,
- final VariableContextEntry context, final Object right) {
- if ( context.extractor.isNullValue( workingMemory, right )) {
- return context.isLeftNull();
- } else if ( context.isLeftNull() ) {
- return false;
- }
-
- return ((LongVariableContextEntry) context).left == context.extractor.getShortValue( workingMemory, right );
- }
-
- public boolean evaluate(InternalWorkingMemory workingMemory,
- final Extractor extractor1,
- final Object object1,
- final Extractor extractor2, final Object object2) {
- if (extractor1.isNullValue( workingMemory, object1 )) {
- return extractor2.isNullValue( workingMemory, object2 );
- } else if (extractor2.isNullValue( workingMemory, object2 )) {
- return false;
- }
-
- return extractor1.getShortValue( workingMemory, object1 ) == extractor2.getShortValue( workingMemory, object2 );
- }
-
- public String toString() {
- return "Short ==";
- }
- }
-
- static class ShortNotEqualEvaluator extends BaseEvaluator {
- /**
- *
- */
- private static final long serialVersionUID = 400L;
- private static final Evaluator INSTANCE = new ShortNotEqualEvaluator();
-
- private ShortNotEqualEvaluator() {
- super( ValueType.PSHORT_TYPE,
- Operator.NOT_EQUAL );
- }
-
- public boolean evaluate(InternalWorkingMemory workingMemory,
- final Extractor extractor,
- final Object object1, final FieldValue object2) {
- if ( extractor.isNullValue( workingMemory, object1 ) ) {
- return !object2.isNull();
- } else if ( object2.isNull() ) {
- return true;
- }
-
- return extractor.getShortValue( workingMemory, object1 ) != object2.getShortValue();
- }
-
- public boolean evaluateCachedRight(InternalWorkingMemory workingMemory,
- final VariableContextEntry context, final Object left) {
- if ( context.declaration.getExtractor().isNullValue( workingMemory, left ) ) {
- return !context.isRightNull();
- } else if ( context.isRightNull() ) {
- return true;
- }
-
- return context.declaration.getExtractor().getShortValue( workingMemory, left ) != ((LongVariableContextEntry) context).right;
- }
-
- public boolean evaluateCachedLeft(InternalWorkingMemory workingMemory,
- final VariableContextEntry context, final Object right) {
- if ( context.extractor.isNullValue( workingMemory, right ) ) {
- return !context.isLeftNull();
- } else if ( context.isLeftNull() ) {
- return true;
- }
-
- return ((LongVariableContextEntry) context).left != context.extractor.getShortValue( workingMemory, right );
- }
-
- public boolean evaluate(InternalWorkingMemory workingMemory,
- final Extractor extractor1,
- final Object object1,
- final Extractor extractor2, final Object object2) {
- if (extractor1.isNullValue( workingMemory, object1 )) {
- return !extractor2.isNullValue( workingMemory, object2 );
- } else if (extractor2.isNullValue( workingMemory, object2 )) {
- return true;
- }
-
- return extractor1.getShortValue( workingMemory, object1 ) != extractor2.getShortValue( workingMemory, object2 );
- }
-
- public String toString() {
- return "Short !=";
- }
- }
-
- static class ShortLessEvaluator extends BaseEvaluator {
- /**
- *
- */
- private static final long serialVersionUID = 400L;
- private static final Evaluator INSTANCE = new ShortLessEvaluator();
-
- private ShortLessEvaluator() {
- super( ValueType.PSHORT_TYPE,
- Operator.LESS );
- }
-
- public boolean evaluate(InternalWorkingMemory workingMemory,
- final Extractor extractor,
- final Object object1, final FieldValue object2) {
- if( extractor.isNullValue( workingMemory, object1 ) ) {
- return false;
- }
- return extractor.getShortValue( workingMemory, object1 ) < object2.getShortValue();
- }
-
- public boolean evaluateCachedRight(InternalWorkingMemory workingMemory,
- final VariableContextEntry context, final Object left) {
- if( context.rightNull ) {
- return false;
- }
- return ((LongVariableContextEntry) context).right < context.declaration.getExtractor().getShortValue( workingMemory, left );
- }
-
- public boolean evaluateCachedLeft(InternalWorkingMemory workingMemory,
- final VariableContextEntry context, final Object right) {
- if( context.extractor.isNullValue( workingMemory, right ) ) {
- return false;
- }
- return context.extractor.getShortValue( workingMemory, right ) < ((LongVariableContextEntry) context).left;
- }
-
- public boolean evaluate(InternalWorkingMemory workingMemory,
- final Extractor extractor1,
- final Object object1,
- final Extractor extractor2, final Object object2) {
- if( extractor1.isNullValue( workingMemory, object1 ) ) {
- return false;
- }
- return extractor1.getShortValue( workingMemory, object1 ) < extractor2.getShortValue( workingMemory, object2 );
- }
-
- public String toString() {
- return "Short <";
- }
- }
-
- static class ShortLessOrEqualEvaluator extends BaseEvaluator {
- /**
- *
- */
- private static final long serialVersionUID = 400L;
- private static final Evaluator INSTANCE = new ShortLessOrEqualEvaluator();
-
- private ShortLessOrEqualEvaluator() {
- super( ValueType.PSHORT_TYPE,
- Operator.LESS_OR_EQUAL );
- }
-
- public boolean evaluate(InternalWorkingMemory workingMemory,
- final Extractor extractor,
- final Object object1, final FieldValue object2) {
- if( extractor.isNullValue( workingMemory, object1 ) ) {
- return false;
- }
- return extractor.getShortValue( workingMemory, object1 ) <= object2.getShortValue();
- }
-
- public boolean evaluateCachedRight(InternalWorkingMemory workingMemory,
- final VariableContextEntry context, final Object left) {
- if( context.rightNull ) {
- return false;
- }
- return ((LongVariableContextEntry) context).right <= context.declaration.getExtractor().getShortValue( workingMemory, left );
- }
-
- public boolean evaluateCachedLeft(InternalWorkingMemory workingMemory,
- final VariableContextEntry context, final Object right) {
- if( context.extractor.isNullValue( workingMemory, right ) ) {
- return false;
- }
- return context.extractor.getShortValue( workingMemory, right ) <= ((LongVariableContextEntry) context).left;
- }
-
- public boolean evaluate(InternalWorkingMemory workingMemory,
- final Extractor extractor1,
- final Object object1,
- final Extractor extractor2, final Object object2) {
- if( extractor1.isNullValue( workingMemory, object1 ) ) {
- return false;
- }
- return extractor1.getShortValue( workingMemory, object1 ) <= extractor2.getShortValue( workingMemory, object2 );
- }
-
- public String toString() {
- return "Boolean <=";
- }
- }
-
- static class ShortGreaterEvaluator extends BaseEvaluator {
- /**
- *
- */
- private static final long serialVersionUID = 400L;
- private static final Evaluator INSTANCE = new ShortGreaterEvaluator();
-
- private ShortGreaterEvaluator() {
- super( ValueType.PSHORT_TYPE,
- Operator.GREATER );
- }
-
- public boolean evaluate(InternalWorkingMemory workingMemory,
- final Extractor extractor,
- final Object object1, final FieldValue object2) {
- if( extractor.isNullValue( workingMemory, object1 ) ) {
- return false;
- }
- return extractor.getShortValue( workingMemory, object1 ) > object2.getShortValue();
- }
-
- public boolean evaluateCachedRight(InternalWorkingMemory workingMemory,
- final VariableContextEntry context, final Object left) {
- if( context.rightNull ) {
- return false;
- }
- return ((LongVariableContextEntry) context).right > context.declaration.getExtractor().getShortValue( workingMemory, left );
- }
-
- public boolean evaluateCachedLeft(InternalWorkingMemory workingMemory,
- final VariableContextEntry context, final Object right) {
- if( context.extractor.isNullValue( workingMemory, right ) ) {
- return false;
- }
- return context.extractor.getShortValue( workingMemory, right ) > ((LongVariableContextEntry) context).left;
- }
-
- public boolean evaluate(InternalWorkingMemory workingMemory,
- final Extractor extractor1,
- final Object object1,
- final Extractor extractor2, final Object object2) {
- if( extractor1.isNullValue( workingMemory, object1 ) ) {
- return false;
- }
- return extractor1.getShortValue( workingMemory, object1 ) > extractor2.getShortValue( workingMemory, object2 );
- }
-
- public String toString() {
- return "Short >";
- }
- }
-
- static class ShortGreaterOrEqualEvaluator extends BaseEvaluator {
- /**
- *
- */
- private static final long serialVersionUID = 400L;
- private static final Evaluator INSTANCE = new ShortGreaterOrEqualEvaluator();
-
- private ShortGreaterOrEqualEvaluator() {
- super( ValueType.PSHORT_TYPE,
- Operator.GREATER_OR_EQUAL );
- }
-
- public boolean evaluate(InternalWorkingMemory workingMemory,
- final Extractor extractor,
- final Object object1, final FieldValue object2) {
- if( extractor.isNullValue( workingMemory, object1 ) ) {
- return false;
- }
- return extractor.getShortValue( workingMemory, object1 ) >= object2.getShortValue();
- }
-
- public boolean evaluateCachedRight(InternalWorkingMemory workingMemory,
- final VariableContextEntry context, final Object left) {
- if( context.rightNull ) {
- return false;
- }
- return ((LongVariableContextEntry) context).right >= context.declaration.getExtractor().getShortValue( workingMemory, left );
- }
-
- public boolean evaluateCachedLeft(InternalWorkingMemory workingMemory,
- final VariableContextEntry context, final Object right) {
- if( context.extractor.isNullValue( workingMemory, right ) ) {
- return false;
- }
- return context.extractor.getShortValue( workingMemory, right ) >= ((LongVariableContextEntry) context).left;
- }
-
- public boolean evaluate(InternalWorkingMemory workingMemory,
- final Extractor extractor1,
- final Object object1,
- final Extractor extractor2, final Object object2) {
- if( extractor1.isNullValue( workingMemory, object1 ) ) {
- return false;
- }
- return extractor1.getShortValue( workingMemory, object1 ) >= extractor2.getShortValue( workingMemory, object2 );
- }
-
- public String toString() {
- return "Short >=";
- }
- }
-
- static class ShortMemberOfEvaluator extends BaseMemberOfEvaluator {
-
- private static final long serialVersionUID = 400L;
- public final static Evaluator INSTANCE = new ShortMemberOfEvaluator();
-
- private ShortMemberOfEvaluator() {
- super( ValueType.PSHORT_TYPE,
- Operator.MEMBEROF );
- }
-
- public String toString() {
- return "Short memberOf";
- }
- }
-
- static class ShortNotMemberOfEvaluator extends BaseNotMemberOfEvaluator {
-
- private static final long serialVersionUID = 400L;
- public final static Evaluator INSTANCE = new ShortNotMemberOfEvaluator();
-
- private ShortNotMemberOfEvaluator() {
- super( ValueType.PSHORT_TYPE,
- Operator.NOTMEMBEROF );
- }
-
- public String toString() {
- return "Short not memberOf";
- }
- }
-
-}
\ No newline at end of file
Added: labs/jbossrules/branches/temporal_rete/drools-core/src/main/java/org/drools/base/evaluators/SoundslikeEvaluatorsDefinition.java
===================================================================
--- labs/jbossrules/branches/temporal_rete/drools-core/src/main/java/org/drools/base/evaluators/SoundslikeEvaluatorsDefinition.java (rev 0)
+++ labs/jbossrules/branches/temporal_rete/drools-core/src/main/java/org/drools/base/evaluators/SoundslikeEvaluatorsDefinition.java 2007-12-07 14:10:27 UTC (rev 17089)
@@ -0,0 +1,214 @@
+/*
+ * Copyright 2007 JBoss Inc
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ * Created on Dec 6, 2007
+ */
+package org.drools.base.evaluators;
+
+import org.drools.base.BaseEvaluator;
+import org.drools.base.ValueType;
+import org.drools.common.InternalWorkingMemory;
+import org.drools.rule.VariableRestriction.ObjectVariableContextEntry;
+import org.drools.rule.VariableRestriction.VariableContextEntry;
+import org.drools.spi.Evaluator;
+import org.drools.spi.Extractor;
+import org.drools.spi.FieldValue;
+import org.mvel.Soundex;
+
+/**
+ * This class defines the soundslike evaluator
+ *
+ * @author etirelli
+ */
+public class SoundslikeEvaluatorsDefinition implements EvaluatorDefinition {
+
+ public static final Operator SOUNDSLIKE = Operator.addOperatorToRegistry( "soundslike",
+ false );
+ public static final Operator NOT_SOUNDSLIKE = Operator.addOperatorToRegistry( "soundslike",
+ true );
+
+ private static final String[] SUPPORTED_IDS = { SOUNDSLIKE.getOperatorString() };
+ private EvaluatorRegistry evaluators = new EvaluatorRegistry() {
+ private static final long serialVersionUID = 4782368623L;
+ {
+ addEvaluator( ValueType.STRING_TYPE, SOUNDSLIKE, StringSoundsLikeEvaluator.INSTANCE );
+ addEvaluator( ValueType.STRING_TYPE, NOT_SOUNDSLIKE, StringNotSoundsLikeEvaluator.INSTANCE );
+ }
+ };
+
+ /**
+ * @inheridDoc
+ */
+ public Evaluator getEvaluator(ValueType type,
+ Operator operator) {
+ return this.evaluators.getEvaluator( type,
+ operator );
+ }
+
+ /**
+ * @inheridDoc
+ */
+ public Evaluator getEvaluator(ValueType type,
+ Operator operator,
+ String parameterText) {
+ return this.evaluators.getEvaluator( type,
+ operator );
+ }
+
+ public Evaluator getEvaluator(final ValueType type,
+ final String operatorId,
+ final boolean isNegated,
+ final String parameterText) {
+ return this.evaluators.getEvaluator( type,
+ Operator.determineOperator( operatorId,
+ isNegated ) );
+ }
+
+ public String[] getEvaluatorIds() {
+ return SUPPORTED_IDS;
+ }
+
+ public boolean isNegatable() {
+ return true;
+ }
+
+ public boolean operatesOnFactHandles() {
+ return false;
+ }
+
+ public boolean supportsType(ValueType type) {
+ return this.evaluators.supportsType( type );
+ }
+
+ /* *********************************************************
+ * Evaluator Implementations
+ * *********************************************************
+ */
+ static class StringSoundsLikeEvaluator extends BaseEvaluator {
+
+ private static final long serialVersionUID = 400L;
+ public final static Evaluator INSTANCE = new StringSoundsLikeEvaluator();
+
+ private StringSoundsLikeEvaluator() {
+ super( ValueType.STRING_TYPE,
+ SOUNDSLIKE );
+ }
+
+ public boolean evaluate(InternalWorkingMemory workingMemory,
+ final Extractor extractor,
+ final Object object1, final FieldValue object2) {
+ final String value1 = (String) extractor.getValue( workingMemory, object1 );
+ final String value2 = (String) object2.getValue();
+ if ( value1 == null ) {
+ return false;
+ }
+
+ return Soundex.soundex( value1 ).equals( Soundex.soundex(value2) );
+ }
+
+ public boolean evaluateCachedRight(InternalWorkingMemory workingMemory,
+ final VariableContextEntry context, final Object left) {
+ final String value = (String) ((ObjectVariableContextEntry) context).right;
+ if ( value == null ) {
+ return false;
+ }
+ return Soundex.soundex( value ).equals( Soundex.soundex((String) context.declaration.getExtractor().getValue( workingMemory, left )) );
+ }
+
+ public boolean evaluateCachedLeft(InternalWorkingMemory workingMemory,
+ final VariableContextEntry context, final Object right) {
+ final String value = (String) context.extractor.getValue( workingMemory, right );
+ if ( value == null ) {
+ return false;
+ }
+ return Soundex.soundex(value).equals( Soundex.soundex((String) ((ObjectVariableContextEntry) context).left ));
+ }
+
+ public boolean evaluate(InternalWorkingMemory workingMemory,
+ final Extractor extractor1,
+ final Object object1,
+ final Extractor extractor2, final Object object2) {
+ final Object value1 = extractor1.getValue( workingMemory, object1 );
+ final Object value2 = extractor2.getValue( workingMemory, object2 );
+ if ( value1 == null ) {
+ return false;
+ }
+ return Soundex.soundex( ((String) value1)).equals( Soundex.soundex( (String) value2 ));
+ }
+
+ public String toString() {
+ return "Strings sound alike";
+ }
+ }
+
+ static class StringNotSoundsLikeEvaluator extends BaseEvaluator {
+
+ private static final long serialVersionUID = 400L;
+ public final static Evaluator INSTANCE = new StringNotSoundsLikeEvaluator();
+
+ private StringNotSoundsLikeEvaluator() {
+ super( ValueType.STRING_TYPE,
+ NOT_SOUNDSLIKE );
+ }
+
+ public boolean evaluate(InternalWorkingMemory workingMemory,
+ final Extractor extractor,
+ final Object object1, final FieldValue object2) {
+ final String value1 = (String) extractor.getValue( workingMemory, object1 );
+ final String value2 = (String) object2.getValue();
+ if ( value1 == null ) {
+ return false;
+ }
+
+ return ! Soundex.soundex( value1 ).equals( Soundex.soundex(value2) );
+ }
+
+ public boolean evaluateCachedRight(InternalWorkingMemory workingMemory,
+ final VariableContextEntry context, final Object left) {
+ final String value = (String) ((ObjectVariableContextEntry) context).right;
+ if ( value == null ) {
+ return false;
+ }
+ return ! Soundex.soundex( value ).equals( Soundex.soundex((String) context.declaration.getExtractor().getValue( workingMemory, left )) );
+ }
+
+ public boolean evaluateCachedLeft(InternalWorkingMemory workingMemory,
+ final VariableContextEntry context, final Object right) {
+ final String value = (String) context.extractor.getValue( workingMemory, right );
+ if ( value == null ) {
+ return false;
+ }
+ return ! Soundex.soundex(value).equals( Soundex.soundex((String) ((ObjectVariableContextEntry) context).left ));
+ }
+
+ public boolean evaluate(InternalWorkingMemory workingMemory,
+ final Extractor extractor1,
+ final Object object1,
+ final Extractor extractor2, final Object object2) {
+ final Object value1 = extractor1.getValue( workingMemory, object1 );
+ final Object value2 = extractor2.getValue( workingMemory, object2 );
+ if ( value1 == null ) {
+ return false;
+ }
+ return ! Soundex.soundex( ((String) value1)).equals( Soundex.soundex( (String) value2 ));
+ }
+
+ public String toString() {
+ return "Strings not sound alike";
+ }
+ }
+
+
+}
Deleted: labs/jbossrules/branches/temporal_rete/drools-core/src/main/java/org/drools/base/evaluators/StringFactory.java
===================================================================
--- labs/jbossrules/branches/temporal_rete/drools-core/src/main/java/org/drools/base/evaluators/StringFactory.java 2007-12-07 13:39:06 UTC (rev 17088)
+++ labs/jbossrules/branches/temporal_rete/drools-core/src/main/java/org/drools/base/evaluators/StringFactory.java 2007-12-07 14:10:27 UTC (rev 17089)
@@ -1,395 +0,0 @@
-package org.drools.base.evaluators;
-
-/*
- * Copyright 2005 JBoss Inc
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-import org.drools.base.BaseEvaluator;
-import org.drools.base.ValueType;
-import org.drools.common.InternalWorkingMemory;
-import org.drools.rule.VariableRestriction.ObjectVariableContextEntry;
-import org.drools.rule.VariableRestriction.VariableContextEntry;
-import org.drools.spi.Evaluator;
-import org.drools.spi.Extractor;
-import org.drools.spi.FieldValue;
-import org.mvel.Soundex;
-
-/**
- * This is the misc "bucket" evaluator factory for objects.
- * It is fairly limited in operations,
- * and what operations are available are dependent on the exact type.
- *
- * @author Michael Neale
- */
-public class StringFactory
- implements
- EvaluatorFactory {
-
- private static final long serialVersionUID = 400L;
- private static EvaluatorFactory INSTANCE = new StringFactory();
-
- private StringFactory() {
-
- }
-
- public static EvaluatorFactory getInstance() {
- if ( StringFactory.INSTANCE == null ) {
- StringFactory.INSTANCE = new StringFactory();
- }
- return StringFactory.INSTANCE;
- }
-
- public Evaluator getEvaluator(final Operator operator) {
- if ( operator == Operator.EQUAL ) {
- return StringEqualEvaluator.INSTANCE;
- } else if ( operator == Operator.NOT_EQUAL ) {
- return StringNotEqualEvaluator.INSTANCE;
- } else if ( operator == Operator.MATCHES ) {
- return StringMatchesEvaluator.INSTANCE;
- } else if ( operator == Operator.NOT_MATCHES ) {
- return StringNotMatchesEvaluator.INSTANCE;
- } else if ( operator == Operator.MEMBEROF ) {
- return StringMemberOfEvaluator.INSTANCE;
- } else if ( operator == Operator.NOTMEMBEROF ) {
- return StringNotMemberOfEvaluator.INSTANCE;
- } else if (operator == Operator.SOUNDSLIKE ){
- return StringSoundsLikeEvaluator.INSTANCE;
- } else {
- throw new RuntimeException( "Operator '" + operator + "' does not exist for StringEvaluator" );
- }
- }
-
- static class StringEqualEvaluator extends BaseEvaluator {
- /**
- *
- */
- private static final long serialVersionUID = 400L;
- public final static Evaluator INSTANCE = new StringEqualEvaluator();
-
- private StringEqualEvaluator() {
- super( ValueType.STRING_TYPE,
- Operator.EQUAL );
- }
-
- public boolean evaluate(InternalWorkingMemory workingMemory,
- final Extractor extractor,
- final Object object1, final FieldValue object2) {
- final Object value1 = extractor.getValue( workingMemory, object1 );
- final Object value2 = object2.getValue();
- if ( value1 == null ) {
- return value2 == null;
- }
- return value1.equals( value2 );
- }
-
- public boolean evaluateCachedRight(InternalWorkingMemory workingMemory,
- final VariableContextEntry context, final Object left) {
- final Object value = context.declaration.getExtractor().getValue( workingMemory, left );
- if ( value == null ) {
- return ((ObjectVariableContextEntry) context).right == null;
- }
- return value.equals( ((ObjectVariableContextEntry) context).right );
- }
-
- public boolean evaluateCachedLeft(InternalWorkingMemory workingMemory,
- final VariableContextEntry context, final Object right) {
- final Object value = context.extractor.getValue( workingMemory, right );
- if ( ((ObjectVariableContextEntry) context).left == null ) {
- return value == null;
- }
- return ((ObjectVariableContextEntry) context).left.equals( value );
- }
-
- public boolean evaluate(InternalWorkingMemory workingMemory,
- final Extractor extractor1,
- final Object object1,
- final Extractor extractor2, final Object object2) {
- final Object value1 = extractor1.getValue( workingMemory, object1 );
- final Object value2 = extractor2.getValue( workingMemory, object2 );
- if ( value1 == null ) {
- return value2 == null;
- }
- return value1.equals( value2 );
- }
-
- public String toString() {
- return "String ==";
- }
-
- }
-
- static class StringNotEqualEvaluator extends BaseEvaluator {
- /**
- *
- */
- private static final long serialVersionUID = 400L;
- public final static Evaluator INSTANCE = new StringNotEqualEvaluator();
-
- private StringNotEqualEvaluator() {
- super( ValueType.STRING_TYPE,
- Operator.NOT_EQUAL );
- }
-
- public boolean evaluate(InternalWorkingMemory workingMemory,
- final Extractor extractor,
- final Object object1, final FieldValue object2) {
- final Object value1 = extractor.getValue( workingMemory, object1 );
- final Object value2 = object2.getValue();
- if ( value1 == null ) {
- return value2 != null;
- }
- return !value1.equals( value2 );
- }
-
- public boolean evaluateCachedRight(InternalWorkingMemory workingMemory,
- final VariableContextEntry context, final Object left) {
- final Object value = context.declaration.getExtractor().getValue( workingMemory, left );
- if ( value == null ) {
- return ((ObjectVariableContextEntry) context).right != null;
- }
- return !value.equals( ((ObjectVariableContextEntry) context).right );
- }
-
- public boolean evaluateCachedLeft(InternalWorkingMemory workingMemory,
- final VariableContextEntry context, final Object right) {
- final Object value = context.extractor.getValue( workingMemory, right );
- if ( ((ObjectVariableContextEntry) context).left == null ) {
- return value != null;
- }
- return !((ObjectVariableContextEntry) context).left.equals( value );
- }
-
- public boolean evaluate(InternalWorkingMemory workingMemory,
- final Extractor extractor1,
- final Object object1,
- final Extractor extractor2, final Object object2) {
- final Object value1 = extractor1.getValue( workingMemory, object1 );
- final Object value2 = extractor2.getValue( workingMemory, object2 );
- if ( value1 == null ) {
- return value2 != null;
- }
- return !value1.equals( value2 );
- }
-
- public String toString() {
- return "String !=";
- }
- }
-
- static class StringMatchesEvaluator extends BaseEvaluator {
- /**
- *
- */
- private static final long serialVersionUID = 400L;
- public final static Evaluator INSTANCE = new StringMatchesEvaluator();
-
- private StringMatchesEvaluator() {
- super( ValueType.STRING_TYPE,
- Operator.MATCHES );
- }
-
- public boolean evaluate(InternalWorkingMemory workingMemory,
- final Extractor extractor,
- final Object object1, final FieldValue object2) {
- final String value1 = (String) extractor.getValue( workingMemory, object1 );
- final String value2 = (String) object2.getValue();
- if ( value1 == null ) {
- return false;
- }
- return value1.matches( value2 );
- }
-
- public boolean evaluateCachedRight(InternalWorkingMemory workingMemory,
- final VariableContextEntry context, final Object left) {
- final String value = (String) ((ObjectVariableContextEntry) context).right;
- if ( value == null ) {
- return false;
- }
- return value.matches( (String) context.declaration.getExtractor().getValue( workingMemory, left ) );
- }
-
- public boolean evaluateCachedLeft(InternalWorkingMemory workingMemory,
- final VariableContextEntry context, final Object right) {
- final String value = (String) context.extractor.getValue( workingMemory, right );
- if ( value == null ) {
- return false;
- }
- return value.matches( (String) ((ObjectVariableContextEntry) context).left );
- }
-
- public boolean evaluate(InternalWorkingMemory workingMemory,
- final Extractor extractor1,
- final Object object1,
- final Extractor extractor2, final Object object2) {
- final Object value1 = extractor1.getValue( workingMemory, object1 );
- final Object value2 = extractor2.getValue( workingMemory, object2 );
- if ( value1 == null ) {
- return false;
- }
- return ((String) value1).matches( (String) value2 );
- }
-
- public String toString() {
- return "String matches";
- }
- }
-
- static class StringNotMatchesEvaluator extends BaseEvaluator {
- /**
- *
- */
- private static final long serialVersionUID = 400L;
- public final static Evaluator INSTANCE = new StringNotMatchesEvaluator();
-
- private StringNotMatchesEvaluator() {
- super( ValueType.STRING_TYPE,
- Operator.NOT_MATCHES );
- }
-
- public boolean evaluate(InternalWorkingMemory workingMemory,
- final Extractor extractor,
- final Object object1, final FieldValue object2) {
- final String value1 = (String) extractor.getValue( workingMemory, object1 );
- final String value2 = (String) object2.getValue();
- if ( value1 == null ) {
- return false;
- }
- return ! value1.matches( value2 );
- }
-
- public boolean evaluateCachedRight(InternalWorkingMemory workingMemory,
- final VariableContextEntry context, final Object left) {
- final String value = (String) ((ObjectVariableContextEntry) context).right;
- if ( value == null ) {
- return false;
- }
- return ! value.matches( (String) context.declaration.getExtractor().getValue( workingMemory, left ) );
- }
-
- public boolean evaluateCachedLeft(InternalWorkingMemory workingMemory,
- final VariableContextEntry context, final Object right) {
- final String value = (String) context.extractor.getValue( workingMemory, right );
- if ( value == null ) {
- return false;
- }
- return ! value.matches( (String) ((ObjectVariableContextEntry) context).left );
- }
-
- public boolean evaluate(InternalWorkingMemory workingMemory,
- final Extractor extractor1,
- final Object object1,
- final Extractor extractor2, final Object object2) {
- final Object value1 = extractor1.getValue( workingMemory, object1 );
- final Object value2 = extractor2.getValue( workingMemory, object2 );
- if ( value1 == null ) {
- return false;
- }
- return ! ((String) value1).matches( (String) value2 );
- }
-
- public String toString() {
- return "String not matches";
- }
- }
-
- static class StringMemberOfEvaluator extends BaseMemberOfEvaluator {
-
- private static final long serialVersionUID = 400L;
- public final static Evaluator INSTANCE = new StringMemberOfEvaluator();
-
- private StringMemberOfEvaluator() {
- super( ValueType.STRING_TYPE,
- Operator.MEMBEROF );
- }
-
- public String toString() {
- return "String memberOf";
- }
- }
-
- static class StringNotMemberOfEvaluator extends BaseNotMemberOfEvaluator {
-
- private static final long serialVersionUID = 400L;
- public final static Evaluator INSTANCE = new StringNotMemberOfEvaluator();
-
- private StringNotMemberOfEvaluator() {
- super( ValueType.STRING_TYPE,
- Operator.NOTMEMBEROF );
- }
-
- public String toString() {
- return "String not memberOf";
- }
- }
-
- static class StringSoundsLikeEvaluator extends BaseEvaluator {
-
- private static final long serialVersionUID = 400L;
- public final static Evaluator INSTANCE = new StringSoundsLikeEvaluator();
-
- private StringSoundsLikeEvaluator() {
- super( ValueType.STRING_TYPE,
- Operator.SOUNDSLIKE );
- }
-
- public boolean evaluate(InternalWorkingMemory workingMemory,
- final Extractor extractor,
- final Object object1, final FieldValue object2) {
- final String value1 = (String) extractor.getValue( workingMemory, object1 );
- final String value2 = (String) object2.getValue();
- if ( value1 == null ) {
- return false;
- }
-
- return Soundex.soundex( value1 ).equals( Soundex.soundex(value2) );
- }
-
- public boolean evaluateCachedRight(InternalWorkingMemory workingMemory,
- final VariableContextEntry context, final Object left) {
- final String value = (String) ((ObjectVariableContextEntry) context).right;
- if ( value == null ) {
- return false;
- }
- return Soundex.soundex( value ).equals( Soundex.soundex((String) context.declaration.getExtractor().getValue( workingMemory, left )) );
- }
-
- public boolean evaluateCachedLeft(InternalWorkingMemory workingMemory,
- final VariableContextEntry context, final Object right) {
- final String value = (String) context.extractor.getValue( workingMemory, right );
- if ( value == null ) {
- return false;
- }
- return Soundex.soundex(value).equals( Soundex.soundex((String) ((ObjectVariableContextEntry) context).left ));
- }
-
- public boolean evaluate(InternalWorkingMemory workingMemory,
- final Extractor extractor1,
- final Object object1,
- final Extractor extractor2, final Object object2) {
- final Object value1 = extractor1.getValue( workingMemory, object1 );
- final Object value2 = extractor2.getValue( workingMemory, object2 );
- if ( value1 == null ) {
- return false;
- }
- return Soundex.soundex( ((String) value1)).equals( Soundex.soundex( (String) value2 ));
- }
-
- public String toString() {
- return "Strings sound alike";
- }
- }
-
-
-}
\ No newline at end of file
Modified: labs/jbossrules/branches/temporal_rete/drools-core/src/main/java/org/drools/base/mvel/MVELCalendarCoercion.java
===================================================================
--- labs/jbossrules/branches/temporal_rete/drools-core/src/main/java/org/drools/base/mvel/MVELCalendarCoercion.java 2007-12-07 13:39:06 UTC (rev 17088)
+++ labs/jbossrules/branches/temporal_rete/drools-core/src/main/java/org/drools/base/mvel/MVELCalendarCoercion.java 2007-12-07 14:10:27 UTC (rev 17089)
@@ -2,7 +2,7 @@
import java.util.Calendar;
-import org.drools.base.evaluators.DateFactory;
+import org.drools.util.DateUtils;
import org.mvel.ConversionHandler;
public class MVELCalendarCoercion implements ConversionHandler {
@@ -18,7 +18,7 @@
public Object convertFrom(Object o) {
if (o instanceof String) {
Calendar cal = Calendar.getInstance();
- cal.setTime( DateFactory.parseDate( (String) o) );
+ cal.setTime( DateUtils.parseDate( (String) o) );
return cal;
} else {
return o;
Modified: labs/jbossrules/branches/temporal_rete/drools-core/src/main/java/org/drools/base/mvel/MVELDateCoercion.java
===================================================================
--- labs/jbossrules/branches/temporal_rete/drools-core/src/main/java/org/drools/base/mvel/MVELDateCoercion.java 2007-12-07 13:39:06 UTC (rev 17088)
+++ labs/jbossrules/branches/temporal_rete/drools-core/src/main/java/org/drools/base/mvel/MVELDateCoercion.java 2007-12-07 14:10:27 UTC (rev 17089)
@@ -2,7 +2,7 @@
import java.util.Date;
-import org.drools.base.evaluators.DateFactory;
+import org.drools.util.DateUtils;
import org.mvel.ConversionHandler;
public class MVELDateCoercion implements ConversionHandler {
@@ -17,7 +17,7 @@
public Object convertFrom(Object o) {
if (o instanceof String) {
- return DateFactory.parseDate( (String) o);
+ return DateUtils.parseDate( (String) o);
} else {
return o;
}
Modified: labs/jbossrules/branches/temporal_rete/drools-core/src/main/java/org/drools/common/BetaConstraints.java
===================================================================
--- labs/jbossrules/branches/temporal_rete/drools-core/src/main/java/org/drools/common/BetaConstraints.java 2007-12-07 13:39:06 UTC (rev 17088)
+++ labs/jbossrules/branches/temporal_rete/drools-core/src/main/java/org/drools/common/BetaConstraints.java 2007-12-07 14:10:27 UTC (rev 17089)
@@ -17,7 +17,7 @@
public void updateFromFactHandle(InternalWorkingMemory workingMemory,
InternalFactHandle handle);
- public boolean isAllowedCachedLeft(Object object);
+ public boolean isAllowedCachedLeft(InternalFactHandle handle);
public boolean isAllowedCachedRight(ReteTuple tuple);
Modified: labs/jbossrules/branches/temporal_rete/drools-core/src/main/java/org/drools/common/DefaultBetaConstraints.java
===================================================================
--- labs/jbossrules/branches/temporal_rete/drools-core/src/main/java/org/drools/common/DefaultBetaConstraints.java 2007-12-07 13:39:06 UTC (rev 17088)
+++ labs/jbossrules/branches/temporal_rete/drools-core/src/main/java/org/drools/common/DefaultBetaConstraints.java 2007-12-07 14:10:27 UTC (rev 17089)
@@ -30,11 +30,9 @@
import org.drools.rule.VariableConstraint;
import org.drools.spi.BetaNodeFieldConstraint;
import org.drools.spi.Constraint;
-import org.drools.util.Entry;
-import org.drools.util.FactHashTable;
import org.drools.util.FactHandleIndexHashTable;
+import org.drools.util.FactHashTable;
import org.drools.util.FactList;
-import org.drools.util.Iterator;
import org.drools.util.LinkedList;
import org.drools.util.LinkedListEntry;
import org.drools.util.TupleHashTable;
@@ -155,14 +153,14 @@
/* (non-Javadoc)
* @see org.drools.common.BetaNodeConstraints#isAllowedCachedLeft(java.lang.Object)
*/
- public boolean isAllowedCachedLeft(final Object object) {
+ public boolean isAllowedCachedLeft(final InternalFactHandle handle) {
// skip the indexed constraints
LinkedListEntry entry = (LinkedListEntry) findNode( this.indexed );
ContextEntry context = findContext( this.indexed );
while ( entry != null ) {
if ( !((BetaNodeFieldConstraint) entry.getObject()).isAllowedCachedLeft( context,
- object ) ) {
+ handle ) ) {
return false;
}
entry = (LinkedListEntry) entry.getNext();
Modified: labs/jbossrules/branches/temporal_rete/drools-core/src/main/java/org/drools/common/DoubleBetaConstraints.java
===================================================================
--- labs/jbossrules/branches/temporal_rete/drools-core/src/main/java/org/drools/common/DoubleBetaConstraints.java 2007-12-07 13:39:06 UTC (rev 17088)
+++ labs/jbossrules/branches/temporal_rete/drools-core/src/main/java/org/drools/common/DoubleBetaConstraints.java 2007-12-07 14:10:27 UTC (rev 17089)
@@ -29,8 +29,8 @@
import org.drools.rule.ContextEntry;
import org.drools.rule.VariableConstraint;
import org.drools.spi.BetaNodeFieldConstraint;
+import org.drools.util.FactHandleIndexHashTable;
import org.drools.util.FactHashTable;
-import org.drools.util.FactHandleIndexHashTable;
import org.drools.util.FactList;
import org.drools.util.LinkedList;
import org.drools.util.LinkedListEntry;
@@ -67,7 +67,7 @@
public DoubleBetaConstraints(final BetaNodeFieldConstraint[] constraints,
final RuleBaseConfiguration conf,
final boolean disableIndexing) {
- if ( disableIndexing || ( !conf.isIndexLeftBetaMemory() && !conf.isIndexRightBetaMemory() ) ) {
+ if ( disableIndexing || (!conf.isIndexLeftBetaMemory() && !conf.isIndexRightBetaMemory()) ) {
this.indexed0 = false;
this.indexed1 = false;
} else {
@@ -115,7 +115,7 @@
} else {
return false;
}
- }
+ }
/* (non-Javadoc)
* @see org.drools.common.BetaNodeConstraints#updateFromTuple(org.drools.reteoo.ReteTuple)
@@ -142,10 +142,10 @@
/* (non-Javadoc)
* @see org.drools.common.BetaNodeConstraints#isAllowedCachedLeft(java.lang.Object)
*/
- public boolean isAllowedCachedLeft(final Object object) {
+ public boolean isAllowedCachedLeft(final InternalFactHandle handle) {
return (this.indexed0 || this.constraint0.isAllowedCachedLeft( this.context0,
- object )) && (this.indexed1 || this.constraint1.isAllowedCachedLeft( this.context1,
- object ));
+ handle )) && (this.indexed1 || this.constraint1.isAllowedCachedLeft( this.context1,
+ handle ));
}
/* (non-Javadoc)
@@ -160,7 +160,7 @@
public boolean isIndexed() {
return this.indexed0;
}
-
+
public int getIndexCount() {
int count = 0;
if ( this.indexed0 ) {
@@ -168,9 +168,9 @@
}
if ( this.indexed1 ) {
count++;
- }
- return count;
- }
+ }
+ return count;
+ }
public boolean isEmpty() {
return false;
Modified: labs/jbossrules/branches/temporal_rete/drools-core/src/main/java/org/drools/common/EmptyBetaConstraints.java
===================================================================
--- labs/jbossrules/branches/temporal_rete/drools-core/src/main/java/org/drools/common/EmptyBetaConstraints.java 2007-12-07 13:39:06 UTC (rev 17088)
+++ labs/jbossrules/branches/temporal_rete/drools-core/src/main/java/org/drools/common/EmptyBetaConstraints.java 2007-12-07 14:10:27 UTC (rev 17089)
@@ -63,7 +63,7 @@
/* (non-Javadoc)
* @see org.drools.common.BetaNodeConstraints#isAllowedCachedLeft(java.lang.Object)
*/
- public boolean isAllowedCachedLeft(final Object object) {
+ public boolean isAllowedCachedLeft(final InternalFactHandle handle) {
return true;
}
Modified: labs/jbossrules/branches/temporal_rete/drools-core/src/main/java/org/drools/common/InstanceEqualsConstraint.java
===================================================================
--- labs/jbossrules/branches/temporal_rete/drools-core/src/main/java/org/drools/common/InstanceEqualsConstraint.java 2007-12-07 13:39:06 UTC (rev 17088)
+++ labs/jbossrules/branches/temporal_rete/drools-core/src/main/java/org/drools/common/InstanceEqualsConstraint.java 2007-12-07 14:10:27 UTC (rev 17089)
@@ -62,8 +62,8 @@
}
public boolean isAllowedCachedLeft(final ContextEntry context,
- final Object object) {
- return ((InstanceEqualsConstraintContextEntry) context).left == object;
+ final InternalFactHandle handle) {
+ return ((InstanceEqualsConstraintContextEntry) context).left == handle.getObject();
}
public boolean isAllowedCachedRight(final ReteTuple tuple,
Modified: labs/jbossrules/branches/temporal_rete/drools-core/src/main/java/org/drools/common/InstanceNotEqualsConstraint.java
===================================================================
--- labs/jbossrules/branches/temporal_rete/drools-core/src/main/java/org/drools/common/InstanceNotEqualsConstraint.java 2007-12-07 13:39:06 UTC (rev 17088)
+++ labs/jbossrules/branches/temporal_rete/drools-core/src/main/java/org/drools/common/InstanceNotEqualsConstraint.java 2007-12-07 14:10:27 UTC (rev 17089)
@@ -58,8 +58,8 @@
}
public boolean isAllowedCachedLeft(final ContextEntry context,
- final Object object) {
- return ((InstanceNotEqualsConstraintContextEntry) context).left != object;
+ final InternalFactHandle handle) {
+ return ((InstanceNotEqualsConstraintContextEntry) context).left != handle.getObject();
}
public boolean isAllowedCachedRight(final ReteTuple tuple,
Modified: labs/jbossrules/branches/temporal_rete/drools-core/src/main/java/org/drools/common/QuadroupleBetaConstraints.java
===================================================================
--- labs/jbossrules/branches/temporal_rete/drools-core/src/main/java/org/drools/common/QuadroupleBetaConstraints.java 2007-12-07 13:39:06 UTC (rev 17088)
+++ labs/jbossrules/branches/temporal_rete/drools-core/src/main/java/org/drools/common/QuadroupleBetaConstraints.java 2007-12-07 14:10:27 UTC (rev 17089)
@@ -29,8 +29,8 @@
import org.drools.rule.ContextEntry;
import org.drools.rule.VariableConstraint;
import org.drools.spi.BetaNodeFieldConstraint;
+import org.drools.util.FactHandleIndexHashTable;
import org.drools.util.FactHashTable;
-import org.drools.util.FactHandleIndexHashTable;
import org.drools.util.FactList;
import org.drools.util.LinkedList;
import org.drools.util.LinkedListEntry;
@@ -203,18 +203,18 @@
/* (non-Javadoc)
* @see org.drools.common.BetaNodeConstraints#isAllowedCachedLeft(java.lang.Object)
*/
- public boolean isAllowedCachedLeft(final Object object) {
+ public boolean isAllowedCachedLeft(final InternalFactHandle handle) {
// return ( this.indexed0 || this.constraint0.isAllowedCachedLeft( context0,
// object ) ) && this.constraint1.isAllowedCachedLeft( context1,
// object ) && this.constraint2.isAllowedCachedLeft( context2,
// object );
return (this.indexed0 || this.constraint0.isAllowedCachedLeft( this.context0,
- object )) && (this.indexed1 || this.constraint1.isAllowedCachedLeft( this.context1,
- object )) && (this.indexed2 || this.constraint2.isAllowedCachedLeft( this.context2,
- object ))
+ handle )) && (this.indexed1 || this.constraint1.isAllowedCachedLeft( this.context1,
+ handle )) && (this.indexed2 || this.constraint2.isAllowedCachedLeft( this.context2,
+ handle ))
&& (this.indexed3 || this.constraint3.isAllowedCachedLeft( this.context3,
- object ));
+ handle ));
}
/* (non-Javadoc)
Modified: labs/jbossrules/branches/temporal_rete/drools-core/src/main/java/org/drools/common/SingleBetaConstraints.java
===================================================================
--- labs/jbossrules/branches/temporal_rete/drools-core/src/main/java/org/drools/common/SingleBetaConstraints.java 2007-12-07 13:39:06 UTC (rev 17088)
+++ labs/jbossrules/branches/temporal_rete/drools-core/src/main/java/org/drools/common/SingleBetaConstraints.java 2007-12-07 14:10:27 UTC (rev 17089)
@@ -113,9 +113,9 @@
/* (non-Javadoc)
* @see org.drools.common.BetaNodeConstraints#isAllowedCachedLeft(java.lang.Object)
*/
- public boolean isAllowedCachedLeft(final Object object) {
+ public boolean isAllowedCachedLeft(final InternalFactHandle handle) {
return this.indexed || this.constraint.isAllowedCachedLeft( this.context,
- object );
+ handle );
}
/* (non-Javadoc)
Modified: labs/jbossrules/branches/temporal_rete/drools-core/src/main/java/org/drools/common/TripleBetaConstraints.java
===================================================================
--- labs/jbossrules/branches/temporal_rete/drools-core/src/main/java/org/drools/common/TripleBetaConstraints.java 2007-12-07 13:39:06 UTC (rev 17088)
+++ labs/jbossrules/branches/temporal_rete/drools-core/src/main/java/org/drools/common/TripleBetaConstraints.java 2007-12-07 14:10:27 UTC (rev 17089)
@@ -169,16 +169,16 @@
/* (non-Javadoc)
* @see org.drools.common.BetaNodeConstraints#isAllowedCachedLeft(java.lang.Object)
*/
- public boolean isAllowedCachedLeft(final Object object) {
+ public boolean isAllowedCachedLeft(final InternalFactHandle handle) {
// return ( this.indexed0 || this.constraint0.isAllowedCachedLeft( context0,
// object ) ) && this.constraint1.isAllowedCachedLeft( context1,
// object ) && this.constraint2.isAllowedCachedLeft( context2,
// object );
return (this.indexed0 || this.constraint0.isAllowedCachedLeft( this.context0,
- object )) && (this.indexed1 || this.constraint1.isAllowedCachedLeft( this.context1,
- object )) && (this.indexed2 || this.constraint2.isAllowedCachedLeft( this.context2,
- object ));
+ handle )) && (this.indexed1 || this.constraint1.isAllowedCachedLeft( this.context1,
+ handle )) && (this.indexed2 || this.constraint2.isAllowedCachedLeft( this.context2,
+ handle ));
}
/* (non-Javadoc)
@@ -194,7 +194,7 @@
public boolean isIndexed() {
return this.indexed0;
}
-
+
public int getIndexCount() {
int count = 0;
if ( this.indexed0 ) {
@@ -205,9 +205,9 @@
}
if ( this.indexed2 ) {
count++;
- }
- return count;
- }
+ }
+ return count;
+ }
public boolean isEmpty() {
return false;
Modified: labs/jbossrules/branches/temporal_rete/drools-core/src/main/java/org/drools/common/TupleStartEqualsConstraint.java
===================================================================
--- labs/jbossrules/branches/temporal_rete/drools-core/src/main/java/org/drools/common/TupleStartEqualsConstraint.java 2007-12-07 13:39:06 UTC (rev 17088)
+++ labs/jbossrules/branches/temporal_rete/drools-core/src/main/java/org/drools/common/TupleStartEqualsConstraint.java 2007-12-07 14:10:27 UTC (rev 17089)
@@ -74,9 +74,9 @@
}
public boolean isAllowedCachedLeft(final ContextEntry context,
- final Object object) {
+ final InternalFactHandle handle) {
// object MUST be a ReteTuple
- final ReteTuple tuple = ((ReteTuple) object).getSubTuple( ((TupleStartEqualsConstraintContextEntry) context).compareSize );
+ final ReteTuple tuple = ((ReteTuple) handle.getObject()).getSubTuple( ((TupleStartEqualsConstraintContextEntry) context).compareSize );
return ((TupleStartEqualsConstraintContextEntry) context).left.equals( tuple );
}
Modified: labs/jbossrules/branches/temporal_rete/drools-core/src/main/java/org/drools/reteoo/AccumulateNode.java
===================================================================
--- labs/jbossrules/branches/temporal_rete/drools-core/src/main/java/org/drools/reteoo/AccumulateNode.java 2007-12-07 13:39:06 UTC (rev 17088)
+++ labs/jbossrules/branches/temporal_rete/drools-core/src/main/java/org/drools/reteoo/AccumulateNode.java 2007-12-07 14:10:27 UTC (rev 17089)
@@ -119,7 +119,7 @@
for ( FactEntry entry = (FactEntry) it.next(); entry != null; entry = (FactEntry) it.next() ) {
InternalFactHandle handle = entry.getFactHandle();
- if ( this.constraints.isAllowedCachedLeft( handle.getObject() ) ) {
+ if ( this.constraints.isAllowedCachedLeft( handle ) ) {
if ( this.unwrapRightObject ) {
// if there is a subnetwork, handle must be unwrapped
ReteTuple tuple = (ReteTuple) handle.getObject();
@@ -150,8 +150,10 @@
// First alpha node filters
boolean isAllowed = true;
+ final InternalFactHandle handle = workingMemory.getFactHandleFactory().newFactHandle( result, false, workingMemory ); // so far, result is not an event
+
for ( int i = 0, length = this.resultConstraints.length; i < length; i++ ) {
- if ( !this.resultConstraints[i].isAllowed( result,
+ if ( !this.resultConstraints[i].isAllowed( handle,
workingMemory ) ) {
isAllowed = false;
break;
@@ -160,15 +162,18 @@
if ( isAllowed ) {
this.resultBinder.updateFromTuple( workingMemory,
leftTuple );
- if ( this.resultBinder.isAllowedCachedLeft( result ) ) {
- final InternalFactHandle handle = workingMemory.getFactHandleFactory().newFactHandle( result, false, workingMemory ); // so far, result is not an event
+ if ( this.resultBinder.isAllowedCachedLeft( handle ) ) {
accresult.handle = handle;
this.sink.propagateAssertTuple( leftTuple,
handle,
context,
workingMemory );
+ } else {
+ workingMemory.getFactHandleFactory().destroyFactHandle( handle );
}
+ } else {
+ workingMemory.getFactHandleFactory().destroyFactHandle( handle );
}
}
@@ -368,8 +373,9 @@
// First alpha node filters
boolean isAllowed = true;
+ final InternalFactHandle createdHandle = workingMemory.getFactHandleFactory().newFactHandle( result, false, workingMemory ); // so far, result is not an event
for ( int i = 0, length = this.resultConstraints.length; i < length; i++ ) {
- if ( !this.resultConstraints[i].isAllowed( result,
+ if ( !this.resultConstraints[i].isAllowed( createdHandle,
workingMemory ) ) {
isAllowed = false;
break;
@@ -378,15 +384,18 @@
if ( isAllowed ) {
this.resultBinder.updateFromTuple( workingMemory,
leftTuple );
- if ( this.resultBinder.isAllowedCachedLeft( result ) ) {
- final InternalFactHandle createdHandle = workingMemory.getFactHandleFactory().newFactHandle( result, false, workingMemory ); // so far, result is not an event
+ if ( this.resultBinder.isAllowedCachedLeft( createdHandle ) ) {
accresult.handle = createdHandle;
this.sink.propagateAssertTuple( leftTuple,
createdHandle,
context,
workingMemory );
+ } else {
+ workingMemory.getFactHandleFactory().destroyFactHandle( createdHandle );
}
+ } else {
+ workingMemory.getFactHandleFactory().destroyFactHandle( createdHandle );
}
}
Modified: labs/jbossrules/branches/temporal_rete/drools-core/src/main/java/org/drools/reteoo/AlphaNode.java
===================================================================
--- labs/jbossrules/branches/temporal_rete/drools-core/src/main/java/org/drools/reteoo/AlphaNode.java 2007-12-07 13:39:06 UTC (rev 17088)
+++ labs/jbossrules/branches/temporal_rete/drools-core/src/main/java/org/drools/reteoo/AlphaNode.java 2007-12-07 14:10:27 UTC (rev 17089)
@@ -129,7 +129,7 @@
public void assertObject(final InternalFactHandle handle,
final PropagationContext context,
final InternalWorkingMemory workingMemory) throws FactException {
- if ( this.constraint.isAllowed( handle.getObject(),
+ if ( this.constraint.isAllowed( handle,
workingMemory ) ) {
if ( isObjectMemoryEnabled() ) {
final FactHashTable memory = (FactHashTable) workingMemory.getNodeMemory( this );
@@ -151,7 +151,7 @@
final FactHashTable memory = (FactHashTable) workingMemory.getNodeMemory( this );
propagate = memory.remove( handle );
} else {
- propagate = this.constraint.isAllowed( handle.getObject(),
+ propagate = this.constraint.isAllowed( handle,
workingMemory );
}
if ( propagate ) {
@@ -311,7 +311,7 @@
public void assertObject(final InternalFactHandle handle,
final PropagationContext context,
final InternalWorkingMemory workingMemory) {
- if ( this.constraint.isAllowed( handle.getObject(),
+ if ( this.constraint.isAllowed( handle,
workingMemory ) ) {
this.sink.assertObject( handle,
context,
Modified: labs/jbossrules/branches/temporal_rete/drools-core/src/main/java/org/drools/reteoo/CollectNode.java
===================================================================
--- labs/jbossrules/branches/temporal_rete/drools-core/src/main/java/org/drools/reteoo/CollectNode.java 2007-12-07 13:39:06 UTC (rev 17088)
+++ labs/jbossrules/branches/temporal_rete/drools-core/src/main/java/org/drools/reteoo/CollectNode.java 2007-12-07 14:10:27 UTC (rev 17089)
@@ -20,7 +20,6 @@
import java.util.Collection;
import org.drools.common.BetaConstraints;
-import org.drools.common.EmptyBetaConstraints;
import org.drools.common.InternalFactHandle;
import org.drools.common.InternalWorkingMemory;
import org.drools.reteoo.builder.BuildContext;
@@ -127,7 +126,7 @@
for ( FactEntry entry = (FactEntry) it.next(); entry != null; entry = (FactEntry) it.next() ) {
InternalFactHandle handle = entry.getFactHandle();
- if ( this.constraints.isAllowedCachedLeft( handle.getObject() ) ) {
+ if ( this.constraints.isAllowedCachedLeft( handle ) ) {
if( this.unwrapRightObject ) {
handle = ((ReteTuple) handle.getObject()).getLastHandle();
}
@@ -138,7 +137,7 @@
// First alpha node filters
boolean isAllowed = true;
for ( int i = 0, length = this.resultConstraints.length; i < length; i++ ) {
- if ( !this.resultConstraints[i].isAllowed( result,
+ if ( !this.resultConstraints[i].isAllowed( resultHandle,
workingMemory ) ) {
isAllowed = false;
break;
@@ -147,7 +146,7 @@
if ( isAllowed ) {
this.resultsBinder.updateFromTuple( workingMemory,
leftTuple );
- if ( this.resultsBinder.isAllowedCachedLeft( result ) ) {
+ if ( this.resultsBinder.isAllowedCachedLeft( resultHandle ) ) {
colresult.propagated = true;
this.sink.propagateAssertTuple( leftTuple,
resultHandle,
@@ -301,7 +300,7 @@
// First alpha node filters
boolean isAllowed = true;
for ( int i = 0, length = this.resultConstraints.length; i < length; i++ ) {
- if ( !this.resultConstraints[i].isAllowed( result.handle.getObject(),
+ if ( !this.resultConstraints[i].isAllowed( result.handle,
workingMemory ) ) {
isAllowed = false;
break;
@@ -310,7 +309,7 @@
if ( isAllowed ) {
this.resultsBinder.updateFromTuple( workingMemory,
leftTuple );
- if ( this.resultsBinder.isAllowedCachedLeft( result.handle.getObject() ) ) {
+ if ( this.resultsBinder.isAllowedCachedLeft( result.handle ) ) {
result.propagated = true;
this.sink.propagateAssertTuple( leftTuple,
result.handle,
Modified: labs/jbossrules/branches/temporal_rete/drools-core/src/main/java/org/drools/reteoo/ExistsNode.java
===================================================================
--- labs/jbossrules/branches/temporal_rete/drools-core/src/main/java/org/drools/reteoo/ExistsNode.java 2007-12-07 13:39:06 UTC (rev 17088)
+++ labs/jbossrules/branches/temporal_rete/drools-core/src/main/java/org/drools/reteoo/ExistsNode.java 2007-12-07 14:10:27 UTC (rev 17089)
@@ -17,7 +17,6 @@
package org.drools.reteoo;
import org.drools.common.BetaConstraints;
-import org.drools.common.EmptyBetaConstraints;
import org.drools.common.InternalFactHandle;
import org.drools.common.InternalWorkingMemory;
import org.drools.reteoo.builder.BuildContext;
@@ -102,7 +101,7 @@
int matches = 0;
for ( FactEntry entry = (FactEntry) it.next(); entry != null; entry = (FactEntry) it.next() ) {
final InternalFactHandle handle = entry.getFactHandle();
- if ( this.constraints.isAllowedCachedLeft( handle.getObject() ) ) {
+ if ( this.constraints.isAllowedCachedLeft( handle ) ) {
matches++;
}
}
Modified: labs/jbossrules/branches/temporal_rete/drools-core/src/main/java/org/drools/reteoo/FromNode.java
===================================================================
--- labs/jbossrules/branches/temporal_rete/drools-core/src/main/java/org/drools/reteoo/FromNode.java 2007-12-07 13:39:06 UTC (rev 17088)
+++ labs/jbossrules/branches/temporal_rete/drools-core/src/main/java/org/drools/reteoo/FromNode.java 2007-12-07 14:10:27 UTC (rev 17089)
@@ -66,31 +66,30 @@
context ); it.hasNext(); ) {
final Object object = it.next();
+ final InternalFactHandle handle = workingMemory.getFactHandleFactory().newFactHandle( object, false, workingMemory );
+
+ boolean isAllowed = true;
if ( this.alphaConstraints != null ) {
// First alpha node filters
- boolean isAllowed = true;
for ( int i = 0, length = this.alphaConstraints.length; i < length; i++ ) {
- if ( !this.alphaConstraints[i].isAllowed( object,
+ if ( !this.alphaConstraints[i].isAllowed( handle,
workingMemory ) ) {
// next iteration
isAllowed = false;
break;
}
}
- if ( !isAllowed ) {
- continue;
- }
}
- if ( this.betaConstraints.isAllowedCachedLeft( object ) ) {
- final InternalFactHandle handle = workingMemory.getFactHandleFactory().newFactHandle( object, false, workingMemory );
-
+ if ( isAllowed && this.betaConstraints.isAllowedCachedLeft( handle ) ) {
list.add( new LinkedListEntry( handle ) );
this.sink.propagateAssertTuple( leftTuple,
handle,
context,
workingMemory );
+ } else {
+ workingMemory.getFactHandleFactory().destroyFactHandle( handle );
}
}
if ( !list.isEmpty() ) {
Modified: labs/jbossrules/branches/temporal_rete/drools-core/src/main/java/org/drools/reteoo/JoinNode.java
===================================================================
--- labs/jbossrules/branches/temporal_rete/drools-core/src/main/java/org/drools/reteoo/JoinNode.java 2007-12-07 13:39:06 UTC (rev 17088)
+++ labs/jbossrules/branches/temporal_rete/drools-core/src/main/java/org/drools/reteoo/JoinNode.java 2007-12-07 14:10:27 UTC (rev 17089)
@@ -103,7 +103,7 @@
leftTuple );
for ( FactEntry entry = (FactEntry) it.next(); entry != null; entry = (FactEntry) it.next() ) {
final InternalFactHandle handle = entry.getFactHandle();
- if ( this.constraints.isAllowedCachedLeft( handle.getObject() ) ) {
+ if ( this.constraints.isAllowedCachedLeft( handle ) ) {
this.sink.propagateAssertTuple( leftTuple,
handle,
context,
@@ -212,7 +212,7 @@
leftTuple );
for ( FactEntry entry = (FactEntry) it.next(); entry != null; entry = (FactEntry) it.next() ) {
final InternalFactHandle handle = entry.getFactHandle();
- if ( this.constraints.isAllowedCachedLeft( handle.getObject() ) ) {
+ if ( this.constraints.isAllowedCachedLeft( handle ) ) {
this.sink.propagateRetractTuple( leftTuple,
handle,
context,
@@ -237,7 +237,7 @@
tuple );
for ( FactEntry entry = (FactEntry) objectIter.next(); entry != null; entry = (FactEntry) objectIter.next() ) {
final InternalFactHandle handle = entry.getFactHandle();
- if ( this.constraints.isAllowedCachedLeft( handle.getObject() ) ) {
+ if ( this.constraints.isAllowedCachedLeft( handle ) ) {
sink.assertTuple( new ReteTuple( tuple,
handle ),
context,
Modified: labs/jbossrules/branches/temporal_rete/drools-core/src/main/java/org/drools/reteoo/NotNode.java
===================================================================
--- labs/jbossrules/branches/temporal_rete/drools-core/src/main/java/org/drools/reteoo/NotNode.java 2007-12-07 13:39:06 UTC (rev 17088)
+++ labs/jbossrules/branches/temporal_rete/drools-core/src/main/java/org/drools/reteoo/NotNode.java 2007-12-07 14:10:27 UTC (rev 17089)
@@ -99,7 +99,7 @@
int matches = 0;
for ( FactEntry entry = (FactEntry) it.next(); entry != null; entry = (FactEntry) it.next() ) {
final InternalFactHandle handle = entry.getFactHandle();
- if ( this.constraints.isAllowedCachedLeft( handle.getObject() ) ) {
+ if ( this.constraints.isAllowedCachedLeft( handle ) ) {
matches++;
}
}
Modified: labs/jbossrules/branches/temporal_rete/drools-core/src/main/java/org/drools/rule/AndCompositeRestriction.java
===================================================================
--- labs/jbossrules/branches/temporal_rete/drools-core/src/main/java/org/drools/rule/AndCompositeRestriction.java 2007-12-07 13:39:06 UTC (rev 17088)
+++ labs/jbossrules/branches/temporal_rete/drools-core/src/main/java/org/drools/rule/AndCompositeRestriction.java 2007-12-07 14:10:27 UTC (rev 17089)
@@ -1,5 +1,6 @@
package org.drools.rule;
+import org.drools.common.InternalFactHandle;
import org.drools.common.InternalWorkingMemory;
import org.drools.reteoo.ReteTuple;
import org.drools.spi.Extractor;
@@ -14,11 +15,11 @@
}
public boolean isAllowed(final Extractor extractor,
- final Object object,
+ final InternalFactHandle handle,
final InternalWorkingMemory workingMemory) {
for ( int i = 0, ilength = this.restrictions.length; i < ilength; i++ ) {
if ( !this.restrictions[i].isAllowed( extractor,
- object,
+ handle,
workingMemory ) ) {
return false;
}
@@ -27,10 +28,10 @@
}
public boolean isAllowedCachedLeft(final ContextEntry context,
- final Object object) {
+ final InternalFactHandle handle) {
for ( int i = 0, ilength = this.restrictions.length; i < ilength; i++ ) {
if ( !this.restrictions[i].isAllowedCachedLeft( this.contextEntry.contextEntries[i],
- object ) ) {
+ handle ) ) {
return false;
}
}
Modified: labs/jbossrules/branches/temporal_rete/drools-core/src/main/java/org/drools/rule/AndConstraint.java
===================================================================
--- labs/jbossrules/branches/temporal_rete/drools-core/src/main/java/org/drools/rule/AndConstraint.java 2007-12-07 13:39:06 UTC (rev 17088)
+++ labs/jbossrules/branches/temporal_rete/drools-core/src/main/java/org/drools/rule/AndConstraint.java 2007-12-07 14:10:27 UTC (rev 17089)
@@ -19,9 +19,9 @@
import java.util.Arrays;
+import org.drools.common.InternalFactHandle;
import org.drools.common.InternalWorkingMemory;
import org.drools.reteoo.ReteTuple;
-import org.drools.rule.AbstractCompositeConstraint.MultiFieldConstraintContextEntry;
import org.drools.util.ArrayUtils;
/**
@@ -39,11 +39,11 @@
/**
* {@inheritDoc}
*/
- public boolean isAllowed(Object object,
+ public boolean isAllowed(InternalFactHandle handle,
InternalWorkingMemory workingMemory) {
if ( this.alphaConstraints.length > 0 ) {
for ( int i = 0; i < this.alphaConstraints.length; i++ ) {
- if ( !this.alphaConstraints[i].isAllowed( object,
+ if ( !this.alphaConstraints[i].isAllowed( handle,
workingMemory ) ) {
return false;
}
@@ -56,11 +56,11 @@
* {@inheritDoc}
*/
public boolean isAllowedCachedLeft(ContextEntry context,
- Object object) {
+ InternalFactHandle handle) {
if ( this.betaConstraints.length > 0 ) {
for ( int i = 0; i < this.betaConstraints.length; i++ ) {
if ( !this.betaConstraints[i].isAllowedCachedLeft( ((MultiFieldConstraintContextEntry)context).contexts[i],
- object ) ) {
+ handle ) ) {
return false;
}
}
Modified: labs/jbossrules/branches/temporal_rete/drools-core/src/main/java/org/drools/rule/LiteralConstraint.java
===================================================================
--- labs/jbossrules/branches/temporal_rete/drools-core/src/main/java/org/drools/rule/LiteralConstraint.java 2007-12-07 13:39:06 UTC (rev 17088)
+++ labs/jbossrules/branches/temporal_rete/drools-core/src/main/java/org/drools/rule/LiteralConstraint.java 2007-12-07 14:10:27 UTC (rev 17089)
@@ -16,6 +16,7 @@
* limitations under the License.
*/
+import org.drools.common.InternalFactHandle;
import org.drools.common.InternalWorkingMemory;
import org.drools.spi.AlphaNodeFieldConstraint;
import org.drools.spi.Evaluator;
@@ -77,10 +78,10 @@
newDecl );
}
- public boolean isAllowed(final Object object,
+ public boolean isAllowed(final InternalFactHandle handle,
final InternalWorkingMemory workingMemory) {
return this.restriction.isAllowed( this.extractor,
- object,
+ handle,
workingMemory );
}
Modified: labs/jbossrules/branches/temporal_rete/drools-core/src/main/java/org/drools/rule/LiteralRestriction.java
===================================================================
--- labs/jbossrules/branches/temporal_rete/drools-core/src/main/java/org/drools/rule/LiteralRestriction.java 2007-12-07 13:39:06 UTC (rev 17088)
+++ labs/jbossrules/branches/temporal_rete/drools-core/src/main/java/org/drools/rule/LiteralRestriction.java 2007-12-07 14:10:27 UTC (rev 17089)
@@ -29,7 +29,7 @@
implements
Restriction {
- private static final long serialVersionUID = 400L;
+ private static final long serialVersionUID = 400L;
private final FieldValue field;
@@ -56,25 +56,28 @@
}
public boolean isAllowed(final Extractor extractor,
- final Object object,
+ final InternalFactHandle handle,
final InternalWorkingMemory workingMemoiry) {
return this.evaluator.evaluate( null,
extractor,
- object, this.field );
+ handle.getObject(),
+ this.field );
}
public boolean isAllowedCachedLeft(final ContextEntry context,
- final Object object) {
+ final InternalFactHandle handle) {
return this.evaluator.evaluate( null,
((LiteralContextEntry) context).getFieldExtractor(),
- object, this.field );
+ handle.getObject(),
+ this.field );
}
public boolean isAllowedCachedRight(final ReteTuple tuple,
final ContextEntry context) {
return this.evaluator.evaluate( null,
((LiteralContextEntry) context).getFieldExtractor(),
- ((LiteralContextEntry) context).getObject(), this.field );
+ ((LiteralContextEntry) context).getObject(),
+ this.field );
}
/**
@@ -85,7 +88,7 @@
public Declaration[] getRequiredDeclarations() {
return LiteralRestriction.requiredDeclarations;
}
-
+
public void replaceDeclaration(Declaration oldDecl,
Declaration newDecl) {
}
@@ -123,9 +126,9 @@
ContextEntry {
private static final long serialVersionUID = 2621864784428098347L;
- public FieldExtractor extractor;
- public Object object;
- public ContextEntry next;
+ public FieldExtractor extractor;
+ public Object object;
+ public ContextEntry next;
public LiteralContextEntry(final FieldExtractor extractor) {
this.extractor = extractor;
Modified: labs/jbossrules/branches/temporal_rete/drools-core/src/main/java/org/drools/rule/MultiRestrictionFieldConstraint.java
===================================================================
--- labs/jbossrules/branches/temporal_rete/drools-core/src/main/java/org/drools/rule/MultiRestrictionFieldConstraint.java 2007-12-07 13:39:06 UTC (rev 17088)
+++ labs/jbossrules/branches/temporal_rete/drools-core/src/main/java/org/drools/rule/MultiRestrictionFieldConstraint.java 2007-12-07 14:10:27 UTC (rev 17089)
@@ -1,5 +1,6 @@
package org.drools.rule;
+import org.drools.common.InternalFactHandle;
import org.drools.common.InternalWorkingMemory;
import org.drools.reteoo.ReteTuple;
import org.drools.spi.AlphaNodeFieldConstraint;
@@ -65,10 +66,10 @@
return this.extractor.equals( other.extractor ) && this.restrictions.equals( other.restrictions );
}
- public boolean isAllowed(final Object object,
+ public boolean isAllowed(final InternalFactHandle handle,
final InternalWorkingMemory workingMemory) {
return this.restrictions.isAllowed( this.extractor,
- object,
+ handle,
workingMemory );
}
@@ -77,9 +78,9 @@
}
public boolean isAllowedCachedLeft(final ContextEntry context,
- final Object object) {
+ final InternalFactHandle handle) {
return this.restrictions.isAllowedCachedLeft( context,
- object );
+ handle );
}
public boolean isAllowedCachedRight(final ReteTuple tuple,
Modified: labs/jbossrules/branches/temporal_rete/drools-core/src/main/java/org/drools/rule/OrCompositeRestriction.java
===================================================================
--- labs/jbossrules/branches/temporal_rete/drools-core/src/main/java/org/drools/rule/OrCompositeRestriction.java 2007-12-07 13:39:06 UTC (rev 17088)
+++ labs/jbossrules/branches/temporal_rete/drools-core/src/main/java/org/drools/rule/OrCompositeRestriction.java 2007-12-07 14:10:27 UTC (rev 17089)
@@ -1,5 +1,6 @@
package org.drools.rule;
+import org.drools.common.InternalFactHandle;
import org.drools.common.InternalWorkingMemory;
import org.drools.reteoo.ReteTuple;
import org.drools.spi.Extractor;
@@ -14,11 +15,11 @@
}
public boolean isAllowed(final Extractor extractor,
- final Object object,
+ final InternalFactHandle handle,
final InternalWorkingMemory workingMemory) {
for ( int i = 0, ilength = this.restrictions.length; i < ilength; i++ ) {
if ( this.restrictions[i].isAllowed( extractor,
- object,
+ handle,
workingMemory ) ) {
return true;
}
@@ -27,10 +28,10 @@
}
public boolean isAllowedCachedLeft(final ContextEntry context,
- final Object object) {
+ final InternalFactHandle handle) {
for ( int i = 0, ilength = this.restrictions.length; i < ilength; i++ ) {
if ( this.restrictions[i].isAllowedCachedLeft( this.contextEntry.contextEntries[i],
- object ) ) {
+ handle ) ) {
return true;
}
}
Modified: labs/jbossrules/branches/temporal_rete/drools-core/src/main/java/org/drools/rule/OrConstraint.java
===================================================================
--- labs/jbossrules/branches/temporal_rete/drools-core/src/main/java/org/drools/rule/OrConstraint.java 2007-12-07 13:39:06 UTC (rev 17088)
+++ labs/jbossrules/branches/temporal_rete/drools-core/src/main/java/org/drools/rule/OrConstraint.java 2007-12-07 14:10:27 UTC (rev 17089)
@@ -18,6 +18,7 @@
import java.util.Arrays;
+import org.drools.common.InternalFactHandle;
import org.drools.common.InternalWorkingMemory;
import org.drools.reteoo.ReteTuple;
import org.drools.util.ArrayUtils;
@@ -40,11 +41,11 @@
/**
* {@inheritDoc}
*/
- public boolean isAllowed(Object object,
+ public boolean isAllowed(InternalFactHandle handle,
InternalWorkingMemory workingMemory) {
if ( this.alphaConstraints.length > 0 ) {
for ( int i = 0; i < this.alphaConstraints.length; i++ ) {
- if ( this.alphaConstraints[i].isAllowed( object,
+ if ( this.alphaConstraints[i].isAllowed( handle,
workingMemory ) ) {
return true;
}
@@ -58,11 +59,11 @@
* {@inheritDoc}
*/
public boolean isAllowedCachedLeft(ContextEntry context,
- Object object) {
+ InternalFactHandle handle) {
if ( this.betaConstraints.length > 0 ) {
for ( int i = 0; i < this.betaConstraints.length; i++ ) {
if ( this.betaConstraints[i].isAllowedCachedLeft( ((MultiFieldConstraintContextEntry)context).contexts[i],
- object ) ) {
+ handle ) ) {
return true;
}
}
Modified: labs/jbossrules/branches/temporal_rete/drools-core/src/main/java/org/drools/rule/PredicateConstraint.java
===================================================================
--- labs/jbossrules/branches/temporal_rete/drools-core/src/main/java/org/drools/rule/PredicateConstraint.java 2007-12-07 13:39:06 UTC (rev 17088)
+++ labs/jbossrules/branches/temporal_rete/drools-core/src/main/java/org/drools/rule/PredicateConstraint.java 2007-12-07 14:10:27 UTC (rev 17089)
@@ -214,10 +214,10 @@
return new PredicateContextEntry();
}
- public boolean isAllowed(final Object object,
+ public boolean isAllowed(final InternalFactHandle handle,
final InternalWorkingMemory workingMemory) {
try {
- return this.expression.evaluate( object,
+ return this.expression.evaluate( handle.getObject(),
null,
this.previousDeclarations,
this.localDeclarations,
@@ -229,16 +229,16 @@
}
public boolean isAllowed(Extractor extractor,
- Object object,
+ InternalFactHandle handle,
InternalWorkingMemory workingMemory) {
throw new UnsupportedOperationException("Method not supported. Please contact development team.");
}
public boolean isAllowedCachedLeft(final ContextEntry context,
- final Object object) {
+ final InternalFactHandle handle) {
try {
final PredicateContextEntry ctx = (PredicateContextEntry) context;
- return this.expression.evaluate( object,
+ return this.expression.evaluate( handle.getObject(),
ctx.leftTuple,
this.previousDeclarations,
this.localDeclarations,
Modified: labs/jbossrules/branches/temporal_rete/drools-core/src/main/java/org/drools/rule/ReturnValueConstraint.java
===================================================================
--- labs/jbossrules/branches/temporal_rete/drools-core/src/main/java/org/drools/rule/ReturnValueConstraint.java 2007-12-07 13:39:06 UTC (rev 17088)
+++ labs/jbossrules/branches/temporal_rete/drools-core/src/main/java/org/drools/rule/ReturnValueConstraint.java 2007-12-07 14:10:27 UTC (rev 17089)
@@ -17,6 +17,7 @@
*/
import org.drools.RuntimeDroolsException;
+import org.drools.common.InternalFactHandle;
import org.drools.common.InternalWorkingMemory;
import org.drools.reteoo.ReteTuple;
import org.drools.rule.ReturnValueRestriction.ReturnValueContextEntry;
@@ -97,11 +98,11 @@
return this.restriction.getContextEntry();
}
- public boolean isAllowed(final Object object,
+ public boolean isAllowed(final InternalFactHandle handle,
final InternalWorkingMemory workingMemory) {
try {
return this.restriction.isAllowed( this.fieldExtractor,
- object,
+ handle,
null,
workingMemory );
} catch ( final Exception e ) {
@@ -111,11 +112,11 @@
}
public boolean isAllowedCachedLeft(final ContextEntry context,
- final Object object) {
+ final InternalFactHandle handle) {
try {
final ReturnValueContextEntry ctx = (ReturnValueContextEntry) context;
return this.restriction.isAllowed( this.fieldExtractor,
- object,
+ handle,
ctx.getTuple(),
ctx.getWorkingMemory() );
} catch ( final Exception e ) {
@@ -129,7 +130,7 @@
try {
final ReturnValueContextEntry ctx = (ReturnValueContextEntry) context;
return this.restriction.isAllowed( this.fieldExtractor,
- ctx.getObject(),
+ ctx.getHandle(),
tuple,
ctx.getWorkingMemory() );
} catch ( final Exception e ) {
Modified: labs/jbossrules/branches/temporal_rete/drools-core/src/main/java/org/drools/rule/ReturnValueRestriction.java
===================================================================
--- labs/jbossrules/branches/temporal_rete/drools-core/src/main/java/org/drools/rule/ReturnValueRestriction.java 2007-12-07 13:39:06 UTC (rev 17088)
+++ labs/jbossrules/branches/temporal_rete/drools-core/src/main/java/org/drools/rule/ReturnValueRestriction.java 2007-12-07 14:10:27 UTC (rev 17089)
@@ -155,13 +155,13 @@
}
public boolean isAllowed(final Extractor extractor,
- final Object object,
+ final InternalFactHandle handle,
final Tuple tuple,
final WorkingMemory workingMemory) {
try {
return this.evaluator.evaluate( null,
extractor,
- object, this.expression.evaluate( object,
+ handle.getObject(), this.expression.evaluate( handle.getObject(),
tuple,
this.previousDeclarations,
this.localDeclarations,
@@ -172,13 +172,13 @@
}
public boolean isAllowed(final Extractor extractor,
- final Object object,
+ final InternalFactHandle handle,
final InternalWorkingMemory workingMemoiry) {
throw new UnsupportedOperationException( "does not support method call isAllowed(Object object, InternalWorkingMemory workingMemoiry)" );
}
public boolean isAllowedCachedLeft(final ContextEntry context,
- final Object object) {
+ final InternalFactHandle handle) {
throw new UnsupportedOperationException( "does not support method call isAllowed(Object object, InternalWorkingMemory workingMemoiry)" );
}
@@ -262,7 +262,7 @@
private static final long serialVersionUID = 400L;
public FieldExtractor fieldExtractor;
- public Object object;
+ public InternalFactHandle handle;
public ReteTuple leftTuple;
public InternalWorkingMemory workingMemory;
public Declaration[] previousDeclarations;
@@ -289,7 +289,7 @@
public void updateFromFactHandle(final InternalWorkingMemory workingMemory,
final InternalFactHandle handle) {
this.workingMemory = workingMemory;
- this.object = handle.getObject();
+ this.handle = handle;
}
public void updateFromTuple(final InternalWorkingMemory workingMemory,
@@ -315,8 +315,8 @@
/* (non-Javadoc)
* @see org.drools.rule.ReturnValueContextEntry#getObject()
*/
- public Object getObject() {
- return this.object;
+ public InternalFactHandle getHandle() {
+ return this.handle;
}
/* (non-Javadoc)
Modified: labs/jbossrules/branches/temporal_rete/drools-core/src/main/java/org/drools/rule/VariableConstraint.java
===================================================================
--- labs/jbossrules/branches/temporal_rete/drools-core/src/main/java/org/drools/rule/VariableConstraint.java 2007-12-07 13:39:06 UTC (rev 17088)
+++ labs/jbossrules/branches/temporal_rete/drools-core/src/main/java/org/drools/rule/VariableConstraint.java 2007-12-07 14:10:27 UTC (rev 17089)
@@ -16,6 +16,7 @@
* limitations under the License.
*/
+import org.drools.common.InternalFactHandle;
import org.drools.common.InternalWorkingMemory;
import org.drools.reteoo.ReteTuple;
import org.drools.spi.AlphaNodeFieldConstraint;
@@ -66,17 +67,17 @@
return this.restriction.getEvaluator();
}
- public boolean isAllowed(final Object object,
+ public boolean isAllowed(final InternalFactHandle handle,
final InternalWorkingMemory workingMemory) {
return this.restriction.isAllowed( this.fieldExtractor,
- object,
+ handle,
workingMemory );
}
public boolean isAllowedCachedLeft(final ContextEntry context,
- final Object object) {
+ final InternalFactHandle handle) {
return this.restriction.isAllowedCachedLeft( context,
- object );
+ handle );
}
public boolean isAllowedCachedRight(final ReteTuple tuple,
Modified: labs/jbossrules/branches/temporal_rete/drools-core/src/main/java/org/drools/rule/VariableRestriction.java
===================================================================
--- labs/jbossrules/branches/temporal_rete/drools-core/src/main/java/org/drools/rule/VariableRestriction.java 2007-12-07 13:39:06 UTC (rev 17088)
+++ labs/jbossrules/branches/temporal_rete/drools-core/src/main/java/org/drools/rule/VariableRestriction.java 2007-12-07 14:10:27 UTC (rev 17089)
@@ -69,20 +69,20 @@
}
public boolean isAllowed(final Extractor extractor,
- final Object object,
+ final InternalFactHandle handle,
final InternalWorkingMemory workingMemory) {
return this.evaluator.evaluate( workingMemory,
this.contextEntry.extractor,
- object,
+ handle.getObject(),
this.contextEntry.declaration.getExtractor(),
- object );
+ handle.getObject() );
}
public boolean isAllowedCachedLeft(final ContextEntry context,
- final Object object) {
+ final InternalFactHandle handle) {
return this.evaluator.evaluateCachedLeft( ((VariableContextEntry) context).workingMemory,
(VariableContextEntry) context,
- object );
+ handle.getObject() );
}
public boolean isAllowedCachedRight(final ReteTuple tuple,
@@ -125,7 +125,8 @@
private final VariableContextEntry createContextEntry(final Evaluator eval,
final FieldExtractor fieldExtractor) {
- if ( Operator.MEMBEROF.equals( eval.getOperator() ) || Operator.NOTMEMBEROF.equals( eval.getOperator() ) ) {
+ // FIXME: remove this hardcoded reference to operator
+ if ( "memberOf".equals( eval.getOperator().getOperatorString() ) ) {
return new ObjectVariableContextEntry( fieldExtractor,
this.declaration );
} else {
Modified: labs/jbossrules/branches/temporal_rete/drools-core/src/main/java/org/drools/spi/AlphaNodeFieldConstraint.java
===================================================================
--- labs/jbossrules/branches/temporal_rete/drools-core/src/main/java/org/drools/spi/AlphaNodeFieldConstraint.java 2007-12-07 13:39:06 UTC (rev 17088)
+++ labs/jbossrules/branches/temporal_rete/drools-core/src/main/java/org/drools/spi/AlphaNodeFieldConstraint.java 2007-12-07 14:10:27 UTC (rev 17089)
@@ -16,12 +16,13 @@
* limitations under the License.
*/
+import org.drools.common.InternalFactHandle;
import org.drools.common.InternalWorkingMemory;
public interface AlphaNodeFieldConstraint
extends
Constraint {
- public boolean isAllowed(Object object,
+ public boolean isAllowed(InternalFactHandle handle,
InternalWorkingMemory workingMemory);
}
\ No newline at end of file
Modified: labs/jbossrules/branches/temporal_rete/drools-core/src/main/java/org/drools/spi/BetaNodeFieldConstraint.java
===================================================================
--- labs/jbossrules/branches/temporal_rete/drools-core/src/main/java/org/drools/spi/BetaNodeFieldConstraint.java 2007-12-07 13:39:06 UTC (rev 17088)
+++ labs/jbossrules/branches/temporal_rete/drools-core/src/main/java/org/drools/spi/BetaNodeFieldConstraint.java 2007-12-07 14:10:27 UTC (rev 17089)
@@ -16,6 +16,7 @@
* limitations under the License.
*/
+import org.drools.common.InternalFactHandle;
import org.drools.reteoo.ReteTuple;
import org.drools.rule.ContextEntry;
@@ -24,7 +25,7 @@
Constraint {
public boolean isAllowedCachedLeft(ContextEntry context,
- Object object);
+ InternalFactHandle handle);
public boolean isAllowedCachedRight(ReteTuple tuple,
ContextEntry context);
Modified: labs/jbossrules/branches/temporal_rete/drools-core/src/main/java/org/drools/spi/Evaluator.java
===================================================================
--- labs/jbossrules/branches/temporal_rete/drools-core/src/main/java/org/drools/spi/Evaluator.java 2007-12-07 13:39:06 UTC (rev 17088)
+++ labs/jbossrules/branches/temporal_rete/drools-core/src/main/java/org/drools/spi/Evaluator.java 2007-12-07 14:10:27 UTC (rev 17089)
@@ -23,12 +23,25 @@
import org.drools.common.InternalWorkingMemory;
import org.drools.rule.VariableRestriction.VariableContextEntry;
+/**
+ * A public interface to be implemented by all evaluators
+ */
public interface Evaluator
extends
Serializable {
+ /**
+ * Returns the type of the values this evaluator operates upon.
+ *
+ * @return
+ */
public ValueType getValueType();
+ /**
+ * Returns the operator representation object for this evaluator
+ *
+ * @return
+ */
public Operator getOperator();
/**
Modified: labs/jbossrules/branches/temporal_rete/drools-core/src/main/java/org/drools/spi/Restriction.java
===================================================================
--- labs/jbossrules/branches/temporal_rete/drools-core/src/main/java/org/drools/spi/Restriction.java 2007-12-07 13:39:06 UTC (rev 17088)
+++ labs/jbossrules/branches/temporal_rete/drools-core/src/main/java/org/drools/spi/Restriction.java 2007-12-07 14:10:27 UTC (rev 17089)
@@ -2,6 +2,7 @@
import java.io.Serializable;
+import org.drools.common.InternalFactHandle;
import org.drools.common.InternalWorkingMemory;
import org.drools.reteoo.ReteTuple;
import org.drools.rule.ContextEntry;
@@ -13,11 +14,11 @@
Declaration[] getRequiredDeclarations();
public boolean isAllowed(Extractor extractor,
- Object object,
+ InternalFactHandle handle,
InternalWorkingMemory workingMemory);
public boolean isAllowedCachedLeft(ContextEntry context,
- Object object);
+ InternalFactHandle handle);
public boolean isAllowedCachedRight(ReteTuple tuple,
ContextEntry context);
Modified: labs/jbossrules/branches/temporal_rete/drools-core/src/main/java/org/drools/temporal/SessionPseudoClock.java
===================================================================
--- labs/jbossrules/branches/temporal_rete/drools-core/src/main/java/org/drools/temporal/SessionPseudoClock.java 2007-12-07 13:39:06 UTC (rev 17088)
+++ labs/jbossrules/branches/temporal_rete/drools-core/src/main/java/org/drools/temporal/SessionPseudoClock.java 2007-12-07 14:10:27 UTC (rev 17089)
@@ -46,4 +46,8 @@
return this.timer;
}
+ public void setStartupTime(int i) {
+ this.timer = i;
+ }
+
}
Added: labs/jbossrules/branches/temporal_rete/drools-core/src/main/java/org/drools/util/DateUtils.java
===================================================================
--- labs/jbossrules/branches/temporal_rete/drools-core/src/main/java/org/drools/util/DateUtils.java (rev 0)
+++ labs/jbossrules/branches/temporal_rete/drools-core/src/main/java/org/drools/util/DateUtils.java 2007-12-07 14:10:27 UTC (rev 17089)
@@ -0,0 +1,67 @@
+/*
+ * Copyright 2007 JBoss Inc
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ * Created on Dec 6, 2007
+ */
+package org.drools.util;
+
+import java.text.ParseException;
+import java.text.SimpleDateFormat;
+import java.util.Date;
+
+/**
+ * @author etirelli
+ *
+ */
+public class DateUtils {
+
+ private static final long serialVersionUID = 400L;
+ private static final String DEFAULT_FORMAT_MASK = "dd-MMM-yyyy";
+ private static final String DATE_FORMAT_MASK = getDateFormatMask();
+ private static SimpleDateFormat df = new SimpleDateFormat( DATE_FORMAT_MASK );
+
+
+ /** Use the simple date formatter to read the date from a string */
+ public static Date parseDate(final String input) {
+ try {
+ return df.parse( input );
+ } catch ( final ParseException e ) {
+ throw new IllegalArgumentException( "Invalid date input format: [" + input + "] it should follow: [" + DATE_FORMAT_MASK + "]" );
+ }
+ }
+
+ /** Converts the right hand side date as appropriate */
+ public static Date getRightDate(final Object object2) {
+ if ( object2 == null ) {
+ return null;
+ }
+ if ( object2 instanceof String ) {
+ return parseDate( (String) object2 );
+ } else if ( object2 instanceof Date ) {
+ return (Date) object2;
+ } else {
+ throw new IllegalArgumentException( "Unable to convert " + object2.getClass() + " to a Date." );
+ }
+ }
+
+ /** Check for the system property override, if it exists */
+ public static String getDateFormatMask() {
+ String fmt = System.getProperty( "drools.dateformat" );
+ if ( fmt == null ) {
+ fmt = DEFAULT_FORMAT_MASK;
+ }
+ return fmt;
+ }
+}
Modified: labs/jbossrules/branches/temporal_rete/drools-core/src/test/java/org/drools/base/EvaluatorFactoryTest.java
===================================================================
--- labs/jbossrules/branches/temporal_rete/drools-core/src/test/java/org/drools/base/EvaluatorFactoryTest.java 2007-12-07 13:39:06 UTC (rev 17088)
+++ labs/jbossrules/branches/temporal_rete/drools-core/src/test/java/org/drools/base/EvaluatorFactoryTest.java 2007-12-07 14:10:27 UTC (rev 17089)
@@ -29,7 +29,12 @@
import junit.framework.TestCase;
-import org.drools.base.evaluators.Operator;
+import org.drools.base.evaluators.ComparableEvaluatorsDefinition;
+import org.drools.base.evaluators.EqualityEvaluatorsDefinition;
+import org.drools.base.evaluators.EvaluatorDefinitionRegistry;
+import org.drools.base.evaluators.MatchesEvaluatorsDefinition;
+import org.drools.base.evaluators.SetEvaluatorsDefinition;
+import org.drools.base.evaluators.SoundslikeEvaluatorsDefinition;
import org.drools.common.InternalWorkingMemory;
import org.drools.rule.Declaration;
import org.drools.rule.VariableRestriction.BooleanVariableContextEntry;
@@ -50,6 +55,20 @@
*/
public class EvaluatorFactoryTest extends TestCase {
+ private EvaluatorDefinitionRegistry registry;
+
+ @Override
+ protected void setUp() throws Exception {
+ super.setUp();
+ registry = new EvaluatorDefinitionRegistry();
+ registry.addEvaluatorDefinition( new EqualityEvaluatorsDefinition() );
+ registry.addEvaluatorDefinition( new ComparableEvaluatorsDefinition() );
+ registry.addEvaluatorDefinition( new SetEvaluatorsDefinition() );
+ registry.addEvaluatorDefinition( new MatchesEvaluatorsDefinition() );
+ registry.addEvaluatorDefinition( new SoundslikeEvaluatorsDefinition() );
+ }
+
+
public void testObject() {
final List list = new ArrayList();
@@ -590,7 +609,7 @@
final Object[] row = data[i];
boolean isNegated = ((String) row[1]).startsWith("not ");
String evaluatorStr = isNegated ? ((String)row[1]).substring( 4 ) : (String)row[1];
- final Evaluator evaluator = valueType.getEvaluator( Operator.determineOperator( evaluatorStr, isNegated ) );
+ final Evaluator evaluator = registry.getEvaluatorDefinition( evaluatorStr ).getEvaluator( valueType, evaluatorStr, isNegated, null );
checkEvaluatorMethodWithFieldValue( valueType,
extractor,
row,
@@ -726,8 +745,7 @@
extractor,
null );
- if( Operator.MEMBEROF.equals( evaluator.getOperator() ) ||
- Operator.NOTMEMBEROF.equals( evaluator.getOperator() ) ) {
+ if( "memberOf".equals( evaluator.getOperator().getOperatorString() ) ) {
final ObjectVariableContextEntry context = new ObjectVariableContextEntry( extractor,
declaration );
Modified: labs/jbossrules/branches/temporal_rete/drools-core/src/test/java/org/drools/base/mvel/MVELCalendarCoercionTest.java
===================================================================
--- labs/jbossrules/branches/temporal_rete/drools-core/src/test/java/org/drools/base/mvel/MVELCalendarCoercionTest.java 2007-12-07 13:39:06 UTC (rev 17088)
+++ labs/jbossrules/branches/temporal_rete/drools-core/src/test/java/org/drools/base/mvel/MVELCalendarCoercionTest.java 2007-12-07 14:10:27 UTC (rev 17089)
@@ -3,10 +3,10 @@
import java.util.Calendar;
import java.util.Date;
-import org.drools.base.evaluators.DateFactory;
-
import junit.framework.TestCase;
+import org.drools.util.DateUtils;
+
public class MVELCalendarCoercionTest extends TestCase {
public void testCalendar() {
@@ -23,7 +23,7 @@
assertTrue(co.canConvertFrom( Calendar.class ));
String dt = "10-Jul-1974";
- Date dt_ = DateFactory.parseDate( dt );
+ Date dt_ = DateUtils.parseDate( dt );
Calendar cal = Calendar.getInstance();
cal.setTime( dt_ );
assertEquals(cal, co.convertFrom( dt ));
Modified: labs/jbossrules/branches/temporal_rete/drools-core/src/test/java/org/drools/base/mvel/MVELDateCoercionTest.java
===================================================================
--- labs/jbossrules/branches/temporal_rete/drools-core/src/test/java/org/drools/base/mvel/MVELDateCoercionTest.java 2007-12-07 13:39:06 UTC (rev 17088)
+++ labs/jbossrules/branches/temporal_rete/drools-core/src/test/java/org/drools/base/mvel/MVELDateCoercionTest.java 2007-12-07 14:10:27 UTC (rev 17089)
@@ -2,10 +2,10 @@
import java.util.Date;
-import org.drools.base.evaluators.DateFactory;
-
import junit.framework.TestCase;
+import org.drools.util.DateUtils;
+
public class MVELDateCoercionTest extends TestCase {
public void testDate() {
@@ -22,7 +22,7 @@
assertTrue(co.canConvertFrom( Date.class ));
String dt = "10-Jul-1974";
- Date dt_ = DateFactory.parseDate( dt );
+ Date dt_ = DateUtils.parseDate( dt );
assertEquals(dt_, co.convertFrom( dt ));
}
Modified: labs/jbossrules/branches/temporal_rete/drools-core/src/test/java/org/drools/common/BaseBetaConstraintsTest.java
===================================================================
--- labs/jbossrules/branches/temporal_rete/drools-core/src/test/java/org/drools/common/BaseBetaConstraintsTest.java 2007-12-07 13:39:06 UTC (rev 17088)
+++ labs/jbossrules/branches/temporal_rete/drools-core/src/test/java/org/drools/common/BaseBetaConstraintsTest.java 2007-12-07 14:10:27 UTC (rev 17089)
@@ -3,11 +3,18 @@
import java.util.ArrayList;
import java.util.List;
+import junit.framework.TestCase;
+
import org.drools.RuleBaseConfiguration;
import org.drools.base.ClassFieldExtractorCache;
import org.drools.base.ClassObjectType;
+import org.drools.base.evaluators.ComparableEvaluatorsDefinition;
+import org.drools.base.evaluators.EqualityEvaluatorsDefinition;
+import org.drools.base.evaluators.EvaluatorDefinitionRegistry;
+import org.drools.base.evaluators.MatchesEvaluatorsDefinition;
import org.drools.base.evaluators.Operator;
-import org.drools.base.evaluators.StringFactory;
+import org.drools.base.evaluators.SetEvaluatorsDefinition;
+import org.drools.base.evaluators.SoundslikeEvaluatorsDefinition;
import org.drools.reteoo.BetaMemory;
import org.drools.rule.Declaration;
import org.drools.rule.Pattern;
@@ -24,9 +31,16 @@
import org.drools.util.AbstractHashTable.FieldIndex;
import org.drools.util.AbstractHashTable.Index;
-import junit.framework.TestCase;
-
public abstract class BaseBetaConstraintsTest extends TestCase {
+
+ public static EvaluatorDefinitionRegistry registry = new EvaluatorDefinitionRegistry();
+ static {
+ registry.addEvaluatorDefinition( new EqualityEvaluatorsDefinition() );
+ registry.addEvaluatorDefinition( new ComparableEvaluatorsDefinition() );
+ registry.addEvaluatorDefinition( new SetEvaluatorsDefinition() );
+ registry.addEvaluatorDefinition( new MatchesEvaluatorsDefinition() );
+ registry.addEvaluatorDefinition( new SoundslikeEvaluatorsDefinition() );
+ }
protected BetaNodeFieldConstraint getConstraint(String identifier,
Operator operator,
@@ -39,7 +53,10 @@
extractor,
new Pattern( 0,
new ClassObjectType( clazz ) ) );
- Evaluator evaluator = StringFactory.getInstance().getEvaluator( operator );
+ Evaluator evaluator = registry.getEvaluatorDefinition( operator.getOperatorString() ).getEvaluator( extractor.getValueType(),
+ operator.getOperatorString(),
+ operator.isNegated(),
+ null );
return new VariableConstraint( extractor,
declaration,
evaluator );
Modified: labs/jbossrules/branches/temporal_rete/drools-core/src/test/java/org/drools/common/TripleBetaConstraintsTest.java
===================================================================
--- labs/jbossrules/branches/temporal_rete/drools-core/src/test/java/org/drools/common/TripleBetaConstraintsTest.java 2007-12-07 13:39:06 UTC (rev 17088)
+++ labs/jbossrules/branches/temporal_rete/drools-core/src/test/java/org/drools/common/TripleBetaConstraintsTest.java 2007-12-07 14:10:27 UTC (rev 17089)
@@ -1,30 +1,9 @@
package org.drools.common;
-import java.util.ArrayList;
-import java.util.List;
-
import org.drools.Cheese;
-import org.drools.RuleBaseConfiguration;
-import org.drools.base.ClassFieldExtractorCache;
-import org.drools.base.ClassObjectType;
import org.drools.base.evaluators.Operator;
-import org.drools.base.evaluators.StringFactory;
-import org.drools.reteoo.BetaMemory;
-import org.drools.rule.Declaration;
-import org.drools.rule.Pattern;
import org.drools.rule.VariableConstraint;
-import org.drools.spi.BetaNodeFieldConstraint;
-import org.drools.spi.Evaluator;
-import org.drools.spi.FieldExtractor;
-import org.drools.util.FactHandleIndexHashTable;
-import org.drools.util.FactHashTable;
-import org.drools.util.TupleHashTable;
-import org.drools.util.TupleIndexHashTable;
-import org.drools.util.AbstractHashTable.FieldIndex;
-import org.drools.util.AbstractHashTable.Index;
-import junit.framework.TestCase;
-
public class TripleBetaConstraintsTest extends BaseBetaConstraintsTest {
Modified: labs/jbossrules/branches/temporal_rete/drools-core/src/test/java/org/drools/event/AgendaEventSupportTest.java
===================================================================
--- labs/jbossrules/branches/temporal_rete/drools-core/src/test/java/org/drools/event/AgendaEventSupportTest.java 2007-12-07 13:39:06 UTC (rev 17088)
+++ labs/jbossrules/branches/temporal_rete/drools-core/src/test/java/org/drools/event/AgendaEventSupportTest.java 2007-12-07 14:10:27 UTC (rev 17089)
@@ -33,7 +33,13 @@
import org.drools.base.FieldFactory;
import org.drools.base.ShadowProxy;
import org.drools.base.ValueType;
+import org.drools.base.evaluators.ComparableEvaluatorsDefinition;
+import org.drools.base.evaluators.EqualityEvaluatorsDefinition;
+import org.drools.base.evaluators.EvaluatorDefinitionRegistry;
+import org.drools.base.evaluators.MatchesEvaluatorsDefinition;
import org.drools.base.evaluators.Operator;
+import org.drools.base.evaluators.SetEvaluatorsDefinition;
+import org.drools.base.evaluators.SoundslikeEvaluatorsDefinition;
import org.drools.rule.LiteralConstraint;
import org.drools.rule.Package;
import org.drools.rule.Pattern;
@@ -47,6 +53,16 @@
* @author <a href="mailto:simon at redhillconsulting.com.au">Simon Harris</a>
*/
public class AgendaEventSupportTest extends TestCase {
+
+ public static EvaluatorDefinitionRegistry registry = new EvaluatorDefinitionRegistry();
+ static {
+ registry.addEvaluatorDefinition( new EqualityEvaluatorsDefinition() );
+ registry.addEvaluatorDefinition( new ComparableEvaluatorsDefinition() );
+ registry.addEvaluatorDefinition( new SetEvaluatorsDefinition() );
+ registry.addEvaluatorDefinition( new MatchesEvaluatorsDefinition() );
+ registry.addEvaluatorDefinition( new SoundslikeEvaluatorsDefinition() );
+ }
+
public void testIsSerializable() {
assertTrue( Serializable.class.isAssignableFrom( AgendaEventSupport.class ) );
}
@@ -68,7 +84,9 @@
final FieldValue field = FieldFactory.getFieldValue( "cheddar" );
- final Evaluator evaluator = ValueType.STRING_TYPE.getEvaluator( Operator.EQUAL );
+ final Evaluator evaluator = registry.getEvaluator( ValueType.STRING_TYPE,
+ Operator.EQUAL,
+ null );
final LiteralConstraint constraint = new LiteralConstraint( extractor,
evaluator,
Modified: labs/jbossrules/branches/temporal_rete/drools-core/src/test/java/org/drools/event/RuleBaseEventListenerTest.java
===================================================================
--- labs/jbossrules/branches/temporal_rete/drools-core/src/test/java/org/drools/event/RuleBaseEventListenerTest.java 2007-12-07 13:39:06 UTC (rev 17088)
+++ labs/jbossrules/branches/temporal_rete/drools-core/src/test/java/org/drools/event/RuleBaseEventListenerTest.java 2007-12-07 14:10:27 UTC (rev 17089)
@@ -28,6 +28,7 @@
import org.drools.base.ClassObjectType;
import org.drools.base.FieldFactory;
import org.drools.base.ValueType;
+import org.drools.base.evaluators.EqualityEvaluatorsDefinition;
import org.drools.base.evaluators.Operator;
import org.drools.rule.LiteralConstraint;
import org.drools.rule.Package;
@@ -72,7 +73,7 @@
final FieldValue field = FieldFactory.getFieldValue( "cheddar" );
- final Evaluator evaluator = ValueType.STRING_TYPE.getEvaluator( Operator.EQUAL );
+ final Evaluator evaluator = new EqualityEvaluatorsDefinition().getEvaluator( ValueType.STRING_TYPE, Operator.EQUAL, null );
final LiteralConstraint constraint = new LiteralConstraint( extractor,
evaluator,
Modified: labs/jbossrules/branches/temporal_rete/drools-core/src/test/java/org/drools/examples/manners/BaseMannersTest.java
===================================================================
--- labs/jbossrules/branches/temporal_rete/drools-core/src/test/java/org/drools/examples/manners/BaseMannersTest.java 2007-12-07 13:39:06 UTC (rev 17088)
+++ labs/jbossrules/branches/temporal_rete/drools-core/src/test/java/org/drools/examples/manners/BaseMannersTest.java 2007-12-07 14:10:27 UTC (rev 17089)
@@ -33,22 +33,21 @@
import junit.framework.TestCase;
import org.drools.WorkingMemory;
-import org.drools.base.ClassFieldExtractor;
import org.drools.base.ClassFieldExtractorCache;
import org.drools.base.ClassObjectType;
-import org.drools.base.ShadowProxyFactory;
import org.drools.base.ValueType;
+import org.drools.base.evaluators.EqualityEvaluatorsDefinition;
import org.drools.base.evaluators.Operator;
import org.drools.base.field.BooleanFieldImpl;
import org.drools.base.field.LongFieldImpl;
import org.drools.common.InternalWorkingMemory;
-import org.drools.rule.Pattern;
import org.drools.rule.Declaration;
import org.drools.rule.GroupElement;
import org.drools.rule.GroupElementFactory;
import org.drools.rule.InvalidRuleException;
import org.drools.rule.LiteralConstraint;
import org.drools.rule.Package;
+import org.drools.rule.Pattern;
import org.drools.rule.Rule;
import org.drools.rule.VariableConstraint;
import org.drools.spi.AlphaNodeFieldConstraint;
@@ -113,12 +112,11 @@
//shadow = ShadowProxyFactory.getProxy( Chosen.class );
this.chosenType = new ClassObjectType( Chosen.class );
- this.integerEqualEvaluator = ValueType.PINTEGER_TYPE.getEvaluator( Operator.EQUAL );
- //this.integerNotEqualEvaluator = ValueType.INTEGER_TYPE.getEvaluator( Operator.NOT_EQUAL );
- this.objectEqualEvaluator = ValueType.OBJECT_TYPE.getEvaluator( Operator.EQUAL );
- this.objectNotEqualEvaluator = ValueType.OBJECT_TYPE.getEvaluator( Operator.NOT_EQUAL );
- this.booleanEqualEvaluator = ValueType.PBOOLEAN_TYPE.getEvaluator( Operator.EQUAL );
- //this.booleanNotEqualEvaluator = ValueType.BOOLEAN_TYPE.getEvaluator( Operator.NOT_EQUAL );
+ EqualityEvaluatorsDefinition evals = new EqualityEvaluatorsDefinition();
+ this.integerEqualEvaluator = evals.getEvaluator( ValueType.PINTEGER_TYPE, Operator.EQUAL, null );
+ this.objectEqualEvaluator = evals.getEvaluator( ValueType.OBJECT_TYPE, Operator.EQUAL, null );
+ this.objectNotEqualEvaluator = evals.getEvaluator( ValueType.OBJECT_TYPE, Operator.NOT_EQUAL, null );
+ this.booleanEqualEvaluator = evals.getEvaluator( ValueType.PBOOLEAN_TYPE, Operator.EQUAL, null );
this.pkg = new Package( "org.drools.examples.manners" );
this.pkg.addRule( getAssignFirstSeatRule() );
Modified: labs/jbossrules/branches/temporal_rete/drools-core/src/test/java/org/drools/reteoo/AlphaNodeTest.java
===================================================================
--- labs/jbossrules/branches/temporal_rete/drools-core/src/test/java/org/drools/reteoo/AlphaNodeTest.java 2007-12-07 13:39:06 UTC (rev 17088)
+++ labs/jbossrules/branches/temporal_rete/drools-core/src/test/java/org/drools/reteoo/AlphaNodeTest.java 2007-12-07 14:10:27 UTC (rev 17089)
@@ -27,6 +27,7 @@
import org.drools.base.ClassFieldExtractorCache;
import org.drools.base.FieldFactory;
import org.drools.base.ValueType;
+import org.drools.base.evaluators.EqualityEvaluatorsDefinition;
import org.drools.base.evaluators.Operator;
import org.drools.common.DefaultFactHandle;
import org.drools.common.PropagationContextImpl;
@@ -42,6 +43,7 @@
public class AlphaNodeTest extends DroolsTestCase {
ClassFieldExtractorCache cache = ClassFieldExtractorCache.getInstance();
+ EqualityEvaluatorsDefinition equals = new EqualityEvaluatorsDefinition();
public void testMemory() {
RuleBaseConfiguration config = new RuleBaseConfiguration();
@@ -83,7 +85,7 @@
final FieldValue field = FieldFactory.getFieldValue( "cheddar" );
- final Evaluator evaluator = ValueType.OBJECT_TYPE.getEvaluator( Operator.EQUAL );
+ final Evaluator evaluator = equals.getEvaluator( ValueType.OBJECT_TYPE, Operator.EQUAL );
final LiteralConstraint constraint = new LiteralConstraint( extractor,
evaluator,
field );
@@ -170,7 +172,7 @@
final FieldValue field = FieldFactory.getFieldValue( "cheddar" );
- final Evaluator evaluator = ValueType.OBJECT_TYPE.getEvaluator( Operator.EQUAL );
+ final Evaluator evaluator = equals.getEvaluator( ValueType.OBJECT_TYPE, Operator.EQUAL );
final LiteralConstraint constraint = new LiteralConstraint( extractor,
evaluator,
field );
@@ -233,7 +235,7 @@
final FieldValue field = FieldFactory.getFieldValue( "cheddar" );
- final Evaluator evaluator = ValueType.OBJECT_TYPE.getEvaluator( Operator.EQUAL );
+ final Evaluator evaluator = equals.getEvaluator( ValueType.OBJECT_TYPE, Operator.EQUAL );
final LiteralConstraint constraint = new LiteralConstraint( extractor,
evaluator,
field );
@@ -320,7 +322,7 @@
final FieldValue field = FieldFactory.getFieldValue( "cheddar" );
- final Evaluator evaluator = ValueType.OBJECT_TYPE.getEvaluator( Operator.EQUAL );
+ final Evaluator evaluator = equals.getEvaluator( ValueType.OBJECT_TYPE, Operator.EQUAL );
final LiteralConstraint constraint = new LiteralConstraint( extractor,
evaluator,
field );
@@ -407,7 +409,7 @@
final FieldValue field = FieldFactory.getFieldValue( "cheddar" );
- final Evaluator evaluator = ValueType.OBJECT_TYPE.getEvaluator( Operator.EQUAL );
+ final Evaluator evaluator = equals.getEvaluator( ValueType.OBJECT_TYPE, Operator.EQUAL );
final LiteralConstraint constraint = new LiteralConstraint( extractor,
evaluator,
field );
@@ -475,7 +477,7 @@
final FieldValue field = FieldFactory.getFieldValue( "cheddar" );
- final Evaluator evaluator = ValueType.OBJECT_TYPE.getEvaluator( Operator.EQUAL );
+ final Evaluator evaluator = equals.getEvaluator( ValueType.OBJECT_TYPE, Operator.EQUAL );
final LiteralConstraint constraint = new LiteralConstraint( extractor,
evaluator,
field );
@@ -559,7 +561,7 @@
final FieldValue field = FieldFactory.getFieldValue( "cheddar" );
- final Evaluator evaluator = ValueType.OBJECT_TYPE.getEvaluator( Operator.EQUAL );
+ final Evaluator evaluator = equals.getEvaluator( ValueType.OBJECT_TYPE, Operator.EQUAL );
final LiteralConstraint constraint = new LiteralConstraint( extractor,
evaluator,
field );
@@ -647,7 +649,7 @@
final FieldValue field = FieldFactory.getFieldValue( "cheddar" );
- final Evaluator evaluator = ValueType.OBJECT_TYPE.getEvaluator( Operator.EQUAL );
+ final Evaluator evaluator = equals.getEvaluator( ValueType.OBJECT_TYPE, Operator.EQUAL );
final LiteralConstraint constraint = new LiteralConstraint( extractor,
evaluator,
field );
@@ -731,7 +733,7 @@
final FieldValue field = FieldFactory.getFieldValue( "cheddar" );
- final Evaluator evaluator = ValueType.OBJECT_TYPE.getEvaluator( Operator.EQUAL );
+ final Evaluator evaluator = equals.getEvaluator( ValueType.OBJECT_TYPE, Operator.EQUAL );
final LiteralConstraint constraint = new LiteralConstraint( extractor,
evaluator,
field );
Modified: labs/jbossrules/branches/temporal_rete/drools-core/src/test/java/org/drools/reteoo/CompositeObjectSinkAdapterTest.java
===================================================================
--- labs/jbossrules/branches/temporal_rete/drools-core/src/test/java/org/drools/reteoo/CompositeObjectSinkAdapterTest.java 2007-12-07 13:39:06 UTC (rev 17088)
+++ labs/jbossrules/branches/temporal_rete/drools-core/src/test/java/org/drools/reteoo/CompositeObjectSinkAdapterTest.java 2007-12-07 14:10:27 UTC (rev 17089)
@@ -8,8 +8,8 @@
import org.drools.RuleBaseFactory;
import org.drools.base.ClassFieldExtractorCache;
import org.drools.base.ValueType;
+import org.drools.base.evaluators.EqualityEvaluatorsDefinition;
import org.drools.base.evaluators.Operator;
-import org.drools.base.evaluators.StringFactory;
import org.drools.base.field.ObjectFieldImpl;
import org.drools.common.EmptyBetaConstraints;
import org.drools.common.InternalFactHandle;
@@ -23,6 +23,8 @@
public class CompositeObjectSinkAdapterTest extends TestCase {
private ReteooRuleBase ruleBase;
private BuildContext buildContext;
+
+ private EqualityEvaluatorsDefinition equals = new EqualityEvaluatorsDefinition();
protected void setUp() throws Exception {
this.ruleBase = (ReteooRuleBase) RuleBaseFactory.newRuleBase();
@@ -87,7 +89,7 @@
final CompositeObjectSinkAdapter ad = new CompositeObjectSinkAdapter();
final LiteralConstraint lit = new LiteralConstraint( new MockExtractor(),
- StringFactory.getInstance().getEvaluator( Operator.EQUAL ),
+ equals.getEvaluator( ValueType.STRING_TYPE, Operator.EQUAL ),
new ObjectFieldImpl( "stilton" ) );
final AlphaNode al = new AlphaNode( buildContext.getNextId(),
lit,
@@ -113,7 +115,7 @@
final CompositeObjectSinkAdapter ad = new CompositeObjectSinkAdapter();
final LiteralConstraint lit = new LiteralConstraint( new MockExtractor(),
- StringFactory.getInstance().getEvaluator( Operator.EQUAL ),
+ equals.getEvaluator( ValueType.STRING_TYPE, Operator.EQUAL ),
new ObjectFieldImpl( "stilton" ) );
final AlphaNode al = new AlphaNode( buildContext.getNextId(),
lit,
@@ -130,7 +132,7 @@
ad.getSinks()[0] );
final LiteralConstraint lit2 = new LiteralConstraint( new MockExtractor(),
- StringFactory.getInstance().getEvaluator( Operator.EQUAL ),
+ equals.getEvaluator( ValueType.STRING_TYPE, Operator.EQUAL ),
new ObjectFieldImpl( "cheddar" ) );
final AlphaNode al2 = new AlphaNode( buildContext.getNextId(),
lit2,
@@ -171,7 +173,7 @@
public void testTripleAlpha() {
final CompositeObjectSinkAdapter ad = new CompositeObjectSinkAdapter();
final LiteralConstraint lit = new LiteralConstraint( new MockExtractor(),
- StringFactory.getInstance().getEvaluator( Operator.EQUAL ),
+ equals.getEvaluator( ValueType.STRING_TYPE, Operator.EQUAL ),
new ObjectFieldImpl( "stilton" ) );
final AlphaNode al = new AlphaNode( buildContext.getNextId(),
lit,
@@ -188,7 +190,7 @@
ad.getSinks()[0] );
final LiteralConstraint lit2 = new LiteralConstraint( new MockExtractor(),
- StringFactory.getInstance().getEvaluator( Operator.EQUAL ),
+ equals.getEvaluator( ValueType.STRING_TYPE, Operator.EQUAL ),
new ObjectFieldImpl( "cheddar" ) );
final AlphaNode al2 = new AlphaNode( buildContext.getNextId(),
lit2,
@@ -202,7 +204,7 @@
ad.hashableSinks.size() );
final LiteralConstraint lit3 = new LiteralConstraint( new MockExtractor(),
- StringFactory.getInstance().getEvaluator( Operator.EQUAL ),
+ equals.getEvaluator( ValueType.STRING_TYPE, Operator.EQUAL ),
new ObjectFieldImpl( "stinky" ) );
final AlphaNode al3 = new AlphaNode( buildContext.getNextId(),
lit3,
@@ -230,7 +232,7 @@
"type",
this.getClass().getClassLoader() );
final LiteralConstraint lit1 = new LiteralConstraint( extractor,
- StringFactory.getInstance().getEvaluator( Operator.EQUAL ),
+ equals.getEvaluator( ValueType.STRING_TYPE, Operator.EQUAL ),
new ObjectFieldImpl( "stilton" ) );
final AlphaNode al1 = new AlphaNode( buildContext.getNextId(),
lit1,
@@ -238,7 +240,7 @@
buildContext );
final LiteralConstraint lit2 = new LiteralConstraint( extractor,
- StringFactory.getInstance().getEvaluator( Operator.EQUAL ),
+ equals.getEvaluator( ValueType.STRING_TYPE, Operator.EQUAL ),
new ObjectFieldImpl( "brie" ) );
final AlphaNode al2 = new AlphaNode( buildContext.getNextId(),
lit2,
@@ -246,7 +248,7 @@
buildContext );
final LiteralConstraint lit3 = new LiteralConstraint( extractor,
- StringFactory.getInstance().getEvaluator( Operator.EQUAL ),
+ equals.getEvaluator( ValueType.STRING_TYPE, Operator.EQUAL ),
new ObjectFieldImpl( "muzzarela" ) );
final AlphaNode al3 = new AlphaNode( buildContext.getNextId(),
lit3,
Modified: labs/jbossrules/branches/temporal_rete/drools-core/src/test/java/org/drools/reteoo/FromNodeTest.java
===================================================================
--- labs/jbossrules/branches/temporal_rete/drools-core/src/test/java/org/drools/reteoo/FromNodeTest.java 2007-12-07 13:39:06 UTC (rev 17088)
+++ labs/jbossrules/branches/temporal_rete/drools-core/src/test/java/org/drools/reteoo/FromNodeTest.java 2007-12-07 14:10:27 UTC (rev 17089)
@@ -17,6 +17,7 @@
import org.drools.base.ClassObjectType;
import org.drools.base.FieldFactory;
import org.drools.base.ValueType;
+import org.drools.base.evaluators.EqualityEvaluatorsDefinition;
import org.drools.base.evaluators.Operator;
import org.drools.common.BetaConstraints;
import org.drools.common.DefaultFactHandle;
@@ -37,6 +38,7 @@
public class FromNodeTest extends TestCase {
ClassFieldExtractorCache cache = ClassFieldExtractorCache.getInstance();
+ EqualityEvaluatorsDefinition equals = new EqualityEvaluatorsDefinition();
public void testAlphaNode() {
final PropagationContext context = new PropagationContextImpl( 0,
@@ -51,7 +53,7 @@
final FieldValue field = FieldFactory.getFieldValue( "stilton" );
final LiteralConstraint constraint = new LiteralConstraint( extractor,
- ValueType.STRING_TYPE.getEvaluator( Operator.EQUAL ),
+ equals.getEvaluator( ValueType.STRING_TYPE, Operator.EQUAL ),
field );
final List list = new ArrayList();
@@ -154,7 +156,7 @@
final VariableConstraint variableConstraint = new VariableConstraint( priceExtractor,
declaration,
- ValueType.PINTEGER_TYPE.getEvaluator( Operator.EQUAL ) );
+ equals.getEvaluator( ValueType.PINTEGER_TYPE, Operator.EQUAL ) );
final RuleBaseConfiguration configuration = new RuleBaseConfiguration();
configuration.setIndexRightBetaMemory( false );
configuration.setIndexLeftBetaMemory( false );
@@ -248,7 +250,7 @@
final FieldValue field = FieldFactory.getFieldValue( "stilton" );
final LiteralConstraint constraint = new LiteralConstraint( extractor,
- ValueType.STRING_TYPE.getEvaluator( Operator.EQUAL ),
+ equals.getEvaluator( ValueType.STRING_TYPE, Operator.EQUAL ),
field );
final List list = new ArrayList();
Modified: labs/jbossrules/branches/temporal_rete/drools-core/src/test/java/org/drools/reteoo/QueryTerminalNodeTest.java
===================================================================
--- labs/jbossrules/branches/temporal_rete/drools-core/src/test/java/org/drools/reteoo/QueryTerminalNodeTest.java 2007-12-07 13:39:06 UTC (rev 17088)
+++ labs/jbossrules/branches/temporal_rete/drools-core/src/test/java/org/drools/reteoo/QueryTerminalNodeTest.java 2007-12-07 14:10:27 UTC (rev 17089)
@@ -34,6 +34,7 @@
import org.drools.base.DroolsQuery;
import org.drools.base.FieldFactory;
import org.drools.base.ValueType;
+import org.drools.base.evaluators.EqualityEvaluatorsDefinition;
import org.drools.base.evaluators.Operator;
import org.drools.common.EmptyBetaConstraints;
import org.drools.reteoo.builder.BuildContext;
@@ -47,6 +48,7 @@
private BuildContext buildContext;
ClassFieldExtractorCache cache = ClassFieldExtractorCache.getInstance();
+ private EqualityEvaluatorsDefinition equals = new EqualityEvaluatorsDefinition();
protected void setUp() throws Exception {
this.ruleBase = (ReteooRuleBase) RuleBaseFactory.newRuleBase();
@@ -67,7 +69,7 @@
FieldValue field = FieldFactory.getFieldValue( "query-1" );
- final Evaluator evaluator = ValueType.STRING_TYPE.getEvaluator( Operator.EQUAL );
+ final Evaluator evaluator = equals.getEvaluator( ValueType.STRING_TYPE, Operator.EQUAL );
LiteralConstraint constraint = new LiteralConstraint( extractor,
evaluator,
field );
Modified: labs/jbossrules/branches/temporal_rete/drools-core/src/test/java/org/drools/rule/FieldConstraintTest.java
===================================================================
--- labs/jbossrules/branches/temporal_rete/drools-core/src/test/java/org/drools/rule/FieldConstraintTest.java 2007-12-07 13:39:06 UTC (rev 17088)
+++ labs/jbossrules/branches/temporal_rete/drools-core/src/test/java/org/drools/rule/FieldConstraintTest.java 2007-12-07 14:10:27 UTC (rev 17089)
@@ -30,6 +30,8 @@
import org.drools.base.FieldFactory;
import org.drools.base.ShadowProxy;
import org.drools.base.ValueType;
+import org.drools.base.evaluators.ComparableEvaluatorsDefinition;
+import org.drools.base.evaluators.EqualityEvaluatorsDefinition;
import org.drools.base.evaluators.Operator;
import org.drools.common.InternalFactHandle;
import org.drools.common.InternalWorkingMemory;
@@ -47,6 +49,8 @@
public class FieldConstraintTest extends TestCase {
ClassFieldExtractorCache cache = ClassFieldExtractorCache.getInstance();
+ EqualityEvaluatorsDefinition equals = new EqualityEvaluatorsDefinition();
+ ComparableEvaluatorsDefinition comparables = new ComparableEvaluatorsDefinition();
public FieldConstraintTest() {
super();
@@ -76,7 +80,7 @@
final FieldValue field = FieldFactory.getFieldValue( "cheddar" );
- final Evaluator evaluator = ValueType.STRING_TYPE.getEvaluator( Operator.EQUAL );
+ final Evaluator evaluator = equals.getEvaluator( ValueType.STRING_TYPE, Operator.EQUAL );
final LiteralConstraint constraint = new LiteralConstraint( extractor,
evaluator,
@@ -88,7 +92,7 @@
final InternalFactHandle cheddarHandle = (InternalFactHandle) workingMemory.insert( cheddar );
// check constraint
- assertTrue( constraint.isAllowed( cheddarHandle.getObject(),
+ assertTrue( constraint.isAllowed( cheddarHandle,
workingMemory ) );
final Cheese stilton = new Cheese( "stilton",
@@ -97,7 +101,7 @@
final InternalFactHandle stiltonHandle = (InternalFactHandle) workingMemory.insert( stilton );
// check constraint
- assertFalse( constraint.isAllowed( stiltonHandle.getObject(),
+ assertFalse( constraint.isAllowed( stiltonHandle,
workingMemory ) );
}
@@ -122,7 +126,7 @@
final FieldValue field = FieldFactory.getFieldValue( 5 );
- final Evaluator evaluator = ValueType.PINTEGER_TYPE.getEvaluator( Operator.EQUAL );
+ final Evaluator evaluator = equals.getEvaluator( ValueType.PINTEGER_TYPE, Operator.EQUAL );
final LiteralConstraint constraint = new LiteralConstraint( extractor,
evaluator,
@@ -134,7 +138,7 @@
final InternalFactHandle cheddarHandle = (InternalFactHandle) workingMemory.insert( cheddar );
// check constraint
- assertTrue( constraint.isAllowed( cheddarHandle.getObject(),
+ assertTrue( constraint.isAllowed( cheddarHandle,
workingMemory ) );
final Cheese stilton = new Cheese( "stilton",
@@ -143,7 +147,7 @@
final InternalFactHandle stiltonHandle = (InternalFactHandle) workingMemory.insert( stilton );
// check constraint
- assertFalse( constraint.isAllowed( stiltonHandle.getObject(),
+ assertFalse( constraint.isAllowed( stiltonHandle,
workingMemory ) );
}
@@ -228,7 +232,7 @@
context.updateFromTuple( workingMemory,
tuple );
assertTrue( constraint1.isAllowedCachedLeft( context,
- f1.getObject() ) );
+ f1 ) );
}
/**
@@ -284,7 +288,7 @@
new Declaration[]{priceDeclaration},
new Declaration[0],
new String[0],
- ValueType.INTEGER_TYPE.getEvaluator( Operator.EQUAL ) );
+ equals.getEvaluator( ValueType.INTEGER_TYPE, Operator.EQUAL ) );
final ReturnValueConstraint constraint1 = new ReturnValueConstraint( priceExtractor,
restriction1 );
@@ -294,7 +298,7 @@
new Declaration[]{priceDeclaration},
new Declaration[0],
new String[0],
- ValueType.INTEGER_TYPE.getEvaluator( Operator.GREATER ) );
+ comparables.getEvaluator( ValueType.INTEGER_TYPE, Operator.GREATER ) );
final ReturnValueConstraint constraint2 = new ReturnValueConstraint( priceExtractor,
restriction2 );
@@ -315,13 +319,13 @@
context1.updateFromTuple( workingMemory,
tuple );
assertTrue( constraint1.isAllowedCachedLeft( context1,
- f1.getObject() ) );
+ f1 ) );
final ReturnValueContextEntry context2 = (ReturnValueContextEntry) constraint2.getContextEntry();
context2.updateFromTuple( workingMemory,
tuple );
assertFalse( constraint2.isAllowedCachedLeft( context2,
- f1.getObject() ) );
+ f1 ) );
final Cheese cheddar2 = new Cheese( "cheddar",
11 );
@@ -329,7 +333,7 @@
final InternalFactHandle f2 = (InternalFactHandle) workingMemory.insert( cheddar2 );
assertTrue( constraint2.isAllowedCachedLeft( context2,
- f2.getObject() ) );
+ f2 ) );
}
/**
@@ -356,7 +360,7 @@
final FieldValue field = FieldFactory.getFieldValue( "cheddar" );
- final Evaluator evaluator = ValueType.STRING_TYPE.getEvaluator( Operator.EQUAL );
+ final Evaluator evaluator = equals.getEvaluator( ValueType.STRING_TYPE, Operator.EQUAL );
final LiteralConstraint constraint1 = new LiteralConstraint( extractor,
evaluator,
@@ -368,7 +372,7 @@
final FieldValue priceField = FieldFactory.getFieldValue( 10 );
- final Evaluator priceEvaluator = ValueType.INTEGER_TYPE.getEvaluator( Operator.GREATER );
+ final Evaluator priceEvaluator = comparables.getEvaluator( ValueType.INTEGER_TYPE, Operator.GREATER );
final LiteralConstraint constraint2 = new LiteralConstraint( priceExtractor,
priceEvaluator,
@@ -384,22 +388,22 @@
final InternalFactHandle cheddarHandle = (InternalFactHandle) workingMemory.insert( cheddar );
// check constraint
- assertTrue( constraint.isAllowed( cheddarHandle.getObject(),
+ assertTrue( constraint.isAllowed( cheddarHandle,
workingMemory ) );
cheddar.setPrice( 5 );
((ShadowProxy) cheddarHandle.getObject()).updateProxy();
- assertFalse( constraint.isAllowed( cheddarHandle.getObject(),
+ assertFalse( constraint.isAllowed( cheddarHandle,
workingMemory ) );
cheddar.setType( "stilton" );
((ShadowProxy) cheddarHandle.getObject()).updateProxy();
- assertFalse( constraint.isAllowed( cheddarHandle.getObject(),
+ assertFalse( constraint.isAllowed( cheddarHandle,
workingMemory ) );
cheddar.setPrice( 15 );
((ShadowProxy) cheddarHandle.getObject()).updateProxy();
- assertFalse( constraint.isAllowed( cheddarHandle.getObject(),
+ assertFalse( constraint.isAllowed( cheddarHandle,
workingMemory ) );
}
@@ -426,7 +430,7 @@
final FieldValue field = FieldFactory.getFieldValue( "cheddar" );
- final Evaluator evaluator = ValueType.STRING_TYPE.getEvaluator( Operator.EQUAL );
+ final Evaluator evaluator = equals.getEvaluator( ValueType.STRING_TYPE, Operator.EQUAL );
final LiteralConstraint constraint1 = new LiteralConstraint( extractor,
evaluator,
@@ -438,7 +442,7 @@
final FieldValue priceField = FieldFactory.getFieldValue( 10 );
- final Evaluator priceEvaluator = ValueType.INTEGER_TYPE.getEvaluator( Operator.GREATER );
+ final Evaluator priceEvaluator = comparables.getEvaluator( ValueType.INTEGER_TYPE, Operator.GREATER );
final LiteralConstraint constraint2 = new LiteralConstraint( priceExtractor,
priceEvaluator,
@@ -454,22 +458,22 @@
final InternalFactHandle cheddarHandle = (InternalFactHandle) workingMemory.insert( cheddar );
// check constraint
- assertTrue( constraint.isAllowed( cheddarHandle.getObject(),
+ assertTrue( constraint.isAllowed( cheddarHandle,
workingMemory ) );
cheddar.setPrice( 5 );
((ShadowProxy) cheddarHandle.getObject()).updateProxy();
- assertTrue( constraint.isAllowed( cheddarHandle.getObject(),
+ assertTrue( constraint.isAllowed( cheddarHandle,
workingMemory ) );
cheddar.setType( "stilton" );
((ShadowProxy) cheddarHandle.getObject()).updateProxy();
- assertFalse( constraint.isAllowed( cheddarHandle.getObject(),
+ assertFalse( constraint.isAllowed( cheddarHandle,
workingMemory ) );
cheddar.setPrice( 15 );
((ShadowProxy) cheddarHandle.getObject()).updateProxy();
- assertTrue( constraint.isAllowed( cheddarHandle.getObject(),
+ assertTrue( constraint.isAllowed( cheddarHandle,
workingMemory ) );
}
@@ -496,7 +500,7 @@
final FieldValue cheddarField = FieldFactory.getFieldValue( "cheddar" );
- final Evaluator stringEqual = ValueType.STRING_TYPE.getEvaluator( Operator.EQUAL );
+ final Evaluator stringEqual = equals.getEvaluator( ValueType.STRING_TYPE, Operator.EQUAL );
// type == 'cheddar'
final LiteralConstraint constraint1 = new LiteralConstraint( typeExtractor,
@@ -509,7 +513,7 @@
final FieldValue field10 = FieldFactory.getFieldValue( 10 );
- final Evaluator integerGreater = ValueType.INTEGER_TYPE.getEvaluator( Operator.GREATER );
+ final Evaluator integerGreater = comparables.getEvaluator( ValueType.INTEGER_TYPE, Operator.GREATER );
// price > 10
final LiteralConstraint constraint2 = new LiteralConstraint( priceExtractor,
@@ -527,7 +531,7 @@
stringEqual,
stiltonField );
- final Evaluator integerLess = ValueType.INTEGER_TYPE.getEvaluator( Operator.LESS );
+ final Evaluator integerLess = comparables.getEvaluator( ValueType.INTEGER_TYPE, Operator.LESS );
// price < 10
final LiteralConstraint constraint4 = new LiteralConstraint( priceExtractor,
@@ -550,22 +554,22 @@
final InternalFactHandle cheddarHandle = (InternalFactHandle) workingMemory.insert( cheddar );
// check constraint
- assertTrue( constraint.isAllowed( cheddarHandle.getObject(),
+ assertTrue( constraint.isAllowed( cheddarHandle,
workingMemory ) );
cheddar.setPrice( 5 );
((ShadowProxy) cheddarHandle.getObject()).updateProxy();
- assertFalse( constraint.isAllowed( cheddarHandle.getObject(),
+ assertFalse( constraint.isAllowed( cheddarHandle,
workingMemory ) );
cheddar.setType( "stilton" );
((ShadowProxy) cheddarHandle.getObject()).updateProxy();
- assertTrue( constraint.isAllowed( cheddarHandle.getObject(),
+ assertTrue( constraint.isAllowed( cheddarHandle,
workingMemory ) );
cheddar.setPrice( 15 );
((ShadowProxy) cheddarHandle.getObject()).updateProxy();
- assertFalse( constraint.isAllowed( cheddarHandle.getObject(),
+ assertFalse( constraint.isAllowed( cheddarHandle,
workingMemory ) );
}
Modified: labs/jbossrules/branches/temporal_rete/drools-core/src/test/java/org/drools/spi/MockConstraint.java
===================================================================
--- labs/jbossrules/branches/temporal_rete/drools-core/src/test/java/org/drools/spi/MockConstraint.java 2007-12-07 13:39:06 UTC (rev 17088)
+++ labs/jbossrules/branches/temporal_rete/drools-core/src/test/java/org/drools/spi/MockConstraint.java 2007-12-07 14:10:27 UTC (rev 17089)
@@ -36,7 +36,7 @@
public boolean isAllowed = true;
- public boolean isAllowed(final Object object,
+ public boolean isAllowed(final InternalFactHandle handle,
final Tuple tuple,
final WorkingMemory workingMemory) {
return this.isAllowed;
@@ -74,7 +74,7 @@
}
public boolean isAllowedCachedLeft(final ContextEntry context,
- final Object object) {
+ final InternalFactHandle handle) {
return this.isAllowed;
}
Modified: labs/jbossrules/branches/temporal_rete/drools-core/src/test/java/org/drools/util/FieldIndexEntryTest.java
===================================================================
--- labs/jbossrules/branches/temporal_rete/drools-core/src/test/java/org/drools/util/FieldIndexEntryTest.java 2007-12-07 13:39:06 UTC (rev 17088)
+++ labs/jbossrules/branches/temporal_rete/drools-core/src/test/java/org/drools/util/FieldIndexEntryTest.java 2007-12-07 14:10:27 UTC (rev 17089)
@@ -5,8 +5,9 @@
import org.drools.Cheese;
import org.drools.base.ClassFieldExtractor;
import org.drools.base.ClassFieldExtractorCache;
+import org.drools.base.ValueType;
+import org.drools.base.evaluators.EqualityEvaluatorsDefinition;
import org.drools.base.evaluators.Operator;
-import org.drools.base.evaluators.StringFactory;
import org.drools.common.DefaultFactHandle;
import org.drools.common.InternalFactHandle;
import org.drools.util.AbstractHashTable.FactEntryImpl;
@@ -16,6 +17,7 @@
public class FieldIndexEntryTest extends TestCase {
ClassFieldExtractorCache cache = ClassFieldExtractorCache.getInstance();
+ EqualityEvaluatorsDefinition equals = new EqualityEvaluatorsDefinition();
public void testSingleEntry() {
final ClassFieldExtractor extractor = cache.getExtractor( Cheese.class,
@@ -24,7 +26,7 @@
final FieldIndex fieldIndex = new FieldIndex( extractor,
null,
- StringFactory.getInstance().getEvaluator( Operator.EQUAL ) );
+ equals.getEvaluator( ValueType.STRING_TYPE, Operator.EQUAL ) );
final SingleIndex singleIndex = new SingleIndex( new FieldIndex[]{fieldIndex},
1 );
@@ -67,7 +69,7 @@
getClass().getClassLoader() );
final FieldIndex fieldIndex = new FieldIndex( extractor,
null,
- StringFactory.getInstance().getEvaluator( Operator.EQUAL ) );
+ equals.getEvaluator( ValueType.STRING_TYPE, Operator.EQUAL ) );
final SingleIndex singleIndex = new SingleIndex( new FieldIndex[]{fieldIndex},
1 );
@@ -119,7 +121,7 @@
getClass().getClassLoader() );
final FieldIndex fieldIndex = new FieldIndex( extractor,
null,
- StringFactory.getInstance().getEvaluator( Operator.EQUAL ) );
+ equals.getEvaluator( ValueType.STRING_TYPE, Operator.EQUAL ) );
final SingleIndex singleIndex = new SingleIndex( new FieldIndex[]{fieldIndex},
1 );
Modified: labs/jbossrules/branches/temporal_rete/drools-core/src/test/java/org/drools/util/FieldIndexHashTableTest.java
===================================================================
--- labs/jbossrules/branches/temporal_rete/drools-core/src/test/java/org/drools/util/FieldIndexHashTableTest.java 2007-12-07 13:39:06 UTC (rev 17088)
+++ labs/jbossrules/branches/temporal_rete/drools-core/src/test/java/org/drools/util/FieldIndexHashTableTest.java 2007-12-07 14:10:27 UTC (rev 17089)
@@ -9,9 +9,9 @@
import org.drools.Cheese;
import org.drools.base.ClassFieldExtractorCache;
import org.drools.base.ClassObjectType;
-import org.drools.base.evaluators.ObjectFactory;
+import org.drools.base.ValueType;
+import org.drools.base.evaluators.EqualityEvaluatorsDefinition;
import org.drools.base.evaluators.Operator;
-import org.drools.base.evaluators.StringFactory;
import org.drools.common.DefaultFactHandle;
import org.drools.common.InternalFactHandle;
import org.drools.reteoo.ReteTuple;
@@ -25,6 +25,7 @@
public class FieldIndexHashTableTest extends TestCase {
ClassFieldExtractorCache cache = ClassFieldExtractorCache.getInstance();
+ EqualityEvaluatorsDefinition equals = new EqualityEvaluatorsDefinition();
public void testSingleEntry() throws Exception {
final FieldExtractor extractor = cache.getExtractor( Cheese.class,
@@ -40,7 +41,7 @@
final FieldIndex fieldIndex = new FieldIndex( extractor,
declaration,
- StringFactory.getInstance().getEvaluator( Operator.EQUAL ) );
+ equals.getEvaluator( ValueType.STRING_TYPE, Operator.EQUAL ) );
final FactHandleIndexHashTable map = new FactHandleIndexHashTable( new FieldIndex[]{fieldIndex} );
@@ -89,7 +90,7 @@
final FieldIndex fieldIndex = new FieldIndex( extractor,
declaration,
- StringFactory.getInstance().getEvaluator( Operator.EQUAL ) );
+ equals.getEvaluator( ValueType.STRING_TYPE, Operator.EQUAL ) );
final FactHandleIndexHashTable map = new FactHandleIndexHashTable( new FieldIndex[]{fieldIndex} );
@@ -146,7 +147,7 @@
final FieldIndex fieldIndex = new FieldIndex( extractor,
declaration,
- StringFactory.getInstance().getEvaluator( Operator.EQUAL ) );
+ equals.getEvaluator( ValueType.STRING_TYPE, Operator.EQUAL ) );
final FactHandleIndexHashTable map = new FactHandleIndexHashTable( new FieldIndex[]{fieldIndex} );
@@ -203,7 +204,7 @@
final FieldIndex fieldIndex = new FieldIndex( extractor,
declaration,
- ObjectFactory.getInstance().getEvaluator( Operator.EQUAL ) );
+ equals.getEvaluator( ValueType.OBJECT_TYPE, Operator.EQUAL ) );
final FactHandleIndexHashTable map = new FactHandleIndexHashTable( new FieldIndex[]{fieldIndex} );
@@ -250,7 +251,7 @@
final FieldIndex fieldIndex = new FieldIndex( extractor,
declaration,
- StringFactory.getInstance().getEvaluator( Operator.EQUAL ) );
+ equals.getEvaluator( ValueType.STRING_TYPE, Operator.EQUAL ) );
final FactHandleIndexHashTable map = new FactHandleIndexHashTable( new FieldIndex[]{fieldIndex} );
@@ -317,7 +318,7 @@
final FieldIndex fieldIndex = new FieldIndex( extractor,
declaration,
- StringFactory.getInstance().getEvaluator( Operator.EQUAL ) );
+ equals.getEvaluator( ValueType.STRING_TYPE, Operator.EQUAL ) );
final FactHandleIndexHashTable map = new FactHandleIndexHashTable( new FieldIndex[]{fieldIndex} );
@@ -534,7 +535,7 @@
final FieldIndex fieldIndex = new FieldIndex( extractor,
declaration,
- StringFactory.getInstance().getEvaluator( Operator.EQUAL ) );
+ equals.getEvaluator( ValueType.STRING_TYPE, Operator.EQUAL ) );
final FactHandleIndexHashTable map = new FactHandleIndexHashTable( new FieldIndex[]{fieldIndex} );
More information about the jboss-svn-commits
mailing list