Generifying the general Mutable, and the underlying MutableObject. This then allows for typed checking of a MutableBigDecimal for example as per LANG-276

git-svn-id: https://svn.apache.org/repos/asf/commons/proper/lang/trunk@788263 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Henri Yandell 2009-06-25 05:25:23 +00:00
parent 171fa698d3
commit 47cd2e5536
2 changed files with 15 additions and 15 deletions

View File

@ -30,14 +30,14 @@ package org.apache.commons.lang.mutable;
* @since 2.1
* @version $Id$
*/
public interface Mutable {
public interface Mutable<T> {
/**
* Gets the value of this mutable.
*
* @return the stored value
*/
Object getValue();
T getValue();
/**
* Sets the value of this mutable.
@ -49,6 +49,6 @@ public interface Mutable {
* @throws ClassCastException
* if the type is invalid
*/
void setValue(Object value);
void setValue(T value);
}

View File

@ -25,7 +25,7 @@ import java.io.Serializable;
* @since 2.1
* @version $Id$
*/
public class MutableObject implements Mutable, Serializable {
public class MutableObject<T> implements Mutable<T>, Serializable {
/**
* Required for serialization support.
@ -35,7 +35,7 @@ public class MutableObject implements Mutable, Serializable {
private static final long serialVersionUID = 86241875189L;
/** The mutable value. */
private Object value;
private T value;
/**
* Constructs a new MutableObject with the default value of <code>null</code>.
@ -50,7 +50,7 @@ public class MutableObject implements Mutable, Serializable {
* @param value
* a value.
*/
public MutableObject(Object value) {
public MutableObject(T value) {
super();
this.value = value;
}
@ -61,7 +61,7 @@ public class MutableObject implements Mutable, Serializable {
*
* @return the value
*/
public Object getValue() {
public T getValue() {
return this.value;
}
@ -71,27 +71,27 @@ public class MutableObject implements Mutable, Serializable {
* @param value
* the value to set
*/
public void setValue(Object value) {
public void setValue(T value) {
this.value = value;
}
//-----------------------------------------------------------------------
/**
* Compares this object against the specified object. The result is <code>true</code> if and only if the argument
* is not <code>null</code> and is a <code>MutableObject</code> object that contains the same <code>Object</code>
* is not <code>null</code> and is a <code>MutableObject</code> object that contains the same <code>T</code>
* value as this object.
*
* @param obj
* the object to compare with.
* @return <code>true</code> if the objects are the same; <code>false</code> otherwise.
*/
@Override
public boolean equals(Object obj) {
if (obj instanceof MutableObject) {
Object other = ((MutableObject) obj).value;
return value == other || (value != null && value.equals(other));
public boolean equals(MutableObject<T> obj) {
if(obj == null) {
return false;
}
return false;
T other = obj.value;
return value == other || (value != null && value.equals(other));
}
/**