Example #1
0
 /**
  * Gets the value for the given key as an enum value.
  *
  * @param key the key to get the value for
  * @param enumType the type of the enum
  * @param <T> the type of the enum
  * @return the value for the given key as an enum value
  */
 public static <T extends Enum<T>> T getEnum(String key, Class<T> enumType) {
   if (!PROPERTIES.containsKey(key)) {
     throw new RuntimeException(ExceptionMessage.INVALID_CONFIGURATION_KEY.getMessage(key));
   }
   final String val = get(key);
   return Enum.valueOf(enumType, val);
 }
Example #2
0
 /**
  * Gets the value for the given key in the {@link Properties}.
  *
  * @param key the key to get the value for
  * @return the value for the given key
  */
 public static String get(String key) {
   if (!PROPERTIES.containsKey(key)) {
     // if key is not found among the default properties
     throw new RuntimeException(ExceptionMessage.INVALID_CONFIGURATION_KEY.getMessage(key));
   }
   String raw = PROPERTIES.getProperty(key);
   return lookup(raw);
 }
Example #3
0
 /**
  * Gets the bytes of the value for the given key.
  *
  * @param key the key to get the value for
  * @return the bytes of the value for the given key
  */
 public static long getBytes(String key) {
   if (PROPERTIES.containsKey(key)) {
     String rawValue = get(key);
     try {
       return FormatUtils.parseSpaceSize(rawValue);
     } catch (Exception ex) {
       throw new RuntimeException(ExceptionMessage.KEY_NOT_BYTES.getMessage(key));
     }
   }
   throw new RuntimeException(ExceptionMessage.INVALID_CONFIGURATION_KEY.getMessage(key));
 }
Example #4
0
 /**
  * Gets the value for the given key as a list.
  *
  * @param key the key to get the value for
  * @param delimiter the delimiter to split the values
  * @return the list of values for the given key
  */
 public static List<String> getList(String key, String delimiter) {
   Preconditions.checkArgument(
       delimiter != null, "Illegal separator for Alluxio properties as " + "list");
   if (PROPERTIES.containsKey(key)) {
     String rawValue = PROPERTIES.getProperty(key);
     return Lists.newLinkedList(
         Splitter.on(delimiter).trimResults().omitEmptyStrings().split(rawValue));
   }
   // if key is not found among the default properties
   throw new RuntimeException(ExceptionMessage.INVALID_CONFIGURATION_KEY.getMessage(key));
 }
Example #5
0
 /**
  * Gets the float representation of the value for the given key.
  *
  * @param key the key to get the value for
  * @return the value for the given key as a {@code float}
  */
 public static float getFloat(String key) {
   if (PROPERTIES.containsKey(key)) {
     String rawValue = PROPERTIES.getProperty(key);
     try {
       return Float.parseFloat(lookup(rawValue));
     } catch (NumberFormatException e) {
       LOG.warn("Configuration cannot evaluate key {} as float.", key);
     }
   }
   // if key is not found among the default properties
   throw new RuntimeException(ExceptionMessage.INVALID_CONFIGURATION_KEY.getMessage(key));
 }
Example #6
0
 /**
  * Gets the double representation of the value for the given key.
  *
  * @param key the key to get the value for
  * @return the value for the given key as a {@code double}
  */
 public static double getDouble(String key) {
   if (PROPERTIES.containsKey(key)) {
     String rawValue = PROPERTIES.getProperty(key);
     try {
       return Double.parseDouble(lookup(rawValue));
     } catch (NumberFormatException e) {
       throw new RuntimeException(ExceptionMessage.KEY_NOT_DOUBLE.getMessage(key));
     }
   }
   // if key is not found among the default properties
   throw new RuntimeException(ExceptionMessage.INVALID_CONFIGURATION_KEY.getMessage(key));
 }
Example #7
0
 /**
  * Gets the value for the given key as a class.
  *
  * @param key the key to get the value for
  * @param <T> the type of the class
  * @return the value for the given key as a class
  */
 public static <T> Class<T> getClass(String key) {
   if (PROPERTIES.containsKey(key)) {
     String rawValue = PROPERTIES.getProperty(key);
     try {
       @SuppressWarnings("unchecked")
       Class<T> clazz = (Class<T>) Class.forName(rawValue);
       return clazz;
     } catch (Exception e) {
       LOG.error("requested class could not be loaded: {}", rawValue, e);
       throw Throwables.propagate(e);
     }
   }
   // if key is not found among the default properties
   throw new RuntimeException(ExceptionMessage.INVALID_CONFIGURATION_KEY.getMessage(key));
 }
Example #8
0
 /**
  * Gets the boolean representation of the value for the given key.
  *
  * @param key the key to get the value for
  * @return the value for the given key as a {@code boolean}
  */
 public static boolean getBoolean(String key) {
   if (PROPERTIES.containsKey(key)) {
     String rawValue = PROPERTIES.getProperty(key);
     String value = lookup(rawValue);
     if (value.equalsIgnoreCase("true")) {
       return true;
     } else if (value.equalsIgnoreCase("false")) {
       return false;
     } else {
       throw new RuntimeException(ExceptionMessage.KEY_NOT_BOOLEAN.getMessage(key));
     }
   }
   // if key is not found among the default properties
   throw new RuntimeException(ExceptionMessage.INVALID_CONFIGURATION_KEY.getMessage(key));
 }