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/09/07 19:52:54 UTC
svn commit: r812235 - in /commons/proper/lang/trunk/src:
java/org/apache/commons/lang/mutable/ test/org/apache/commons/lang/mutable/
Author: bayard
Date: Mon Sep 7 17:52:53 2009
New Revision: 812235
URL: http://svn.apache.org/viewvc?rev=812235&view=rev
Log:
Applying Ivan Bilenjkij's patch such that the Mutable classes implement an appropriately typed Mutable interface. LANG-528
Modified:
commons/proper/lang/trunk/src/java/org/apache/commons/lang/mutable/MutableBoolean.java
commons/proper/lang/trunk/src/java/org/apache/commons/lang/mutable/MutableByte.java
commons/proper/lang/trunk/src/java/org/apache/commons/lang/mutable/MutableDouble.java
commons/proper/lang/trunk/src/java/org/apache/commons/lang/mutable/MutableFloat.java
commons/proper/lang/trunk/src/java/org/apache/commons/lang/mutable/MutableInt.java
commons/proper/lang/trunk/src/java/org/apache/commons/lang/mutable/MutableLong.java
commons/proper/lang/trunk/src/java/org/apache/commons/lang/mutable/MutableShort.java
commons/proper/lang/trunk/src/test/org/apache/commons/lang/mutable/MutableBooleanTest.java
commons/proper/lang/trunk/src/test/org/apache/commons/lang/mutable/MutableByteTest.java
commons/proper/lang/trunk/src/test/org/apache/commons/lang/mutable/MutableDoubleTest.java
commons/proper/lang/trunk/src/test/org/apache/commons/lang/mutable/MutableFloatTest.java
commons/proper/lang/trunk/src/test/org/apache/commons/lang/mutable/MutableIntTest.java
commons/proper/lang/trunk/src/test/org/apache/commons/lang/mutable/MutableLongTest.java
commons/proper/lang/trunk/src/test/org/apache/commons/lang/mutable/MutableObjectTest.java
commons/proper/lang/trunk/src/test/org/apache/commons/lang/mutable/MutableShortTest.java
Modified: commons/proper/lang/trunk/src/java/org/apache/commons/lang/mutable/MutableBoolean.java
URL: http://svn.apache.org/viewvc/commons/proper/lang/trunk/src/java/org/apache/commons/lang/mutable/MutableBoolean.java?rev=812235&r1=812234&r2=812235&view=diff
==============================================================================
--- commons/proper/lang/trunk/src/java/org/apache/commons/lang/mutable/MutableBoolean.java (original)
+++ commons/proper/lang/trunk/src/java/org/apache/commons/lang/mutable/MutableBoolean.java Mon Sep 7 17:52:53 2009
@@ -27,7 +27,7 @@
* @author Apache Software Foundation
* @version $Id$
*/
-public class MutableBoolean implements Mutable, Serializable, Comparable<MutableBoolean> {
+public class MutableBoolean implements Mutable<Boolean>, Serializable, Comparable<MutableBoolean> {
/**
* Required for serialization support.
@@ -88,8 +88,6 @@
* @return zero if this object represents the same boolean value as the argument; a positive value if this object
* represents true and the argument represents false; and a negative value if this object represents false
* and the argument represents true
- * @throws ClassCastException
- * if the argument is not a MutableInt
*/
public int compareTo(MutableBoolean other) {
boolean anotherVal = other.value;
@@ -120,7 +118,7 @@
*
* @return the value as a Boolean
*/
- public Object getValue() {
+ public Boolean getValue() {
return Boolean.valueOf(this.value);
}
@@ -152,11 +150,9 @@
* the value to set
* @throws NullPointerException
* if the object is null
- * @throws ClassCastException
- * if the type is not a {@link Boolean}
*/
- public void setValue(Object value) {
- setValue(((Boolean) value).booleanValue());
+ public void setValue(Boolean value) {
+ this.value = value.booleanValue();
}
/**
Modified: commons/proper/lang/trunk/src/java/org/apache/commons/lang/mutable/MutableByte.java
URL: http://svn.apache.org/viewvc/commons/proper/lang/trunk/src/java/org/apache/commons/lang/mutable/MutableByte.java?rev=812235&r1=812234&r2=812235&view=diff
==============================================================================
--- commons/proper/lang/trunk/src/java/org/apache/commons/lang/mutable/MutableByte.java (original)
+++ commons/proper/lang/trunk/src/java/org/apache/commons/lang/mutable/MutableByte.java Mon Sep 7 17:52:53 2009
@@ -23,7 +23,7 @@
* @since 2.1
* @version $Id$
*/
-public class MutableByte extends Number implements Comparable<MutableByte>, Mutable {
+public class MutableByte extends Number implements Comparable<MutableByte>, Mutable<Number> {
/**
* Required for serialization support.
@@ -72,7 +72,7 @@
*
* @return the value as a Byte
*/
- public Object getValue() {
+ public Byte getValue() {
return Byte.valueOf(this.value);
}
@@ -93,11 +93,9 @@
* the value to set
* @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());
+ public void setValue(Number value) {
+ this.value = value.byteValue();
}
//-----------------------------------------------------------------------
Modified: commons/proper/lang/trunk/src/java/org/apache/commons/lang/mutable/MutableDouble.java
URL: http://svn.apache.org/viewvc/commons/proper/lang/trunk/src/java/org/apache/commons/lang/mutable/MutableDouble.java?rev=812235&r1=812234&r2=812235&view=diff
==============================================================================
--- commons/proper/lang/trunk/src/java/org/apache/commons/lang/mutable/MutableDouble.java (original)
+++ commons/proper/lang/trunk/src/java/org/apache/commons/lang/mutable/MutableDouble.java Mon Sep 7 17:52:53 2009
@@ -23,7 +23,7 @@
* @since 2.1
* @version $Id$
*/
-public class MutableDouble extends Number implements Comparable<MutableDouble>, Mutable {
+public class MutableDouble extends Number implements Comparable<MutableDouble>, Mutable<Number> {
/**
* Required for serialization support.
@@ -72,7 +72,7 @@
*
* @return the value as a Double
*/
- public Object getValue() {
+ public Double getValue() {
return new Double(this.value);
}
@@ -93,11 +93,9 @@
* the value to set
* @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());
+ public void setValue(Number value) {
+ this.value = value.doubleValue();
}
//-----------------------------------------------------------------------
@@ -296,7 +294,6 @@
* @param other
* the mutable to compare to
* @return negative if this is less, zero if equal, positive if greater
- * @throws ClassCastException if the argument is not a MutableDouble
*/
public int compareTo(MutableDouble other) {
double anotherVal = other.value;
Modified: commons/proper/lang/trunk/src/java/org/apache/commons/lang/mutable/MutableFloat.java
URL: http://svn.apache.org/viewvc/commons/proper/lang/trunk/src/java/org/apache/commons/lang/mutable/MutableFloat.java?rev=812235&r1=812234&r2=812235&view=diff
==============================================================================
--- commons/proper/lang/trunk/src/java/org/apache/commons/lang/mutable/MutableFloat.java (original)
+++ commons/proper/lang/trunk/src/java/org/apache/commons/lang/mutable/MutableFloat.java Mon Sep 7 17:52:53 2009
@@ -23,7 +23,7 @@
* @since 2.1
* @version $Id$
*/
-public class MutableFloat extends Number implements Comparable<MutableFloat>, Mutable {
+public class MutableFloat extends Number implements Comparable<MutableFloat>, Mutable<Number> {
/**
* Required for serialization support.
@@ -72,7 +72,7 @@
*
* @return the value as a Float
*/
- public Object getValue() {
+ public Float getValue() {
return new Float(this.value);
}
@@ -93,11 +93,9 @@
* the value to set
* @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).floatValue());
+ public void setValue(Number value) {
+ this.value = value.floatValue();
}
//-----------------------------------------------------------------------
Modified: commons/proper/lang/trunk/src/java/org/apache/commons/lang/mutable/MutableInt.java
URL: http://svn.apache.org/viewvc/commons/proper/lang/trunk/src/java/org/apache/commons/lang/mutable/MutableInt.java?rev=812235&r1=812234&r2=812235&view=diff
==============================================================================
--- commons/proper/lang/trunk/src/java/org/apache/commons/lang/mutable/MutableInt.java (original)
+++ commons/proper/lang/trunk/src/java/org/apache/commons/lang/mutable/MutableInt.java Mon Sep 7 17:52:53 2009
@@ -23,7 +23,7 @@
* @since 2.1
* @version $Id$
*/
-public class MutableInt extends Number implements Comparable<MutableInt>, Mutable {
+public class MutableInt extends Number implements Comparable<MutableInt>, Mutable<Number> {
/**
* Required for serialization support.
@@ -72,7 +72,7 @@
*
* @return the value as a Integer
*/
- public Object getValue() {
+ public Integer getValue() {
return new Integer(this.value);
}
@@ -96,8 +96,8 @@
* @throws ClassCastException
* if the type is not a {@link Number}
*/
- public void setValue(Object value) {
- setValue(((Number) value).intValue());
+ public void setValue(Number value) {
+ this.value = value.intValue();
}
//-----------------------------------------------------------------------
@@ -258,7 +258,6 @@
* @param other
* the mutable to compare to
* @return negative if this is less, zero if equal, positive if greater
- * @throws ClassCastException if the argument is not a MutableInt
*/
public int compareTo(MutableInt other) {
int anotherVal = other.value;
Modified: commons/proper/lang/trunk/src/java/org/apache/commons/lang/mutable/MutableLong.java
URL: http://svn.apache.org/viewvc/commons/proper/lang/trunk/src/java/org/apache/commons/lang/mutable/MutableLong.java?rev=812235&r1=812234&r2=812235&view=diff
==============================================================================
--- commons/proper/lang/trunk/src/java/org/apache/commons/lang/mutable/MutableLong.java (original)
+++ commons/proper/lang/trunk/src/java/org/apache/commons/lang/mutable/MutableLong.java Mon Sep 7 17:52:53 2009
@@ -23,7 +23,7 @@
* @since 2.1
* @version $Id$
*/
-public class MutableLong extends Number implements Comparable<MutableLong>, Mutable {
+public class MutableLong extends Number implements Comparable<MutableLong>, Mutable<Number> {
/**
* Required for serialization support.
@@ -72,7 +72,7 @@
*
* @return the value as a Long
*/
- public Object getValue() {
+ public Long getValue() {
return new Long(this.value);
}
@@ -93,11 +93,9 @@
* the value to set
* @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());
+ public void setValue(Number value) {
+ this.value = value.longValue();
}
//-----------------------------------------------------------------------
@@ -258,7 +256,6 @@
* @param other
* the mutable to compare to
* @return negative if this is less, zero if equal, positive if greater
- * @throws ClassCastException if the argument is not a MutableLong
*/
public int compareTo(MutableLong other) {
long anotherVal = other.value;
Modified: commons/proper/lang/trunk/src/java/org/apache/commons/lang/mutable/MutableShort.java
URL: http://svn.apache.org/viewvc/commons/proper/lang/trunk/src/java/org/apache/commons/lang/mutable/MutableShort.java?rev=812235&r1=812234&r2=812235&view=diff
==============================================================================
--- commons/proper/lang/trunk/src/java/org/apache/commons/lang/mutable/MutableShort.java (original)
+++ commons/proper/lang/trunk/src/java/org/apache/commons/lang/mutable/MutableShort.java Mon Sep 7 17:52:53 2009
@@ -23,7 +23,7 @@
* @since 2.1
* @version $Id$
*/
-public class MutableShort extends Number implements Comparable<MutableShort>, Mutable {
+public class MutableShort extends Number implements Comparable<MutableShort>, Mutable<Number> {
/**
* Required for serialization support.
@@ -72,7 +72,7 @@
*
* @return the value as a Short
*/
- public Object getValue() {
+ public Short getValue() {
return new Short(this.value);
}
@@ -93,11 +93,9 @@
* the value to set
* @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());
+ public void setValue(Number value) {
+ this.value = value.shortValue();
}
//-----------------------------------------------------------------------
@@ -268,7 +266,6 @@
* @param other
* the mutable to compare to
* @return negative if this is less, zero if equal, positive if greater
- * @throws ClassCastException if the argument is not a MutableShort
*/
public int compareTo(MutableShort other) {
short anotherVal = other.value;
Modified: commons/proper/lang/trunk/src/test/org/apache/commons/lang/mutable/MutableBooleanTest.java
URL: http://svn.apache.org/viewvc/commons/proper/lang/trunk/src/test/org/apache/commons/lang/mutable/MutableBooleanTest.java?rev=812235&r1=812234&r2=812235&view=diff
==============================================================================
--- commons/proper/lang/trunk/src/test/org/apache/commons/lang/mutable/MutableBooleanTest.java (original)
+++ commons/proper/lang/trunk/src/test/org/apache/commons/lang/mutable/MutableBooleanTest.java Mon Sep 7 17:52:53 2009
@@ -113,11 +113,6 @@
fail();
} catch (NullPointerException ex) {
}
- try {
- mutBool.setValue("false");
- fail();
- } catch (ClassCastException ex) {
- }
}
public void testHashCode() {
Modified: commons/proper/lang/trunk/src/test/org/apache/commons/lang/mutable/MutableByteTest.java
URL: http://svn.apache.org/viewvc/commons/proper/lang/trunk/src/test/org/apache/commons/lang/mutable/MutableByteTest.java?rev=812235&r1=812234&r2=812235&view=diff
==============================================================================
--- commons/proper/lang/trunk/src/test/org/apache/commons/lang/mutable/MutableByteTest.java (original)
+++ commons/proper/lang/trunk/src/test/org/apache/commons/lang/mutable/MutableByteTest.java Mon Sep 7 17:52:53 2009
@@ -75,10 +75,6 @@
mutNum.setValue(null);
fail();
} catch (NullPointerException ex) {}
- try {
- mutNum.setValue("0");
- fail();
- } catch (ClassCastException ex) {}
}
public void testEquals() {
Modified: commons/proper/lang/trunk/src/test/org/apache/commons/lang/mutable/MutableDoubleTest.java
URL: http://svn.apache.org/viewvc/commons/proper/lang/trunk/src/test/org/apache/commons/lang/mutable/MutableDoubleTest.java?rev=812235&r1=812234&r2=812235&view=diff
==============================================================================
--- commons/proper/lang/trunk/src/test/org/apache/commons/lang/mutable/MutableDoubleTest.java (original)
+++ commons/proper/lang/trunk/src/test/org/apache/commons/lang/mutable/MutableDoubleTest.java Mon Sep 7 17:52:53 2009
@@ -75,10 +75,6 @@
mutNum.setValue(null);
fail();
} catch (NullPointerException ex) {}
- try {
- mutNum.setValue("0");
- fail();
- } catch (ClassCastException ex) {}
}
public void testNanInfinite() {
Modified: commons/proper/lang/trunk/src/test/org/apache/commons/lang/mutable/MutableFloatTest.java
URL: http://svn.apache.org/viewvc/commons/proper/lang/trunk/src/test/org/apache/commons/lang/mutable/MutableFloatTest.java?rev=812235&r1=812234&r2=812235&view=diff
==============================================================================
--- commons/proper/lang/trunk/src/test/org/apache/commons/lang/mutable/MutableFloatTest.java (original)
+++ commons/proper/lang/trunk/src/test/org/apache/commons/lang/mutable/MutableFloatTest.java Mon Sep 7 17:52:53 2009
@@ -75,10 +75,6 @@
mutNum.setValue(null);
fail();
} catch (NullPointerException ex) {}
- try {
- mutNum.setValue("0");
- fail();
- } catch (ClassCastException ex) {}
}
public void testNanInfinite() {
Modified: commons/proper/lang/trunk/src/test/org/apache/commons/lang/mutable/MutableIntTest.java
URL: http://svn.apache.org/viewvc/commons/proper/lang/trunk/src/test/org/apache/commons/lang/mutable/MutableIntTest.java?rev=812235&r1=812234&r2=812235&view=diff
==============================================================================
--- commons/proper/lang/trunk/src/test/org/apache/commons/lang/mutable/MutableIntTest.java (original)
+++ commons/proper/lang/trunk/src/test/org/apache/commons/lang/mutable/MutableIntTest.java Mon Sep 7 17:52:53 2009
@@ -75,10 +75,6 @@
mutNum.setValue(null);
fail();
} catch (NullPointerException ex) {}
- try {
- mutNum.setValue("0");
- fail();
- } catch (ClassCastException ex) {}
}
public void testEquals() {
Modified: commons/proper/lang/trunk/src/test/org/apache/commons/lang/mutable/MutableLongTest.java
URL: http://svn.apache.org/viewvc/commons/proper/lang/trunk/src/test/org/apache/commons/lang/mutable/MutableLongTest.java?rev=812235&r1=812234&r2=812235&view=diff
==============================================================================
--- commons/proper/lang/trunk/src/test/org/apache/commons/lang/mutable/MutableLongTest.java (original)
+++ commons/proper/lang/trunk/src/test/org/apache/commons/lang/mutable/MutableLongTest.java Mon Sep 7 17:52:53 2009
@@ -75,10 +75,6 @@
mutNum.setValue(null);
fail();
} catch (NullPointerException ex) {}
- try {
- mutNum.setValue("0");
- fail();
- } catch (ClassCastException ex) {}
}
public void testEquals() {
Modified: commons/proper/lang/trunk/src/test/org/apache/commons/lang/mutable/MutableObjectTest.java
URL: http://svn.apache.org/viewvc/commons/proper/lang/trunk/src/test/org/apache/commons/lang/mutable/MutableObjectTest.java?rev=812235&r1=812234&r2=812235&view=diff
==============================================================================
--- commons/proper/lang/trunk/src/test/org/apache/commons/lang/mutable/MutableObjectTest.java (original)
+++ commons/proper/lang/trunk/src/test/org/apache/commons/lang/mutable/MutableObjectTest.java Mon Sep 7 17:52:53 2009
@@ -43,17 +43,17 @@
// ----------------------------------------------------------------
public void testConstructors() {
- assertEquals(null, new MutableObject().getValue());
+ assertEquals(null, new MutableObject<String>().getValue());
Integer i = new Integer(6);
- assertSame(i, new MutableObject(i).getValue());
- assertSame("HI", new MutableObject("HI").getValue());
- assertSame(null, new MutableObject(null).getValue());
+ assertSame(i, new MutableObject<Integer>(i).getValue());
+ assertSame("HI", new MutableObject<String>("HI").getValue());
+ assertSame(null, new MutableObject<Object>(null).getValue());
}
public void testGetSet() {
- final MutableObject mutNum = new MutableObject();
- assertEquals(null, new MutableObject().getValue());
+ final MutableObject<String> mutNum = new MutableObject<String>();
+ assertEquals(null, new MutableObject<Object>().getValue());
mutNum.setValue("HELLO");
assertSame("HELLO", mutNum.getValue());
@@ -63,10 +63,10 @@
}
public void testEquals() {
- final MutableObject mutNumA = new MutableObject("ALPHA");
- final MutableObject mutNumB = new MutableObject("ALPHA");
- final MutableObject mutNumC = new MutableObject("BETA");
- final MutableObject mutNumD = new MutableObject(null);
+ final MutableObject<String> mutNumA = new MutableObject<String>("ALPHA");
+ final MutableObject<String> mutNumB = new MutableObject<String>("ALPHA");
+ final MutableObject<String> mutNumC = new MutableObject<String>("BETA");
+ final MutableObject<String> mutNumD = new MutableObject<String>(null);
assertEquals(true, mutNumA.equals(mutNumA));
assertEquals(true, mutNumA.equals(mutNumB));
@@ -84,10 +84,10 @@
}
public void testHashCode() {
- final MutableObject mutNumA = new MutableObject("ALPHA");
- final MutableObject mutNumB = new MutableObject("ALPHA");
- final MutableObject mutNumC = new MutableObject("BETA");
- final MutableObject mutNumD = new MutableObject(null);
+ final MutableObject<String> mutNumA = new MutableObject<String>("ALPHA");
+ final MutableObject<String> mutNumB = new MutableObject<String>("ALPHA");
+ final MutableObject<String> mutNumC = new MutableObject<String>("BETA");
+ final MutableObject<String> mutNumD = new MutableObject<String>(null);
assertEquals(true, mutNumA.hashCode() == mutNumA.hashCode());
assertEquals(true, mutNumA.hashCode() == mutNumB.hashCode());
@@ -98,9 +98,9 @@
}
public void testToString() {
- assertEquals("HI", new MutableObject("HI").toString());
- assertEquals("10.0", new MutableObject(new Double(10)).toString());
- assertEquals("null", new MutableObject(null).toString());
+ assertEquals("HI", new MutableObject<String>("HI").toString());
+ assertEquals("10.0", new MutableObject<Double>(new Double(10)).toString());
+ assertEquals("null", new MutableObject<Object>(null).toString());
}
}
Modified: commons/proper/lang/trunk/src/test/org/apache/commons/lang/mutable/MutableShortTest.java
URL: http://svn.apache.org/viewvc/commons/proper/lang/trunk/src/test/org/apache/commons/lang/mutable/MutableShortTest.java?rev=812235&r1=812234&r2=812235&view=diff
==============================================================================
--- commons/proper/lang/trunk/src/test/org/apache/commons/lang/mutable/MutableShortTest.java (original)
+++ commons/proper/lang/trunk/src/test/org/apache/commons/lang/mutable/MutableShortTest.java Mon Sep 7 17:52:53 2009
@@ -75,10 +75,6 @@
mutNum.setValue(null);
fail();
} catch (NullPointerException ex) {}
- try {
- mutNum.setValue("0");
- fail();
- } catch (ClassCastException ex) {}
}
public void testEquals() {