ex00 commented on a change in pull request #8632: [FLINK-12744][ml] add shared 
params in ml package
URL: https://github.com/apache/flink/pull/8632#discussion_r293370308
 
 

 ##########
 File path: 
flink-ml-parent/flink-ml-api/src/main/java/org/apache/flink/ml/api/misc/param/Params.java
 ##########
 @@ -44,17 +86,39 @@
         * @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 RuntimeException if the Params doesn't contains the specific 
parameter, while the
-        *                          param is not optional but has no default 
value in the {@code info}
+        * @throws IllegalArgumentException if the Params doesn't contains the 
specific parameter, while the
+        *                          param is not optional but has no default 
value in the {@code info} or
+        *                          if the Params contains the specific 
parameter and alias, but has more
+        *                          than one value or
+        *                          if the Params doesn't contains the specific 
parameter, while the ParamInfo
+        *                          is optional but has no default value
         */
-       @SuppressWarnings("unchecked")
        public <V> V get(ParamInfo<V> info) {
-               V value = (V) paramMap.getOrDefault(info.getName(), 
info.getDefaultValue());
-               if (value == null && !info.isOptional() && 
!info.hasDefaultValue()) {
-                       throw new RuntimeException(info.getName() +
-                               " not exist which is not optional and don't 
have a default value");
+               String value = null;
+               String usedParamName = null;
+               for (String nameOrAlias : getParamNameAndAlias(info)) {
+                       String v = params.get(nameOrAlias);
+                       if (value != null && v != null) {
+                               throw new 
IllegalArgumentException(String.format("Duplicate parameters of %s and %s",
+                                       usedParamName, nameOrAlias));
+                       } else if (v != null) {
+                               value = v;
+                               usedParamName = nameOrAlias;
 
 Review comment:
   If don't check duplicate we could leave the loop here.

----------------------------------------------------------------
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