All Downloads are FREE. Search and download functionalities are using the official Maven repository.

edu.stanford.nlp.util.MutableDouble Maven / Gradle / Ivy

Go to download

Stanford CoreNLP provides a set of natural language analysis tools which can take raw English language text input and give the base forms of words, their parts of speech, whether they are names of companies, people, etc., normalize dates, times, and numeric quantities, mark up the structure of sentences in terms of phrases and word dependencies, and indicate which noun phrases refer to the same entities. It provides the foundational building blocks for higher level text understanding applications.

There is a newer version: 4.5.7
Show newest version
package edu.stanford.nlp.util;

/**
 * A class for Double objects that you can change.
 *
 * @author Dan Klein
 */
public final class MutableDouble extends Number implements Comparable {

  private double d;

  // Mutable
  public void set(double d) {
    this.d = d;
  }

  @Override
  public int hashCode() {
    long bits = Double.doubleToLongBits(d);
    return (int) (bits ^ (bits >>> 32));
  }

  /**
   * Compares this object to the specified object.  The result is
   * true if and only if the argument is not
   * null and is an MutableDouble object that
   * contains the same double value as this object.
   * Note that a MutableDouble isn't and can't be equal to an Double.
   *
   * @param obj the object to compare with.
   * @return true if the objects are the same;
   *         false otherwise.
   */
  @Override
  public boolean equals(Object obj) {
    return obj instanceof MutableDouble && d == ((MutableDouble) obj).d;
  }

  @Override
  public String toString() {
    return Double.toString(d);
  }

  // Comparable interface

  /**
   * Compares two MutableDouble objects numerically.
   *
   * @param anotherMutableDouble the MutableDouble to be
   *                             compared.
   * @return Tthe value 0 if this MutableDouble is
   *         equal to the argument MutableDouble; a value less than
   *         0 if this MutableDouble is numerically less
   *         than the argument MutableDouble; and a value greater
   *         than 0 if this MutableDouble is numerically
   *         greater than the argument MutableDouble (signed
   *         comparison).
   */
  public int compareTo(MutableDouble anotherMutableDouble) {
    double thisVal = this.d;
    double anotherVal = anotherMutableDouble.d;
    return (thisVal < anotherVal ? -1 : (thisVal == anotherVal ? 0 : 1));
  }

  // Number interface
  @Override
  public int intValue() {
    return (int) d;
  }

  @Override
  public long longValue() {
    return (long) d;
  }

  @Override
  public short shortValue() {
    return (short) d;
  }

  @Override
  public byte byteValue() {
    return (byte) d;
  }

  @Override
  public float floatValue() {
    return (float) d;
  }

  @Override
  public double doubleValue() {
    return d;
  }

  public MutableDouble() {
    this(0.0);
  }

  public MutableDouble(double d) {
    this.d = d;
  }

  public MutableDouble(Number num) {
    this.d = num.doubleValue();
  }

  private static final long serialVersionUID = 624465615824626762L;

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy