All Downloads are FREE. Search and download functionalities are using the official Maven repository.

io.phasetwo.keycloak.config.Configurable Maven / Gradle / Ivy

The newest version!
package io.phasetwo.keycloak.config;

import java.util.Map;

public interface Configurable {
  void setConfig(Map config);

  default String getOr(Map config, String key, String defaultValue) {
    if (config == null) return defaultValue;
    Object o = config.get(key);
    if (o != null) return o.toString();
    else return defaultValue;
  }

  default boolean getBooleanOr(Map config, String key, boolean defaultValue) {
    if (config == null) return defaultValue;
    Object o = config.get(key);
    if (o != null) {
      if (o instanceof String) {
        return Boolean.parseBoolean((String) o);
      } else {
        return (boolean) o;
      }
    } else {
      return defaultValue;
    }
  }

  default int getIntOr(Map config, String key, int defaultValue) {
    if (config == null) return defaultValue;
    Object o = config.get(key);
    if (o != null) {
      if (o instanceof String) {
        return Integer.parseInt((String) o);
      } else {
        return (int) o;
      }
    } else {
      return defaultValue;
    }
  }

  default double getDoubleOr(Map config, String key, double defaultValue) {
    if (config == null) return defaultValue;
    Object o = config.get(key);
    if (o != null) {
      if (o instanceof String) {
        return Double.parseDouble((String) o);
      } else {
        return (double) o;
      }
    } else {
      return defaultValue;
    }
  }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy