public MutableInt postIncrement(MutableInt x) { int valueBeforeIncrement = x.intValue(); x.add(1); return new MutableInt(valueBeforeIncrement); }
MutableInt x = new MutableInt(); // x is 0. MutableInt y = new MutableInt(); // y is 0. MutableInt temp = postIncrement(x); // Now x is 1, and temp is 0. y = temp; // y is still 0.
/** * Compares this object to the specified object. The result is <code>true</code> if and only if the argument * is not <code>null</code> and is a <code>MutableLong</code> object that contains the same <code>long</code> * value as this object. * * @param obj the object to compare with, null returns false * @return <code>true</code> if the objects are the same; <code>false</code> otherwise. */ public boolean equals(Object obj) { if (obj instanceof MutableLong) { return value == ((MutableLong) obj).longValue(); } return false; }
/** * Sets the value from any Boolean instance. * * @param value the value to set, not null * @throws NullPointerException if the object is null */ public void setValue(Object value) { setValue(((Boolean) value).booleanValue()); }
/** * Compares this object to the specified object. The result is <code>true</code> if and only if the argument is * not <code>null</code> and is a <code>MutableInt</code> object that contains the same <code>int</code> value * as this object. * * @param obj the object to compare with, null returns false * @return <code>true</code> if the objects are the same; <code>false</code> otherwise. */ public boolean equals(Object obj) { if (obj instanceof MutableInt) { return value == ((MutableInt) obj).intValue(); } return false; }
/** * Compares this object to the specified object. The result is <code>true</code> if and only if the argument is * not <code>null</code> and is an <code>MutableBoolean</code> object that contains the same * <code>boolean</code> value as this object. * * @param obj the object to compare with, null returns false * @return <code>true</code> if the objects are the same; <code>false</code> otherwise. */ public boolean equals(Object obj) { if (obj instanceof MutableBoolean) { return value == ((MutableBoolean) obj).booleanValue(); } return false; }
/** * Sets the value from any Number instance. * * @param value the value to set, not null * @throws NullPointerException if the object is null * @throws ClassCastException if the type is not a {@link Number} */ public void setValue(Object value) { setValue(((Number) value).longValue()); }
/** * Sets the value from any Number instance. * * @param value the value to set, not null * @throws NullPointerException if the object is null * @throws ClassCastException if the type is not a {@link Number} */ public void setValue(Object value) { setValue(((Number) value).intValue()); }
/** * Gets this mutable as an instance of Double. * * @return a Double instance containing the value from this mutable, never null */ public Double toDouble() { return new Double(doubleValue()); }
/** * Sets the value from any Number instance. * * @param value the value to set, not null * @throws NullPointerException if the object is null * @throws ClassCastException if the type is not a {@link Number} */ public void setValue(Object value) { setValue(((Number) value).doubleValue()); }
/** * Gets this mutable as an instance of Float. * * @return a Float instance containing the value from this mutable, never null */ public Float toFloat() { return new Float(floatValue()); }
/** * Compares this object to the specified object. The result is <code>true</code> if and only if the argument * is not <code>null</code> and is a <code>MutableShort</code> object that contains the same <code>short</code> * value as this object. * * @param obj the object to compare with, null returns false * @return <code>true</code> if the objects are the same; <code>false</code> otherwise. */ public boolean equals(Object obj) { if (obj instanceof MutableShort) { return value == ((MutableShort) obj).shortValue(); } return false; }
/** * Sets the value from any Number instance. * * @param value the value to set, not null * @throws NullPointerException if the object is null * @throws ClassCastException if the type is not a {@link Number} */ public void setValue(Object value) { setValue(((Number) value).shortValue()); }
/** * Compares this object to the specified object. The result is <code>true</code> if and only if the argument is * not <code>null</code> and is a <code>MutableByte</code> object that contains the same <code>byte</code> value * as this object. * * @param obj the object to compare with, null returns false * @return <code>true</code> if the objects are the same; <code>false</code> otherwise. */ public boolean equals(Object obj) { if (obj instanceof MutableByte) { return value == ((MutableByte) obj).byteValue(); } return false; }
/** * Sets the value from any Number instance. * * @param value the value to set, not null * @throws NullPointerException if the object is null * @throws ClassCastException if the type is not a {@link Number} */ public void setValue(Object value) { setValue(((Number) value).byteValue()); }
MutableInt x = new MutableInt(); // x is 0. MutableInt temp = postIncrement(x); // Now x is 1, and temp is 0. x = temp; // Now x is 0 again.
/** * Gets this mutable as an instance of Integer. * * @return a Integer instance containing the value from this mutable, never null */ public Integer toInteger() { return new Integer(intValue()); }
/** * Gets this mutable as an instance of Long. * * @return a Long instance containing the value from this mutable, never null */ public Long toLong() { return new Long(longValue()); }
/** * Gets this mutable as an instance of Short. * * @return a Short instance containing the value from this mutable, never null */ public Short toShort() { return new Short(shortValue()); }
MutableInt x = new MutableInt(); x = postIncrement(x);