/** Implement the Comparable interface */
 public int compare(Object other) {
   if (!(other instanceof Number)) return 1;
   Number you = (Number) other;
   int myInt = this.intValue();
   int yourInt = you.intValue();
   if (myInt > yourInt) return 1;
   else if (myInt < yourInt) return -1;
   else return 0;
 }
예제 #2
0
  /**
   * Get a single-precision (32-bit) floating point number (float) parameter.
   *
   * @param key the key identifying the parameter
   * @param min the minimum allowed value, a {@link java.lang.IllegalArgumentException
   *     IllegalArgumentException} will be thrown if this constraint is violated
   * @param max the maximum allowed value, a {@link java.lang.IllegalArgumentException
   *     IllegalArgumentException} will be thrown if this constraint is violated
   * @param def the default value
   * @return the parameter value, a float parsed from the configuration data
   */
  public final float getFloat(final String key, final float min, final float max, final float def) {
    final String k;
    final Object v;
    final java.lang.Number number;

    k = Configuration.__checkKey(key);

    synchronized (this.m_data) {
      v = this.m_data.get(k);

      if (v == null) {
        return def;
      }

      number = new FloatParser(min, max).parse(v);

      if (number != v) {
        this.m_data.put(key, v);
      }
    }

    return number.floatValue();
  }