Author: sebb Date: Wed Jan 14 19:53:51 2015 New Revision: 1651790 URL: http://svn.apache.org/r1651790 Log: Fix some generics
Modified: commons/proper/validator/trunk/src/main/java/org/apache/commons/validator/Field.java commons/proper/validator/trunk/src/main/java/org/apache/commons/validator/Form.java commons/proper/validator/trunk/src/main/java/org/apache/commons/validator/ValidatorAction.java Modified: commons/proper/validator/trunk/src/main/java/org/apache/commons/validator/Field.java URL: http://svn.apache.org/viewvc/commons/proper/validator/trunk/src/main/java/org/apache/commons/validator/Field.java?rev=1651790&r1=1651789&r2=1651790&view=diff ============================================================================== --- commons/proper/validator/trunk/src/main/java/org/apache/commons/validator/Field.java (original) +++ commons/proper/validator/trunk/src/main/java/org/apache/commons/validator/Field.java Wed Jan 14 19:53:51 2015 @@ -124,7 +124,7 @@ public class Field implements Cloneable, * synchronized so a call to setDepends() (which clears the List) won't * interfere with a call to isDependency(). */ - private final List dependencyList = Collections.synchronizedList(new ArrayList()); + private final List<String> dependencyList = Collections.synchronizedList(new ArrayList<String>()); /** * @deprecated Subclasses should use getVarMap() instead. @@ -142,7 +142,8 @@ public class Field implements Cloneable, * only grow to the size of the highest argument position. * @since Validator 1.1 */ - protected Map[] args = new Map[0]; + @SuppressWarnings("unchecked") // cannot instantiate generic array, so have to assume this is OK + protected Map<String, Arg>[] args = new Map[0]; /** * Gets the page value that the Field is associated with for @@ -333,9 +334,9 @@ public class Field implements Cloneable, determineArgPosition(arg); ensureArgsCapacity(arg); - Map argMap = this.args[arg.getPosition()]; + Map<String, Arg> argMap = this.args[arg.getPosition()]; if (argMap == null) { - argMap = new HashMap(); + argMap = new HashMap<String, Arg>(); this.args[arg.getPosition()] = argMap; } @@ -396,7 +397,7 @@ public class Field implements Cloneable, */ private void ensureArgsCapacity(Arg arg) { if (arg.getPosition() >= this.args.length) { - Map[] newArgs = new Map[arg.getPosition() + 1]; + Map<String, Arg>[] newArgs = new Map[arg.getPosition() + 1]; System.arraycopy(this.args, 0, newArgs, 0, this.args.length); this.args = newArgs; } @@ -555,18 +556,18 @@ public class Field implements Cloneable, * Replace constants with values in fields and process the depends field * to create the dependency <code>Map</code>. */ - void process(Map globalConstants, Map constants) { + void process(Map<String, String> globalConstants, Map<String, String> constants) { this.hMsgs.setFast(false); this.hVars.setFast(true); this.generateKey(); // Process FormSet Constants - for (Iterator i = constants.entrySet().iterator(); i.hasNext();) { - Entry entry = (Entry) i.next(); - String key = (String) entry.getKey(); + for (Iterator<Entry<String, String>> i = constants.entrySet().iterator(); i.hasNext();) { + Entry<String, String> entry = i.next(); + String key = entry.getKey(); String key2 = TOKEN_START + key + TOKEN_END; - String replaceValue = (String) entry.getValue(); + String replaceValue = entry.getValue(); property = ValidatorUtils.replace(property, key2, replaceValue); @@ -576,11 +577,11 @@ public class Field implements Cloneable, } // Process Global Constants - for (Iterator i = globalConstants.entrySet().iterator(); i.hasNext();) { - Entry entry = (Entry) i.next(); - String key = (String) entry.getKey(); + for (Iterator<Entry<String, String>> i = globalConstants.entrySet().iterator(); i.hasNext();) { + Entry<String, String> entry = i.next(); + String key = entry.getKey(); String key2 = TOKEN_START + key + TOKEN_END; - String replaceValue = (String) entry.getValue(); + String replaceValue = entry.getValue(); property = ValidatorUtils.replace(property, key2, replaceValue); @@ -606,9 +607,9 @@ public class Field implements Cloneable, * Replace the vars value with the key/value pairs passed in. */ private void processVars(String key, String replaceValue) { - Iterator i = this.hVars.keySet().iterator(); + Iterator<String> i = this.hVars.keySet().iterator(); while (i.hasNext()) { - String varKey = (String) i.next(); + String varKey = i.next(); Var var = this.getVar(varKey); var.setValue(ValidatorUtils.replace(var.getValue(), key, replaceValue)); @@ -623,8 +624,8 @@ public class Field implements Cloneable, String varKey = TOKEN_START + TOKEN_VAR; // Process Messages if (key != null && !key.startsWith(varKey)) { - for (Iterator i = hMsgs.values().iterator(); i.hasNext();) { - Msg msg = (Msg) i.next(); + for (Iterator<Msg> i = hMsgs.values().iterator(); i.hasNext();) { + Msg msg = i.next(); msg.setKey(ValidatorUtils.replace(msg.getKey(), key, replaceValue)); } } @@ -639,14 +640,14 @@ public class Field implements Cloneable, private void processArg(String key, String replaceValue) { for (int i = 0; i < this.args.length; i++) { - Map argMap = this.args[i]; + Map<String, Arg> argMap = this.args[i]; if (argMap == null) { continue; } - Iterator iter = argMap.values().iterator(); + Iterator<Arg> iter = argMap.values().iterator(); while (iter.hasNext()) { - Arg arg = (Arg) iter.next(); + Arg arg = iter.next(); if (arg != null) { arg.setKey( @@ -670,7 +671,7 @@ public class Field implements Cloneable, * order they were defined in parameter passed to the setDepends() method. * @return A list of the Field's dependancies. */ - public List getDependencyList() { + public List<String> getDependencyList() { return Collections.unmodifiableList(this.dependencyList); } @@ -692,13 +693,13 @@ public class Field implements Cloneable, continue; } - Map argMap = new HashMap(this.args[i]); - Iterator iter = argMap.entrySet().iterator(); + Map<String, Arg> argMap = new HashMap<String, Arg>(this.args[i]); + Iterator<Entry<String, Arg>> iter = argMap.entrySet().iterator(); while (iter.hasNext()) { - Entry entry = (Entry) iter.next(); - String validatorName = (String) entry.getKey(); - Arg arg = (Arg) entry.getValue(); - argMap.put(validatorName, arg.clone()); + Entry<String, Arg> entry = iter.next(); + String validatorName = entry.getKey(); + Arg arg = entry.getValue(); + argMap.put(validatorName, (Arg) arg.clone()); } field.args[i] = argMap; } @@ -726,7 +727,7 @@ public class Field implements Cloneable, if (hVars != null) { results.append("\t\tVars:\n"); - for (Iterator i = hVars.keySet().iterator(); i.hasNext();) { + for (Iterator<?> i = hVars.keySet().iterator(); i.hasNext();) { Object key = i.next(); results.append("\t\t\t"); results.append(key); @@ -844,22 +845,22 @@ public class Field implements Cloneable, private boolean runDependentValidators( ValidatorAction va, ValidatorResults results, - Map actions, + Map<String, ValidatorAction> actions, Map params, int pos) throws ValidatorException { - List dependentValidators = va.getDependencyList(); + List<String> dependentValidators = va.getDependencyList(); if (dependentValidators.isEmpty()) { return true; } - Iterator iter = dependentValidators.iterator(); + Iterator<String> iter = dependentValidators.iterator(); while (iter.hasNext()) { - String depend = (String) iter.next(); + String depend = iter.next(); - ValidatorAction action = (ValidatorAction) actions.get(depend); + ValidatorAction action = actions.get(depend); if (action == null) { this.handleMissingAction(depend); } @@ -898,10 +899,10 @@ public class Field implements Cloneable, for (int fieldNumber = 0; fieldNumber < numberOfFieldsToValidate; fieldNumber++) { - Iterator dependencies = this.dependencyList.iterator(); + Iterator<String> dependencies = this.dependencyList.iterator(); ValidatorResults results = new ValidatorResults(); while (dependencies.hasNext()) { - String depend = (String) dependencies.next(); + String depend = dependencies.next(); ValidatorAction action = (ValidatorAction) actions.get(depend); if (action == null) { Modified: commons/proper/validator/trunk/src/main/java/org/apache/commons/validator/Form.java URL: http://svn.apache.org/viewvc/commons/proper/validator/trunk/src/main/java/org/apache/commons/validator/Form.java?rev=1651790&r1=1651789&r2=1651790&view=diff ============================================================================== --- commons/proper/validator/trunk/src/main/java/org/apache/commons/validator/Form.java (original) +++ commons/proper/validator/trunk/src/main/java/org/apache/commons/validator/Form.java Wed Jan 14 19:53:51 2015 @@ -49,7 +49,7 @@ public class Form implements Serializabl * in although individual <code>Field</code>s can be retrieved using <code>Map</code> * of <code>Field</code>s. */ - protected List lFields = new ArrayList(); + protected List<Field> lFields = new ArrayList<Field>(); /** * Map of <code>Field</code>s keyed on their property value. @@ -105,7 +105,7 @@ public class Form implements Serializabl * * @return The fields value */ - public List getFields() { + public List<Field> getFields() { return Collections.unmodifiableList(lFields); } @@ -142,9 +142,9 @@ public class Form implements Serializabl */ protected void merge(Form depends) { - List templFields = new ArrayList(); - Map temphFields = new FastHashMap(); - Iterator dependsIt = depends.getFields().iterator(); + List<Field> templFields = new ArrayList<Field>(); + Map<String, Field> temphFields = new FastHashMap(); + Iterator<Field> dependsIt = depends.getFields().iterator(); while (dependsIt.hasNext()) { Field defaultField = (Field) dependsIt.next(); if (defaultField != null) { @@ -187,8 +187,8 @@ public class Form implements Serializabl //we want to go all the way up the tree parent.process(constants, globalConstants, forms); } - for (Iterator i = parent.getFields().iterator(); i.hasNext(); ) { - Field f = (Field) i.next(); + for (Iterator<Field> i = parent.getFields().iterator(); i.hasNext(); ) { + Field f = i.next(); //we want to be able to override any fields we like if (hFields.get(f.getKey()) == null) { lFields.add(n, f); @@ -200,8 +200,8 @@ public class Form implements Serializabl } hFields.setFast(true); //no need to reprocess parent's fields, we iterate from 'n' - for (Iterator i = lFields.listIterator(n); i.hasNext(); ) { - Field f = (Field) i.next(); + for (Iterator<Field> i = lFields.listIterator(n); i.hasNext(); ) { + Field f = i.next(); f.process(globalConstants, constants); } @@ -220,7 +220,7 @@ public class Form implements Serializabl results.append(name); results.append("\n"); - for (Iterator i = lFields.iterator(); i.hasNext(); ) { + for (Iterator<Field> i = lFields.iterator(); i.hasNext(); ) { results.append("\tField: \n"); results.append(i.next()); results.append("\n"); @@ -261,9 +261,9 @@ public class Form implements Serializabl * @throws ValidatorException * @since 1.2.0 */ - ValidatorResults validate(Map params, Map actions, int page, String fieldName) + ValidatorResults validate(Map<String, ? super Object> params, Map actions, int page, String fieldName) throws ValidatorException { - +// TODO the params map contains both ValidatorResults and Field entries ValidatorResults results = new ValidatorResults(); params.put(Validator.VALIDATOR_RESULTS_PARAM, results); @@ -280,9 +280,9 @@ public class Form implements Serializabl results.merge(field.validate(params, actions)); } } else { - Iterator fields = this.lFields.iterator(); + Iterator<Field> fields = this.lFields.iterator(); while (fields.hasNext()) { - Field field = (Field) fields.next(); + Field field = fields.next(); params.put(Validator.FIELD_PARAM, field); Modified: commons/proper/validator/trunk/src/main/java/org/apache/commons/validator/ValidatorAction.java URL: http://svn.apache.org/viewvc/commons/proper/validator/trunk/src/main/java/org/apache/commons/validator/ValidatorAction.java?rev=1651790&r1=1651789&r2=1651790&view=diff ============================================================================== --- commons/proper/validator/trunk/src/main/java/org/apache/commons/validator/ValidatorAction.java (original) +++ commons/proper/validator/trunk/src/main/java/org/apache/commons/validator/ValidatorAction.java Wed Jan 14 19:53:51 2015 @@ -66,7 +66,7 @@ public class ValidatorAction implements /** * The Class object loaded from the classname. */ - private Class validationClass = null; + private Class<?> validationClass = null; /** * The full method name of the validation to be performed. The method @@ -103,7 +103,7 @@ public class ValidatorAction implements /** * The Class objects for each entry in methodParameterList. */ - private Class[] parameterClasses = null; + private Class<?>[] parameterClasses = null; /** * The other <code>ValidatorAction</code>s that this one depends on. If @@ -149,13 +149,13 @@ public class ValidatorAction implements * setDepends() (which clears the List) won't interfere with a call to * isDependency(). */ - private final List dependencyList = Collections.synchronizedList(new ArrayList()); + private final List<String> dependencyList = Collections.synchronizedList(new ArrayList<String>()); /** * An internal List representation of all the validation method's * parameters defined in the methodParams String. */ - private final List methodParameterList = new ArrayList(); + private final List<String> methodParameterList = new ArrayList<String>(); /** * Gets the name of the validator action. @@ -491,7 +491,7 @@ public class ValidatorAction implements * <code>List</code>. * @return List of the validator action's depedents. */ - public List getDependencyList() { + public List<String> getDependencyList() { return Collections.unmodifiableList(this.dependencyList); } @@ -518,6 +518,8 @@ public class ValidatorAction implements */ boolean executeValidationMethod( Field field, + // TODO What is this the correct value type? + // both ValidatorAction and Validator are added as parameters Map params, ValidatorResults results, int pos) @@ -641,7 +643,7 @@ public class ValidatorAction implements return; } - Class[] parameterClasses = new Class[this.methodParameterList.size()]; + Class<?>[] parameterClasses = new Class[this.methodParameterList.size()]; for (int i = 0; i < this.methodParameterList.size(); i++) { String paramClassName = (String) this.methodParameterList.get(i); @@ -665,12 +667,12 @@ public class ValidatorAction implements * array is in the same order as the given List and is suitable for passing * to the validation method. */ - private Object[] getParameterValues(Map params) { + private Object[] getParameterValues(Map<String, ? super Object> params) { Object[] paramValue = new Object[this.methodParameterList.size()]; for (int i = 0; i < this.methodParameterList.size(); i++) { - String paramClassName = (String) this.methodParameterList.get(i); + String paramClassName = this.methodParameterList.get(i); paramValue[i] = params.get(paramClassName); } @@ -759,6 +761,7 @@ public class ValidatorAction implements /** * Returns the ClassLoader set in the Validator contained in the parameter * Map. + * TODO expects Map to contain <String, Validator> */ private ClassLoader getClassLoader(Map params) { Validator v = (Validator) params.get(Validator.VALIDATOR_PARAM); @@ -768,6 +771,7 @@ public class ValidatorAction implements /** * Returns the onlyReturnErrors setting in the Validator contained in the * parameter Map. + * TODO expects Map to contain <String, Validator> */ private boolean onlyReturnErrors(Map params) { Validator v = (Validator) params.get(Validator.VALIDATOR_PARAM);