Patch from Michael Rudolf in LANG-522 applied with additional String constructor tests added

git-svn-id: https://svn.apache.org/repos/asf/commons/proper/lang/trunk@829283 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Henri Yandell 2009-10-24 00:00:47 +00:00
parent 51a130b544
commit 3d17fad6d6
12 changed files with 102 additions and 6 deletions

View File

@ -66,6 +66,19 @@ public class MutableByte extends Number implements Comparable<MutableByte>, Muta
this.value = value.byteValue();
}
/**
* Constructs a new MutableByte parsing the given string.
*
* @param value
* the string to parse.
* @throws NumberFormatException
* if the string cannot be parsed into a byte
*/
public MutableByte(String value) throws NumberFormatException {
super();
this.value = Byte.parseByte(value);
}
//-----------------------------------------------------------------------
/**
* Gets the value as a Byte instance.

View File

@ -66,6 +66,19 @@ public class MutableDouble extends Number implements Comparable<MutableDouble>,
this.value = value.doubleValue();
}
/**
* Constructs a new MutableDouble parsing the given string.
*
* @param value
* the string to parse.
* @throws NumberFormatException
* if the string cannot be parsed into a double
*/
public MutableDouble(String value) throws NumberFormatException {
super();
this.value = Double.parseDouble(value);
}
//-----------------------------------------------------------------------
/**
* Gets the value as a Double instance.

View File

@ -66,6 +66,19 @@ public class MutableFloat extends Number implements Comparable<MutableFloat>, Mu
this.value = value.floatValue();
}
/**
* Constructs a new MutableFloat parsing the given string.
*
* @param value
* the string to parse.
* @throws NumberFormatException
* if the string cannot be parsed into a float
*/
public MutableFloat(String value) throws NumberFormatException {
super();
this.value = Float.parseFloat(value);
}
//-----------------------------------------------------------------------
/**
* Gets the value as a Float instance.

View File

@ -66,6 +66,19 @@ public class MutableInt extends Number implements Comparable<MutableInt>, Mutabl
this.value = value.intValue();
}
/**
* Constructs a new MutableInt parsing the given string.
*
* @param value
* the string to parse.
* @throws NumberFormatException
* if the string cannot be parsed into an int
*/
public MutableInt(String value) throws NumberFormatException {
super();
this.value = Integer.parseInt(value);
}
//-----------------------------------------------------------------------
/**
* Gets the value as a Integer instance.

View File

@ -66,6 +66,19 @@ public class MutableLong extends Number implements Comparable<MutableLong>, Muta
this.value = value.longValue();
}
/**
* Constructs a new MutableLong parsing the given string.
*
* @param value
* the string to parse.
* @throws NumberFormatException
* if the string cannot be parsed into a long
*/
public MutableLong(String value) throws NumberFormatException {
super();
this.value = Long.parseLong(value);
}
//-----------------------------------------------------------------------
/**
* Gets the value as a Long instance.

View File

@ -66,6 +66,19 @@ public class MutableShort extends Number implements Comparable<MutableShort>, Mu
this.value = value.shortValue();
}
/**
* Constructs a new MutableShort parsing the given string.
*
* @param value
* the string to parse.
* @throws NumberFormatException
* if the string cannot be parsed into a short
*/
public MutableShort(String value) throws NumberFormatException {
super();
this.value = Short.parseShort(value);
}
//-----------------------------------------------------------------------
/**
* Gets the value as a Short instance.

View File

@ -49,8 +49,11 @@ public class MutableByteTest extends TestCase {
assertEquals((byte) 2, new MutableByte(Byte.valueOf((byte) 2)).byteValue());
assertEquals((byte) 3, new MutableByte(new MutableByte((byte) 3)).byteValue());
assertEquals((byte) 2, new MutableByte("2").byteValue());
try {
new MutableByte(null);
new MutableByte((Number)null);
fail();
} catch (NullPointerException ex) {}
}

View File

@ -49,8 +49,11 @@ public class MutableDoubleTest extends TestCase {
assertEquals(2d, new MutableDouble(new Double(2d)).doubleValue(), 0.0001d);
assertEquals(3d, new MutableDouble(new MutableDouble(3d)).doubleValue(), 0.0001d);
assertEquals(2d, new MutableDouble("2.0").doubleValue(), 0.0001d);
try {
new MutableDouble(null);
new MutableDouble((Number)null);
fail();
} catch (NullPointerException ex) {}
}

View File

@ -49,8 +49,11 @@ public class MutableFloatTest extends TestCase {
assertEquals(2f, new MutableFloat(new Float(2f)).floatValue(), 0.0001f);
assertEquals(3f, new MutableFloat(new MutableFloat(3f)).floatValue(), 0.0001f);
assertEquals(2f, new MutableDouble("2.0").floatValue(), 0.0001f);
try {
new MutableFloat(null);
new MutableFloat((Number)null);
fail();
} catch (NullPointerException ex) {}
}

View File

@ -49,8 +49,11 @@ public class MutableIntTest extends TestCase {
assertEquals(2, new MutableInt(new Integer(2)).intValue());
assertEquals(3, new MutableInt(new MutableLong(3)).intValue());
assertEquals(2, new MutableInt("2").intValue());
try {
new MutableInt(null);
new MutableInt((Number)null);
fail();
} catch (NullPointerException ex) {}
}

View File

@ -49,8 +49,11 @@ public class MutableLongTest extends TestCase {
assertEquals(2, new MutableLong(new Long(2)).longValue());
assertEquals(3, new MutableLong(new MutableLong(3)).longValue());
assertEquals(2, new MutableLong("2").longValue());
try {
new MutableLong(null);
new MutableLong((Number)null);
fail();
} catch (NullPointerException ex) {}
}

View File

@ -49,8 +49,11 @@ public class MutableShortTest extends TestCase {
assertEquals((short) 2, new MutableShort(new Short((short) 2)).shortValue());
assertEquals((short) 3, new MutableShort(new MutableShort((short) 3)).shortValue());
assertEquals((short) 2, new MutableShort("2").shortValue());
try {
new MutableShort(null);
new MutableShort((Number)null);
fail();
} catch (NullPointerException ex) {}
}