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

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

Go to download

Stanford Parser processes raw text in English, Chinese, German, Arabic, and French, and extracts constituency parse trees.

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

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

  private int i;

  // Mutable
  public void set(int i) {
    this.i = i;
  }

  @Override
  public int hashCode() {
    return i;
  }

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

  @Override
  public String toString() {
    return Integer.toString(i);
  }

  // Comparable interface

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


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

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

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

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

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

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

  /** Add the argument to the value of this integer.  A convenience method.
   *
   * @param val Value to be added to this integer
   */
  public void incValue(int val) {
    i += val;
  }

  public MutableInteger() {
    this(0);
  }

  public MutableInteger(int i) {
    this.i = i;
  }

  private static final long serialVersionUID = 624465615824626762L;
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy