You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ofbiz.apache.org by do...@apache.org on 2009/05/03 22:16:24 UTC
svn commit: r771120 -
/ofbiz/trunk/framework/entity/src/org/ofbiz/entity/condition/EntityFunction.java
Author: doogie
Date: Sun May 3 20:16:24 2009
New Revision: 771120
URL: http://svn.apache.org/viewvc?rev=771120&view=rev
Log:
No more generics warnings.
Modified:
ofbiz/trunk/framework/entity/src/org/ofbiz/entity/condition/EntityFunction.java
Modified: ofbiz/trunk/framework/entity/src/org/ofbiz/entity/condition/EntityFunction.java
URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/entity/src/org/ofbiz/entity/condition/EntityFunction.java?rev=771120&r1=771119&r2=771120&view=diff
==============================================================================
--- ofbiz/trunk/framework/entity/src/org/ofbiz/entity/condition/EntityFunction.java (original)
+++ ofbiz/trunk/framework/entity/src/org/ofbiz/entity/condition/EntityFunction.java Sun May 3 20:16:24 2009
@@ -20,6 +20,7 @@
package org.ofbiz.entity.condition;
import java.util.List;
+import java.util.EnumMap;
import java.util.Map;
import javolution.context.ObjectFactory;
@@ -41,26 +42,24 @@
T getValue(Object value);
}
- public static enum SQLFunction {
- LENGTH {
- public EntityFunction.LENGTH createFunction(EntityConditionValue nested) { EntityFunction.LENGTH ef = EntityFunction.LENGTH.lengthFactory.object(); ef.init(nested); return ef;}
- public EntityFunction.LENGTH createFunction(Object value) { EntityFunction.LENGTH ef = EntityFunction.LENGTH.lengthFactory.object(); ef.init(value); return ef;}
- },
- TRIM {
- public EntityFunction.TRIM createFunction(EntityConditionValue nested) { EntityFunction.TRIM ef = EntityFunction.TRIM.trimFactory.object(); ef.init(nested); return ef;}
- public EntityFunction.TRIM createFunction(Object value) { EntityFunction.TRIM ef = EntityFunction.TRIM.trimFactory.object(); ef.init(value); return ef;}
- },
- UPPER {
- public EntityFunction.UPPER createFunction(EntityConditionValue nested) { EntityFunction.UPPER ef = EntityFunction.UPPER.upperFactory.object(); ef.init(nested); return ef;}
- public EntityFunction.UPPER createFunction(Object value) { EntityFunction.UPPER ef = EntityFunction.UPPER.upperFactory.object(); ef.init(value); return ef;}
- },
- LOWER {
- public EntityFunction.LOWER createFunction(EntityConditionValue nested) { EntityFunction.LOWER ef = EntityFunction.LOWER.lowerFactory.object(); ef.init(nested); return ef;}
- public EntityFunction.LOWER createFunction(Object value) { EntityFunction.LOWER ef = EntityFunction.LOWER.lowerFactory.object(); ef.init(value); return ef;}
- };
+ public abstract static class SQLFunctionFactory<T extends Comparable<T>, F extends EntityFunction<T>> extends ObjectFactory<F> {
+ protected abstract void init(F function, Object value);
+
+ protected F createFunction(EntityConditionValue nested) {
+ F ef = object();
+ init(ef, nested);
+ return ef;
+ }
- public abstract <T extends Comparable> EntityFunction<T> createFunction(EntityConditionValue nested);
- public abstract <T extends Comparable> EntityFunction<T> createFunction(Object value);
+ protected F createFunction(Object value) {
+ F ef = object();
+ init(ef, value);
+ return ef;
+ }
+ }
+
+ public static enum SQLFunction {
+ LENGTH, TRIM, UPPER, LOWER;
}
public static final int ID_LENGTH = SQLFunction.LENGTH.ordinal();
@@ -68,24 +67,28 @@
public static final int ID_UPPER = SQLFunction.UPPER.ordinal();
public static final int ID_LOWER = SQLFunction.LOWER.ordinal();
- public static EntityFunction<Integer> LENGTH(EntityConditionValue nested) { return SQLFunction.LENGTH.createFunction(nested); }
- public static EntityFunction<Integer> LENGTH(Object value) { return SQLFunction.LENGTH.createFunction(value); }
- public static EntityFunction<String> TRIM(EntityConditionValue nested) { return SQLFunction.TRIM.createFunction(nested); }
- public static EntityFunction<String> TRIM(Object value) { return SQLFunction.TRIM.createFunction(value); }
- public static EntityFunction<String> UPPER(EntityConditionValue nested) { return SQLFunction.UPPER.createFunction(nested); }
- public static EntityFunction<String> UPPER(Object value) { return SQLFunction.UPPER.createFunction(value); }
- public static EntityFunction<String> UPPER_FIELD(String fieldName) { return SQLFunction.UPPER.createFunction(EntityFieldValue.makeFieldValue(fieldName)); }
- public static EntityFunction<String> LOWER(EntityConditionValue nested) { return SQLFunction.LOWER.createFunction(nested); }
- public static EntityFunction<String> LOWER(Object value) { return SQLFunction.LOWER.createFunction(value); }
+ public static EntityFunction<Integer> LENGTH(EntityConditionValue nested) { return LENGTH.lengthFactory.createFunction(nested); }
+ public static EntityFunction<Integer> LENGTH(Object value) { return LENGTH.lengthFactory.createFunction(value); }
+ public static EntityFunction<String> TRIM(EntityConditionValue nested) { return TRIM.trimFactory.createFunction(nested); }
+ public static EntityFunction<String> TRIM(Object value) { return TRIM.trimFactory.createFunction(value); }
+ public static EntityFunction<String> UPPER(EntityConditionValue nested) { return UPPER.upperFactory.createFunction(nested); }
+ public static EntityFunction<String> UPPER(Object value) { return UPPER.upperFactory.createFunction(value); }
+ public static EntityFunction<String> UPPER_FIELD(String fieldName) { return UPPER.upperFactory.createFunction(EntityFieldValue.makeFieldValue(fieldName)); }
+ public static EntityFunction<String> LOWER(EntityConditionValue nested) { return LOWER.lowerFactory.createFunction(nested); }
+ public static EntityFunction<String> LOWER(Object value) { return LOWER.lowerFactory.createFunction(value); }
public static class LENGTH extends EntityFunction<Integer> {
public static Fetcher<Integer> FETCHER = new Fetcher<Integer>() {
public Integer getValue(Object value) { return value.toString().length(); }
};
- protected static final ObjectFactory<LENGTH> lengthFactory = new ObjectFactory<LENGTH>() {
+ protected static final SQLFunctionFactory<Integer, LENGTH> lengthFactory = new SQLFunctionFactory<Integer, LENGTH>() {
protected LENGTH create() {
return new LENGTH();
}
+
+ protected void init(LENGTH function, Object value) {
+ function.init(value);
+ }
};
protected LENGTH() {}
/** @deprecated Use EntityCondition.LENGTH() instead */
@@ -101,10 +104,14 @@
public static Fetcher<String> FETCHER = new Fetcher<String>() {
public String getValue(Object value) { return value.toString().trim(); }
};
- protected static final ObjectFactory<TRIM> trimFactory = new ObjectFactory<TRIM>() {
+ protected static final SQLFunctionFactory<String, TRIM> trimFactory = new SQLFunctionFactory<String, TRIM>() {
protected TRIM create() {
return new TRIM();
}
+
+ protected void init(TRIM function, Object value) {
+ function.init(value);
+ }
};
protected TRIM() {}
/** @deprecated Use EntityCondition.TRIM() instead */
@@ -120,10 +127,14 @@
public static Fetcher<String> FETCHER = new Fetcher<String>() {
public String getValue(Object value) { return value.toString().toUpperCase(); }
};
- protected static final ObjectFactory<UPPER> upperFactory = new ObjectFactory<UPPER>() {
+ protected static final SQLFunctionFactory<String, UPPER> upperFactory = new SQLFunctionFactory<String, UPPER>() {
protected UPPER create() {
return new UPPER();
}
+
+ protected void init(UPPER function, Object value) {
+ function.init(value);
+ }
};
protected UPPER() {}
/** @deprecated Use EntityCondition.UPPER() instead */
@@ -139,10 +150,14 @@
public static Fetcher<String> FETCHER = new Fetcher<String>() {
public String getValue(Object value) { return value.toString().toLowerCase(); }
};
- protected static final ObjectFactory<LOWER> lowerFactory = new ObjectFactory<LOWER>() {
+ protected static final SQLFunctionFactory<String, LOWER> lowerFactory = new SQLFunctionFactory<String, LOWER>() {
protected LOWER create() {
return new LOWER();
}
+
+ protected void init(LOWER function, Object value) {
+ function.init(value);
+ }
};
protected LOWER() {}
/** @deprecated Use EntityCondition.LOWER() instead */