yifan-c commented on code in PR #63:
URL: 
https://github.com/apache/cassandra-analytics/pull/63#discussion_r1680053097


##########
cassandra-analytics-common/src/main/java/org/apache/cassandra/spark/utils/MapUtils.java:
##########
@@ -239,4 +245,35 @@ public static boolean containsKey(Map<String, String> 
options, String key)
     {
         return options.containsKey(lowerCaseKey(key));
     }
+
+    /**
+     * Resolve the value by consolidating the value associated with the 
current option and the deprecated option.
+     * The method assumes that both the new and the deprecated options expect 
the same value type.
+     * The value of the new option has the precedence over the deprecated one. 
Meaning when both options are present,
+     * the value associated with the new option is returned.
+     *
+     * @param options option keys and values map
+     * @param option new option
+     * @param deprecated deprecated option
+     * @param resolver function to resolve the value. If the input of the 
function is null, it asks for the default value
+     * @return resolved value
+     * @param <T> value type
+     */
+    public static <T> T resolveDeprecated(Map<String, String> options, String 
option, String deprecated, Function<String, T> resolver)
+    {
+        T deprecatedOptionValue = null;
+        if (options.containsKey(deprecated))
+        {
+            LOGGER.warn("The option: {} is deprecated. Please use {} instead. 
See option description for details.", deprecated, option);
+            deprecatedOptionValue = resolver.apply(deprecated);
+        }
+
+        if (options.containsKey(option))
+        {
+            LOGGER.info("The option: {} is defined. Favor the value over {}", 
option, deprecated);

Review Comment:
   good idea



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

To unsubscribe, e-mail: commits-unsubscr...@cassandra.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscr...@cassandra.apache.org
For additional commands, e-mail: commits-h...@cassandra.apache.org

Reply via email to