Exemple #1
0
 @Override
 public double getDouble(final String key) {
   final Number number = this.extractNumber(this.findLastTag(key));
   if (number == null) {
     return 0.0;
   }
   return number.doubleValue();
 }
 /**
  * Looks up the given key in the given map, converting the result into a {@link Double}. First,
  * {@link #getNumber(Map,Object)} is invoked. If the result is null, then null is returned.
  * Otherwise, the double value of the resulting {@link Number} is returned.
  *
  * @param map the map whose value to look up
  * @param key the key whose value to look up in that map
  * @return a {@link Double} or null
  */
 public static Double getDouble(Map map, Object key) {
   Number answer = getNumber(map, key);
   if (answer == null) {
     return null;
   } else if (answer instanceof Double) {
     return (Double) answer;
   }
   return new Double(answer.doubleValue());
 }
Exemple #3
0
 /** Return a double parsed from the given string, possibly formatted with a "%" sign */
 public static double parseDouble(String val) throws NumberFormatException, ParseException {
   NumberFormat formatPercent = NumberFormat.getPercentInstance(Locale.US); // for zoom factor
   if (val.indexOf("%") == -1) { // not in percent format !
     return Double.parseDouble(val);
   }
   // else it's a percent format -> parse it
   Number n = formatPercent.parse(val);
   return n.doubleValue();
 }
Exemple #4
0
 public void putByGlobalType(long i, Number element) {
   if (globalType == Type.INT || type == Type.INT) {
     int anElement = element.intValue();
     put(i, anElement);
   } else if (globalType == Type.FLOAT) {
     float anElement = element.floatValue();
     put(i, anElement);
   } else if (globalType == Type.DOUBLE) {
     double anElement = element.doubleValue();
     put(i, anElement);
   }
 }
Exemple #5
0
 /**
  * @return a double parsed from the value associated with the given key in the given Properties.
  *     returns "def" in key wasn't found, or if a parsing error occured. If "value" contains a "%"
  *     sign, we use a <code>NumberFormat.getPercentInstance</code> to convert it to a double.
  */
 public static double parseProperty(Properties preferences, String key, double def) {
   NumberFormat formatPercent = NumberFormat.getPercentInstance(Locale.US); // for zoom factor
   String val = preferences.getProperty(key);
   if (val == null) return def;
   if (val.indexOf("%") == -1) { // not in percent format !
     try {
       return Double.parseDouble(val);
     } catch (NumberFormatException nfe) {
       nfe.printStackTrace();
       return def;
     }
   }
   // else it's a percent format -> parse it
   try {
     Number n = formatPercent.parse(val);
     return n.doubleValue();
   } catch (ParseException ex) {
     ex.printStackTrace();
     return def;
   }
 }
Exemple #6
0
 @Override
 public void assign(Number value, long offset) {
   // note here that the final put will take care of the offset
   for (long i = offset; i < length(); i++) put(i, value.doubleValue());
 }
Exemple #7
0
 @Override
 public void assign(Number value, int offset) {
   for (int i = offset; i < length(); i++) put(i, value.doubleValue());
 }
  /**
   * Helper method to try to call appropriate write method for given untyped Object. At this point,
   * no structural conversions should be done, only simple basic types are to be coerced as
   * necessary.
   *
   * @param value Non-null value to write
   */
  protected void _writeSimpleObject(Object value) throws IOException, JsonGenerationException {
    /* 31-Dec-2009, tatu: Actually, we could just handle some basic
     *    types even without codec. This can improve interoperability,
     *    and specifically help with TokenBuffer.
     */
    if (value == null) {
      writeNull();
      return;
    }
    if (value instanceof String) {
      writeString((String) value);
      return;
    }
    if (value instanceof Number) {
      Number n = (Number) value;
      if (n instanceof Integer) {
        writeNumber(n.intValue());
        return;
      } else if (n instanceof Long) {
        writeNumber(n.longValue());
        return;
      } else if (n instanceof Double) {
        writeNumber(n.doubleValue());
        return;
      } else if (n instanceof Float) {
        writeNumber(n.floatValue());
        return;
      } else if (n instanceof Short) {
        writeNumber(n.shortValue());
        return;
      } else if (n instanceof Byte) {
        writeNumber(n.byteValue());
        return;
      } else if (n instanceof BigInteger) {
        writeNumber((BigInteger) n);
        return;
      } else if (n instanceof BigDecimal) {
        writeNumber((BigDecimal) n);
        return;

        // then Atomic types

      } else if (n instanceof AtomicInteger) {
        writeNumber(((AtomicInteger) n).get());
        return;
      } else if (n instanceof AtomicLong) {
        writeNumber(((AtomicLong) n).get());
        return;
      }
    } else if (value instanceof byte[]) {
      writeBinary((byte[]) value);
      return;
    } else if (value instanceof Boolean) {
      writeBoolean(((Boolean) value).booleanValue());
      return;
    } else if (value instanceof AtomicBoolean) {
      writeBoolean(((AtomicBoolean) value).get());
      return;
    }
    throw new IllegalStateException(
        "No ObjectCodec defined for the generator, can only serialize simple wrapper types (type passed "
            + value.getClass().getName()
            + ")");
  }
 public double getStrokeMiterLimitFactor() {
   Number value = (Number) getAttribute(AttributeKeys.STROKE_MITER_LIMIT);
   return (value != null) ? value.doubleValue() : 10f;
 }