Esempio n. 1
0
  /**
   * Constructs a new {@code MathContext} from a string. The string has to specify the precision and
   * the rounding mode to be used and has to follow the following syntax:
   * "precision=<precision> roundingMode=<roundingMode>" This is the same form as the
   * one returned by the {@link #toString} method.
   *
   * @throws IllegalArgumentException if the string is not in the correct format or if the precision
   *     specified is < 0.
   */
  @DSComment("From safe class list")
  @DSSafe(DSCat.SAFE_LIST)
  @DSGenerator(
      tool_name = "Doppelganger",
      tool_version = "2.0",
      generated_on = "2013-12-30 12:56:34.348 -0500",
      hash_original_method = "1D8B76B7C700FBF158167DD4C05A3C30",
      hash_generated_method = "96CB7A0DB097A7BF33DE16B65A96E3E8")
  public MathContext(String s) {
    int precisionLength = "precision=".length();
    int roundingModeLength = "roundingMode=".length();

    int spaceIndex;
    if (!s.startsWith("precision=") || (spaceIndex = s.indexOf(' ', precisionLength)) == -1) {
      throw invalidMathContext("Missing precision", s);
    }
    String precisionString = s.substring(precisionLength, spaceIndex);
    try {
      this.precision = Integer.parseInt(precisionString);
    } catch (NumberFormatException nfe) {
      throw invalidMathContext("Bad precision", s);
    }

    int roundingModeStart = spaceIndex + 1;
    if (!s.regionMatches(roundingModeStart, "roundingMode=", 0, roundingModeLength)) {
      throw invalidMathContext("Missing rounding mode", s);
    }
    roundingModeStart += roundingModeLength;
    this.roundingMode = RoundingMode.valueOf(s.substring(roundingModeStart));

    checkValid();
  }
Esempio n. 2
0
 /**
  * Constructs a new {@code MathContext} with the specified precision and with the specified
  * rounding mode. If the precision passed is zero, then this implies that the computations have to
  * be performed exact, the rounding mode in this case is irrelevant.
  *
  * @param precision the precision for the new {@code MathContext}.
  * @param roundingMode the rounding mode for the new {@code MathContext}.
  * @throws IllegalArgumentException if {@code precision < 0}.
  * @throws NullPointerException if {@code roundingMode} is {@code null}.
  */
 @DSComment("From safe class list")
 @DSSafe(DSCat.SAFE_LIST)
 @DSGenerator(
     tool_name = "Doppelganger",
     tool_version = "2.0",
     generated_on = "2013-12-30 12:56:34.345 -0500",
     hash_original_method = "8370E5A41DB25B2BD130B4958C97346D",
     hash_generated_method = "326C198F27A28956CF1D6E22903C6750")
 public MathContext(int precision, RoundingMode roundingMode) {
   this.precision = precision;
   this.roundingMode = roundingMode;
   checkValid();
 }
Esempio n. 3
0
 /**
  * Makes checks upon deserialization of a {@code MathContext} instance. Checks whether {@code
  * precision >= 0} and {@code roundingMode != null}
  *
  * @throws StreamCorruptedException if {@code precision < 0}
  * @throws StreamCorruptedException if {@code roundingMode == null}
  */
 @DSComment("Private Method")
 @DSBan(DSCat.PRIVATE_METHOD)
 @DSGenerator(
     tool_name = "Doppelganger",
     tool_version = "2.0",
     generated_on = "2013-12-30 12:56:34.369 -0500",
     hash_original_method = "323BCE51E980C267DF7F7C47AD5D1D50",
     hash_generated_method = "0C99EEF0C4D6801AF7A92F869AD842C8")
 private void readObject(ObjectInputStream s) throws IOException, ClassNotFoundException {
   s.defaultReadObject();
   try {
     checkValid();
   } catch (Exception ex) {
     throw new StreamCorruptedException(ex.getMessage());
   }
 }