becketqin commented on a change in pull request #8776: [FLINK-12881][ml] Add 
more functionalities for ML Params and ParamInfo class
URL: https://github.com/apache/flink/pull/8776#discussion_r296513114
 
 

 ##########
 File path: 
flink-ml-parent/flink-ml-api/src/main/java/org/apache/flink/ml/api/misc/param/Params.java
 ##########
 @@ -25,16 +25,58 @@
 
 import java.io.IOException;
 import java.io.Serializable;
+import java.util.ArrayList;
+import java.util.Arrays;
 import java.util.HashMap;
+import java.util.List;
 import java.util.Map;
 
 /**
  * The map-like container class for parameter. This class is provided to unify 
the interaction with
  * parameters.
  */
 @PublicEvolving
-public class Params implements Serializable {
-       private final Map<String, Object> paramMap = new HashMap<>();
+public class Params implements Serializable, Cloneable {
+       private static final long serialVersionUID = 1L;
+
+       /**
+        * A mapping from param name to its value.
+        *
+        * <p>The value is stored in map using json format.
+        */
+       private final Map<String, String> params;
+
+       private transient ObjectMapper mapper;
+
+       public Params() {
+               this.params = new HashMap<>();
+       }
+
+       /**
+        * Return the number of params.
+        *
+        * @return Return the number of params.
+        */
+       public int size() {
+               return params.size();
+       }
+
+       /**
+        * Removes all of the params.
+        * The params will be empty after this call returns.
+        */
+       public void clear() {
+               params.clear();
+       }
+
+       /**
+        * Returns <tt>true</tt> if this params contains no mappings.
+        *
+        * @return <tt>true</tt> if this map contains no mappings
+        */
+       public boolean isEmpty() {
+               return params.isEmpty();
+       }
 
        /**
         * Returns the value of the specific parameter, or default value 
defined in the {@code info} if
 
 Review comment:
   I moved some of the java doc from ParamInfo to here. See if it is clearer.
   
   ```
        /**
         * Returns the value of the specific parameter, or default value 
defined in the {@code info} if
         * this Params doesn't have a value set for the parameter. An exception 
will be thrown in the
         * following cases because no value could be found for the specified 
parameter.
         * <ul>
         *     <li>
         *         Non-optional parameter: no value is defined in this params 
for a non-optional parameter.
         *     </li>
         *     <li>
         *         Optional parameter: no value is defined in this params and 
no default value is defined.
         *     </li>
         * </ul>
         *
         * @param info the info of the specific parameter, usually with default 
value
         * @param <V>  the type of the specific parameter
         * @return the value of the specific parameter, or default value 
defined in the {@code info} if
         * this Params doesn't contain the parameter
         * @throws IllegalArgumentException if no value can be found for 
specified parameter
         */
   ```

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
[email protected]


With regards,
Apache Git Services

Reply via email to