Author: doogie
Date: Wed Oct 17 20:33:25 2007 New Revision: 585824 URL: http://svn.apache.org/viewvc?rev=585824&view=rev Log: Add generics markup for Comparator and Comparable. Modified: ofbiz/trunk/framework/entity/src/org/ofbiz/entity/GenericEntity.java ofbiz/trunk/framework/entity/src/org/ofbiz/entity/condition/OrderByItem.java ofbiz/trunk/framework/entity/src/org/ofbiz/entity/condition/OrderByList.java ofbiz/trunk/framework/entity/src/org/ofbiz/entity/model/ModelEntity.java ofbiz/trunk/framework/entity/src/org/ofbiz/entity/util/ByteWrapper.java 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=585824&r1=585823&r2=585824&view=diff ============================================================================== --- ofbiz/trunk/framework/entity/src/org/ofbiz/entity/GenericEntity.java (original) +++ ofbiz/trunk/framework/entity/src/org/ofbiz/entity/GenericEntity.java Wed Oct 17 20:33:25 2007 @@ -65,7 +65,7 @@ * <code>Observer</code>. * */ -public class GenericEntity extends Observable implements Map, LocalizedMap, Serializable, Comparable, Cloneable, Reusable { +public class GenericEntity extends Observable implements Map, LocalizedMap, Serializable, Comparable<GenericEntity>, Cloneable, Reusable { public static final String module = GenericEntity.class.getName(); public static final GenericEntity NULL_ENTITY = new NullGenericEntity(); public static final NullField NULL_FIELD = new NullField(); @@ -1148,11 +1148,11 @@ *@return boolean stating if the two objects are equal */ public boolean equals(Object obj) { - if (obj == null) return false; + if (!(obj instanceof GenericEntity)) return false; // from here, use the compareTo method since it is more efficient: try { - return this.compareTo(obj) == 0; + return this.compareTo((GenericEntity) obj) == 0; } catch (ClassCastException e) { return false; } @@ -1258,14 +1258,9 @@ *@param obj Object to compare this to *@return int representing the result of the comparison (-1,0, or 1) */ - public int compareTo(Object obj) { + public int compareTo(GenericEntity that) { // if null, it will push to the beginning - if (obj == null) return -1; - - // rather than doing an if instanceof, just cast it and let it throw an exception if - // it fails, this will be faster for the expected case (that it IS a GenericEntity) - // if not a GenericEntity throw ClassCastException, as the spec says - GenericEntity that = (GenericEntity) obj; + if (that == null) return -1; int tempResult = this.entityName.compareTo(that.entityName); @@ -1379,14 +1374,14 @@ } } - public static class NullField implements NULL, Comparable { + public static class NullField implements NULL, Comparable<NullField> { protected NullField() { } public String toString() { return "[null-field]"; } - public int compareTo(Object other) { + public int compareTo(NullField other) { return this != other ? -1 : 0; } } 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=585824&r1=585823&r2=585824&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 Wed Oct 17 20:33:25 2007 @@ -26,7 +26,7 @@ import org.ofbiz.entity.config.DatasourceInfo; import org.ofbiz.entity.model.ModelEntity; -public class OrderByItem implements Comparator { +public class OrderByItem implements Comparator<GenericEntity> { public static final int DEFAULT = 0; public static final int UPPER = 1; public static final int LOWER = 2; @@ -123,10 +123,6 @@ return new OrderByItem(value, descending); } - public int compare(java.lang.Object obj1, java.lang.Object obj2) { - return compare((GenericEntity) obj1, (GenericEntity) obj2); - } - public void checkOrderBy(ModelEntity modelEntity) throws GenericModelException { value.validateSql(modelEntity); } Modified: ofbiz/trunk/framework/entity/src/org/ofbiz/entity/condition/OrderByList.java URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/entity/src/org/ofbiz/entity/condition/OrderByList.java?rev=585824&r1=585823&r2=585824&view=diff ============================================================================== --- ofbiz/trunk/framework/entity/src/org/ofbiz/entity/condition/OrderByList.java (original) +++ ofbiz/trunk/framework/entity/src/org/ofbiz/entity/condition/OrderByList.java Wed Oct 17 20:33:25 2007 @@ -31,7 +31,7 @@ import org.ofbiz.entity.config.DatasourceInfo; import org.ofbiz.entity.model.ModelEntity; -public class OrderByList implements Comparator { +public class OrderByList implements Comparator<GenericEntity> { protected List orderByList = new ArrayList(); public OrderByList() { @@ -96,10 +96,6 @@ OrderByItem orderByItem = (OrderByItem) orderByList.get(i); orderByItem.makeOrderByString(sb, modelEntity, includeTablenamePrefix, datasourceInfo); } - } - - public int compare(Object obj1, Object obj2) { - return compare((GenericEntity) obj1, (GenericEntity) obj2); } public int compare(GenericEntity entity1, GenericEntity entity2) { Modified: ofbiz/trunk/framework/entity/src/org/ofbiz/entity/model/ModelEntity.java URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/entity/src/org/ofbiz/entity/model/ModelEntity.java?rev=585824&r1=585823&r2=585824&view=diff ============================================================================== --- ofbiz/trunk/framework/entity/src/org/ofbiz/entity/model/ModelEntity.java (original) +++ ofbiz/trunk/framework/entity/src/org/ofbiz/entity/model/ModelEntity.java Wed Oct 17 20:33:25 2007 @@ -49,7 +49,7 @@ * Generic Entity - Entity model class * */ -public class ModelEntity extends ModelInfo implements Comparable, Serializable { +public class ModelEntity extends ModelInfo implements Comparable<ModelEntity>, Serializable { public static final String module = ModelEntity.class.getName(); @@ -1169,8 +1169,7 @@ return returnString.toString(); } - public int compareTo(Object obj) { - ModelEntity otherModelEntity = (ModelEntity) obj; + public int compareTo(ModelEntity otherModelEntity) { /* This DOESN'T WORK, so forget it... using two passes //sort list by fk dependencies Modified: ofbiz/trunk/framework/entity/src/org/ofbiz/entity/util/ByteWrapper.java URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/entity/src/org/ofbiz/entity/util/ByteWrapper.java?rev=585824&r1=585823&r2=585824&view=diff ============================================================================== --- ofbiz/trunk/framework/entity/src/org/ofbiz/entity/util/ByteWrapper.java (original) +++ ofbiz/trunk/framework/entity/src/org/ofbiz/entity/util/ByteWrapper.java Wed Oct 17 20:33:25 2007 @@ -23,7 +23,7 @@ /** * A very simple class to wrap a byte array for persistence. */ -public class ByteWrapper implements Comparable, Serializable { +public class ByteWrapper implements Comparable<ByteWrapper>, Serializable { protected byte[] bytes; protected ByteWrapper() {} @@ -44,8 +44,7 @@ return bytes.length; } - public int compareTo(Object obj) { - ByteWrapper other = (ByteWrapper) obj; + public int compareTo(ByteWrapper other) { int r = bytes.length - other.bytes.length; if (r != 0) return r; int i = 0; |
Free forum by Nabble | Edit this page |