Author: doogie
Date: Mon Sep 14 06:35:44 2009 New Revision: 814492 URL: http://svn.apache.org/viewvc?rev=814492&view=rev Log: Start adding generics to the operators, to document what they operate on(more to come). Modified: ofbiz/trunk/framework/entity/src/org/ofbiz/entity/condition/EntityComparisonOperator.java ofbiz/trunk/framework/entity/src/org/ofbiz/entity/condition/EntityExpr.java ofbiz/trunk/framework/entity/src/org/ofbiz/entity/condition/EntityJoinOperator.java ofbiz/trunk/framework/entity/src/org/ofbiz/entity/condition/EntityOperator.java Modified: ofbiz/trunk/framework/entity/src/org/ofbiz/entity/condition/EntityComparisonOperator.java URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/entity/src/org/ofbiz/entity/condition/EntityComparisonOperator.java?rev=814492&r1=814491&r2=814492&view=diff ============================================================================== --- ofbiz/trunk/framework/entity/src/org/ofbiz/entity/condition/EntityComparisonOperator.java (original) +++ ofbiz/trunk/framework/entity/src/org/ofbiz/entity/condition/EntityComparisonOperator.java Mon Sep 14 06:35:44 2009 @@ -41,7 +41,7 @@ /** * Encapsulates operations between entities and entity fields. This is a immutable class. */ -public class EntityComparisonOperator extends EntityOperator<Boolean> { +public class EntityComparisonOperator<L, R> extends EntityOperator<L, R, Boolean> { public static final String module = EntityComparisonOperator.class.getName(); Modified: ofbiz/trunk/framework/entity/src/org/ofbiz/entity/condition/EntityExpr.java URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/entity/src/org/ofbiz/entity/condition/EntityExpr.java?rev=814492&r1=814491&r2=814492&view=diff ============================================================================== --- ofbiz/trunk/framework/entity/src/org/ofbiz/entity/condition/EntityExpr.java (original) +++ ofbiz/trunk/framework/entity/src/org/ofbiz/entity/condition/EntityExpr.java Mon Sep 14 06:35:44 2009 @@ -51,7 +51,7 @@ }; private Object lhs = null; - private EntityOperator<?> operator = null; + private EntityOperator<?, ?, ?> operator = null; private Object rhs = null; protected EntityExpr() {} Modified: ofbiz/trunk/framework/entity/src/org/ofbiz/entity/condition/EntityJoinOperator.java URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/entity/src/org/ofbiz/entity/condition/EntityJoinOperator.java?rev=814492&r1=814491&r2=814492&view=diff ============================================================================== --- ofbiz/trunk/framework/entity/src/org/ofbiz/entity/condition/EntityJoinOperator.java (original) +++ ofbiz/trunk/framework/entity/src/org/ofbiz/entity/condition/EntityJoinOperator.java Mon Sep 14 06:35:44 2009 @@ -35,7 +35,7 @@ * Encapsulates operations between entities and entity fields. This is a immutable class. * */ -public class EntityJoinOperator extends EntityOperator<Boolean> { +public class EntityJoinOperator extends EntityOperator<EntityCondition, EntityCondition, Boolean> { protected boolean shortCircuitValue; Modified: ofbiz/trunk/framework/entity/src/org/ofbiz/entity/condition/EntityOperator.java URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/entity/src/org/ofbiz/entity/condition/EntityOperator.java?rev=814492&r1=814491&r2=814492&view=diff ============================================================================== --- ofbiz/trunk/framework/entity/src/org/ofbiz/entity/condition/EntityOperator.java (original) +++ ofbiz/trunk/framework/entity/src/org/ofbiz/entity/condition/EntityOperator.java Mon Sep 14 06:35:44 2009 @@ -36,7 +36,7 @@ * Encapsulates operations between entities and entity fields. This is an immutable class. * */ -public abstract class EntityOperator<T> extends EntityConditionBase { +public abstract class EntityOperator<L, R, T> extends EntityConditionBase { public static final int ID_EQUALS = 1; public static final int ID_NOT_EQUAL = 2; @@ -77,7 +77,7 @@ return (EntityJoinOperator)operator; } - public static final EntityComparisonOperator EQUALS = new EntityComparisonOperator(ID_EQUALS, "=") { + public static final EntityComparisonOperator EQUALS = new ComparableEntityComparisonOperator(ID_EQUALS, "=") { @Override public boolean compare(Comparable lhs, Object rhs) { return EntityComparisonOperator.compareEqual(lhs, rhs); } @Override @@ -92,7 +92,7 @@ } }; static { register("equals", EQUALS); } - public static final EntityComparisonOperator NOT_EQUAL = new EntityComparisonOperator(ID_NOT_EQUAL, "<>") { + public static final EntityComparisonOperator NOT_EQUAL = new ComparableEntityComparisonOperator(ID_NOT_EQUAL, "<>") { @Override public boolean compare(Comparable lhs, Object rhs) { return EntityComparisonOperator.compareNotEqual(lhs, rhs); } @Override @@ -107,65 +107,65 @@ static { register("not-equal", NOT_EQUAL); } static { register("not-equals", NOT_EQUAL); } static { register("notEqual", NOT_EQUAL); } - public static final EntityComparisonOperator LESS_THAN = new EntityComparisonOperator(ID_LESS_THAN, "<") { + public static final EntityComparisonOperator LESS_THAN = new ComparableEntityComparisonOperator(ID_LESS_THAN, "<") { @Override public <T> boolean compare(Comparable<T> lhs, T rhs) { return EntityComparisonOperator.compareLessThan(lhs, rhs); } }; static { register("less", LESS_THAN); } static { register("less-than", LESS_THAN); } static { register("lessThan", LESS_THAN); } - public static final EntityComparisonOperator GREATER_THAN = new EntityComparisonOperator(ID_GREATER_THAN, ">") { + public static final EntityComparisonOperator GREATER_THAN = new ComparableEntityComparisonOperator(ID_GREATER_THAN, ">") { @Override public <T> boolean compare(Comparable<T> lhs, T rhs) { return EntityComparisonOperator.compareGreaterThan(lhs, rhs); } }; static { register("greater", GREATER_THAN); } static { register("greater-than", GREATER_THAN); } static { register("greaterThan", GREATER_THAN); } - public static final EntityComparisonOperator LESS_THAN_EQUAL_TO = new EntityComparisonOperator(ID_LESS_THAN_EQUAL_TO, "<=") { + public static final EntityComparisonOperator LESS_THAN_EQUAL_TO = new ComparableEntityComparisonOperator(ID_LESS_THAN_EQUAL_TO, "<=") { @Override public <T> boolean compare(Comparable<T> lhs, T rhs) { return EntityComparisonOperator.compareLessThanEqualTo(lhs, rhs); } }; static { register("less-equals", LESS_THAN_EQUAL_TO); } static { register("less-than-equal-to", LESS_THAN_EQUAL_TO); } static { register("lessThanEqualTo", LESS_THAN_EQUAL_TO); } - public static final EntityComparisonOperator GREATER_THAN_EQUAL_TO = new EntityComparisonOperator(ID_GREATER_THAN_EQUAL_TO, ">=") { + public static final EntityComparisonOperator GREATER_THAN_EQUAL_TO = new ComparableEntityComparisonOperator(ID_GREATER_THAN_EQUAL_TO, ">=") { @Override public <T> boolean compare(Comparable<T> lhs, T rhs) { return EntityComparisonOperator.compareGreaterThanEqualTo(lhs, rhs); } }; static { register("greater-equals", GREATER_THAN_EQUAL_TO); } static { register("greater-than-equal-to", GREATER_THAN_EQUAL_TO); } static { register("greaterThanEqualTo", GREATER_THAN_EQUAL_TO); } - public static final EntityComparisonOperator IN = new EntityComparisonOperator(ID_IN, "IN") { + public static final EntityComparisonOperator IN = new ListEntityComparisonOperator(ID_IN, "IN") { @Override public <T> boolean compare(Comparable<T> lhs, T rhs) { return EntityComparisonOperator.compareIn(lhs, rhs); } @Override protected void makeRHSWhereStringValue(ModelEntity entity, List<EntityConditionParam> entityConditionParams, StringBuilder sb, ModelField field, Object rhs, DatasourceInfo datasourceInfo) { appendRHSList(entityConditionParams, sb, field, rhs); } }; static { register("in", IN); } - public static final EntityComparisonOperator BETWEEN = new EntityComparisonOperator(ID_BETWEEN, "BETWEEN") { + public static final EntityComparisonOperator BETWEEN = new ListEntityComparisonOperator(ID_BETWEEN, "BETWEEN") { @Override public <T> boolean compare(Comparable<T> lhs, T rhs) { return EntityComparisonOperator.compareIn(lhs, rhs); } @Override protected void makeRHSWhereStringValue(ModelEntity entity, List<EntityConditionParam> entityConditionParams, StringBuilder sb, ModelField field, Object rhs, DatasourceInfo datasourceInfo) { appendRHSBetweenList(entityConditionParams, sb, field, rhs); } }; static { register("between", BETWEEN); } - public static final EntityComparisonOperator NOT = new EntityComparisonOperator(ID_NOT, "NOT"); + public static final EntityComparisonOperator NOT = new EntityComparisonOperator<Object, EntityCondition>(ID_NOT, "NOT"); static { register("not", NOT); } public static final EntityJoinOperator AND = new EntityJoinOperator(ID_AND, "AND", false); static { register("and", AND); } public static final EntityJoinOperator OR = new EntityJoinOperator(ID_OR, "OR", true); static { register("or", OR); } - public static final EntityComparisonOperator LIKE = new EntityComparisonOperator(ID_LIKE, "LIKE") { + public static final EntityComparisonOperator LIKE = new ComparableEntityComparisonOperator(ID_LIKE, "LIKE") { @Override public boolean compare(Comparable lhs, Object rhs) { return EntityComparisonOperator.compareLike(lhs, rhs); } }; static { register("like", LIKE); } - public static final EntityComparisonOperator NOT_LIKE = new EntityComparisonOperator(ID_NOT_LIKE, "NOT LIKE") { + public static final EntityComparisonOperator NOT_LIKE = new ComparableEntityComparisonOperator(ID_NOT_LIKE, "NOT LIKE") { @Override public <T> boolean compare(Comparable<T> lhs, T rhs) { return !EntityComparisonOperator.compareLike(lhs, rhs); } }; static { register("not-like", NOT_LIKE); } - public static final EntityComparisonOperator NOT_IN = new EntityComparisonOperator(ID_NOT_IN, "NOT IN") { + public static final EntityComparisonOperator NOT_IN = new ListEntityComparisonOperator(ID_NOT_IN, "NOT IN") { @Override public <T> boolean compare(Comparable<T> lhs, T rhs) { return !EntityComparisonOperator.compareIn(lhs, rhs); } @Override @@ -277,4 +277,16 @@ return "(WILDCARD)"; } }; + + public static abstract class ListEntityComparisonOperator extends EntityComparisonOperator<Comparable, List<Comparable>> { + public ListEntityComparisonOperator(int id, String code) { + super(id, code); + } + } + + public static abstract class ComparableEntityComparisonOperator extends EntityComparisonOperator<Comparable, Object> { + public ComparableEntityComparisonOperator(int id, String code) { + super(id, code); + } + } } |
Free forum by Nabble | Edit this page |