Applying Ivan Bilenjkij's patch such that the Mutable classes implement an appropriately typed Mutable interface. LANG-528

git-svn-id: https://svn.apache.org/repos/asf/commons/proper/lang/trunk@812235 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Henri Yandell 2009-09-07 17:52:53 +00:00
parent bb75332087
commit 02f510c204
15 changed files with 45 additions and 92 deletions

View File

@ -27,7 +27,7 @@ import java.io.Serializable;
* @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 @@ public class MutableBoolean implements Mutable, Serializable, Comparable<Mutable
* @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 @@ public class MutableBoolean implements Mutable, Serializable, Comparable<Mutable
*
* @return the value as a Boolean
*/
public Object getValue() {
public Boolean getValue() {
return Boolean.valueOf(this.value);
}
@ -152,11 +150,9 @@ public class MutableBoolean implements Mutable, Serializable, Comparable<Mutable
* 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();
}
/**

View File

@ -23,7 +23,7 @@ package org.apache.commons.lang.mutable;
* @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 @@ public class MutableByte extends Number implements Comparable<MutableByte>, Muta
*
* @return the value as a Byte
*/
public Object getValue() {
public Byte getValue() {
return Byte.valueOf(this.value);
}
@ -93,11 +93,9 @@ public class MutableByte extends Number implements Comparable<MutableByte>, Muta
* 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();
}
//-----------------------------------------------------------------------

View File

@ -23,7 +23,7 @@ package org.apache.commons.lang.mutable;
* @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 @@ public class MutableDouble extends Number implements Comparable<MutableDouble>,
*
* @return the value as a Double
*/
public Object getValue() {
public Double getValue() {
return new Double(this.value);
}
@ -93,11 +93,9 @@ public class MutableDouble extends Number implements Comparable<MutableDouble>,
* 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 @@ public class MutableDouble extends Number implements Comparable<MutableDouble>,
* @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;

View File

@ -23,7 +23,7 @@ package org.apache.commons.lang.mutable;
* @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 @@ public class MutableFloat extends Number implements Comparable<MutableFloat>, Mu
*
* @return the value as a Float
*/
public Object getValue() {
public Float getValue() {
return new Float(this.value);
}
@ -93,11 +93,9 @@ public class MutableFloat extends Number implements Comparable<MutableFloat>, Mu
* 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();
}
//-----------------------------------------------------------------------

View File

@ -23,7 +23,7 @@ package org.apache.commons.lang.mutable;
* @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 @@ public class MutableInt extends Number implements Comparable<MutableInt>, Mutabl
*
* @return the value as a Integer
*/
public Object getValue() {
public Integer getValue() {
return new Integer(this.value);
}
@ -96,8 +96,8 @@ public class MutableInt extends Number implements Comparable<MutableInt>, Mutabl
* @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 @@ public class MutableInt extends Number implements Comparable<MutableInt>, Mutabl
* @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;

View File

@ -23,7 +23,7 @@ package org.apache.commons.lang.mutable;
* @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 @@ public class MutableLong extends Number implements Comparable<MutableLong>, Muta
*
* @return the value as a Long
*/
public Object getValue() {
public Long getValue() {
return new Long(this.value);
}
@ -93,11 +93,9 @@ public class MutableLong extends Number implements Comparable<MutableLong>, Muta
* 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 @@ public class MutableLong extends Number implements Comparable<MutableLong>, Muta
* @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;

View File

@ -23,7 +23,7 @@ package org.apache.commons.lang.mutable;
* @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 @@ public class MutableShort extends Number implements Comparable<MutableShort>, Mu
*
* @return the value as a Short
*/
public Object getValue() {
public Short getValue() {
return new Short(this.value);
}
@ -93,11 +93,9 @@ public class MutableShort extends Number implements Comparable<MutableShort>, Mu
* 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 @@ public class MutableShort extends Number implements Comparable<MutableShort>, Mu
* @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;

View File

@ -113,11 +113,6 @@ public class MutableBooleanTest extends TestCase {
fail();
} catch (NullPointerException ex) {
}
try {
mutBool.setValue("false");
fail();
} catch (ClassCastException ex) {
}
}
public void testHashCode() {

View File

@ -75,10 +75,6 @@ public class MutableByteTest extends TestCase {
mutNum.setValue(null);
fail();
} catch (NullPointerException ex) {}
try {
mutNum.setValue("0");
fail();
} catch (ClassCastException ex) {}
}
public void testEquals() {

View File

@ -75,10 +75,6 @@ public class MutableDoubleTest extends TestCase {
mutNum.setValue(null);
fail();
} catch (NullPointerException ex) {}
try {
mutNum.setValue("0");
fail();
} catch (ClassCastException ex) {}
}
public void testNanInfinite() {

View File

@ -75,10 +75,6 @@ public class MutableFloatTest extends TestCase {
mutNum.setValue(null);
fail();
} catch (NullPointerException ex) {}
try {
mutNum.setValue("0");
fail();
} catch (ClassCastException ex) {}
}
public void testNanInfinite() {

View File

@ -75,10 +75,6 @@ public class MutableIntTest extends TestCase {
mutNum.setValue(null);
fail();
} catch (NullPointerException ex) {}
try {
mutNum.setValue("0");
fail();
} catch (ClassCastException ex) {}
}
public void testEquals() {

View File

@ -75,10 +75,6 @@ public class MutableLongTest extends TestCase {
mutNum.setValue(null);
fail();
} catch (NullPointerException ex) {}
try {
mutNum.setValue("0");
fail();
} catch (ClassCastException ex) {}
}
public void testEquals() {

View File

@ -43,17 +43,17 @@ public class MutableObjectTest extends TestCase {
// ----------------------------------------------------------------
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 class MutableObjectTest extends TestCase {
}
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 class MutableObjectTest extends TestCase {
}
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 class MutableObjectTest extends TestCase {
}
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());
}
}

View File

@ -75,10 +75,6 @@ public class MutableShortTest extends TestCase {
mutNum.setValue(null);
fail();
} catch (NullPointerException ex) {}
try {
mutNum.setValue("0");
fail();
} catch (ClassCastException ex) {}
}
public void testEquals() {