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

edu.stanford.nlp.util.MutableLong 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 Long objects that you can change.
 *
 * @author Dan Klein
 */
public final class MutableLong extends Number implements Comparable {

  private long i;

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

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

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

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

  // Comparable interface

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


  // Number interface
  @Override
  public int intValue() {
    return (int) 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 long.  A convenience method.
   *
   * @param val Value to be added to this long
   */
  public void incValue(long val) {
    i += val;
  }

  public MutableLong() {
    this(0);
  }

  public MutableLong(long i) {
    this.i = i;
  }

  private static final long serialVersionUID = 624465615824626762L;

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy