Code example for Properties

Methods: containsKeygetProperty

0
  public static int getRequiredIntParamInRange(Properties props, String name, int defaultValue,
                                               int rangeMin, int rangeMax)
                                               throws IllegalArgumentException 
  { 
    int value = defaultValue;
    if(props.containsKey(name))
        value = Integer.parseInt(props.getProperty(name));
 
    if(value < rangeMin || value > rangeMax)
      throw new IllegalArgumentException(name + " has value " + value + " which is not in the range (" + rangeMin + "," + rangeMax + ").");
 
    return value;
  } 
 
  /** 
   * Obtain the value of an optional long property 
   * @param  props          the property collection 
   * @param  paramName      the property name 
   * @param  defaultValue   default value if absent 
   * @return the property value 
   */