From e9a4e0cfdab64a9b08badff161a46f64d4a7ce45 Mon Sep 17 00:00:00 2001 From: Chris Maeda Date: Tue, 2 Mar 2021 20:53:39 -0500 Subject: [PATCH] Remove commons-collections; Replace FastHashMap with ConcurrentHashMap --- pom.xml | 25 ++++---- .../org/apache/commons/validator/Field.java | 21 ++----- .../org/apache/commons/validator/Form.java | 16 ++--- .../commons/validator/ValidatorResources.java | 20 ++---- .../validator/util/ValidatorUtils.java | 61 +++---------------- 5 files changed, 35 insertions(+), 108 deletions(-) diff --git a/pom.xml b/pom.xml index e614b804d..cbc39d5aa 100644 --- a/pom.xml +++ b/pom.xml @@ -27,7 +27,7 @@ commons-validator commons-validator - 1.8-SNAPSHOT + 1.8.brickst Apache Commons Validator Apache Commons Validator provides the building blocks for both client side validation and server side data validation. @@ -40,7 +40,7 @@ validator org.apache.commons.validator - 1.7 + 1.8.brickst RC2 (requires JDK ${maven.compiler.target}) 1.6 @@ -51,8 +51,8 @@ site-content https://svn.apache.org/repos/infra/websites/production/commons/content/proper/commons-validator - 1.7 - 1.7 + 1.8 + 1.8 UTF-8 UTF-8 true @@ -131,12 +131,19 @@ + + + jitpack.io + https://jitpack.io + + + - commons-beanutils + com.github.BrickStreetSoftware commons-beanutils - 1.9.4 + c5585f2 @@ -162,12 +169,6 @@ 1.2 - - commons-collections - commons-collections - 3.2.2 - - org.apache.commons diff --git a/src/main/java/org/apache/commons/validator/Field.java b/src/main/java/org/apache/commons/validator/Field.java index 5dd7373cc..bda04b38b 100644 --- a/src/main/java/org/apache/commons/validator/Field.java +++ b/src/main/java/org/apache/commons/validator/Field.java @@ -27,9 +27,9 @@ import java.util.Map; import java.util.Map.Entry; import java.util.StringTokenizer; +import java.util.concurrent.ConcurrentHashMap; import org.apache.commons.beanutils.PropertyUtils; -import org.apache.commons.collections.FastHashMap; // DEPRECATED import org.apache.commons.validator.util.ValidatorUtils; /** @@ -37,10 +37,6 @@ * message information and variables to perform the validations and generate * error messages. Instances of this class are configured with a * <field> xml element. - *

- * The use of FastHashMap is deprecated and will be replaced in a future - * release. - *

* * @version $Revision$ * @see org.apache.commons.validator.Form @@ -131,13 +127,13 @@ public class Field implements Cloneable, Serializable { * @deprecated Subclasses should use getVarMap() instead. */ @Deprecated - protected FastHashMap hVars = new FastHashMap(); // + protected ConcurrentHashMap hVars = new ConcurrentHashMap<>(); // /** * @deprecated Subclasses should use getMsgMap() instead. */ @Deprecated - protected FastHashMap hMsgs = new FastHashMap(); // + protected ConcurrentHashMap hMsgs = new ConcurrentHashMap<>(); // /** * Holds Maps of arguments. args[0] returns the Map for the first @@ -560,9 +556,6 @@ public void generateKey() { * to create the dependency Map. */ void process(Map globalConstants, Map constants) { - this.hMsgs.setFast(false); - this.hVars.setFast(true); - this.generateKey(); // Process FormSet Constants @@ -599,8 +592,6 @@ void process(Map globalConstants, Map constants) this.processMessageComponents(key2, replaceValue); } - - hMsgs.setFast(true); } /** @@ -705,8 +696,8 @@ public Object clone() { field.args[i] = argMap; } - field.hVars = ValidatorUtils.copyFastHashMap(hVars); - field.hMsgs = ValidatorUtils.copyFastHashMap(hMsgs); + field.hVars = ValidatorUtils.copyMap(hVars); + field.hMsgs = ValidatorUtils.copyMap(hMsgs); return field; } @@ -934,7 +925,6 @@ private void handleMissingAction(String name) throws ValidatorException { * @since Validator 1.2.0 * @return A Map of the Field's messages. */ - @SuppressWarnings("unchecked") // FastHashMap does not support generics protected Map getMsgMap() { return hMsgs; } @@ -944,7 +934,6 @@ protected Map getMsgMap() { * @since Validator 1.2.0 * @return A Map of the Field's variables. */ - @SuppressWarnings("unchecked") // FastHashMap does not support generics protected Map getVarMap() { return hVars; } diff --git a/src/main/java/org/apache/commons/validator/Form.java b/src/main/java/org/apache/commons/validator/Form.java index e522f98b2..a25b8b35b 100644 --- a/src/main/java/org/apache/commons/validator/Form.java +++ b/src/main/java/org/apache/commons/validator/Form.java @@ -22,18 +22,14 @@ import java.util.Iterator; import java.util.List; import java.util.Map; - -import org.apache.commons.collections.FastHashMap;// DEPRECATED +import java.util.concurrent.ConcurrentHashMap; /** *

* * This contains a set of validation rules for a form/JavaBean. The information * is contained in a list of Field objects. Instances of this class - * are configured with a <form> xml element.

- * - * The use of FastHashMap is deprecated and will be replaced in a future - * release.

+ * are configured with a <form> xml element.

* * @version $Revision$ */ @@ -57,8 +53,7 @@ public class Form implements Serializable { * * @deprecated Subclasses should use getFieldMap() instead. */ - @Deprecated - protected FastHashMap hFields = new FastHashMap(); // + protected ConcurrentHashMap hFields = new ConcurrentHashMap<>(); // /** * The name/key of the form which this form extends from. @@ -145,8 +140,7 @@ public boolean containsField(String fieldName) { protected void merge(Form depends) { List templFields = new ArrayList<>(); - @SuppressWarnings("unchecked") // FastHashMap is not generic - Map temphFields = new FastHashMap(); + Map temphFields = new ConcurrentHashMap(); Iterator dependsIt = depends.getFields().iterator(); while (dependsIt.hasNext()) { Field defaultField = dependsIt.next(); @@ -200,7 +194,6 @@ protected void process(Map globalConstants, Map } } } - hFields.setFast(true); //no need to reprocess parent's fields, we iterate from 'n' for (Iterator i = lFields.listIterator(n); i.hasNext(); ) { Field f = i.next(); @@ -344,7 +337,6 @@ public boolean isExtending() { * @return The fieldMap value * @since Validator 1.2.0 */ - @SuppressWarnings("unchecked") // FastHashMap is not generic protected Map getFieldMap() { return hFields; } diff --git a/src/main/java/org/apache/commons/validator/ValidatorResources.java b/src/main/java/org/apache/commons/validator/ValidatorResources.java index cde2574f4..25cf2285f 100644 --- a/src/main/java/org/apache/commons/validator/ValidatorResources.java +++ b/src/main/java/org/apache/commons/validator/ValidatorResources.java @@ -23,8 +23,8 @@ import java.util.Collections; import java.util.Locale; import java.util.Map; +import java.util.concurrent.ConcurrentHashMap; -import org.apache.commons.collections.FastHashMap; // DEPRECATED import org.apache.commons.digester.Digester; import org.apache.commons.digester.Rule; import org.apache.commons.digester.xmlrules.DigesterLoader; @@ -44,11 +44,6 @@ * must be Serializable so that instances may be used in distributable * application server environments.

* - *

- * The use of FastHashMap is deprecated and will be replaced in a future - * release. - *

- * * @version $Revision$ */ //TODO mutable non-private fields @@ -89,7 +84,7 @@ public class ValidatorResources implements Serializable { * @deprecated Subclasses should use getFormSets() instead. */ @Deprecated - protected FastHashMap hFormSets = new FastHashMap(); // + protected ConcurrentHashMap hFormSets = new ConcurrentHashMap<>(); // /** * Map of global constant values with @@ -97,7 +92,7 @@ public class ValidatorResources implements Serializable { * @deprecated Subclasses should use getConstants() instead. */ @Deprecated - protected FastHashMap hConstants = new FastHashMap(); // + protected ConcurrentHashMap hConstants = new ConcurrentHashMap<>(); // /** * Map of ValidatorActions with @@ -105,7 +100,7 @@ public class ValidatorResources implements Serializable { * @deprecated Subclasses should use getActions() instead. */ @Deprecated - protected FastHashMap hActions = new FastHashMap(); // + protected ConcurrentHashMap hActions = new ConcurrentHashMap<>(); // /** * The default locale on our server. @@ -515,10 +510,6 @@ public Form getForm(String language, String country, String variant, * this method when finished. */ public void process() { - hFormSets.setFast(true); - hConstants.setFast(true); - hActions.setFast(true); - this.processForms(); } @@ -607,7 +598,6 @@ FormSet getFormSet(String language, String country, String variant) { * @return Map of Form sets * @since Validator 1.2.0 */ - @SuppressWarnings("unchecked") // FastHashMap is not generic protected Map getFormSets() { return hFormSets; } @@ -617,7 +607,6 @@ protected Map getFormSets() { * @return Map of Constants * @since Validator 1.2.0 */ - @SuppressWarnings("unchecked") // FastHashMap is not generic protected Map getConstants() { return hConstants; } @@ -627,7 +616,6 @@ protected Map getConstants() { * @return Map of Validator Actions * @since Validator 1.2.0 */ - @SuppressWarnings("unchecked") // FastHashMap is not generic protected Map getActions() { return hActions; } diff --git a/src/main/java/org/apache/commons/validator/util/ValidatorUtils.java b/src/main/java/org/apache/commons/validator/util/ValidatorUtils.java index da92df1c3..2f76ae834 100644 --- a/src/main/java/org/apache/commons/validator/util/ValidatorUtils.java +++ b/src/main/java/org/apache/commons/validator/util/ValidatorUtils.java @@ -18,13 +18,12 @@ import java.lang.reflect.InvocationTargetException; import java.util.Collection; -import java.util.HashMap; import java.util.Iterator; import java.util.Map; import java.util.Map.Entry; +import java.util.concurrent.ConcurrentHashMap; import org.apache.commons.beanutils.PropertyUtils; -import org.apache.commons.collections.FastHashMap; // DEPRECATED import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.apache.commons.validator.Arg; @@ -33,10 +32,6 @@ /** * Basic utility methods. - *

- * The use of FastHashMap is deprecated and will be replaced in a future - * release. - *

* * @version $Revision$ */ @@ -124,44 +119,6 @@ public static String getValueAsString(Object bean, String property) { } - /** - * Makes a deep copy of a FastHashMap if the values - * are Msg, Arg, - * or Var. Otherwise it is a shallow copy. - * - * @param map FastHashMap to copy. - * @return FastHashMap A copy of the FastHashMap that was - * passed in. - * @deprecated This method is not part of Validator's public API. Validator - * will use it internally until FastHashMap references are removed. Use - * copyMap() instead. - */ - @Deprecated - public static FastHashMap copyFastHashMap(FastHashMap map) { - FastHashMap results = new FastHashMap(); - - @SuppressWarnings("unchecked") // FastHashMap is not generic - Iterator> i = map.entrySet().iterator(); - while (i.hasNext()) { - Entry entry = i.next(); - String key = entry.getKey(); - Object value = entry.getValue(); - - if (value instanceof Msg) { - results.put(key, ((Msg) value).clone()); - } else if (value instanceof Arg) { - results.put(key, ((Arg) value).clone()); - } else if (value instanceof Var) { - results.put(key, ((Var) value).clone()); - } else { - results.put(key, value); - } - } - - results.setFast(true); - return results; - } - /** * Makes a deep copy of a Map if the values are * Msg, Arg, or Var. Otherwise, @@ -171,21 +128,21 @@ public static FastHashMap copyFastHashMap(FastHashMap map) { * * @return A copy of the Map that was passed in. */ - public static Map copyMap(Map map) { - Map results = new HashMap<>(); + public static ConcurrentHashMap copyMap(Map map) { + ConcurrentHashMap results = new ConcurrentHashMap<>(); - Iterator> i = map.entrySet().iterator(); + Iterator> i = map.entrySet().iterator(); while (i.hasNext()) { - Entry entry = i.next(); + Entry entry = i.next(); String key = entry.getKey(); - Object value = entry.getValue(); + T value = entry.getValue(); if (value instanceof Msg) { - results.put(key, ((Msg) value).clone()); + results.put(key, (T) ((Msg) value).clone()); } else if (value instanceof Arg) { - results.put(key, ((Arg) value).clone()); + results.put(key, (T) ((Arg) value).clone()); } else if (value instanceof Var) { - results.put(key, ((Var) value).clone()); + results.put(key, (T) ((Var) value).clone()); } else { results.put(key, value); }