maobaolong commented on a change in pull request #1369:
URL: https://github.com/apache/hadoop-ozone/pull/1369#discussion_r482199368



##########
File path: 
hadoop-hdds/config/src/main/java/org/apache/hadoop/hdds/conf/ConfigurationReflectionUtil.java
##########
@@ -240,4 +242,52 @@ private static ConfigType detectConfigType(Class<?> 
parameterType,
       }
     }
   }
+
+  public static Optional<String> getDefaultValue(Class<?> configClass,
+      String fieldName) {
+    Config annotation = findFieldConfigAnnotationByName(configClass,
+        fieldName);
+    if (annotation != null) {
+      return Optional.of(annotation.defaultValue());
+    }
+    return Optional.empty();
+  }
+
+  public static Optional<String> getKey(Class<?> configClass,
+      String fieldName) {
+    ConfigGroup configGroup =
+        configClass.getAnnotation(ConfigGroup.class);
+
+    Config annotation = findFieldConfigAnnotationByName(configClass,
+        fieldName);
+    if (annotation != null) {
+      String key = annotation.key();
+      if (configGroup != null) {
+        key = configGroup.prefix() + "." + annotation.key();
+      }
+      return Optional.of(key);
+    }
+    return Optional.empty();
+  }
+
+  public static Optional<ConfigType> getType(Class<?> configClass,
+      String fieldName) {
+    Config config = findFieldConfigAnnotationByName(configClass,
+        fieldName);
+    if (config != null) {
+      return Optional.of(config.type());
+    }
+    return Optional.empty();
+  }
+
+  private static Config findFieldConfigAnnotationByName(Class<?> configClass,
+      String fieldName) {
+    Optional<Field> field = Stream.of(configClass.getDeclaredFields())
+        .filter(f -> f.getName().equals(fieldName))
+        .findFirst();
+    if (field.isPresent()) {
+      return field.get().getAnnotation(Config.class);
+    }
+    return null;

Review comment:
       It looks more clear than before, thanks, done.




----------------------------------------------------------------
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:
us...@infra.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: ozone-issues-unsubscr...@hadoop.apache.org
For additional commands, e-mail: ozone-issues-h...@hadoop.apache.org

Reply via email to