You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@commons.apache.org by sc...@apache.org on 2004/07/08 01:50:28 UTC
cvs commit: jakarta-commons/lang/src/test/org/apache/commons/lang AllLangTestSuite.java
scolebourne 2004/07/07 16:50:28
Modified: lang/src/java/org/apache/commons/lang/mutable
MutableDouble.java MutableLong.java
MutableFloat.java MutableByte.java
MutableShort.java MutableInt.java
lang/src/test/org/apache/commons/lang/mutable
MutableFloatTest.java MutableByteTest.java
MutableShortTest.java MutableDoubleTest.java
MutableTestSuite.java MutableLongTest.java
lang/src/test/org/apache/commons/lang AllLangTestSuite.java
Added: lang/src/test/org/apache/commons/lang/mutable
MutableIntTest.java
Removed: lang/src/java/org/apache/commons/lang/mutable
MutableInteger.java MutableNumber.java
lang/src/test/org/apache/commons/lang/mutable
MutableIntegerTest.java MutableNumberTest.java
Log:
Update mutable package for release 2.1
Revision Changes Path
1.4 +130 -16 jakarta-commons/lang/src/java/org/apache/commons/lang/mutable/MutableDouble.java
Index: MutableDouble.java
===================================================================
RCS file: /home/cvs/jakarta-commons/lang/src/java/org/apache/commons/lang/mutable/MutableDouble.java,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -r1.3 -r1.4
--- MutableDouble.java 24 Jun 2004 04:20:46 -0000 1.3
+++ MutableDouble.java 7 Jul 2004 23:50:28 -0000 1.4
@@ -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 <code>Double</code>
+ * A mutable <code>double</code>.
*
* @since 2.1
* @version $Id$
*/
-public class MutableDouble extends MutableNumber {
+public class MutableDouble extends Number
+ implements Comparable, Mutable, Serializable {
+
+ /** Serialization lock. */
+ private static final long serialVersionUID = 1587163916L;
+
+ /** The mutable value. */
+ private double value;
/**
- * Internal value.
+ * Constructs a new MutableDouble with the default value of zero.
*/
- private double value;
+ public MutableDouble() {
+ super();
+ }
/**
- * Instantiates with the specified value
+ * Constructs a new MutableDouble with the specified value.
+ *
* @param value a value.
*/
public MutableDouble(double value) {
@@ -37,28 +51,128 @@
this.value = 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;
}
- public double doubleValue() {
- return this.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());
+ }
+
+ //-----------------------------------------------------------------------
+ public int intValue() {
+ return (int) value;
}
public long longValue() {
- return (long)this.value;
+ return (long) value;
}
- public int intValue() {
- return (int)this.value;
+ public float floatValue() {
+ return (float) value;
}
- public Object getValue() {
- return new Double(this.value);
+ public double doubleValue() {
+ return value;
}
- public void setValue(Object value) {
- setValue(((Number)value).doubleValue());
+ /**
+ * 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.
+ * <p>
+ * 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);
}
}
1.4 +109 -17 jakarta-commons/lang/src/java/org/apache/commons/lang/mutable/MutableLong.java
Index: MutableLong.java
===================================================================
RCS file: /home/cvs/jakarta-commons/lang/src/java/org/apache/commons/lang/mutable/MutableLong.java,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -r1.3 -r1.4
--- MutableLong.java 24 Jun 2004 04:20:46 -0000 1.3
+++ MutableLong.java 7 Jul 2004 23:50:28 -0000 1.4
@@ -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 <code>Long</code>
+ * A mutable <code>long</code>.
*
* @since 2.1
* @version $Id$
*/
-public class MutableLong extends MutableNumber {
+public class MutableLong extends Number
+ implements Comparable, Mutable, Serializable {
+
+ /** Serialization lock. */
+ private static final long serialVersionUID = 62986528375L;
+
+ /** The mutable value. */
+ private long value;
/**
- * Internal value.
+ * Constructs a new MutableLong with the default value of zero.
*/
- private long value;
+ public MutableLong() {
+ super();
+ }
/**
- * Instantiates with the specified value
+ * Constructs a new MutableLong with the specified value.
+ *
* @param value a value.
*/
public MutableLong(long value) {
super();
- setValue(value);
+ this.value = 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;
}
- public double doubleValue() {
- return this.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());
+ }
+
+ //-----------------------------------------------------------------------
+ public int intValue() {
+ return (int) value;
}
public long longValue() {
- return this.value;
+ return value;
}
- public int intValue() {
- return (int)this.value;
+ public float floatValue() {
+ return (float) value;
}
- public Object getValue() {
- return new Long(this.value);
+ public double doubleValue() {
+ return (double) value;
}
- public void setValue(Object value) {
- setValue(((Number)value).longValue());
+ //-----------------------------------------------------------------------
+ /**
+ * Checks if this object equals the specified object.
+ * <p>
+ * 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);
}
}
1.4 +127 -15 jakarta-commons/lang/src/java/org/apache/commons/lang/mutable/MutableFloat.java
Index: MutableFloat.java
===================================================================
RCS file: /home/cvs/jakarta-commons/lang/src/java/org/apache/commons/lang/mutable/MutableFloat.java,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -r1.3 -r1.4
--- MutableFloat.java 24 Jun 2004 04:20:46 -0000 1.3
+++ MutableFloat.java 7 Jul 2004 23:50:28 -0000 1.4
@@ -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 <code>Float</code>
+ * A mutable <code>float</code>.
*
* @since 2.1
* @version $Id$
*/
-public class MutableFloat extends MutableNumber {
+public class MutableFloat extends Number
+ implements Comparable, Mutable, Serializable {
+
+ /** Serialization lock. */
+ private static final long serialVersionUID = 5787169186L;
+
+ /** The mutable value. */
+ private float value;
/**
- * Internal value.
+ * Constructs a new MutableFloat with the default value of zero.
*/
- private float value;
+ public MutableFloat() {
+ super();
+ }
/**
- * Instantiates with the specified value
+ * Constructs a new MutableFloat with the specified value.
*
* @param value a value.
*/
@@ -38,28 +51,127 @@
this.value = 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;
}
- public double doubleValue() {
- return this.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());
}
+ //-----------------------------------------------------------------------
public int intValue() {
- return (int)this.value;
+ return (int) value;
}
public long longValue() {
- return (long)this.value;
+ return (long) value;
}
- public Object getValue() {
- return new Float(this.value);
+ public float floatValue() {
+ return value;
}
- public void setValue(Object value) {
- setValue(((Number)value).floatValue());
+ 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.
+ * <p>
+ * 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);
}
}
1.4 +108 -18 jakarta-commons/lang/src/java/org/apache/commons/lang/mutable/MutableByte.java
Index: MutableByte.java
===================================================================
RCS file: /home/cvs/jakarta-commons/lang/src/java/org/apache/commons/lang/mutable/MutableByte.java,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -r1.3 -r1.4
--- MutableByte.java 24 Jun 2004 04:20:46 -0000 1.3
+++ MutableByte.java 7 Jul 2004 23:50:28 -0000 1.4
@@ -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 <code>Byte</code>.
+ * A mutable <code>byte</code>.
*
* @since 2.1
* @version $Id$
*/
-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 @@
this.value = value;
}
+ /**
+ * 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);
+ }
+
+ /**
+ * 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());
+ }
+
+ //-----------------------------------------------------------------------
+ public byte byteValue() {
+ return value;
+ }
+
+ public int intValue() {
+ return (int) value;
+ }
+
public long longValue() {
- return this.value;
+ return (long) value;
+ }
+
+ public float floatValue() {
+ return (float) value;
}
public double doubleValue() {
- return this.value;
+ return (double) value;
}
- public int intValue() {
- return this.value;
+ //-----------------------------------------------------------------------
+ /**
+ * Checks if this object equals the specified object.
+ * <p>
+ * 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;
}
/**
- * @return a <code>Byte</code>
+ * Returns a suitable hashcode for this mutable.
+ *
+ * @return a suitable hashcode
*/
- public Object getValue() {
- return new Byte(this.value);
+ public int hashCode() {
+ return (int) value;
}
/**
- * @param value a <code>Byte</code>
+ * 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 void setValue(Object value) {
- setValue(((Number)value).byteValue());
+ 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);
}
}
1.4 +111 -15 jakarta-commons/lang/src/java/org/apache/commons/lang/mutable/MutableShort.java
Index: MutableShort.java
===================================================================
RCS file: /home/cvs/jakarta-commons/lang/src/java/org/apache/commons/lang/mutable/MutableShort.java,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -r1.3 -r1.4
--- MutableShort.java 24 Jun 2004 04:20:46 -0000 1.3
+++ MutableShort.java 7 Jul 2004 23:50:28 -0000 1.4
@@ -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 <code>Short</code>
+ * A mutable <code>short</code>.
*
* @since 2.1
* @version $Id$
*/
-public class MutableShort extends MutableNumber {
+public class MutableShort extends Number
+ implements Comparable, Mutable, Serializable {
+
+ /** Serialization lock. */
+ private static final long serialVersionUID = -2135791679L;
+
+ /** The mutable value. */
+ private short value;
/**
- * Internal value.
+ * Constructs a new MutableShort with the default value of zero.
*/
- private short value;
+ public MutableShort() {
+ super();
+ }
/**
- * Instantiates with the specified value
+ * Constructs a new MutableShort with the specified value.
+ *
* @param value a value.
*/
public MutableShort(short value) {
@@ -37,28 +49,112 @@
this.value = 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;
}
- public double doubleValue() {
- return this.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());
+ }
+
+ //-----------------------------------------------------------------------
+ public short shortValue() {
+ return value;
}
public int intValue() {
- return this.value;
+ return (int) value;
}
public long longValue() {
- return this.value;
+ return (long) value;
}
- public Object getValue() {
- return new Short(this.value);
+ public float floatValue() {
+ return (float) value;
}
- public void setValue(Object value) {
- setValue(((Number)value).shortValue());
+ public double doubleValue() {
+ return (double) value;
+ }
+
+ //-----------------------------------------------------------------------
+ /**
+ * Checks if this object equals the specified object.
+ * <p>
+ * 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);
}
}
1.2 +29 -1 jakarta-commons/lang/src/java/org/apache/commons/lang/mutable/MutableInt.java
Index: MutableInt.java
===================================================================
RCS file: /home/cvs/jakarta-commons/lang/src/java/org/apache/commons/lang/mutable/MutableInt.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- MutableInt.java 5 Jul 2004 22:15:33 -0000 1.1
+++ MutableInt.java 7 Jul 2004 23:50:28 -0000 1.2
@@ -49,15 +49,43 @@
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());
}
1.2 +148 -75 jakarta-commons/lang/src/test/org/apache/commons/lang/mutable/MutableFloatTest.java
Index: MutableFloatTest.java
===================================================================
RCS file: /home/cvs/jakarta-commons/lang/src/test/org/apache/commons/lang/mutable/MutableFloatTest.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- MutableFloatTest.java 11 Jun 2004 02:26:32 -0000 1.1
+++ MutableFloatTest.java 7 Jul 2004 23:50:28 -0000 1.2
@@ -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$
- * @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$
+ * @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());
+ }
+
+}
1.2 +100 -37 jakarta-commons/lang/src/test/org/apache/commons/lang/mutable/MutableByteTest.java
Index: MutableByteTest.java
===================================================================
RCS file: /home/cvs/jakarta-commons/lang/src/test/org/apache/commons/lang/mutable/MutableByteTest.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- MutableByteTest.java 11 Jun 2004 02:26:32 -0000 1.1
+++ MutableByteTest.java 7 Jul 2004 23:50:28 -0000 1.2
@@ -16,6 +16,7 @@
package org.apache.commons.lang.mutable;
import junit.framework.Test;
+import junit.framework.TestCase;
import junit.framework.TestSuite;
import junit.textui.TestRunner;
@@ -25,50 +26,112 @@
* @version $Id$
* @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);
- }
-
- // ----------------------------------------------------------------
- // Converters
- // ----------------------------------------------------------------
-
- public byte byteValue(double value) {
- return (byte)value;
- }
-
- public short shortValue(double value) {
- return (byte)value;
- }
-
- public int intValue(double value) {
- return (byte)value;
- }
-
- public long longValue(double value) {
- return (byte)value;
+ public static void main(String[] args) {
+ TestRunner.run(suite());
}
- public float floatValue(double value) {
- return (byte)value;
+ public static Test suite() {
+ return new TestSuite(MutableByteTest.class);
}
- public double doubleValue(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 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 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 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 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 void testToString() {
+ assertEquals("0", new MutableByte((byte) 0).toString());
+ assertEquals("10", new MutableByte((byte) 10).toString());
+ assertEquals("-123", new MutableByte((byte) -123).toString());
}
-} // MutableByteTest
+}
1.2 +98 -36 jakarta-commons/lang/src/test/org/apache/commons/lang/mutable/MutableShortTest.java
Index: MutableShortTest.java
===================================================================
RCS file: /home/cvs/jakarta-commons/lang/src/test/org/apache/commons/lang/mutable/MutableShortTest.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- MutableShortTest.java 11 Jun 2004 02:26:32 -0000 1.1
+++ MutableShortTest.java 7 Jul 2004 23:50:28 -0000 1.2
@@ -16,6 +16,7 @@
package org.apache.commons.lang.mutable;
import junit.framework.Test;
+import junit.framework.TestCase;
import junit.framework.TestSuite;
import junit.textui.TestRunner;
@@ -25,7 +26,11 @@
* @version $Id$
* @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 @@
return new TestSuite(MutableShortTest.class);
}
- public MutableShortTest(String testName) {
- super(testName);
- }
-
- // ----------------------------------------------------------------
- // Converters
// ----------------------------------------------------------------
-
- public MutableNumber getMutableNumber(double value) {
- return new MutableShort((short)value);
- }
-
- public byte byteValue(double value) {
- return (byte)(short)value;
- }
-
- public short shortValue(double value) {
- return (short)value;
- }
-
- public int intValue(double value) {
- return (short)value;
- }
-
- public long longValue(double value) {
- return (short)value;
- }
-
- public float floatValue(double value) {
- return (short)value;
- }
-
- public double doubleValue(double value) {
- return (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 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 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 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 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 void testToString() {
+ assertEquals("0", new MutableShort((short) 0).toString());
+ assertEquals("10", new MutableShort((short) 10).toString());
+ assertEquals("-123", new MutableShort((short) -123).toString());
}
}
-
1.2 +148 -73 jakarta-commons/lang/src/test/org/apache/commons/lang/mutable/MutableDoubleTest.java
Index: MutableDoubleTest.java
===================================================================
RCS file: /home/cvs/jakarta-commons/lang/src/test/org/apache/commons/lang/mutable/MutableDoubleTest.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- MutableDoubleTest.java 11 Jun 2004 02:26:32 -0000 1.1
+++ MutableDoubleTest.java 7 Jul 2004 23:50:28 -0000 1.2
@@ -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$
- * @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$
+ * @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());
+ }
+
+}
1.3 +3 -3 jakarta-commons/lang/src/test/org/apache/commons/lang/mutable/MutableTestSuite.java
Index: MutableTestSuite.java
===================================================================
RCS file: /home/cvs/jakarta-commons/lang/src/test/org/apache/commons/lang/mutable/MutableTestSuite.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- MutableTestSuite.java 27 Jun 2004 06:28:32 -0000 1.2
+++ MutableTestSuite.java 7 Jul 2004 23:50:28 -0000 1.3
@@ -24,7 +24,7 @@
*
* @version $Id$
*/
-public final class MutableTestSuite {
+public class MutableTestSuite {
public static void main(String[] args) {
TestRunner.run(suite());
@@ -35,7 +35,7 @@
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());
1.2 +137 -74 jakarta-commons/lang/src/test/org/apache/commons/lang/mutable/MutableLongTest.java
Index: MutableLongTest.java
===================================================================
RCS file: /home/cvs/jakarta-commons/lang/src/test/org/apache/commons/lang/mutable/MutableLongTest.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- MutableLongTest.java 11 Jun 2004 02:26:32 -0000 1.1
+++ MutableLongTest.java 7 Jul 2004 23:50:28 -0000 1.2
@@ -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$
- * @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$
+ * @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());
+ }
+
+}
1.1 jakarta-commons/lang/src/test/org/apache/commons/lang/mutable/MutableIntTest.java
Index: MutableIntTest.java
===================================================================
/*
* 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());
}
}
1.7 +4 -1 jakarta-commons/lang/src/test/org/apache/commons/lang/AllLangTestSuite.java
Index: AllLangTestSuite.java
===================================================================
RCS file: /home/cvs/jakarta-commons/lang/src/test/org/apache/commons/lang/AllLangTestSuite.java,v
retrieving revision 1.6
retrieving revision 1.7
diff -u -r1.6 -r1.7
--- AllLangTestSuite.java 1 Jun 2004 20:55:28 -0000 1.6
+++ AllLangTestSuite.java 7 Jul 2004 23:50:28 -0000 1.7
@@ -19,10 +19,12 @@
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;
/**
@@ -59,6 +61,7 @@
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;
}
---------------------------------------------------------------------
To unsubscribe, e-mail: commons-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-dev-help@jakarta.apache.org