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

org.matheclipse.generic.util.MutableInteger Maven / Gradle / Ivy

The newest version!
package org.matheclipse.generic.util;

public class MutableInteger {
	int fValue;

	public MutableInteger(int i) {
		fValue = i;
	}

	public int intValue() {
		return fValue;
	}

	/**
	 * Increment the value
	 * 
	 * @return the incremented value
	 */
	public int inc() {
		return ++fValue;
	}

	/**
	 * Decrement the value
	 * 
	 * @return the decremented value
	 */
	public int dec() {
		return --fValue;
	}

	/**
	 * Returns a hash code for this Integer.
	 * 
	 * @return a hash code value for this object, equal to the primitive
	 *         int value represented by this Integer
	 *         object.
	 */
	public int hashCode() {
		return fValue;
	}

	/**
	 * Compares this object to the specified object. The result is
	 * true if and only if the argument is not null
	 * and is an MutuableInteger object that contains the same
	 * int value as this object.
	 * 
	 * @param obj
	 *          the object to compare with.
	 * @return true if the objects are the same; false
	 *         otherwise.
	 */
	public boolean equals(Object obj) {
		if (this == obj) {
			return true;
		}
		if (obj instanceof MutableInteger) {
			return fValue == ((MutableInteger) obj).intValue();
		}
		return false;
	}

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




© 2015 - 2025 Weber Informatics LLC | Privacy Policy