public static Section fromConfig()

in src/main/java/com/googlesource/gerrit/plugins/rabbitmq/config/section/Sections.java [84:111]


  public static <T extends Section> Section fromConfig(T section, Config... configs) {
    for (Config config : configs) {
      if (config != null) {
        Set<String> names = config.getNames(getName(section));
        Field[] fs = section.getClass().getFields();

        for (Field f : fs) {
          try {
            if (names.contains(f.getName())) {
              Class<?> type = f.getType();
              if (type == String.class) {
                f.set(section, config.getString(getName(section), null, f.getName()));
              } else if (type == Integer.class) {
                f.set(section, config.getInt(getName(section), null, f.getName(), 0));
              } else if (type == Long.class) {
                f.set(section, config.getLong(getName(section), null, f.getName(), 0));
              } else if (type == Boolean.class) {
                f.set(section, config.getBoolean(getName(section), null, f.getName(), false));
              }
            }
          } catch (IllegalAccessException ex) {
            LOGGER.warn("Cannot access field {}. Cause: {}", f.getName(), ex.getMessage());
          }
        }
      }
    }
    return section;
  }