Author: sebb Date: Thu Jan 15 00:03:46 2015 New Revision: 1651904 URL: http://svn.apache.org/r1651904 Log: 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/ValidatorResources.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=1651904&r1=1651903&r2=1651904&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 Thu Jan 15 00:03:46 2015 @@ -885,7 +885,7 @@ public class Field implements Cloneable, * this field. * @throws ValidatorException If an error occurs during validation. */ - public ValidatorResults validate(Map params, Map actions) + public ValidatorResults validate(Map params, Map<String, ValidatorAction> actions) throws ValidatorException { if (this.getDepends() == 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=1651904&r1=1651903&r2=1651904&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 Thu Jan 15 00:03:46 2015 @@ -56,7 +56,7 @@ public class Form implements Serializabl * * @deprecated Subclasses should use getFieldMap() instead. */ - protected FastHashMap hFields = new FastHashMap(); + protected FastHashMap hFields = new FastHashMap(); // <String, Field> /** * The name/key of the form which this form extends from. @@ -96,7 +96,7 @@ public class Form implements Serializabl */ public void addField(Field f) { this.lFields.add(f); - this.hFields.put(f.getKey(), f); + getFieldMap().put(f.getKey(), f); } /** @@ -118,7 +118,7 @@ public class Form implements Serializabl * @since Validator 1.1 */ public Field getField(String fieldName) { - return (Field) this.hFields.get(fieldName); + return getFieldMap().get(fieldName); } /** @@ -129,7 +129,7 @@ public class Form implements Serializabl * @since Validator 1.1 */ public boolean containsField(String fieldName) { - return this.hFields.containsKey(fieldName); + return getFieldMap().containsKey(fieldName); } /** @@ -143,6 +143,7 @@ public class Form implements Serializabl protected void merge(Form depends) { List<Field> templFields = new ArrayList<Field>(); + @SuppressWarnings("unchecked") // FastHashMap is not generic Map<String, Field> temphFields = new FastHashMap(); Iterator<Field> dependsIt = depends.getFields().iterator(); while (dependsIt.hasNext()) { @@ -155,7 +156,7 @@ public class Form implements Serializabl } else { Field old = getField(fieldKey); - hFields.remove(fieldKey); + getFieldMap().remove(fieldKey); lFields.remove(old); templFields.add(old); temphFields.put(fieldKey, old); @@ -163,7 +164,7 @@ public class Form implements Serializabl } } lFields.addAll(0, templFields); - hFields.putAll(temphFields); + getFieldMap().putAll(temphFields); } /** @@ -174,14 +175,14 @@ public class Form implements Serializabl * @param forms Map of forms * @since Validator 1.2.0 */ - protected void process(Map globalConstants, Map constants, Map forms) { + protected void process(Map<String, String> globalConstants, Map<String, String> constants, Map<String, Form> forms) { if (isProcessed()) { return; } int n = 0;//we want the fields from its parent first if (isExtending()) { - Form parent = (Form) forms.get(inherit); + Form parent = forms.get(inherit); if (parent != null) { if (!parent.isProcessed()) { //we want to go all the way up the tree @@ -190,9 +191,9 @@ public class Form implements Serializabl 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) { + if (getFieldMap().get(f.getKey()) == null) { lFields.add(n, f); - hFields.put(f.getKey(), f); + getFieldMap().put(f.getKey(), f); n++; } } @@ -242,7 +243,7 @@ public class Form implements Serializabl * validation messages. * @throws ValidatorException */ - ValidatorResults validate(Map params, Map actions, int page) + ValidatorResults validate(Map params, Map<String, ValidatorAction> actions, int page) throws ValidatorException { return validate(params, actions, page, null); } @@ -261,7 +262,7 @@ public class Form implements Serializabl * @throws ValidatorException * @since 1.2.0 */ - ValidatorResults validate(Map<String, ? super Object> params, Map actions, int page, String fieldName) + ValidatorResults validate(Map<String, ? super Object> params, Map<String, ValidatorAction> actions, int page, String fieldName) throws ValidatorException { // TODO the params map contains both ValidatorResults and Field entries ValidatorResults results = new ValidatorResults(); @@ -269,7 +270,7 @@ public class Form implements Serializabl // Only validate a single field if specified if (fieldName != null) { - Field field = (Field) this.hFields.get(fieldName); + Field field = (Field) getFieldMap().get(fieldName); if (field == null) { throw new ValidatorException("Unknown field "+fieldName+" in form "+getName()); @@ -342,7 +343,8 @@ public class Form implements Serializabl * @return The fieldMap value * @since Validator 1.2.0 */ - protected Map getFieldMap() { + @SuppressWarnings("unchecked") // FastHashMap is not generic + protected Map<String, Field> getFieldMap() { return hFields; } } Modified: commons/proper/validator/trunk/src/main/java/org/apache/commons/validator/ValidatorResources.java URL: http://svn.apache.org/viewvc/commons/proper/validator/trunk/src/main/java/org/apache/commons/validator/ValidatorResources.java?rev=1651904&r1=1651903&r2=1651904&view=diff ============================================================================== --- commons/proper/validator/trunk/src/main/java/org/apache/commons/validator/ValidatorResources.java (original) +++ commons/proper/validator/trunk/src/main/java/org/apache/commons/validator/ValidatorResources.java Thu Jan 15 00:03:46 2015 @@ -85,24 +85,24 @@ public class ValidatorResources implemen /** * <code>Map</code> of <code>FormSet</code>s stored under - * a <code>Locale</code> key. + * a <code>Locale</code> key (expressed as a String). * @deprecated Subclasses should use getFormSets() instead. */ - protected FastHashMap hFormSets = new FastHashMap(); + protected FastHashMap hFormSets = new FastHashMap(); // <String, FormSet> /** * <code>Map</code> of global constant values with * the name of the constant as the key. * @deprecated Subclasses should use getConstants() instead. */ - protected FastHashMap hConstants = new FastHashMap(); + protected FastHashMap hConstants = new FastHashMap(); // <String, String> /** * <code>Map</code> of <code>ValidatorAction</code>s with * the name of the <code>ValidatorAction</code> as the key. * @deprecated Subclasses should use getActions() instead. */ - protected FastHashMap hActions = new FastHashMap(); + protected FastHashMap hActions = new FastHashMap(); // <String, ValidatorAction> /** * The default locale on our server. @@ -328,7 +328,7 @@ public class ValidatorResources implemen } defaultFormSet = fs; } else { - FormSet formset = (FormSet) hFormSets.get(key); + FormSet formset = getFormSets().get(key); if (formset == null) {// it hasn't been included yet if (getLog().isDebugEnabled()) { getLog().debug("Adding FormSet '" + fs.toString() + "'."); @@ -339,7 +339,7 @@ public class ValidatorResources implemen .warn("Overriding FormSet definition. Duplicate for locale: " + key); } - hFormSets.put(key, fs); + getFormSets().put(key, fs); } } @@ -366,7 +366,7 @@ public class ValidatorResources implemen public void addValidatorAction(ValidatorAction va) { va.init(); - this.hActions.put(va.getName(), va); + getActions().put(va.getName(), va); if (getLog().isDebugEnabled()) { getLog().debug("Add ValidatorAction: " + va.getName() + "," + va.getClassname()); @@ -379,15 +379,15 @@ public class ValidatorResources implemen * @return The validator action. */ public ValidatorAction getValidatorAction(String key) { - return (ValidatorAction) hActions.get(key); + return getActions().get(key); } /** * Get an unmodifiable <code>Map</code> of the <code>ValidatorAction</code>s. * @return Map of validator actions. */ - public Map getValidatorActions() { - return Collections.unmodifiableMap(hActions); + public Map<String, ValidatorAction> getValidatorActions() { + return Collections.unmodifiableMap(getActions()); } /** @@ -456,7 +456,7 @@ public class ValidatorResources implemen // Try language/country/variant String key = this.buildLocale(language, country, variant); if (key.length() > 0) { - FormSet formSet = (FormSet)hFormSets.get(key); + FormSet formSet = getFormSets().get(key); if (formSet != null) { form = formSet.getForm(formKey); } @@ -468,7 +468,7 @@ public class ValidatorResources implemen if (form == null) { key = buildLocale(language, country, null); if (key.length() > 0) { - FormSet formSet = (FormSet)hFormSets.get(key); + FormSet formSet = getFormSets().get(key); if (formSet != null) { form = formSet.getForm(formKey); } @@ -479,7 +479,7 @@ public class ValidatorResources implemen if (form == null) { key = buildLocale(language, null, null); if (key.length() > 0) { - FormSet formSet = (FormSet)hFormSets.get(key); + FormSet formSet = getFormSets().get(key); if (formSet != null) { form = formSet.getForm(formKey); } @@ -536,15 +536,15 @@ public class ValidatorResources implemen } defaultFormSet.process(hConstants); // Loop through FormSets and merge if necessary - for (Iterator i = hFormSets.keySet().iterator(); i.hasNext();) { - String key = (String) i.next(); - FormSet fs = (FormSet) hFormSets.get(key); + for (Iterator<String> i = getFormSets().keySet().iterator(); i.hasNext();) { + String key = i.next(); + FormSet fs = getFormSets().get(key); fs.merge(getParent(fs)); } // Process Fully Constructed FormSets - for (Iterator i = hFormSets.values().iterator(); i.hasNext();) { - FormSet fs = (FormSet) i.next(); + for (Iterator<FormSet> i = getFormSets().values().iterator(); i.hasNext();) { + FormSet fs = i.next(); if (!fs.isProcessed()) { fs.process(hConstants); } @@ -567,16 +567,16 @@ public class ValidatorResources implemen if (fs.getType() == FormSet.LANGUAGE_FORMSET) { parent = defaultFormSet; } else if (fs.getType() == FormSet.COUNTRY_FORMSET) { - parent = (FormSet) hFormSets.get(buildLocale(fs.getLanguage(), + parent = (FormSet) getFormSets().get(buildLocale(fs.getLanguage(), null, null)); if (parent == null) { parent = defaultFormSet; } } else if (fs.getType() == FormSet.VARIANT_FORMSET) { - parent = (FormSet) hFormSets.get(buildLocale(fs.getLanguage(), fs + parent = (FormSet) getFormSets().get(buildLocale(fs.getLanguage(), fs .getCountry(), null)); if (parent == null) { - parent = (FormSet) hFormSets.get(buildLocale(fs.getLanguage(), + parent = (FormSet) getFormSets().get(buildLocale(fs.getLanguage(), null, null)); if (parent == null) { parent = defaultFormSet; @@ -603,7 +603,7 @@ public class ValidatorResources implemen return defaultFormSet; } - return (FormSet)hFormSets.get(key); + return (FormSet)getFormSets().get(key); } /** @@ -611,7 +611,8 @@ public class ValidatorResources implemen * @return Map of Form sets * @since Validator 1.2.0 */ - protected Map getFormSets() { + @SuppressWarnings("unchecked") // FastHashMap is not generic + protected Map<String, FormSet> getFormSets() { return hFormSets; } @@ -620,7 +621,8 @@ public class ValidatorResources implemen * @return Map of Constants * @since Validator 1.2.0 */ - protected Map getConstants() { + @SuppressWarnings("unchecked") // FastHashMap is not generic + protected Map<String, String> getConstants() { return hConstants; } @@ -629,7 +631,8 @@ public class ValidatorResources implemen * @return Map of Validator Actions * @since Validator 1.2.0 */ - protected Map getActions() { + @SuppressWarnings("unchecked") // FastHashMap is not generic + protected Map<String, ValidatorAction> getActions() { return hActions; }