From 47cd2e5536d84a8181191a912cded021c2f5b3dc Mon Sep 17 00:00:00 2001 From: Henri Yandell Date: Thu, 25 Jun 2009 05:25:23 +0000 Subject: [PATCH] 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 --- .../apache/commons/lang/mutable/Mutable.java | 6 ++--- .../commons/lang/mutable/MutableObject.java | 24 +++++++++---------- 2 files changed, 15 insertions(+), 15 deletions(-) diff --git a/src/java/org/apache/commons/lang/mutable/Mutable.java b/src/java/org/apache/commons/lang/mutable/Mutable.java index 10247ebae..6c3a0c2e8 100644 --- a/src/java/org/apache/commons/lang/mutable/Mutable.java +++ b/src/java/org/apache/commons/lang/mutable/Mutable.java @@ -30,14 +30,14 @@ package org.apache.commons.lang.mutable; * @since 2.1 * @version $Id$ */ -public interface Mutable { +public interface Mutable { /** * 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); } diff --git a/src/java/org/apache/commons/lang/mutable/MutableObject.java b/src/java/org/apache/commons/lang/mutable/MutableObject.java index 38ccdf98b..8746859ce 100644 --- a/src/java/org/apache/commons/lang/mutable/MutableObject.java +++ b/src/java/org/apache/commons/lang/mutable/MutableObject.java @@ -25,7 +25,7 @@ import java.io.Serializable; * @since 2.1 * @version $Id$ */ -public class MutableObject implements Mutable, Serializable { +public class MutableObject implements Mutable, 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 null. @@ -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 true if and only if the argument - * is not null and is a MutableObject object that contains the same Object + * is not null and is a MutableObject object that contains the same T * value as this object. * * @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 MutableObject) { - Object other = ((MutableObject) obj).value; - return value == other || (value != null && value.equals(other)); + public boolean equals(MutableObject obj) { + if(obj == null) { + return false; } - return false; + + T other = obj.value; + return value == other || (value != null && value.equals(other)); } /**