diff --git a/src/java/org/apache/commons/lang/mutable/MutableByte.java b/src/java/org/apache/commons/lang/mutable/MutableByte.java
index 10231527a..eda44e034 100755
--- a/src/java/org/apache/commons/lang/mutable/MutableByte.java
+++ b/src/java/org/apache/commons/lang/mutable/MutableByte.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2002-2004 The Apache Software Foundation.
+ * Copyright 2004 The Apache Software Foundation.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -15,21 +15,33 @@
*/
package org.apache.commons.lang.mutable;
+import java.io.Serializable;
+
/**
- * A mutable Byte
.
+ * A mutable byte
.
*
* @since 2.1
- * @version $Id: MutableByte.java,v 1.3 2004/06/24 04:20:46 bayard Exp $
+ * @version $Id: MutableByte.java,v 1.4 2004/07/07 23:50:28 scolebourne Exp $
*/
-public class MutableByte extends MutableNumber {
+public class MutableByte extends Number
+ implements Comparable, Mutable, Serializable {
+
+ /** Serialization lock. */
+ private static final long serialVersionUID = -1585823265L;
+
+ /** The mutable value. */
+ private byte value;
/**
- * Internal value.
+ * Constructs a new MutableByte with the default value of zero.
*/
- private byte value;
-
+ public MutableByte() {
+ super();
+ }
+
/**
- * Instantiates with the specified value
+ * Constructs a new MutableByte with the specified value.
+ *
* @param value a value.
*/
public MutableByte(byte value) {
@@ -37,34 +49,112 @@ public MutableByte(byte value) {
this.value = value;
}
- public void setValue(byte value) {
- this.value = value;
- }
-
- public long longValue() {
- return this.value;
- }
-
- public double doubleValue() {
- return this.value;
- }
-
- public int intValue() {
- return this.value;
- }
-
/**
- * @return a Byte
+ * Constructs a new MutableByte with the specified value.
+ *
+ * @param value a value.
+ * @throws NullPointerException if the object is null
+ */
+ public MutableByte(Number value) {
+ super();
+ this.value = value.byteValue();
+ }
+
+ //-----------------------------------------------------------------------
+ /**
+ * Gets the value as a Byte instance.
+ *
+ * @return the value as a Byte
*/
public Object getValue() {
return new Byte(this.value);
}
/**
- * @param value a Byte
+ * Sets the value.
+ *
+ * @param value the value to set
+ */
+ public void setValue(byte value) {
+ this.value = value;
+ }
+
+ /**
+ * Sets the value from any Number instance.
+ *
+ * @param value the value to set
+ * @throws NullPointerException if the object is null
+ * @throws ClassCastException if the type is invalid
*/
public void setValue(Object value) {
- setValue(((Number)value).byteValue());
+ setValue(((Number) value).byteValue());
+ }
+
+ //-----------------------------------------------------------------------
+ public byte byteValue() {
+ return value;
+ }
+
+ public int intValue() {
+ return (int) value;
+ }
+
+ public long longValue() {
+ return (long) value;
+ }
+
+ public float floatValue() {
+ return (float) value;
+ }
+
+ public double doubleValue() {
+ return (double) value;
+ }
+
+ //-----------------------------------------------------------------------
+ /**
+ * Checks if this object equals the specified object.
+ *
+ * The object must be a MutableByte with the same value to be equal.
+ *
+ * @param obj the object to compare to
+ * @return true if equal
+ */
+ public boolean equals(Object obj) {
+ if (obj instanceof MutableByte) {
+ return (value == ((MutableByte) obj).value);
+ }
+ return false;
+ }
+
+ /**
+ * Returns a suitable hashcode for this mutable.
+ *
+ * @return a suitable hashcode
+ */
+ public int hashCode() {
+ return (int) value;
+ }
+
+ /**
+ * Compares this mutable to another in ascending order.
+ *
+ * @param obj the mutable to compare to
+ * @return negative if this is less, zero if equal, positive if greater
+ */
+ public int compareTo(Object obj) {
+ MutableByte other = (MutableByte) obj;
+ byte anotherVal = other.value;
+ return (value < anotherVal ? -1 : (value == anotherVal ? 0 : 1));
+ }
+
+ /**
+ * Returns the String value of this mutable.
+ *
+ * @return the mutable value as a string
+ */
+ public String toString() {
+ return String.valueOf((int) value);
}
}
diff --git a/src/java/org/apache/commons/lang/mutable/MutableDouble.java b/src/java/org/apache/commons/lang/mutable/MutableDouble.java
index 02d18c5f0..3ec68c559 100755
--- a/src/java/org/apache/commons/lang/mutable/MutableDouble.java
+++ b/src/java/org/apache/commons/lang/mutable/MutableDouble.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2002-2004 The Apache Software Foundation.
+ * Copyright 2004 The Apache Software Foundation.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -15,21 +15,35 @@
*/
package org.apache.commons.lang.mutable;
+import java.io.Serializable;
+
+import org.apache.commons.lang.math.NumberUtils;
+
/**
- * A mutable Double
+ * A mutable double
.
*
* @since 2.1
- * @version $Id: MutableDouble.java,v 1.3 2004/06/24 04:20:46 bayard Exp $
+ * @version $Id: MutableDouble.java,v 1.4 2004/07/07 23:50:28 scolebourne Exp $
*/
-public class MutableDouble extends MutableNumber {
+public class MutableDouble extends Number
+ implements Comparable, Mutable, Serializable {
- /**
- * Internal value.
- */
+ /** Serialization lock. */
+ private static final long serialVersionUID = 1587163916L;
+
+ /** The mutable value. */
private double value;
/**
- * Instantiates with the specified value
+ * Constructs a new MutableDouble with the default value of zero.
+ */
+ public MutableDouble() {
+ super();
+ }
+
+ /**
+ * Constructs a new MutableDouble with the specified value.
+ *
* @param value a value.
*/
public MutableDouble(double value) {
@@ -37,28 +51,128 @@ public MutableDouble(double value) {
this.value = value;
}
- public void setValue(double value) {
- this.value = value;
- }
-
- public double doubleValue() {
- return this.value;
- }
-
- public long longValue() {
- return (long)this.value;
- }
-
- public int intValue() {
- return (int)this.value;
+ /**
+ * Constructs a new MutableDouble with the specified value.
+ *
+ * @param value a value.
+ * @throws NullPointerException if the object is null
+ */
+ public MutableDouble(Number value) {
+ super();
+ this.value = value.doubleValue();
}
+ //-----------------------------------------------------------------------
+ /**
+ * Gets the value as a Double instance.
+ *
+ * @return the value as a Double
+ */
public Object getValue() {
return new Double(this.value);
}
+ /**
+ * Sets the value.
+ *
+ * @param value the value to set
+ */
+ public void setValue(double value) {
+ this.value = value;
+ }
+
+ /**
+ * Sets the value from any Number instance.
+ *
+ * @param value the value to set
+ * @throws NullPointerException if the object is null
+ * @throws ClassCastException if the type is invalid
+ */
public void setValue(Object value) {
- setValue(((Number)value).doubleValue());
+ setValue(((Number) value).doubleValue());
+ }
+
+ //-----------------------------------------------------------------------
+ public int intValue() {
+ return (int) value;
+ }
+
+ public long longValue() {
+ return (long) value;
+ }
+
+ public float floatValue() {
+ return (float) value;
+ }
+
+ public double doubleValue() {
+ return value;
+ }
+
+ /**
+ * Checks whether the double value is the special NaN value.
+ *
+ * @return true if NaN
+ */
+ public boolean isNaN() {
+ return Double.isNaN(value);
+ }
+
+ /**
+ * Checks whether the double value is infinite.
+ *
+ * @return true if infinite
+ */
+ public boolean isInfinite() {
+ return Double.isInfinite(value);
+ }
+
+ //-----------------------------------------------------------------------
+ /**
+ * Checks if this object equals the specified object.
+ *
+ * The object must be a MutableDouble with the same value to be equal.
+ *
+ * @param obj the object to compare to
+ * @return true if equal
+ */
+ public boolean equals(Object obj) {
+ if (obj instanceof MutableDouble) {
+ double other = ((MutableDouble) obj).value;
+ return (Double.doubleToLongBits(other) == Double.doubleToLongBits(value));
+ }
+ return false;
+ }
+
+ /**
+ * Returns a suitable hashcode for this mutable.
+ *
+ * @return a suitable hashcode
+ */
+ public int hashCode() {
+ long bits = Double.doubleToLongBits(value);
+ return (int)(bits ^ (bits >>> 32));
+ }
+
+ /**
+ * Compares this mutable to another in ascending order.
+ *
+ * @param obj the mutable to compare to
+ * @return negative if this is less, zero if equal, positive if greater
+ */
+ public int compareTo(Object obj) {
+ MutableDouble other = (MutableDouble) obj;
+ double anotherVal = other.value;
+ return NumberUtils.compare(value, anotherVal);
+ }
+
+ /**
+ * Returns the String value of this mutable.
+ *
+ * @return the mutable value as a string
+ */
+ public String toString() {
+ return String.valueOf(value);
}
}
diff --git a/src/java/org/apache/commons/lang/mutable/MutableFloat.java b/src/java/org/apache/commons/lang/mutable/MutableFloat.java
index 3cde7123e..642e3eab4 100755
--- a/src/java/org/apache/commons/lang/mutable/MutableFloat.java
+++ b/src/java/org/apache/commons/lang/mutable/MutableFloat.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2002-2004 The Apache Software Foundation.
+ * Copyright 2004 The Apache Software Foundation.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -15,21 +15,34 @@
*/
package org.apache.commons.lang.mutable;
+import java.io.Serializable;
+
+import org.apache.commons.lang.math.NumberUtils;
+
/**
- * A mutable Float
+ * A mutable float
.
*
* @since 2.1
- * @version $Id: MutableFloat.java,v 1.3 2004/06/24 04:20:46 bayard Exp $
+ * @version $Id: MutableFloat.java,v 1.4 2004/07/07 23:50:28 scolebourne Exp $
*/
-public class MutableFloat extends MutableNumber {
+public class MutableFloat extends Number
+ implements Comparable, Mutable, Serializable {
- /**
- * Internal value.
- */
+ /** Serialization lock. */
+ private static final long serialVersionUID = 5787169186L;
+
+ /** The mutable value. */
private float value;
/**
- * Instantiates with the specified value
+ * Constructs a new MutableFloat with the default value of zero.
+ */
+ public MutableFloat() {
+ super();
+ }
+
+ /**
+ * Constructs a new MutableFloat with the specified value.
*
* @param value a value.
*/
@@ -38,28 +51,127 @@ public MutableFloat(float value) {
this.value = value;
}
- public void setValue(float value) {
- this.value = value;
- }
-
- public double doubleValue() {
- return this.value;
- }
-
- public int intValue() {
- return (int)this.value;
- }
-
- public long longValue() {
- return (long)this.value;
+ /**
+ * Constructs a new MutableFloat with the specified value.
+ *
+ * @param value a value.
+ * @throws NullPointerException if the object is null
+ */
+ public MutableFloat(Number value) {
+ super();
+ this.value = value.floatValue();
}
+ //-----------------------------------------------------------------------
+ /**
+ * Gets the value as a Float instance.
+ *
+ * @return the value as a Float
+ */
public Object getValue() {
return new Float(this.value);
}
+ /**
+ * Sets the value.
+ *
+ * @param value the value to set
+ */
+ public void setValue(float value) {
+ this.value = value;
+ }
+
+ /**
+ * Sets the value from any Number instance.
+ *
+ * @param value the value to set
+ * @throws NullPointerException if the object is null
+ * @throws ClassCastException if the type is invalid
+ */
public void setValue(Object value) {
- setValue(((Number)value).floatValue());
+ setValue(((Number) value).floatValue());
+ }
+
+ //-----------------------------------------------------------------------
+ public int intValue() {
+ return (int) value;
+ }
+
+ public long longValue() {
+ return (long) value;
+ }
+
+ public float floatValue() {
+ return value;
+ }
+
+ public double doubleValue() {
+ return (double) value;
+ }
+
+ /**
+ * Checks whether the float value is the special NaN value.
+ *
+ * @return true if NaN
+ */
+ public boolean isNaN() {
+ return Float.isNaN(value);
+ }
+
+ /**
+ * Checks whether the float value is infinite.
+ *
+ * @return true if infinite
+ */
+ public boolean isInfinite() {
+ return Float.isInfinite(value);
+ }
+
+ //-----------------------------------------------------------------------
+ /**
+ * Checks if this object equals the specified object.
+ *
+ * The object must be a MutableFloat with the same value to be equal.
+ *
+ * @param obj the object to compare to
+ * @return true if equal
+ */
+ public boolean equals(Object obj) {
+ if (obj instanceof MutableFloat) {
+ float other = ((MutableFloat) obj).value;
+ return (Float.floatToIntBits(other) == Float.floatToIntBits(value));
+ }
+ return false;
+ }
+
+ /**
+ * Returns a suitable hashcode for this mutable.
+ *
+ * @return a suitable hashcode
+ */
+ public int hashCode() {
+ return Float.floatToIntBits(value);
+ }
+
+ /**
+ * Compares this mutable to another in ascending order.
+ *
+ * @param obj the mutable to compare to
+ * @return negative if this is less, zero if equal, positive if greater
+ */
+ public int compareTo(Object obj) {
+ MutableFloat other = (MutableFloat) obj;
+ float anotherVal = other.value;
+ return NumberUtils.compare(value, anotherVal);
+ }
+
+ /**
+ * Returns the String value of this mutable.
+ *
+ * @return the mutable value as a string
+ */
+ public String toString() {
+ return String.valueOf(value);
}
}
diff --git a/src/java/org/apache/commons/lang/mutable/MutableInt.java b/src/java/org/apache/commons/lang/mutable/MutableInt.java
index 39e2ab3ae..2bbdb67bf 100644
--- a/src/java/org/apache/commons/lang/mutable/MutableInt.java
+++ b/src/java/org/apache/commons/lang/mutable/MutableInt.java
@@ -21,7 +21,7 @@
* A mutable int
.
*
* @since 2.1
- * @version $Id: MutableInt.java,v 1.1 2004/07/05 22:15:33 scolebourne Exp $
+ * @version $Id: MutableInt.java,v 1.2 2004/07/07 23:50:28 scolebourne Exp $
*/
public class MutableInt extends Number
implements Comparable, Mutable, Serializable {
@@ -49,15 +49,43 @@ public MutableInt(int value) {
this.value = value;
}
+ /**
+ * Constructs a new MutableInt with the specified value.
+ *
+ * @param value a value.
+ * @throws NullPointerException if the object is null
+ */
+ public MutableInt(Number value) {
+ super();
+ this.value = value.intValue();
+ }
+
//-----------------------------------------------------------------------
+ /**
+ * Gets the value as a Integer instance.
+ *
+ * @return the value as a Integer
+ */
public Object getValue() {
return new Integer(this.value);
}
+ /**
+ * Sets the value.
+ *
+ * @param value the value to set
+ */
public void setValue(int value) {
this.value = value;
}
+ /**
+ * Sets the value from any Number instance.
+ *
+ * @param value the value to set
+ * @throws NullPointerException if the object is null
+ * @throws ClassCastException if the type is invalid
+ */
public void setValue(Object value) {
setValue(((Number) value).intValue());
}
diff --git a/src/java/org/apache/commons/lang/mutable/MutableInteger.java b/src/java/org/apache/commons/lang/mutable/MutableInteger.java
deleted file mode 100755
index cb361136f..000000000
--- a/src/java/org/apache/commons/lang/mutable/MutableInteger.java
+++ /dev/null
@@ -1,65 +0,0 @@
-/*
- * Copyright 2002-2004 The Apache Software Foundation.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.apache.commons.lang.mutable;
-
-/**
- * A mutable Integer
.
- *
- * @since 2.1
- * @version $Id: MutableInteger.java,v 1.4 2004/06/27 05:23:47 bayard Exp $
- */
-public class MutableInteger extends MutableNumber {
-
- /**
- * Internal value.
- */
- private int value;
-
- /**
- * Instantiates with the specified value
- *
- * @param value a value.
- */
- public MutableInteger(int value) {
- super();
- this.value = value;
- }
-
- public void setValue(int value) {
- this.value = value;
- }
-
- public double doubleValue() {
- return this.value;
- }
-
- public long longValue() {
- return this.value;
- }
-
- public int intValue() {
- return this.value;
- }
-
- public Object getValue() {
- return new Integer(this.value);
- }
-
- public void setValue(Object value) {
- setValue(((Number)value).intValue());
- }
-
-}
diff --git a/src/java/org/apache/commons/lang/mutable/MutableLong.java b/src/java/org/apache/commons/lang/mutable/MutableLong.java
index ed7739529..9a5207718 100755
--- a/src/java/org/apache/commons/lang/mutable/MutableLong.java
+++ b/src/java/org/apache/commons/lang/mutable/MutableLong.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2002-2004 The Apache Software Foundation.
+ * Copyright 2004 The Apache Software Foundation.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -15,50 +15,142 @@
*/
package org.apache.commons.lang.mutable;
+import java.io.Serializable;
+
/**
- * A mutable Long
+ * A mutable long
.
*
* @since 2.1
- * @version $Id: MutableLong.java,v 1.3 2004/06/24 04:20:46 bayard Exp $
+ * @version $Id: MutableLong.java,v 1.4 2004/07/07 23:50:28 scolebourne Exp $
*/
-public class MutableLong extends MutableNumber {
+public class MutableLong extends Number
+ implements Comparable, Mutable, Serializable {
- /**
- * Internal value.
- */
+ /** Serialization lock. */
+ private static final long serialVersionUID = 62986528375L;
+
+ /** The mutable value. */
private long value;
/**
- * Instantiates with the specified value
+ * Constructs a new MutableLong with the default value of zero.
+ */
+ public MutableLong() {
+ super();
+ }
+
+ /**
+ * Constructs a new MutableLong with the specified value.
+ *
* @param value a value.
*/
public MutableLong(long value) {
super();
- setValue(value);
- }
-
- public void setValue(long value) {
this.value = value;
}
- public double doubleValue() {
- return this.value;
- }
-
- public long longValue() {
- return this.value;
- }
-
- public int intValue() {
- return (int)this.value;
+ /**
+ * Constructs a new MutableLong with the specified value.
+ *
+ * @param value a value.
+ * @throws NullPointerException if the object is null
+ */
+ public MutableLong(Number value) {
+ super();
+ this.value = value.longValue();
}
+ //-----------------------------------------------------------------------
+ /**
+ * Gets the value as a Long instance.
+ *
+ * @return the value as a Long
+ */
public Object getValue() {
return new Long(this.value);
}
+ /**
+ * Sets the value.
+ *
+ * @param value the value to set
+ */
+ public void setValue(long value) {
+ this.value = value;
+ }
+
+ /**
+ * Sets the value from any Number instance.
+ *
+ * @param value the value to set
+ * @throws NullPointerException if the object is null
+ * @throws ClassCastException if the type is invalid
+ */
public void setValue(Object value) {
- setValue(((Number)value).longValue());
+ setValue(((Number) value).longValue());
+ }
+
+ //-----------------------------------------------------------------------
+ public int intValue() {
+ return (int) value;
+ }
+
+ public long longValue() {
+ return value;
+ }
+
+ public float floatValue() {
+ return (float) value;
+ }
+
+ public double doubleValue() {
+ return (double) value;
+ }
+
+ //-----------------------------------------------------------------------
+ /**
+ * Checks if this object equals the specified object.
+ *
+ * The object must be a MutableLong with the same value to be equal.
+ *
+ * @param obj the object to compare to
+ * @return true if equal
+ */
+ public boolean equals(Object obj) {
+ if (obj instanceof MutableLong) {
+ return (value == ((MutableLong) obj).value);
+ }
+ return false;
+ }
+
+ /**
+ * Returns a suitable hashcode for this mutable.
+ *
+ * @return a suitable hashcode
+ */
+ public int hashCode() {
+ return (int)(value ^ (value >>> 32));
+ }
+
+ /**
+ * Compares this mutable to another in ascending order.
+ *
+ * @param obj the mutable to compare to
+ * @return negative if this is less, zero if equal, positive if greater
+ */
+ public int compareTo(Object obj) {
+ MutableLong other = (MutableLong) obj;
+ long anotherVal = other.value;
+ return (value < anotherVal ? -1 : (value == anotherVal ? 0 : 1));
+ }
+
+ /**
+ * Returns the String value of this mutable.
+ *
+ * @return the mutable value as a string
+ */
+ public String toString() {
+ return String.valueOf(value);
}
}
diff --git a/src/java/org/apache/commons/lang/mutable/MutableNumber.java b/src/java/org/apache/commons/lang/mutable/MutableNumber.java
deleted file mode 100755
index 166e8581b..000000000
--- a/src/java/org/apache/commons/lang/mutable/MutableNumber.java
+++ /dev/null
@@ -1,85 +0,0 @@
-/*
- * Copyright 2002-2004 The Apache Software Foundation.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.commons.lang.mutable;
-
-import java.io.Serializable;
-
-/**
- * A mutable
+ * The object must be a MutableShort with the same value to be equal.
+ *
+ * @param obj the object to compare to
+ * @return true if equal
+ */
+ public boolean equals(Object obj) {
+ if (obj instanceof MutableShort) {
+ return (value == ((MutableShort) obj).value);
+ }
+ return false;
+ }
+
+ /**
+ * Returns a suitable hashcode for this mutable.
+ *
+ * @return a suitable hashcode
+ */
+ public int hashCode() {
+ return (int) value;
+ }
+
+ /**
+ * Compares this mutable to another in ascending order.
+ *
+ * @param obj the mutable to compare to
+ * @return negative if this is less, zero if equal, positive if greater
+ */
+ public int compareTo(Object obj) {
+ MutableShort other = (MutableShort) obj;
+ short anotherVal = other.value;
+ return (value < anotherVal ? -1 : (value == anotherVal ? 0 : 1));
+ }
+
+ /**
+ * Returns the String value of this mutable.
+ *
+ * @return the mutable value as a string
+ */
+ public String toString() {
+ return String.valueOf((int) value);
}
}
diff --git a/src/test/org/apache/commons/lang/AllLangTestSuite.java b/src/test/org/apache/commons/lang/AllLangTestSuite.java
index a2ad55bec..299ae21a7 100644
--- a/src/test/org/apache/commons/lang/AllLangTestSuite.java
+++ b/src/test/org/apache/commons/lang/AllLangTestSuite.java
@@ -19,17 +19,19 @@
import junit.framework.TestCase;
import junit.framework.TestSuite;
import junit.textui.TestRunner;
+
import org.apache.commons.lang.builder.BuilderTestSuite;
import org.apache.commons.lang.enums.EnumTestSuite;
import org.apache.commons.lang.exception.ExceptionTestSuite;
import org.apache.commons.lang.math.MathTestSuite;
+import org.apache.commons.lang.mutable.MutableTestSuite;
import org.apache.commons.lang.time.TimeTestSuite;
/**
* Test suite for [lang].
*
* @author Stephen Colebourne
- * @version $Id: AllLangTestSuite.java,v 1.6 2004/06/01 20:55:28 scolebourne Exp $
+ * @version $Id: AllLangTestSuite.java,v 1.7 2004/07/07 23:50:28 scolebourne Exp $
*/
public class AllLangTestSuite extends TestCase {
@@ -59,6 +61,7 @@ public static Test suite() {
suite.addTest(org.apache.commons.lang.enum.EnumTestSuite.suite());
suite.addTest(ExceptionTestSuite.suite());
suite.addTest(MathTestSuite.suite());
+ suite.addTest(MutableTestSuite.suite());
suite.addTest(TimeTestSuite.suite());
return suite;
}
diff --git a/src/test/org/apache/commons/lang/mutable/MutableByteTest.java b/src/test/org/apache/commons/lang/mutable/MutableByteTest.java
index ff35b7297..dca42d30e 100755
--- a/src/test/org/apache/commons/lang/mutable/MutableByteTest.java
+++ b/src/test/org/apache/commons/lang/mutable/MutableByteTest.java
@@ -16,59 +16,122 @@
package org.apache.commons.lang.mutable;
import junit.framework.Test;
+import junit.framework.TestCase;
import junit.framework.TestSuite;
import junit.textui.TestRunner;
/**
* JUnit tests.
*
- * @version $Id: MutableByteTest.java,v 1.1 2004/06/11 02:26:32 matth Exp $
+ * @version $Id: MutableByteTest.java,v 1.2 2004/07/07 23:50:28 scolebourne Exp $
* @see MutableByte
*/
-public class MutableByteTest extends MutableNumberTest {
-
- public static void main(String[] args) {
- TestRunner.run(suite());
- }
-
- public static Test suite() {
- return new TestSuite(MutableByteTest.class);
- }
+public class MutableByteTest extends TestCase {
public MutableByteTest(String testName) {
super(testName);
}
- public MutableNumber getMutableNumber(double value) {
- return new MutableByte((byte)value);
+ public static void main(String[] args) {
+ TestRunner.run(suite());
+ }
+
+ public static Test suite() {
+ return new TestSuite(MutableByteTest.class);
}
// ----------------------------------------------------------------
- // Converters
- // ----------------------------------------------------------------
-
- public byte byteValue(double value) {
- return (byte)value;
+ public void testConstructors() {
+ assertEquals((byte) 0, new MutableByte().byteValue());
+
+ assertEquals((byte) 1, new MutableByte((byte) 1).byteValue());
+
+ assertEquals((byte) 2, new MutableByte(new Byte((byte) 2)).byteValue());
+ assertEquals((byte) 3, new MutableByte(new MutableByte((byte) 3)).byteValue());
+ try {
+ new MutableByte(null);
+ fail();
+ } catch (NullPointerException ex) {}
}
- public short shortValue(double value) {
- return (byte)value;
+ public void testGetSet() {
+ final MutableByte mutNum = new MutableByte((byte) 0);
+ assertEquals((byte) 0, new MutableByte().byteValue());
+ assertEquals(new Byte((byte) 0), new MutableByte().getValue());
+
+ mutNum.setValue((byte) 1);
+ assertEquals((byte) 1, mutNum.byteValue());
+ assertEquals(new Byte((byte) 1), mutNum.getValue());
+
+ mutNum.setValue(new Byte((byte) 2));
+ assertEquals((byte) 2, mutNum.byteValue());
+ assertEquals(new Byte((byte) 2), mutNum.getValue());
+
+ mutNum.setValue(new MutableByte((byte) 3));
+ assertEquals((byte) 3, mutNum.byteValue());
+ assertEquals(new Byte((byte) 3), mutNum.getValue());
+ try {
+ mutNum.setValue(null);
+ fail();
+ } catch (NullPointerException ex) {}
+ try {
+ mutNum.setValue("0");
+ fail();
+ } catch (ClassCastException ex) {}
}
- public int intValue(double value) {
- return (byte)value;
+ public void testEquals() {
+ final MutableByte mutNumA = new MutableByte((byte) 0);
+ final MutableByte mutNumB = new MutableByte((byte) 0);
+ final MutableByte mutNumC = new MutableByte((byte) 1);
+
+ assertEquals(true, mutNumA.equals(mutNumA));
+ assertEquals(true, mutNumA.equals(mutNumB));
+ assertEquals(true, mutNumB.equals(mutNumA));
+ assertEquals(true, mutNumB.equals(mutNumB));
+ assertEquals(false, mutNumA.equals(mutNumC));
+ assertEquals(false, mutNumB.equals(mutNumC));
+ assertEquals(true, mutNumC.equals(mutNumC));
+ assertEquals(false, mutNumA.equals(null));
+ assertEquals(false, mutNumA.equals(new Byte((byte) 0)));
+ assertEquals(false, mutNumA.equals("0"));
}
- public long longValue(double value) {
- return (byte)value;
+ public void testHashCode() {
+ final MutableByte mutNumA = new MutableByte((byte) 0);
+ final MutableByte mutNumB = new MutableByte((byte) 0);
+ final MutableByte mutNumC = new MutableByte((byte) 1);
+
+ assertEquals(true, mutNumA.hashCode() == mutNumA.hashCode());
+ assertEquals(true, mutNumA.hashCode() == mutNumB.hashCode());
+ assertEquals(false, mutNumA.hashCode() == mutNumC.hashCode());
+ assertEquals(true, mutNumA.hashCode() == new Byte((byte) 0).hashCode());
}
- public float floatValue(double value) {
- return (byte)value;
+ public void testCompareTo() {
+ final MutableByte mutNum = new MutableByte((byte) 0);
+
+ assertEquals((byte) 0, mutNum.compareTo(new MutableByte((byte) 0)));
+ assertEquals((byte) +1, mutNum.compareTo(new MutableByte((byte) -1)));
+ assertEquals((byte) -1, mutNum.compareTo(new MutableByte((byte) 1)));
+ try {
+ mutNum.compareTo(null);
+ fail();
+ } catch (NullPointerException ex) {}
+ try {
+ mutNum.compareTo(new Byte((byte) 0));
+ fail();
+ } catch (ClassCastException ex) {}
+ try {
+ mutNum.compareTo("0");
+ fail();
+ } catch (ClassCastException ex) {}
}
- public double doubleValue(double value) {
- return (byte)value;
+ public void testToString() {
+ assertEquals("0", new MutableByte((byte) 0).toString());
+ assertEquals("10", new MutableByte((byte) 10).toString());
+ assertEquals("-123", new MutableByte((byte) -123).toString());
}
-} // MutableByteTest
+}
diff --git a/src/test/org/apache/commons/lang/mutable/MutableDoubleTest.java b/src/test/org/apache/commons/lang/mutable/MutableDoubleTest.java
index fa6dfeec7..6d669ff0f 100755
--- a/src/test/org/apache/commons/lang/mutable/MutableDoubleTest.java
+++ b/src/test/org/apache/commons/lang/mutable/MutableDoubleTest.java
@@ -1,73 +1,148 @@
-/*
- * Copyright 2002-2004 The Apache Software Foundation.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.apache.commons.lang.mutable;
-
-import junit.framework.Test;
-import junit.framework.TestSuite;
-import junit.textui.TestRunner;
-
-/**
- * JUnit tests.
- *
- * @version $Id: MutableDoubleTest.java,v 1.1 2004/06/11 02:26:32 matth Exp $
- * @see MutableDouble
- */
-public class MutableDoubleTest extends MutableNumberTest {
-
- public static void main(String[] args) {
- TestRunner.run(suite());
- }
-
- public static Test suite() {
- return new TestSuite(MutableDoubleTest.class);
- }
-
- public MutableDoubleTest(String testName) {
- super(testName);
- }
-
- public MutableNumber getMutableNumber(double value) {
- return new MutableDouble(value);
- }
-
- // Converters
- // ----------------------------------------------------------------
-
- public byte byteValue(double value) {
- return (byte)value;
- }
-
- public short shortValue(double value) {
- return (short)value;
- }
-
- public int intValue(double value) {
- return (int)value;
- }
-
- public long longValue(double value) {
- return (long)value;
- }
-
- public float floatValue(double value) {
- return (float)value;
- }
-
- public double doubleValue(double value) {
- return value;
- }
-
-}
+/*
+ * Copyright 2002-2004 The Apache Software Foundation.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.commons.lang.mutable;
+
+import junit.framework.Test;
+import junit.framework.TestCase;
+import junit.framework.TestSuite;
+import junit.textui.TestRunner;
+
+/**
+ * JUnit tests.
+ *
+ * @version $Id: MutableDoubleTest.java,v 1.2 2004/07/07 23:50:28 scolebourne Exp $
+ * @see MutableDouble
+ */
+public class MutableDoubleTest extends TestCase {
+
+ public MutableDoubleTest(String testName) {
+ super(testName);
+ }
+
+ public static void main(String[] args) {
+ TestRunner.run(suite());
+ }
+
+ public static Test suite() {
+ return new TestSuite(MutableDoubleTest.class);
+ }
+
+ // ----------------------------------------------------------------
+ public void testConstructors() {
+ assertEquals(0d, new MutableDouble().doubleValue(), 0.0001d);
+
+ assertEquals(1d, new MutableDouble(1d).doubleValue(), 0.0001d);
+
+ assertEquals(2d, new MutableDouble(new Double(2d)).doubleValue(), 0.0001d);
+ assertEquals(3d, new MutableDouble(new MutableDouble(3d)).doubleValue(), 0.0001d);
+ try {
+ new MutableDouble(null);
+ fail();
+ } catch (NullPointerException ex) {}
+ }
+
+ public void testGetSet() {
+ final MutableDouble mutNum = new MutableDouble(0d);
+ assertEquals(0d, new MutableDouble().doubleValue(), 0.0001d);
+ assertEquals(new Double(0), new MutableDouble().getValue());
+
+ mutNum.setValue(1);
+ assertEquals(1d, mutNum.doubleValue(), 0.0001d);
+ assertEquals(new Double(1d), mutNum.getValue());
+
+ mutNum.setValue(new Double(2d));
+ assertEquals(2d, mutNum.doubleValue(), 0.0001d);
+ assertEquals(new Double(2d), mutNum.getValue());
+
+ mutNum.setValue(new MutableDouble(3d));
+ assertEquals(3d, mutNum.doubleValue(), 0.0001d);
+ assertEquals(new Double(3d), mutNum.getValue());
+ try {
+ mutNum.setValue(null);
+ fail();
+ } catch (NullPointerException ex) {}
+ try {
+ mutNum.setValue("0");
+ fail();
+ } catch (ClassCastException ex) {}
+ }
+
+ public void testNanInfinite() {
+ MutableDouble mutNum = new MutableDouble(Double.NaN);
+ assertEquals(true, mutNum.isNaN());
+
+ mutNum = new MutableDouble(Double.POSITIVE_INFINITY);
+ assertEquals(true, mutNum.isInfinite());
+
+ mutNum = new MutableDouble(Double.NEGATIVE_INFINITY);
+ assertEquals(true, mutNum.isInfinite());
+ }
+
+ public void testEquals() {
+ final MutableDouble mutNumA = new MutableDouble(0d);
+ final MutableDouble mutNumB = new MutableDouble(0d);
+ final MutableDouble mutNumC = new MutableDouble(1d);
+
+ assertEquals(true, mutNumA.equals(mutNumA));
+ assertEquals(true, mutNumA.equals(mutNumB));
+ assertEquals(true, mutNumB.equals(mutNumA));
+ assertEquals(true, mutNumB.equals(mutNumB));
+ assertEquals(false, mutNumA.equals(mutNumC));
+ assertEquals(false, mutNumB.equals(mutNumC));
+ assertEquals(true, mutNumC.equals(mutNumC));
+ assertEquals(false, mutNumA.equals(null));
+ assertEquals(false, mutNumA.equals(new Double(0d)));
+ assertEquals(false, mutNumA.equals("0"));
+ }
+
+ public void testHashCode() {
+ final MutableDouble mutNumA = new MutableDouble(0d);
+ final MutableDouble mutNumB = new MutableDouble(0d);
+ final MutableDouble mutNumC = new MutableDouble(1d);
+
+ assertEquals(true, mutNumA.hashCode() == mutNumA.hashCode());
+ assertEquals(true, mutNumA.hashCode() == mutNumB.hashCode());
+ assertEquals(false, mutNumA.hashCode() == mutNumC.hashCode());
+ assertEquals(true, mutNumA.hashCode() == new Double(0d).hashCode());
+ }
+
+ public void testCompareTo() {
+ final MutableDouble mutNum = new MutableDouble(0d);
+
+ assertEquals(0, mutNum.compareTo(new MutableDouble(0d)));
+ assertEquals(+1, mutNum.compareTo(new MutableDouble(-1d)));
+ assertEquals(-1, mutNum.compareTo(new MutableDouble(1d)));
+ try {
+ mutNum.compareTo(null);
+ fail();
+ } catch (NullPointerException ex) {}
+ try {
+ mutNum.compareTo(new Double(0d));
+ fail();
+ } catch (ClassCastException ex) {}
+ try {
+ mutNum.compareTo("0");
+ fail();
+ } catch (ClassCastException ex) {}
+ }
+
+ public void testToString() {
+ assertEquals("0.0", new MutableDouble(0d).toString());
+ assertEquals("10.0", new MutableDouble(10d).toString());
+ assertEquals("-123.0", new MutableDouble(-123d).toString());
+ }
+
+}
diff --git a/src/test/org/apache/commons/lang/mutable/MutableFloatTest.java b/src/test/org/apache/commons/lang/mutable/MutableFloatTest.java
index 69bbe1f02..1a38cf06e 100755
--- a/src/test/org/apache/commons/lang/mutable/MutableFloatTest.java
+++ b/src/test/org/apache/commons/lang/mutable/MutableFloatTest.java
@@ -1,75 +1,148 @@
-/*
- * Copyright 2002-2004 The Apache Software Foundation.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.apache.commons.lang.mutable;
-
-import junit.framework.Test;
-import junit.framework.TestSuite;
-import junit.textui.TestRunner;
-
-/**
- * JUnit tests.
- *
- * @version $Id: MutableFloatTest.java,v 1.1 2004/06/11 02:26:32 matth Exp $
- * @see MutableFloat
- */
-public class MutableFloatTest extends MutableNumberTest {
-
- public static void main(String[] args) {
- TestRunner.run(suite());
- }
-
- public static Test suite() {
- return new TestSuite(MutableFloatTest.class);
- }
-
- /**
- * @param testName
- */
- public MutableFloatTest(String testName) {
- super(testName);
- }
-
- public MutableNumber getMutableNumber(double value) {
- return new MutableFloat((float)value);
- }
-
- // Converters
- // ----------------------------------------------------------------
- public byte byteValue(double value) {
- return (byte)(float)value;
- }
-
- public short shortValue(double value) {
- return (short)(float)value;
- }
-
- public int intValue(double value) {
- return (int)(float)value;
- }
-
- public long longValue(double value) {
- return (long)(float)value;
- }
-
- public float floatValue(double value) {
- return (float)value;
- }
-
- public double doubleValue(double value) {
- return (float)value;
- }
-
-}
+/*
+ * Copyright 2002-2004 The Apache Software Foundation.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.commons.lang.mutable;
+
+import junit.framework.Test;
+import junit.framework.TestCase;
+import junit.framework.TestSuite;
+import junit.textui.TestRunner;
+
+/**
+ * JUnit tests.
+ *
+ * @version $Id: MutableFloatTest.java,v 1.2 2004/07/07 23:50:28 scolebourne Exp $
+ * @see MutableFloat
+ */
+public class MutableFloatTest extends TestCase {
+
+ public MutableFloatTest(String testName) {
+ super(testName);
+ }
+
+ public static void main(String[] args) {
+ TestRunner.run(suite());
+ }
+
+ public static Test suite() {
+ return new TestSuite(MutableFloatTest.class);
+ }
+
+ // ----------------------------------------------------------------
+ public void testConstructors() {
+ assertEquals(0f, new MutableFloat().floatValue(), 0.0001f);
+
+ assertEquals(1f, new MutableFloat(1f).floatValue(), 0.0001f);
+
+ assertEquals(2f, new MutableFloat(new Float(2f)).floatValue(), 0.0001f);
+ assertEquals(3f, new MutableFloat(new MutableFloat(3f)).floatValue(), 0.0001f);
+ try {
+ new MutableFloat(null);
+ fail();
+ } catch (NullPointerException ex) {}
+ }
+
+ public void testGetSet() {
+ final MutableFloat mutNum = new MutableFloat(0f);
+ assertEquals(0f, new MutableFloat().floatValue(), 0.0001f);
+ assertEquals(new Float(0), new MutableFloat().getValue());
+
+ mutNum.setValue(1);
+ assertEquals(1f, mutNum.floatValue(), 0.0001f);
+ assertEquals(new Float(1f), mutNum.getValue());
+
+ mutNum.setValue(new Float(2f));
+ assertEquals(2f, mutNum.floatValue(), 0.0001f);
+ assertEquals(new Float(2f), mutNum.getValue());
+
+ mutNum.setValue(new MutableFloat(3f));
+ assertEquals(3f, mutNum.floatValue(), 0.0001f);
+ assertEquals(new Float(3f), mutNum.getValue());
+ try {
+ mutNum.setValue(null);
+ fail();
+ } catch (NullPointerException ex) {}
+ try {
+ mutNum.setValue("0");
+ fail();
+ } catch (ClassCastException ex) {}
+ }
+
+ public void testNanInfinite() {
+ MutableFloat mutNum = new MutableFloat(Float.NaN);
+ assertEquals(true, mutNum.isNaN());
+
+ mutNum = new MutableFloat(Float.POSITIVE_INFINITY);
+ assertEquals(true, mutNum.isInfinite());
+
+ mutNum = new MutableFloat(Float.NEGATIVE_INFINITY);
+ assertEquals(true, mutNum.isInfinite());
+ }
+
+ public void testEquals() {
+ final MutableFloat mutNumA = new MutableFloat(0f);
+ final MutableFloat mutNumB = new MutableFloat(0f);
+ final MutableFloat mutNumC = new MutableFloat(1f);
+
+ assertEquals(true, mutNumA.equals(mutNumA));
+ assertEquals(true, mutNumA.equals(mutNumB));
+ assertEquals(true, mutNumB.equals(mutNumA));
+ assertEquals(true, mutNumB.equals(mutNumB));
+ assertEquals(false, mutNumA.equals(mutNumC));
+ assertEquals(false, mutNumB.equals(mutNumC));
+ assertEquals(true, mutNumC.equals(mutNumC));
+ assertEquals(false, mutNumA.equals(null));
+ assertEquals(false, mutNumA.equals(new Float(0f)));
+ assertEquals(false, mutNumA.equals("0"));
+ }
+
+ public void testHashCode() {
+ final MutableFloat mutNumA = new MutableFloat(0f);
+ final MutableFloat mutNumB = new MutableFloat(0f);
+ final MutableFloat mutNumC = new MutableFloat(1f);
+
+ assertEquals(true, mutNumA.hashCode() == mutNumA.hashCode());
+ assertEquals(true, mutNumA.hashCode() == mutNumB.hashCode());
+ assertEquals(false, mutNumA.hashCode() == mutNumC.hashCode());
+ assertEquals(true, mutNumA.hashCode() == new Float(0f).hashCode());
+ }
+
+ public void testCompareTo() {
+ final MutableFloat mutNum = new MutableFloat(0f);
+
+ assertEquals(0, mutNum.compareTo(new MutableFloat(0f)));
+ assertEquals(+1, mutNum.compareTo(new MutableFloat(-1f)));
+ assertEquals(-1, mutNum.compareTo(new MutableFloat(1f)));
+ try {
+ mutNum.compareTo(null);
+ fail();
+ } catch (NullPointerException ex) {}
+ try {
+ mutNum.compareTo(new Float(0f));
+ fail();
+ } catch (ClassCastException ex) {}
+ try {
+ mutNum.compareTo("0");
+ fail();
+ } catch (ClassCastException ex) {}
+ }
+
+ public void testToString() {
+ assertEquals("0.0", new MutableFloat(0f).toString());
+ assertEquals("10.0", new MutableFloat(10f).toString());
+ assertEquals("-123.0", new MutableFloat(-123f).toString());
+ }
+
+}
diff --git a/src/test/org/apache/commons/lang/mutable/MutableIntTest.java b/src/test/org/apache/commons/lang/mutable/MutableIntTest.java
new file mode 100644
index 000000000..1a788e760
--- /dev/null
+++ b/src/test/org/apache/commons/lang/mutable/MutableIntTest.java
@@ -0,0 +1,137 @@
+/*
+ * Copyright 2002-2004 The Apache Software Foundation.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.commons.lang.mutable;
+
+import junit.framework.Test;
+import junit.framework.TestCase;
+import junit.framework.TestSuite;
+import junit.textui.TestRunner;
+
+/**
+ * JUnit tests.
+ *
+ * @version $Id: MutableIntTest.java,v 1.1 2004/07/07 23:50:28 scolebourne Exp $
+ * @see MutableInt
+ */
+public class MutableIntTest extends TestCase {
+
+ public MutableIntTest(String testName) {
+ super(testName);
+ }
+
+ public static void main(String[] args) {
+ TestRunner.run(suite());
+ }
+
+ public static Test suite() {
+ return new TestSuite(MutableIntTest.class);
+ }
+
+ // ----------------------------------------------------------------
+ public void testConstructors() {
+ assertEquals(0, new MutableInt().intValue());
+
+ assertEquals(1, new MutableInt(1).intValue());
+
+ assertEquals(2, new MutableInt(new Integer(2)).intValue());
+ assertEquals(3, new MutableInt(new MutableLong(3)).intValue());
+ try {
+ new MutableInt(null);
+ fail();
+ } catch (NullPointerException ex) {}
+ }
+
+ public void testGetSet() {
+ final MutableInt mutNum = new MutableInt(0);
+ assertEquals(0, new MutableInt().intValue());
+ assertEquals(new Integer(0), new MutableInt().getValue());
+
+ mutNum.setValue(1);
+ assertEquals(1, mutNum.intValue());
+ assertEquals(new Integer(1), mutNum.getValue());
+
+ mutNum.setValue(new Integer(2));
+ assertEquals(2, mutNum.intValue());
+ assertEquals(new Integer(2), mutNum.getValue());
+
+ mutNum.setValue(new MutableLong(3));
+ assertEquals(3, mutNum.intValue());
+ assertEquals(new Integer(3), mutNum.getValue());
+ try {
+ mutNum.setValue(null);
+ fail();
+ } catch (NullPointerException ex) {}
+ try {
+ mutNum.setValue("0");
+ fail();
+ } catch (ClassCastException ex) {}
+ }
+
+ public void testEquals() {
+ final MutableInt mutNumA = new MutableInt(0);
+ final MutableInt mutNumB = new MutableInt(0);
+ final MutableInt mutNumC = new MutableInt(1);
+
+ assertEquals(true, mutNumA.equals(mutNumA));
+ assertEquals(true, mutNumA.equals(mutNumB));
+ assertEquals(true, mutNumB.equals(mutNumA));
+ assertEquals(true, mutNumB.equals(mutNumB));
+ assertEquals(false, mutNumA.equals(mutNumC));
+ assertEquals(false, mutNumB.equals(mutNumC));
+ assertEquals(true, mutNumC.equals(mutNumC));
+ assertEquals(false, mutNumA.equals(null));
+ assertEquals(false, mutNumA.equals(new Integer(0)));
+ assertEquals(false, mutNumA.equals("0"));
+ }
+
+ public void testHashCode() {
+ final MutableInt mutNumA = new MutableInt(0);
+ final MutableInt mutNumB = new MutableInt(0);
+ final MutableInt mutNumC = new MutableInt(1);
+
+ assertEquals(true, mutNumA.hashCode() == mutNumA.hashCode());
+ assertEquals(true, mutNumA.hashCode() == mutNumB.hashCode());
+ assertEquals(false, mutNumA.hashCode() == mutNumC.hashCode());
+ assertEquals(true, mutNumA.hashCode() == new Integer(0).hashCode());
+ }
+
+ public void testCompareTo() {
+ final MutableInt mutNum = new MutableInt(0);
+
+ assertEquals(0, mutNum.compareTo(new MutableInt(0)));
+ assertEquals(+1, mutNum.compareTo(new MutableInt(-1)));
+ assertEquals(-1, mutNum.compareTo(new MutableInt(1)));
+ try {
+ mutNum.compareTo(null);
+ fail();
+ } catch (NullPointerException ex) {}
+ try {
+ mutNum.compareTo(new Integer(0));
+ fail();
+ } catch (ClassCastException ex) {}
+ try {
+ mutNum.compareTo("0");
+ fail();
+ } catch (ClassCastException ex) {}
+ }
+
+ public void testToString() {
+ assertEquals("0", new MutableInt(0).toString());
+ assertEquals("10", new MutableInt(10).toString());
+ assertEquals("-123", new MutableInt(-123).toString());
+ }
+
+}
diff --git a/src/test/org/apache/commons/lang/mutable/MutableIntegerTest.java b/src/test/org/apache/commons/lang/mutable/MutableIntegerTest.java
deleted file mode 100755
index 838d7a1e7..000000000
--- a/src/test/org/apache/commons/lang/mutable/MutableIntegerTest.java
+++ /dev/null
@@ -1,74 +0,0 @@
-/*
- * Copyright 2002-2004 The Apache Software Foundation.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.apache.commons.lang.mutable;
-
-import junit.framework.Test;
-import junit.framework.TestSuite;
-import junit.textui.TestRunner;
-
-/**
- * JUnit tests.
- *
- * @version $Id: MutableIntegerTest.java,v 1.1 2004/06/11 02:26:32 matth Exp $
- * @see MutableInteger
- */
-public class MutableIntegerTest extends MutableNumberTest {
-
- public MutableIntegerTest(String testName) {
- super(testName);
- }
-
- public static void main(String[] args) {
- TestRunner.run(suite());
- }
-
- public static Test suite() {
- return new TestSuite(MutableIntegerTest.class);
- }
-
- public MutableNumber getMutableNumber(double value) {
- return new MutableInteger((int)value);
- }
-
- // ----------------------------------------------------------------
- // Converters
- // ----------------------------------------------------------------
-
- public byte byteValue(double value) {
- return (byte)(int)value;
- }
-
- public double doubleValue(double value) {
- return (int)value;
- }
-
- public float floatValue(double value) {
- return (int)value;
- }
-
- public int intValue(double value) {
- return (int)value;
- }
-
- public long longValue(double value) {
- return (int)value;
- }
-
- public short shortValue(double value) {
- return (short)(int)value;
- }
-
-}
diff --git a/src/test/org/apache/commons/lang/mutable/MutableLongTest.java b/src/test/org/apache/commons/lang/mutable/MutableLongTest.java
index 2014a9fe6..5a7894739 100755
--- a/src/test/org/apache/commons/lang/mutable/MutableLongTest.java
+++ b/src/test/org/apache/commons/lang/mutable/MutableLongTest.java
@@ -1,74 +1,137 @@
-/*
- * Copyright 2002-2004 The Apache Software Foundation.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.apache.commons.lang.mutable;
-
-import junit.framework.Test;
-import junit.framework.TestSuite;
-import junit.textui.TestRunner;
-
-/**
- * JUnit tests.
- *
- * @version $Id: MutableLongTest.java,v 1.1 2004/06/11 02:26:32 matth Exp $
- * @see MutableLong
- */
-public class MutableLongTest extends MutableNumberTest {
-
- public static void main(String[] args) {
- TestRunner.run(suite());
- }
-
- public static Test suite() {
- return new TestSuite(MutableLongTest.class);
- }
-
- public MutableLongTest(String testName) {
- super(testName);
- }
-
- public MutableNumber getMutableNumber(double value) {
- return new MutableLong((long)value);
- }
-
- // ----------------------------------------------------------------
- // Converters
- // ----------------------------------------------------------------
-
- public byte byteValue(double value) {
- return (byte)(long)value;
- }
-
- public short shortValue(double value) {
- return (short)(long)value;
- }
-
- public int intValue(double value) {
- return (int)(long)value;
- }
-
- public long longValue(double value) {
- return (long)value;
- }
-
- public float floatValue(double value) {
- return (long)value;
- }
-
- public double doubleValue(double value) {
- return (long)value;
- }
-
-}
+/*
+ * Copyright 2002-2004 The Apache Software Foundation.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.commons.lang.mutable;
+
+import junit.framework.Test;
+import junit.framework.TestCase;
+import junit.framework.TestSuite;
+import junit.textui.TestRunner;
+
+/**
+ * JUnit tests.
+ *
+ * @version $Id: MutableLongTest.java,v 1.2 2004/07/07 23:50:28 scolebourne Exp $
+ * @see MutableLong
+ */
+public class MutableLongTest extends TestCase {
+
+ public MutableLongTest(String testName) {
+ super(testName);
+ }
+
+ public static void main(String[] args) {
+ TestRunner.run(suite());
+ }
+
+ public static Test suite() {
+ return new TestSuite(MutableLongTest.class);
+ }
+
+ // ----------------------------------------------------------------
+ public void testConstructors() {
+ assertEquals(0, new MutableLong().longValue());
+
+ assertEquals(1, new MutableLong(1).longValue());
+
+ assertEquals(2, new MutableLong(new Long(2)).longValue());
+ assertEquals(3, new MutableLong(new MutableLong(3)).longValue());
+ try {
+ new MutableLong(null);
+ fail();
+ } catch (NullPointerException ex) {}
+ }
+
+ public void testGetSet() {
+ final MutableLong mutNum = new MutableLong(0);
+ assertEquals(0, new MutableLong().longValue());
+ assertEquals(new Long(0), new MutableLong().getValue());
+
+ mutNum.setValue(1);
+ assertEquals(1, mutNum.longValue());
+ assertEquals(new Long(1), mutNum.getValue());
+
+ mutNum.setValue(new Long(2));
+ assertEquals(2, mutNum.longValue());
+ assertEquals(new Long(2), mutNum.getValue());
+
+ mutNum.setValue(new MutableLong(3));
+ assertEquals(3, mutNum.longValue());
+ assertEquals(new Long(3), mutNum.getValue());
+ try {
+ mutNum.setValue(null);
+ fail();
+ } catch (NullPointerException ex) {}
+ try {
+ mutNum.setValue("0");
+ fail();
+ } catch (ClassCastException ex) {}
+ }
+
+ public void testEquals() {
+ final MutableLong mutNumA = new MutableLong(0);
+ final MutableLong mutNumB = new MutableLong(0);
+ final MutableLong mutNumC = new MutableLong(1);
+
+ assertEquals(true, mutNumA.equals(mutNumA));
+ assertEquals(true, mutNumA.equals(mutNumB));
+ assertEquals(true, mutNumB.equals(mutNumA));
+ assertEquals(true, mutNumB.equals(mutNumB));
+ assertEquals(false, mutNumA.equals(mutNumC));
+ assertEquals(false, mutNumB.equals(mutNumC));
+ assertEquals(true, mutNumC.equals(mutNumC));
+ assertEquals(false, mutNumA.equals(null));
+ assertEquals(false, mutNumA.equals(new Long(0)));
+ assertEquals(false, mutNumA.equals("0"));
+ }
+
+ public void testHashCode() {
+ final MutableLong mutNumA = new MutableLong(0);
+ final MutableLong mutNumB = new MutableLong(0);
+ final MutableLong mutNumC = new MutableLong(1);
+
+ assertEquals(true, mutNumA.hashCode() == mutNumA.hashCode());
+ assertEquals(true, mutNumA.hashCode() == mutNumB.hashCode());
+ assertEquals(false, mutNumA.hashCode() == mutNumC.hashCode());
+ assertEquals(true, mutNumA.hashCode() == new Long(0).hashCode());
+ }
+
+ public void testCompareTo() {
+ final MutableLong mutNum = new MutableLong(0);
+
+ assertEquals(0, mutNum.compareTo(new MutableLong(0)));
+ assertEquals(+1, mutNum.compareTo(new MutableLong(-1)));
+ assertEquals(-1, mutNum.compareTo(new MutableLong(1)));
+ try {
+ mutNum.compareTo(null);
+ fail();
+ } catch (NullPointerException ex) {}
+ try {
+ mutNum.compareTo(new Long(0));
+ fail();
+ } catch (ClassCastException ex) {}
+ try {
+ mutNum.compareTo("0");
+ fail();
+ } catch (ClassCastException ex) {}
+ }
+
+ public void testToString() {
+ assertEquals("0", new MutableLong(0).toString());
+ assertEquals("10", new MutableLong(10).toString());
+ assertEquals("-123", new MutableLong(-123).toString());
+ }
+
+}
diff --git a/src/test/org/apache/commons/lang/mutable/MutableNumberTest.java b/src/test/org/apache/commons/lang/mutable/MutableNumberTest.java
deleted file mode 100755
index 93cd8a1c4..000000000
--- a/src/test/org/apache/commons/lang/mutable/MutableNumberTest.java
+++ /dev/null
@@ -1,208 +0,0 @@
-/*
- * Copyright 2002-2004 The Apache Software Foundation.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.apache.commons.lang.mutable;
-
-import junit.framework.TestCase;
-
-/**
- * JUnit tests.
- *
- * @version $Id: MutableNumberTest.java,v 1.1 2004/06/11 02:26:32 matth Exp $
- * @see MutableNumber
- */
-public abstract class MutableNumberTest extends TestCase {
-
- public MutableNumberTest(String testName) {
- super(testName);
- }
-
- /**
- * Gets an instance to test.
- * @param value the value of the number.
- * @return a Number
.
- *
- * @since 2.1
- * @version $Id: MutableNumber.java,v 1.3 2004/06/24 04:20:46 bayard Exp $
- */
-public abstract class MutableNumber
- extends Number
- implements Comparable, Mutable, Serializable {
-
- MutableNumber() {
- super();
- }
-
- // ----------------------------------------------------------------
- // Number overrides
- // ----------------------------------------------------------------
-
- public float floatValue() {
- return (float)doubleValue();
- }
-
- // ----------------------------------------------------------------
- // Object overrides
- // ----------------------------------------------------------------
-
- public String toString() {
- return String.valueOf(doubleValue()).intern();
- }
-
- public int hashCode() {
- return super.hashCode();
- }
-
- /**
- * Compares this
to another object.
- *
- * @param obj an object to compare to
- * @return true
if this
is equal to
- * obj
.
- * @see #compareTo(Object)
- */
- public boolean equals(Object obj) {
- return super.equals(obj);
- }
-
- // ----------------------------------------------------------------
- // Comparable overrides
- // ----------------------------------------------------------------
-
- /**
- * Compares to another object
- *
- * @param o an object to compare to
- * @return -1 if this < o
, 0 if this.equals(o)
,
- * 1 if this > o
- * @throws ClassCastException if
o
is not a
- * Number
.
- */
- public int compareTo(Object o) {
- final double d = ((Number)o).doubleValue();
- return (doubleValue() < d) ? -1 : (doubleValue() > d) ? 1 : 0;
- }
-
-}
diff --git a/src/java/org/apache/commons/lang/mutable/MutableShort.java b/src/java/org/apache/commons/lang/mutable/MutableShort.java
index b6316a727..1cc4b5d1f 100755
--- a/src/java/org/apache/commons/lang/mutable/MutableShort.java
+++ b/src/java/org/apache/commons/lang/mutable/MutableShort.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2002-2004 The Apache Software Foundation.
+ * Copyright 2004 The Apache Software Foundation.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -15,21 +15,33 @@
*/
package org.apache.commons.lang.mutable;
+import java.io.Serializable;
+
/**
- * A mutable Short
+ * A mutable short
.
*
* @since 2.1
- * @version $Id: MutableShort.java,v 1.3 2004/06/24 04:20:46 bayard Exp $
+ * @version $Id: MutableShort.java,v 1.4 2004/07/07 23:50:28 scolebourne Exp $
*/
-public class MutableShort extends MutableNumber {
+public class MutableShort extends Number
+ implements Comparable, Mutable, Serializable {
- /**
- * Internal value.
- */
+ /** Serialization lock. */
+ private static final long serialVersionUID = -2135791679L;
+
+ /** The mutable value. */
private short value;
/**
- * Instantiates with the specified value
+ * Constructs a new MutableShort with the default value of zero.
+ */
+ public MutableShort() {
+ super();
+ }
+
+ /**
+ * Constructs a new MutableShort with the specified value.
+ *
* @param value a value.
*/
public MutableShort(short value) {
@@ -37,28 +49,112 @@ public MutableShort(short value) {
this.value = value;
}
- public void setValue(short value) {
- this.value = value;
- }
-
- public double doubleValue() {
- return this.value;
- }
-
- public int intValue() {
- return this.value;
- }
-
- public long longValue() {
- return this.value;
+ /**
+ * Constructs a new MutableShort with the specified value.
+ *
+ * @param value a value.
+ * @throws NullPointerException if the object is null
+ */
+ public MutableShort(Number value) {
+ super();
+ this.value = value.shortValue();
}
+ //-----------------------------------------------------------------------
+ /**
+ * Gets the value as a Short instance.
+ *
+ * @return the value as a Short
+ */
public Object getValue() {
return new Short(this.value);
}
+ /**
+ * Sets the value.
+ *
+ * @param value the value to set
+ */
+ public void setValue(short value) {
+ this.value = value;
+ }
+
+ /**
+ * Sets the value from any Number instance.
+ *
+ * @param value the value to set
+ * @throws NullPointerException if the object is null
+ * @throws ClassCastException if the type is invalid
+ */
public void setValue(Object value) {
- setValue(((Number)value).shortValue());
+ setValue(((Number) value).shortValue());
+ }
+
+ //-----------------------------------------------------------------------
+ public short shortValue() {
+ return value;
+ }
+
+ public int intValue() {
+ return (int) value;
+ }
+
+ public long longValue() {
+ return (long) value;
+ }
+
+ public float floatValue() {
+ return (float) value;
+ }
+
+ public double doubleValue() {
+ return (double) value;
+ }
+
+ //-----------------------------------------------------------------------
+ /**
+ * Checks if this object equals the specified object.
+ * MutableNumber
- */
- public abstract MutableNumber getMutableNumber(double value);
-
- // ----------------------------------------------------------------
- // Converters
- // ----------------------------------------------------------------
-
- public abstract byte byteValue(double value);
-
- public abstract short shortValue(double value);
-
- public abstract int intValue(double value);
-
- public abstract long longValue(double value);
-
- public abstract float floatValue(double value);
-
- public abstract double doubleValue(double value);
-
- // ----------------------------------------------------------------
- // Tests
- // ----------------------------------------------------------------
-
- public void testCompareTo() {
- final double num = 0;
- final MutableNumber mutNum = getMutableNumber(num);
-
- assertEquals("Equality", 0, mutNum.compareTo(new Double(num)));
-
- assertEquals(
- "Less than",
- -1,
- mutNum.compareTo(new Double(Double.POSITIVE_INFINITY)));
-
- assertEquals(
- "Greater than",
- 1,
- mutNum.compareTo(new Double(Double.NEGATIVE_INFINITY)));
- }
-
- public void testPrimitiveAccessors() {
- testPrimitiveAccessors(0);
- testPrimitiveAccessors(Double.MAX_VALUE);
- testPrimitiveAccessors(-Double.MAX_VALUE);
-
- testPrimitiveAccessors(Float.MAX_VALUE);
- testPrimitiveAccessors(-Float.MAX_VALUE);
-
- testPrimitiveAccessors(Long.MAX_VALUE);
- testPrimitiveAccessors(Long.MIN_VALUE);
-
- testPrimitiveAccessors(Integer.MAX_VALUE);
- testPrimitiveAccessors(Integer.MIN_VALUE);
-
- testPrimitiveAccessors(Short.MAX_VALUE);
- testPrimitiveAccessors(Short.MIN_VALUE);
-
- testPrimitiveAccessors(Byte.MAX_VALUE);
- testPrimitiveAccessors(Byte.MIN_VALUE);
- }
-
- public void XtestObjectAccessors() {
- testObjectAccessors(0);
- testObjectAccessors(Double.MAX_VALUE);
- testObjectAccessors(-Double.MAX_VALUE);
-
- testObjectAccessors(Float.MAX_VALUE);
- testObjectAccessors(-Float.MAX_VALUE);
-
- testObjectAccessors(Long.MAX_VALUE);
- testObjectAccessors(Long.MIN_VALUE);
-
- testObjectAccessors(Integer.MAX_VALUE);
- testObjectAccessors(Integer.MIN_VALUE);
-
- testObjectAccessors(Short.MAX_VALUE);
- testObjectAccessors(Short.MIN_VALUE);
-
- testObjectAccessors(Byte.MAX_VALUE);
- testObjectAccessors(Byte.MIN_VALUE);
- }
-
- public void testSetValue() {
- setValueAndTestAccessors(Double.MAX_VALUE);
- setValueAndTestAccessors(-Double.MAX_VALUE);
-
- setValueAndTestAccessors(Float.MAX_VALUE);
- setValueAndTestAccessors(-Float.MAX_VALUE);
-
- setValueAndTestAccessors(Long.MAX_VALUE);
- setValueAndTestAccessors(Long.MIN_VALUE);
-
- setValueAndTestAccessors(Integer.MAX_VALUE);
- setValueAndTestAccessors(Integer.MIN_VALUE);
-
- setValueAndTestAccessors(Short.MAX_VALUE);
- setValueAndTestAccessors(Short.MIN_VALUE);
-
- setValueAndTestAccessors(Byte.MAX_VALUE);
- setValueAndTestAccessors(Byte.MIN_VALUE);
- }
-
- // ----------------------------------------------------------------
- // Private methods
- // ----------------------------------------------------------------
-
- private void setValueAndTestAccessors(double num) {
- final MutableNumber mutNum = getMutableNumber(0);
- mutNum.setValue(new Double(num));
- testPrimitiveAccessors(mutNum, num);
- //testObjectAccessors(mutNum, num);
- }
-
- private void testPrimitiveAccessors(double num) {
- testPrimitiveAccessors(getMutableNumber(num), num);
- }
-
- private void testPrimitiveAccessors(MutableNumber mutNum, double num) {
- assertEquals("byte comparison", byteValue(num), mutNum.byteValue());
- assertEquals("short comparison", shortValue(num), mutNum.shortValue());
- assertEquals("int comparison", intValue(num), mutNum.intValue());
- assertEquals("long comparison", longValue(num), mutNum.longValue());
-
- assertEquals(
- "float comparison",
- floatValue(num),
- mutNum.floatValue(),
- 0);
-
- assertEquals(
- "double comparison",
- doubleValue(num),
- mutNum.doubleValue(),
- 0);
- }
-
- private void testObjectAccessors(double num) {
- testObjectAccessors(getMutableNumber(num), num);
- }
-
- private void testObjectAccessors(MutableNumber mutNum, double num) {
- assertEquals(
- "byte comparison",
- new Byte(byteValue(num)),
- mutNum.getValue());
-
- assertEquals(
- "short comparison",
- new Short(shortValue(num)),
- mutNum.getValue());
-
- assertEquals(
- "int comparison",
- new Integer(intValue(num)),
- mutNum.getValue());
-
- assertEquals(
- "long comparison",
- new Long(longValue(num)),
- mutNum.getValue());
-
- assertEquals(
- "float comparison",
- new Float(floatValue(num)),
- mutNum.getValue());
-
- assertEquals(
- "double comparison",
- new Double(doubleValue(num)),
- mutNum.getValue());
- }
-
-}
diff --git a/src/test/org/apache/commons/lang/mutable/MutableShortTest.java b/src/test/org/apache/commons/lang/mutable/MutableShortTest.java
index c461c300c..7c21231ff 100755
--- a/src/test/org/apache/commons/lang/mutable/MutableShortTest.java
+++ b/src/test/org/apache/commons/lang/mutable/MutableShortTest.java
@@ -16,16 +16,21 @@
package org.apache.commons.lang.mutable;
import junit.framework.Test;
+import junit.framework.TestCase;
import junit.framework.TestSuite;
import junit.textui.TestRunner;
/**
* JUnit tests.
*
- * @version $Id: MutableShortTest.java,v 1.1 2004/06/11 02:26:32 matth Exp $
+ * @version $Id: MutableShortTest.java,v 1.2 2004/07/07 23:50:28 scolebourne Exp $
* @see MutableShort
*/
-public class MutableShortTest extends MutableNumberTest {
+public class MutableShortTest extends TestCase {
+
+ public MutableShortTest(String testName) {
+ super(testName);
+ }
public static void main(String[] args) {
TestRunner.run(suite());
@@ -35,41 +40,98 @@ public static Test suite() {
return new TestSuite(MutableShortTest.class);
}
- public MutableShortTest(String testName) {
- super(testName);
- }
-
// ----------------------------------------------------------------
- // Converters
- // ----------------------------------------------------------------
-
- public MutableNumber getMutableNumber(double value) {
- return new MutableShort((short)value);
+ public void testConstructors() {
+ assertEquals((short) 0, new MutableShort().shortValue());
+
+ assertEquals((short) 1, new MutableShort((short) 1).shortValue());
+
+ assertEquals((short) 2, new MutableShort(new Short((short) 2)).shortValue());
+ assertEquals((short) 3, new MutableShort(new MutableShort((short) 3)).shortValue());
+ try {
+ new MutableShort(null);
+ fail();
+ } catch (NullPointerException ex) {}
}
- public byte byteValue(double value) {
- return (byte)(short)value;
+ public void testGetSet() {
+ final MutableShort mutNum = new MutableShort((short) 0);
+ assertEquals((short) 0, new MutableShort().shortValue());
+ assertEquals(new Short((short) 0), new MutableShort().getValue());
+
+ mutNum.setValue((short) 1);
+ assertEquals((short) 1, mutNum.shortValue());
+ assertEquals(new Short((short) 1), mutNum.getValue());
+
+ mutNum.setValue(new Short((short) 2));
+ assertEquals((short) 2, mutNum.shortValue());
+ assertEquals(new Short((short) 2), mutNum.getValue());
+
+ mutNum.setValue(new MutableShort((short) 3));
+ assertEquals((short) 3, mutNum.shortValue());
+ assertEquals(new Short((short) 3), mutNum.getValue());
+ try {
+ mutNum.setValue(null);
+ fail();
+ } catch (NullPointerException ex) {}
+ try {
+ mutNum.setValue("0");
+ fail();
+ } catch (ClassCastException ex) {}
}
- public short shortValue(double value) {
- return (short)value;
+ public void testEquals() {
+ final MutableShort mutNumA = new MutableShort((short) 0);
+ final MutableShort mutNumB = new MutableShort((short) 0);
+ final MutableShort mutNumC = new MutableShort((short) 1);
+
+ assertEquals(true, mutNumA.equals(mutNumA));
+ assertEquals(true, mutNumA.equals(mutNumB));
+ assertEquals(true, mutNumB.equals(mutNumA));
+ assertEquals(true, mutNumB.equals(mutNumB));
+ assertEquals(false, mutNumA.equals(mutNumC));
+ assertEquals(false, mutNumB.equals(mutNumC));
+ assertEquals(true, mutNumC.equals(mutNumC));
+ assertEquals(false, mutNumA.equals(null));
+ assertEquals(false, mutNumA.equals(new Short((short) 0)));
+ assertEquals(false, mutNumA.equals("0"));
}
- public int intValue(double value) {
- return (short)value;
+ public void testHashCode() {
+ final MutableShort mutNumA = new MutableShort((short) 0);
+ final MutableShort mutNumB = new MutableShort((short) 0);
+ final MutableShort mutNumC = new MutableShort((short) 1);
+
+ assertEquals(true, mutNumA.hashCode() == mutNumA.hashCode());
+ assertEquals(true, mutNumA.hashCode() == mutNumB.hashCode());
+ assertEquals(false, mutNumA.hashCode() == mutNumC.hashCode());
+ assertEquals(true, mutNumA.hashCode() == new Short((short) 0).hashCode());
}
- public long longValue(double value) {
- return (short)value;
+ public void testCompareTo() {
+ final MutableShort mutNum = new MutableShort((short) 0);
+
+ assertEquals((short) 0, mutNum.compareTo(new MutableShort((short) 0)));
+ assertEquals((short) +1, mutNum.compareTo(new MutableShort((short) -1)));
+ assertEquals((short) -1, mutNum.compareTo(new MutableShort((short) 1)));
+ try {
+ mutNum.compareTo(null);
+ fail();
+ } catch (NullPointerException ex) {}
+ try {
+ mutNum.compareTo(new Short((short) 0));
+ fail();
+ } catch (ClassCastException ex) {}
+ try {
+ mutNum.compareTo("0");
+ fail();
+ } catch (ClassCastException ex) {}
}
- public float floatValue(double value) {
- return (short)value;
- }
-
- public double doubleValue(double value) {
- return (short)value;
+ public void testToString() {
+ assertEquals("0", new MutableShort((short) 0).toString());
+ assertEquals("10", new MutableShort((short) 10).toString());
+ assertEquals("-123", new MutableShort((short) -123).toString());
}
}
-
diff --git a/src/test/org/apache/commons/lang/mutable/MutableTestSuite.java b/src/test/org/apache/commons/lang/mutable/MutableTestSuite.java
index e19f01e2f..3eedb137a 100755
--- a/src/test/org/apache/commons/lang/mutable/MutableTestSuite.java
+++ b/src/test/org/apache/commons/lang/mutable/MutableTestSuite.java
@@ -22,9 +22,9 @@
/**
* JUnit tests.
*
- * @version $Id: MutableTestSuite.java,v 1.2 2004/06/27 06:28:32 bayard Exp $
+ * @version $Id: MutableTestSuite.java,v 1.3 2004/07/07 23:50:28 scolebourne Exp $
*/
-public final class MutableTestSuite {
+public class MutableTestSuite {
public static void main(String[] args) {
TestRunner.run(suite());
@@ -35,7 +35,7 @@ public static Test suite() {
suite.addTest(MutableByteTest.suite());
suite.addTest(MutableShortTest.suite());
- suite.addTest(MutableIntegerTest.suite());
+ suite.addTest(MutableIntTest.suite());
suite.addTest(MutableLongTest.suite());
suite.addTest(MutableFloatTest.suite());
suite.addTest(MutableDoubleTest.suite());