Author: doogie
Date: Sat Aug 2 14:38:01 2008 New Revision: 682056 URL: http://svn.apache.org/viewvc?rev=682056&view=rev Log: Continuing with generics. Modified: ofbiz/trunk/framework/entity/src/org/ofbiz/entity/GenericDelegator.java ofbiz/trunk/framework/entity/src/org/ofbiz/entity/GenericEntity.java ofbiz/trunk/framework/entity/src/org/ofbiz/entity/condition/EntityComparisonOperator.java ofbiz/trunk/framework/entity/src/org/ofbiz/entity/condition/EntityOperator.java ofbiz/trunk/framework/entity/src/org/ofbiz/entity/condition/OrderByItem.java Modified: ofbiz/trunk/framework/entity/src/org/ofbiz/entity/GenericDelegator.java URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/entity/src/org/ofbiz/entity/GenericDelegator.java?rev=682056&r1=682055&r2=682056&view=diff ============================================================================== --- ofbiz/trunk/framework/entity/src/org/ofbiz/entity/GenericDelegator.java (original) +++ ofbiz/trunk/framework/entity/src/org/ofbiz/entity/GenericDelegator.java Sat Aug 2 14:38:01 2008 @@ -208,7 +208,7 @@ } // initialize helpers by group - Set groupNames = getModelGroupReader().getGroupNames(delegatorName); + Set<String> groupNames = getModelGroupReader().getGroupNames(delegatorName); Iterator<String> groups = UtilMisc.toIterator(groupNames); while (groups != null && groups.hasNext()) { String groupName = groups.next(); Modified: ofbiz/trunk/framework/entity/src/org/ofbiz/entity/GenericEntity.java URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/entity/src/org/ofbiz/entity/GenericEntity.java?rev=682056&r1=682055&r2=682056&view=diff ============================================================================== --- ofbiz/trunk/framework/entity/src/org/ofbiz/entity/GenericEntity.java (original) +++ ofbiz/trunk/framework/entity/src/org/ofbiz/entity/GenericEntity.java Sat Aug 2 14:38:01 2008 @@ -43,6 +43,7 @@ import org.ofbiz.base.util.Debug; import org.ofbiz.base.util.ObjectType; import org.ofbiz.base.util.UtilDateTime; +import org.ofbiz.base.util.UtilGenerics; import org.ofbiz.base.util.UtilProperties; import org.ofbiz.base.util.UtilValidate; import org.ofbiz.base.util.UtilXml; @@ -1243,8 +1244,8 @@ } protected int compareToFields(GenericEntity that, String name) { - Comparable thisVal = (Comparable) this.fields.get(name); - Comparable thatVal = (Comparable) that.fields.get(name); + Comparable<Object> thisVal = UtilGenerics.cast(this.fields.get(name)); + Object thatVal = that.fields.get(name); if (thisVal == null) { if (thatVal == null) 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=682056&r1=682055&r2=682056&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 Sat Aug 2 14:38:01 2008 @@ -31,6 +31,7 @@ import org.apache.oro.text.regex.Perl5Compiler; import org.apache.oro.text.regex.Perl5Matcher; import org.ofbiz.base.util.Debug; +import org.ofbiz.base.util.UtilGenerics; import org.ofbiz.base.util.UtilValidate; import org.ofbiz.entity.GenericDelegator; import org.ofbiz.entity.GenericModelException; @@ -126,14 +127,15 @@ } } - public boolean compare(Comparable lhs, Object rhs) { + public <T extends Comparable<T>> boolean compare(T lhs, T rhs) { throw new UnsupportedOperationException(codeString); } public Boolean eval(GenericDelegator delegator, Map<String, ? extends Object> map, Object lhs, Object rhs) { - return mapMatches(delegator, map, lhs, rhs) ? Boolean.TRUE : Boolean.FALSE; + return Boolean.valueOf(mapMatches(delegator, map, lhs, rhs)); } + @SuppressWarnings("unchecked") public boolean mapMatches(GenericDelegator delegator, Map<String, ? extends Object> map, Object lhs, Object rhs) { Object leftValue; if (lhs instanceof EntityConditionValue) { @@ -153,7 +155,7 @@ } if (leftValue == WILDCARD || rightValue == WILDCARD) return true; - return compare((Comparable) leftValue, rightValue); + return compare((Comparable) leftValue, (Comparable) rightValue); } public EntityCondition freeze(Object lhs, Object rhs) { @@ -173,7 +175,7 @@ super(id, code); } - public static final boolean compareEqual(Comparable lhs, Object rhs) { + public static final <T extends Comparable<T>> boolean compareEqual(T lhs, T rhs) { if (lhs == null) { if (rhs != null) { return false; @@ -184,7 +186,7 @@ return true; } - public static final boolean compareNotEqual(Comparable lhs, Object rhs) { + public static final <T extends Comparable<T>> boolean compareNotEqual(T lhs, T rhs) { if (lhs == null) { if (rhs == null) { return false; @@ -195,7 +197,7 @@ return true; } - public static final boolean compareGreaterThan(Comparable lhs, Object rhs) { + public static final <T extends Comparable<T>> boolean compareGreaterThan(T lhs, T rhs) { if (lhs == null) { if (rhs != null) { return false; @@ -206,7 +208,7 @@ return true; } - public static final boolean compareGreaterThanEqualTo(Comparable lhs, Object rhs) { + public static final <T extends Comparable<T>> boolean compareGreaterThanEqualTo(T lhs, T rhs) { if (lhs == null) { if (rhs != null) { return false; @@ -217,7 +219,7 @@ return true; } - public static final boolean compareLessThan(Comparable lhs, Object rhs) { + public static final <T extends Comparable<T>> boolean compareLessThan(T lhs, T rhs) { if (lhs == null) { if (rhs != null) { return false; @@ -228,7 +230,7 @@ return true; } - public static final boolean compareLessThanEqualTo(Comparable lhs, Object rhs) { + public static final <T extends Comparable<T>> boolean compareLessThanEqualTo(T lhs, T rhs) { if (lhs == null) { if (rhs != null) { return false; 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=682056&r1=682055&r2=682056&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 Sat Aug 2 14:38:01 2008 @@ -78,7 +78,7 @@ } public static final EntityComparisonOperator EQUALS = new EntityComparisonOperator(ID_EQUALS, "=") { - public boolean compare(Comparable lhs, Object rhs) { return EntityComparisonOperator.compareEqual(lhs, rhs); } + public <T extends Comparable<T>> boolean compare(T lhs, T rhs) { return EntityComparisonOperator.compareEqual(lhs, rhs); } protected void makeRHSWhereString(ModelEntity entity, List<EntityConditionParam> entityConditionParams, StringBuilder sb, ModelField field, Object rhs, DatasourceInfo datasourceInfo) { if (rhs == null || rhs == GenericEntity.NULL_FIELD) { //Debug.logInfo("makeRHSWhereString: field IS NULL: " + field.getName(), module); @@ -91,7 +91,7 @@ }; static { register( "equals", EQUALS ); } public static final EntityComparisonOperator NOT_EQUAL = new EntityComparisonOperator(ID_NOT_EQUAL, "<>") { - public boolean compare(Comparable lhs, Object rhs) { return EntityComparisonOperator.compareNotEqual(lhs, rhs); } + public <T extends Comparable<T>> boolean compare(T lhs, T rhs) { return EntityComparisonOperator.compareNotEqual(lhs, rhs); } protected void makeRHSWhereString(ModelEntity entity, List<EntityConditionParam> entityConditionParams, StringBuilder sb, ModelField field, Object rhs, DatasourceInfo datasourceInfo) { if (rhs == null || rhs == GenericEntity.NULL_FIELD) { sb.append(" IS NOT NULL"); @@ -104,31 +104,31 @@ static { register( "not-equals", NOT_EQUAL ); } static { register( "notEqual", NOT_EQUAL ); } public static final EntityComparisonOperator LESS_THAN = new EntityComparisonOperator(ID_LESS_THAN, "<") { - public boolean compare(Comparable lhs, Object rhs) { return EntityComparisonOperator.compareLessThan(lhs, rhs); } + public <T extends Comparable<T>> boolean compare(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 boolean compare(Comparable lhs, Object rhs) { return EntityComparisonOperator.compareGreaterThan(lhs, rhs); } + public <T extends Comparable<T>> boolean compare(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 boolean compare(Comparable lhs, Object rhs) { return EntityComparisonOperator.compareLessThanEqualTo(lhs, rhs); } + public <T extends Comparable<T>> boolean compare(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 boolean compare(Comparable lhs, Object rhs) { return EntityComparisonOperator.compareGreaterThanEqualTo(lhs, rhs); } + public <T extends Comparable<T>> boolean compare(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 boolean compare(Comparable lhs, Object rhs) { return EntityComparisonOperator.compareIn(lhs, rhs); } + public <T extends Comparable<T>> boolean compare(T lhs, T rhs) { return EntityComparisonOperator.compareIn(lhs, rhs); } protected void makeRHSWhereStringValue(ModelEntity entity, List<EntityConditionParam> entityConditionParams, StringBuilder sb, ModelField field, Object rhs) { appendRHSList(entityConditionParams, sb, field, rhs); } }; static { register( "in", IN ); } @@ -141,15 +141,15 @@ 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 boolean compare(Comparable lhs, Object rhs) { return EntityComparisonOperator.compareLike(lhs, rhs); } + public <T extends Comparable<T>> boolean compare(T lhs, T rhs) { return EntityComparisonOperator.compareLike(lhs, rhs); } }; static { register( "like", LIKE ); } public static final EntityComparisonOperator NOT_LIKE = new EntityComparisonOperator(ID_NOT_LIKE, "NOT LIKE") { - public boolean compare(Comparable lhs, Object rhs) { return !EntityComparisonOperator.compareLike(lhs, rhs); } + public <T extends Comparable<T>> boolean compare(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 boolean compare(Comparable lhs, Object rhs) { return !EntityComparisonOperator.compareIn(lhs, rhs); } + public <T extends Comparable<T>> boolean compare(T lhs, T rhs) { return !EntityComparisonOperator.compareIn(lhs, rhs); } protected void makeRHSWhereStringValue(ModelEntity entity, List<EntityConditionParam> entityConditionParams, StringBuilder sb, ModelField field, Object rhs) { appendRHSList(entityConditionParams, sb, field, rhs); } }; static { register( "not-in", NOT_IN ); } Modified: ofbiz/trunk/framework/entity/src/org/ofbiz/entity/condition/OrderByItem.java URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/entity/src/org/ofbiz/entity/condition/OrderByItem.java?rev=682056&r1=682055&r2=682056&view=diff ============================================================================== --- ofbiz/trunk/framework/entity/src/org/ofbiz/entity/condition/OrderByItem.java (original) +++ ofbiz/trunk/framework/entity/src/org/ofbiz/entity/condition/OrderByItem.java Sat Aug 2 14:38:01 2008 @@ -21,6 +21,7 @@ import java.util.Comparator; +import org.ofbiz.base.util.UtilGenerics; import org.ofbiz.entity.GenericEntity; import org.ofbiz.entity.GenericModelException; import org.ofbiz.entity.config.DatasourceInfo; @@ -128,8 +129,8 @@ } public int compare(GenericEntity obj1, GenericEntity obj2) { - Comparable value1 = (Comparable) value.getValue(obj1); - Comparable value2 = (Comparable) value.getValue(obj2); + Comparable<Object> value1 = UtilGenerics.cast(value.getValue(obj1)); + Object value2 = value.getValue(obj2); int result; // null is defined as the largest possible value |
Free forum by Nabble | Edit this page |