You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@commons.apache.org by ba...@apache.org on 2009/06/25 07:25:24 UTC
svn commit: r788263 - in
/commons/proper/lang/trunk/src/java/org/apache/commons/lang/mutable:
Mutable.java MutableObject.java
Author: bayard
Date: Thu Jun 25 05:25:23 2009
New Revision: 788263
URL: http://svn.apache.org/viewvc?rev=788263&view=rev
Log:
Generifying the general Mutable, and the underlying MutableObject. This then allows for typed checking of a MutableBigDecimal for example as per LANG-276
Modified:
commons/proper/lang/trunk/src/java/org/apache/commons/lang/mutable/Mutable.java
commons/proper/lang/trunk/src/java/org/apache/commons/lang/mutable/MutableObject.java
Modified: commons/proper/lang/trunk/src/java/org/apache/commons/lang/mutable/Mutable.java
URL: http://svn.apache.org/viewvc/commons/proper/lang/trunk/src/java/org/apache/commons/lang/mutable/Mutable.java?rev=788263&r1=788262&r2=788263&view=diff
==============================================================================
--- commons/proper/lang/trunk/src/java/org/apache/commons/lang/mutable/Mutable.java (original)
+++ commons/proper/lang/trunk/src/java/org/apache/commons/lang/mutable/Mutable.java Thu Jun 25 05:25:23 2009
@@ -30,14 +30,14 @@
* @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 @@
* @throws ClassCastException
* if the type is invalid
*/
- void setValue(Object value);
+ void setValue(T value);
}
Modified: commons/proper/lang/trunk/src/java/org/apache/commons/lang/mutable/MutableObject.java
URL: http://svn.apache.org/viewvc/commons/proper/lang/trunk/src/java/org/apache/commons/lang/mutable/MutableObject.java?rev=788263&r1=788262&r2=788263&view=diff
==============================================================================
--- commons/proper/lang/trunk/src/java/org/apache/commons/lang/mutable/MutableObject.java (original)
+++ commons/proper/lang/trunk/src/java/org/apache/commons/lang/mutable/MutableObject.java Thu Jun 25 05:25:23 2009
@@ -25,7 +25,7 @@
* @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 @@
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 @@
* @param value
* a value.
*/
- public MutableObject(Object value) {
+ public MutableObject(T value) {
super();
this.value = value;
}
@@ -61,7 +61,7 @@
*
* @return the value
*/
- public Object getValue() {
+ public T getValue() {
return this.value;
}
@@ -71,27 +71,27 @@
* @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));
}
/**