You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@openjpa.apache.org by pp...@apache.org on 2009/05/09 10:17:28 UTC
svn commit: r773179 -
/openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/kernel/exps/AbstractExpressionBuilder.java
Author: ppoddar
Date: Sat May 9 08:17:27 2009
New Revision: 773179
URL: http://svn.apache.org/viewvc?rev=773179&view=rev
Log:
OPENJPA-1050: Use generic types where applicable
Modified:
openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/kernel/exps/AbstractExpressionBuilder.java
Modified: openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/kernel/exps/AbstractExpressionBuilder.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/kernel/exps/AbstractExpressionBuilder.java?rev=773179&r1=773178&r2=773179&view=diff
==============================================================================
--- openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/kernel/exps/AbstractExpressionBuilder.java (original)
+++ openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/kernel/exps/AbstractExpressionBuilder.java Sat May 9 08:17:27 2009
@@ -22,7 +22,6 @@
import java.util.Collection;
import java.util.HashMap;
import java.util.HashSet;
-import java.util.Iterator;
import java.util.Map;
import java.util.Set;
@@ -56,12 +55,12 @@
protected static final int EX_UNSUPPORTED = 2;
// common implicit type settings
- protected static final Class TYPE_OBJECT = Object.class;
- protected static final Class TYPE_STRING = String.class;
- protected static final Class TYPE_CHAR_OBJ = Character.class;
- protected static final Class TYPE_NUMBER = Number.class;
- protected static final Class TYPE_COLLECTION = Collection.class;
- protected static final Class TYPE_MAP = Map.class;
+ protected static final Class<Object> TYPE_OBJECT = Object.class;
+ protected static final Class<String> TYPE_STRING = String.class;
+ protected static final Class<Character> TYPE_CHAR_OBJ = Character.class;
+ protected static final Class<Number> TYPE_NUMBER = Number.class;
+ protected static final Class<Collection> TYPE_COLLECTION = Collection.class;
+ protected static final Class<Map> TYPE_MAP = Map.class;
// contains types for setImplicitTypes
protected static final int CONTAINS_TYPE_ELEMENT = 1;
@@ -74,9 +73,9 @@
protected final Resolver resolver;
protected ExpressionFactory factory;
- private final Set _accessPath = new HashSet();
- private Map _seenVars = null;
- private Set _boundVars = null;
+ private final Set<ClassMetaData> _accessPath = new HashSet<ClassMetaData>();
+ private Map<String,Value> _seenVars = null;
+ private Set<Value> _boundVars = null;
/**
* Constructor.
@@ -149,7 +148,7 @@
*/
protected void bind(Value var) {
if (_boundVars == null)
- _boundVars = new HashSet();
+ _boundVars = new HashSet<Value>();
_boundVars.add(var);
}
@@ -162,7 +161,7 @@
return (Value) _seenVars.get(id);
// create and cache var
- Class type = getDeclaredVariableType(id);
+ Class<?> type = getDeclaredVariableType(id);
// add this type to the set of classes in the filter's access path
ClassMetaData meta = null;
@@ -181,7 +180,7 @@
var.setMetaData(meta);
if (_seenVars == null)
- _seenVars = new HashMap();
+ _seenVars = new HashMap<String,Value>();
_seenVars.put(id, var);
return var;
}
@@ -195,13 +194,11 @@
if (_seenVars == null)
return;
- Map.Entry entry;
Value var;
- for (Iterator itr = _seenVars.entrySet().iterator(); itr.hasNext();) {
- entry = (Map.Entry) itr.next();
- var = (Value) entry.getValue();
+ for (Map.Entry<String,Value> entry : _seenVars.entrySet()) {
+ var = entry.getValue();
if (var.getMetaData() == null && !isBound(var)
- && !isDeclaredVariable((String) entry.getKey())) {
+ && !isDeclaredVariable(entry.getKey())) {
throw parseException(EX_USER, "not-unbound-var",
new Object[]{ entry.getKey() }, null);
}
@@ -228,14 +225,14 @@
/**
* Convenience method to get metadata for the given type.
*/
- protected ClassMetaData getMetaData(Class c, boolean required) {
+ protected ClassMetaData getMetaData(Class<?> c, boolean required) {
return getMetaData(c, required, getClassLoader());
}
/**
* Convenience method to get metadata for the given type.
*/
- protected ClassMetaData getMetaData(Class c, boolean required,
+ protected ClassMetaData getMetaData(Class<?> c, boolean required,
ClassLoader loader) {
return resolver.getConfiguration().getMetaDataRepositoryInstance().
getMetaData(c, loader, required);
@@ -284,7 +281,7 @@
Object val = traverseStaticField(meta.getDescribedType(), field);
if (val == null) {
String[] all = meta.getFieldNames();
- Class cls = meta.getDescribedType();
+ Class<?> cls = meta.getDescribedType();
throw parseException(EX_USER, "no-field",
new Object[] {field, cls.getSimpleName(),
StringDistance.getClosestLevenshteinDistance(field, all),
@@ -320,7 +317,7 @@
/**
* Return a constant containing the value of the given static field.
*/
- protected Object traverseStaticField(Class cls, String field) {
+ protected Object traverseStaticField(Class<?> cls, String field) {
try {
return cls.getField(field).get(null);
} catch (Exception e) {
@@ -330,18 +327,18 @@
}
/**
- * Returns the type of the named variabe if it has been declared.
+ * Returns the type of the named variable if it has been declared.
*/
- protected abstract Class getDeclaredVariableType(String name);
+ protected abstract Class<?> getDeclaredVariableType(String name);
/**
* Set the implicit types of the given values based on the fact that
* they're used together, and based on the operator type.
*/
protected void setImplicitTypes(Value val1, Value val2,
- Class expected) {
- Class c1 = val1.getType();
- Class c2 = val2.getType();
+ Class<?> expected) {
+ Class<?> c1 = val1.getType();
+ Class<?> c2 = val2.getType();
boolean o1 = c1 == TYPE_OBJECT;
boolean o2 = c2 == TYPE_OBJECT;
@@ -370,8 +367,8 @@
* Perform conversions to make values compatible.
*/
private void convertTypes(Value val1, Value val2) {
- Class t1 = val1.getType();
- Class t2 = val2.getType();
+ Class<?> t1 = val1.getType();
+ Class<?> t2 = val2.getType();
// allow string-to-char conversions
if (t1 == TYPE_STRING && (Filters.wrap(t2) == TYPE_CHAR_OBJ
@@ -419,8 +416,8 @@
* Perform conversions to make values compatible.
*/
private void convertTypesQuotedNumbers(Value val1, Value val2) {
- Class t1 = val1.getType();
- Class t2 = val2.getType();
+ Class<?> t1 = val1.getType();
+ Class<?> t2 = val2.getType();
// if we're comparing to a single-quoted string, convert
// the value according to the 3.1 rules.
@@ -460,7 +457,7 @@
/**
* Return true if given class can be used as a number.
*/
- private static boolean isNumeric(Class type) {
+ private static boolean isNumeric(Class<?> type) {
type = Filters.wrap(type);
return Number.class.isAssignableFrom(type)
|| type == Character.TYPE || type == TYPE_CHAR_OBJ;
@@ -504,7 +501,7 @@
/**
* Set the implicit type of the given value to the given class.
*/
- protected static void setImplicitType(Value val, Class expected) {
+ protected static void setImplicitType(Value val, Class<?> expected) {
// we never expect a pc type, so no need to worry about metadata
if (val.getType() == TYPE_OBJECT)
val.setImplicitType(expected);