From 62a97240a5833740c5fc5187febdfd4a585b6460 Mon Sep 17 00:00:00 2001 From: Stephen Colebourne Date: Mon, 20 Mar 2006 22:09:44 +0000 Subject: [PATCH] Increment, decrement add and subtract methods from Stephen Putman git-svn-id: https://svn.apache.org/repos/asf/jakarta/commons/proper/lang/trunk@387322 13f79535-47bb-0310-9956-ffa450edef68 --- .../commons/lang/mutable/MutableByte.java | 75 ++++++++++++++++++- .../commons/lang/mutable/MutableDouble.java | 75 ++++++++++++++++++- .../commons/lang/mutable/MutableFloat.java | 75 ++++++++++++++++++- .../commons/lang/mutable/MutableInt.java | 75 ++++++++++++++++++- .../commons/lang/mutable/MutableLong.java | 75 ++++++++++++++++++- .../commons/lang/mutable/MutableShort.java | 75 ++++++++++++++++++- .../commons/lang/mutable/MutableByteTest.java | 46 +++++++++++- .../lang/mutable/MutableDoubleTest.java | 46 +++++++++++- .../lang/mutable/MutableFloatTest.java | 46 +++++++++++- .../commons/lang/mutable/MutableIntTest.java | 50 ++++++++++++- .../commons/lang/mutable/MutableLongTest.java | 50 ++++++++++++- .../lang/mutable/MutableShortTest.java | 46 +++++++++++- 12 files changed, 716 insertions(+), 18 deletions(-) diff --git a/src/java/org/apache/commons/lang/mutable/MutableByte.java b/src/java/org/apache/commons/lang/mutable/MutableByte.java index 513c9fa6e..1ab2a3aaa 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 2004-2005 The Apache Software Foundation. + * Copyright 2004-2006 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. @@ -13,7 +13,6 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - package org.apache.commons.lang.mutable; /** @@ -153,6 +152,78 @@ public class MutableByte extends Number implements Comparable, Mutable { return new Byte(byteValue()); } + //----------------------------------------------------------------------- + /** + * Increments the value. + * + * @since Commons Lang 2.2 + */ + public void increment() { + value++; + } + + /** + * Decrements the value. + * + * @since Commons Lang 2.2 + */ + public void decrement() { + value--; + } + + //----------------------------------------------------------------------- + /** + * Adds a value. + * + * @param operand + * the value to add + * + * @since Commons Lang 2.2 + */ + public void add(byte operand) { + this.value += operand; + } + + /** + * Adds a value. + * + * @param operand + * the value to add + * @throws NullPointerException + * if the object is null + * + * @since Commons Lang 2.2 + */ + public void add(Number operand) { + this.value += operand.byteValue(); + } + + /** + * Subtracts a value. + * + * @param operand + * the value to add + * + * @since Commons Lang 2.2 + */ + public void subtract(byte operand) { + this.value -= operand; + } + + /** + * Subtracts a value. + * + * @param operand + * the value to add + * @throws NullPointerException + * if the object is null + * + * @since Commons Lang 2.2 + */ + public void subtract(Number operand) { + this.value -= operand.byteValue(); + } + //----------------------------------------------------------------------- /** * Compares this object against the specified object. The result is true if and only if the argument diff --git a/src/java/org/apache/commons/lang/mutable/MutableDouble.java b/src/java/org/apache/commons/lang/mutable/MutableDouble.java index a445c7575..992ff5e9d 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 2004-2005 The Apache Software Foundation. + * Copyright 2004-2006 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. @@ -13,7 +13,6 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - package org.apache.commons.lang.mutable; import org.apache.commons.lang.math.NumberUtils; @@ -164,6 +163,78 @@ public class MutableDouble extends Number implements Comparable, Mutable { return new Double(doubleValue()); } + //----------------------------------------------------------------------- + /** + * Increments the value. + * + * @since Commons Lang 2.2 + */ + public void increment() { + value++; + } + + /** + * Decrements the value. + * + * @since Commons Lang 2.2 + */ + public void decrement() { + value--; + } + + //----------------------------------------------------------------------- + /** + * Adds a value. + * + * @param operand + * the value to add + * + * @since Commons Lang 2.2 + */ + public void add(double operand) { + this.value += operand; + } + + /** + * Adds a value. + * + * @param operand + * the value to add + * @throws NullPointerException + * if the object is null + * + * @since Commons Lang 2.2 + */ + public void add(Number operand) { + this.value += operand.doubleValue(); + } + + /** + * Subtracts a value. + * + * @param operand + * the value to add + * + * @since Commons Lang 2.2 + */ + public void subtract(double operand) { + this.value -= operand; + } + + /** + * Subtracts a value. + * + * @param operand + * the value to add + * @throws NullPointerException + * if the object is null + * + * @since Commons Lang 2.2 + */ + public void subtract(Number operand) { + this.value -= operand.doubleValue(); + } + //----------------------------------------------------------------------- /** * Compares this object against the specified object. The result is true if and only if the argument diff --git a/src/java/org/apache/commons/lang/mutable/MutableFloat.java b/src/java/org/apache/commons/lang/mutable/MutableFloat.java index c5164137a..3119d9d16 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 2004-2005 The Apache Software Foundation. + * Copyright 2004-2006 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. @@ -13,7 +13,6 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - package org.apache.commons.lang.mutable; import org.apache.commons.lang.math.NumberUtils; @@ -98,6 +97,78 @@ public class MutableFloat extends Number implements Comparable, Mutable { setValue(((Number) value).floatValue()); } + //----------------------------------------------------------------------- + /** + * Increments the value. + * + * @since Commons Lang 2.2 + */ + public void increment() { + value++; + } + + /** + * Decrements the value. + * + * @since Commons Lang 2.2 + */ + public void decrement() { + value--; + } + + //----------------------------------------------------------------------- + /** + * Adds a value. + * + * @param operand + * the value to add + * + * @since Commons Lang 2.2 + */ + public void add(float operand) { + this.value += operand; + } + + /** + * Adds a value. + * + * @param operand + * the value to add + * @throws NullPointerException + * if the object is null + * + * @since Commons Lang 2.2 + */ + public void add(Number operand) { + this.value += operand.floatValue(); + } + + /** + * Subtracts a value. + * + * @param operand + * the value to add + * + * @since Commons Lang 2.2 + */ + public void subtract(float operand) { + this.value -= operand; + } + + /** + * Subtracts a value. + * + * @param operand + * the value to add + * @throws NullPointerException + * if the object is null + * + * @since Commons Lang 2.2 + */ + public void subtract(Number operand) { + this.value -= operand.floatValue(); + } + //----------------------------------------------------------------------- // shortValue and bytValue rely on Number implementation /** diff --git a/src/java/org/apache/commons/lang/mutable/MutableInt.java b/src/java/org/apache/commons/lang/mutable/MutableInt.java index 1398efd6d..84aa21b95 100644 --- a/src/java/org/apache/commons/lang/mutable/MutableInt.java +++ b/src/java/org/apache/commons/lang/mutable/MutableInt.java @@ -1,5 +1,5 @@ /* - * Copyright 2004-2005 The Apache Software Foundation. + * Copyright 2004-2006 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. @@ -13,7 +13,6 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - package org.apache.commons.lang.mutable; /** @@ -96,6 +95,78 @@ public class MutableInt extends Number implements Comparable, Mutable { setValue(((Number) value).intValue()); } + //----------------------------------------------------------------------- + /** + * Increments the value. + * + * @since Commons Lang 2.2 + */ + public void increment() { + value++; + } + + /** + * Decrements the value. + * + * @since Commons Lang 2.2 + */ + public void decrement() { + value--; + } + + //----------------------------------------------------------------------- + /** + * Adds a value. + * + * @param operand + * the value to add + * + * @since Commons Lang 2.2 + */ + public void add(int operand) { + this.value += operand; + } + + /** + * Adds a value. + * + * @param operand + * the value to add + * @throws NullPointerException + * if the object is null + * + * @since Commons Lang 2.2 + */ + public void add(Number operand) { + this.value += operand.intValue(); + } + + /** + * Subtracts a value. + * + * @param operand + * the value to add + * + * @since Commons Lang 2.2 + */ + public void subtract(int operand) { + this.value -= operand; + } + + /** + * Subtracts a value. + * + * @param operand + * the value to add + * @throws NullPointerException + * if the object is null + * + * @since Commons Lang 2.2 + */ + public void subtract(Number operand) { + this.value -= operand.intValue(); + } + //----------------------------------------------------------------------- // shortValue and bytValue rely on Number implementation /** diff --git a/src/java/org/apache/commons/lang/mutable/MutableLong.java b/src/java/org/apache/commons/lang/mutable/MutableLong.java index b9d0f0e0f..c94d42255 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 2004-2005 The Apache Software Foundation. + * Copyright 2004-2006 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. @@ -13,7 +13,6 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - package org.apache.commons.lang.mutable; /** @@ -96,6 +95,78 @@ public class MutableLong extends Number implements Comparable, Mutable { setValue(((Number) value).longValue()); } + //----------------------------------------------------------------------- + /** + * Increments the value. + * + * @since Commons Lang 2.2 + */ + public void increment() { + value++; + } + + /** + * Decrements the value. + * + * @since Commons Lang 2.2 + */ + public void decrement() { + value--; + } + + //----------------------------------------------------------------------- + /** + * Adds a value. + * + * @param operand + * the value to add + * + * @since Commons Lang 2.2 + */ + public void add(long operand) { + this.value += operand; + } + + /** + * Adds a value. + * + * @param operand + * the value to add + * @throws NullPointerException + * if the object is null + * + * @since Commons Lang 2.2 + */ + public void add(Number operand) { + this.value += operand.longValue(); + } + + /** + * Subtracts a value. + * + * @param operand + * the value to add + * + * @since Commons Lang 2.2 + */ + public void subtract(long operand) { + this.value -= operand; + } + + /** + * Subtracts a value. + * + * @param operand + * the value to add + * @throws NullPointerException + * if the object is null + * + * @since Commons Lang 2.2 + */ + public void subtract(Number operand) { + this.value -= operand.longValue(); + } + //----------------------------------------------------------------------- // shortValue and bytValue rely on Number implementation /** diff --git a/src/java/org/apache/commons/lang/mutable/MutableShort.java b/src/java/org/apache/commons/lang/mutable/MutableShort.java index bb7ba9583..4f75de00a 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 2004-2005 The Apache Software Foundation. + * Copyright 2004-2006 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. @@ -13,7 +13,6 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - package org.apache.commons.lang.mutable; /** @@ -96,6 +95,78 @@ public class MutableShort extends Number implements Comparable, Mutable { setValue(((Number) value).shortValue()); } + //----------------------------------------------------------------------- + /** + * Increments the value. + * + * @since Commons Lang 2.2 + */ + public void increment() { + value++; + } + + /** + * Decrements the value. + * + * @since Commons Lang 2.2 + */ + public void decrement() { + value--; + } + + //----------------------------------------------------------------------- + /** + * Adds a value. + * + * @param operand + * the value to add + * + * @since Commons Lang 2.2 + */ + public void add(short operand) { + this.value += operand; + } + + /** + * Adds a value. + * + * @param operand + * the value to add + * @throws NullPointerException + * if the object is null + * + * @since Commons Lang 2.2 + */ + public void add(Number operand) { + this.value += operand.shortValue(); + } + + /** + * Subtracts a value. + * + * @param operand + * the value to add + * + * @since Commons Lang 2.2 + */ + public void subtract(short operand) { + this.value -= operand; + } + + /** + * Subtracts a value. + * + * @param operand + * the value to add + * @throws NullPointerException + * if the object is null + * + * @since Commons Lang 2.2 + */ + public void subtract(Number operand) { + this.value -= operand.shortValue(); + } + //----------------------------------------------------------------------- // bytValue relies on Number implementation /** diff --git a/src/test/org/apache/commons/lang/mutable/MutableByteTest.java b/src/test/org/apache/commons/lang/mutable/MutableByteTest.java index 2310d11fc..59c35a544 100755 --- a/src/test/org/apache/commons/lang/mutable/MutableByteTest.java +++ b/src/test/org/apache/commons/lang/mutable/MutableByteTest.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2005 The Apache Software Foundation. + * Copyright 2002-2006 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. @@ -144,6 +144,50 @@ public class MutableByteTest extends TestCase { assertEquals(new Byte((byte) 123), new MutableByte((byte) 123).toByte()); } + public void testIncrement() { + MutableByte mutNum = new MutableByte((byte) 1); + mutNum.increment(); + + assertEquals(2, mutNum.intValue()); + assertEquals(2L, mutNum.longValue()); + } + + public void testDecrement() { + MutableByte mutNum = new MutableByte((byte) 1); + mutNum.decrement(); + + assertEquals(0, mutNum.intValue()); + assertEquals(0L, mutNum.longValue()); + } + + public void testAddValuePrimitive() { + MutableByte mutNum = new MutableByte((byte) 1); + mutNum.add((byte)1); + + assertEquals((byte) 2, mutNum.byteValue()); + } + + public void testAddValueObject() { + MutableByte mutNum = new MutableByte((byte) 1); + mutNum.add(new Integer(1)); + + assertEquals((byte) 2, mutNum.byteValue()); + } + + public void testSubtractValuePrimitive() { + MutableByte mutNum = new MutableByte((byte) 1); + mutNum.subtract((byte) 1); + + assertEquals((byte) 0, mutNum.byteValue()); + } + + public void testSubtractValueObject() { + MutableByte mutNum = new MutableByte((byte) 1); + mutNum.subtract(new Integer(1)); + + assertEquals((byte) 0, mutNum.byteValue()); + } + public void testToString() { assertEquals("0", new MutableByte((byte) 0).toString()); assertEquals("10", new MutableByte((byte) 10).toString()); diff --git a/src/test/org/apache/commons/lang/mutable/MutableDoubleTest.java b/src/test/org/apache/commons/lang/mutable/MutableDoubleTest.java index 1d51f6d0f..d39020ea8 100755 --- a/src/test/org/apache/commons/lang/mutable/MutableDoubleTest.java +++ b/src/test/org/apache/commons/lang/mutable/MutableDoubleTest.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2005 The Apache Software Foundation. + * Copyright 2002-2006 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. @@ -155,6 +155,50 @@ public class MutableDoubleTest extends TestCase { assertEquals(new Double(12.3d), new MutableDouble(12.3d).toDouble()); } + public void testIncrement() { + MutableDouble mutNum = new MutableDouble(1); + mutNum.increment(); + + assertEquals(2, mutNum.intValue()); + assertEquals(2L, mutNum.longValue()); + } + + public void testDecrement() { + MutableDouble mutNum = new MutableDouble(1); + mutNum.decrement(); + + assertEquals(0, mutNum.intValue()); + assertEquals(0L, mutNum.longValue()); + } + + public void testAddValuePrimitive() { + MutableDouble mutNum = new MutableDouble(1); + mutNum.add(1.1d); + + assertEquals(2.1d, mutNum.doubleValue(), 0.01d); + } + + public void testAddValueObject() { + MutableDouble mutNum = new MutableDouble(1); + mutNum.add(new Double(1.1d)); + + assertEquals(2.1d, mutNum.doubleValue(), 0.01d); + } + + public void testSubtractValuePrimitive() { + MutableDouble mutNum = new MutableDouble(1); + mutNum.subtract(0.9d); + + assertEquals(0.1d, mutNum.doubleValue(), 0.01d); + } + + public void testSubtractValueObject() { + MutableDouble mutNum = new MutableDouble(1); + mutNum.subtract(new Double(0.9d)); + + assertEquals(0.1d, mutNum.doubleValue(), 0.01d); + } + public void testToString() { assertEquals("0.0", new MutableDouble(0d).toString()); assertEquals("10.0", new MutableDouble(10d).toString()); diff --git a/src/test/org/apache/commons/lang/mutable/MutableFloatTest.java b/src/test/org/apache/commons/lang/mutable/MutableFloatTest.java index 25d59d544..e97eb9983 100755 --- a/src/test/org/apache/commons/lang/mutable/MutableFloatTest.java +++ b/src/test/org/apache/commons/lang/mutable/MutableFloatTest.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2005 The Apache Software Foundation. + * Copyright 2002-2006 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. @@ -155,6 +155,50 @@ public class MutableFloatTest extends TestCase { assertEquals(new Float(12.3f), new MutableFloat(12.3f).toFloat()); } + public void testIncrement() { + MutableFloat mutNum = new MutableFloat(1); + mutNum.increment(); + + assertEquals(2, mutNum.intValue()); + assertEquals(2L, mutNum.longValue()); + } + + public void testDecrement() { + MutableFloat mutNum = new MutableFloat(1); + mutNum.decrement(); + + assertEquals(0, mutNum.intValue()); + assertEquals(0L, mutNum.longValue()); + } + + public void testAddValuePrimitive() { + MutableFloat mutNum = new MutableFloat(1); + mutNum.add(1.1f); + + assertEquals(2.1f, mutNum.floatValue(), 0.01f); + } + + public void testAddValueObject() { + MutableFloat mutNum = new MutableFloat(1); + mutNum.add(new Float(1.1f)); + + assertEquals(2.1f, mutNum.floatValue(), 0.01f); + } + + public void testSubtractValuePrimitive() { + MutableFloat mutNum = new MutableFloat(1); + mutNum.subtract(0.9f); + + assertEquals(0.1f, mutNum.floatValue(), 0.01f); + } + + public void testSubtractValueObject() { + MutableFloat mutNum = new MutableFloat(1); + mutNum.subtract(new Float(0.9f)); + + assertEquals(0.1f, mutNum.floatValue(), 0.01f); + } + public void testToString() { assertEquals("0.0", new MutableFloat(0f).toString()); assertEquals("10.0", new MutableFloat(10f).toString()); diff --git a/src/test/org/apache/commons/lang/mutable/MutableIntTest.java b/src/test/org/apache/commons/lang/mutable/MutableIntTest.java index d0dcd7924..48ed0007a 100644 --- a/src/test/org/apache/commons/lang/mutable/MutableIntTest.java +++ b/src/test/org/apache/commons/lang/mutable/MutableIntTest.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2005 The Apache Software Foundation. + * Copyright 2002-2006 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. @@ -150,6 +150,54 @@ public class MutableIntTest extends TestCase { assertEquals(new Integer(123), new MutableInt(123).toInteger()); } + public void testIncrement() { + MutableInt mutNum = new MutableInt(1); + mutNum.increment(); + + assertEquals(2, mutNum.intValue()); + assertEquals(2L, mutNum.longValue()); + } + + public void testDecrement() { + MutableInt mutNum = new MutableInt(1); + mutNum.decrement(); + + assertEquals(0, mutNum.intValue()); + assertEquals(0L, mutNum.longValue()); + } + + public void testAddValuePrimitive() { + MutableInt mutNum = new MutableInt(1); + mutNum.add(1); + + assertEquals(2, mutNum.intValue()); + assertEquals(2L, mutNum.longValue()); + } + + public void testAddValueObject() { + MutableInt mutNum = new MutableInt(1); + mutNum.add(new Integer(1)); + + assertEquals(2, mutNum.intValue()); + assertEquals(2L, mutNum.longValue()); + } + + public void testSubtractValuePrimitive() { + MutableInt mutNum = new MutableInt(1); + mutNum.subtract(1); + + assertEquals(0, mutNum.intValue()); + assertEquals(0L, mutNum.longValue()); + } + + public void testSubtractValueObject() { + MutableInt mutNum = new MutableInt(1); + mutNum.subtract(new Integer(1)); + + assertEquals(0, mutNum.intValue()); + assertEquals(0L, mutNum.longValue()); + } + public void testToString() { assertEquals("0", new MutableInt(0).toString()); assertEquals("10", new MutableInt(10).toString()); diff --git a/src/test/org/apache/commons/lang/mutable/MutableLongTest.java b/src/test/org/apache/commons/lang/mutable/MutableLongTest.java index add179073..b5c64075f 100755 --- a/src/test/org/apache/commons/lang/mutable/MutableLongTest.java +++ b/src/test/org/apache/commons/lang/mutable/MutableLongTest.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2005 The Apache Software Foundation. + * Copyright 2002-2006 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. @@ -144,6 +144,54 @@ public class MutableLongTest extends TestCase { assertEquals(new Long(123L), new MutableLong(123L).toLong()); } + public void testIncrement() { + MutableLong mutNum = new MutableLong(1); + mutNum.increment(); + + assertEquals(2, mutNum.intValue()); + assertEquals(2L, mutNum.longValue()); + } + + public void testDecrement() { + MutableLong mutNum = new MutableLong(1); + mutNum.decrement(); + + assertEquals(0, mutNum.intValue()); + assertEquals(0L, mutNum.longValue()); + } + + public void testAddValuePrimitive() { + MutableLong mutNum = new MutableLong(1); + mutNum.add(1); + + assertEquals(2, mutNum.intValue()); + assertEquals(2L, mutNum.longValue()); + } + + public void testAddValueObject() { + MutableLong mutNum = new MutableLong(1); + mutNum.add(new Long(1)); + + assertEquals(2, mutNum.intValue()); + assertEquals(2L, mutNum.longValue()); + } + + public void testSubtractValuePrimitive() { + MutableLong mutNum = new MutableLong(1); + mutNum.subtract(1); + + assertEquals(0, mutNum.intValue()); + assertEquals(0L, mutNum.longValue()); + } + + public void testSubtractValueObject() { + MutableLong mutNum = new MutableLong(1); + mutNum.subtract(new Long(1)); + + assertEquals(0, mutNum.intValue()); + assertEquals(0L, mutNum.longValue()); + } + public void testToString() { assertEquals("0", new MutableLong(0).toString()); assertEquals("10", new MutableLong(10).toString()); diff --git a/src/test/org/apache/commons/lang/mutable/MutableShortTest.java b/src/test/org/apache/commons/lang/mutable/MutableShortTest.java index 0ad8951c1..2f880a7f2 100755 --- a/src/test/org/apache/commons/lang/mutable/MutableShortTest.java +++ b/src/test/org/apache/commons/lang/mutable/MutableShortTest.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2005 The Apache Software Foundation. + * Copyright 2002-2006 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. @@ -144,6 +144,50 @@ public class MutableShortTest extends TestCase { assertEquals(new Short((short) 123), new MutableShort((short) 123).toShort()); } + public void testIncrement() { + MutableShort mutNum = new MutableShort((short) 1); + mutNum.increment(); + + assertEquals(2, mutNum.intValue()); + assertEquals(2L, mutNum.longValue()); + } + + public void testDecrement() { + MutableShort mutNum = new MutableShort((short) 1); + mutNum.decrement(); + + assertEquals(0, mutNum.intValue()); + assertEquals(0L, mutNum.longValue()); + } + + public void testAddValuePrimitive() { + MutableShort mutNum = new MutableShort((short) 1); + mutNum.add((short) 1); + + assertEquals((short) 2, mutNum.shortValue()); + } + + public void testAddValueObject() { + MutableShort mutNum = new MutableShort((short) 1); + mutNum.add(new Short((short) 1)); + + assertEquals((short) 2, mutNum.shortValue()); + } + + public void testSubtractValuePrimitive() { + MutableShort mutNum = new MutableShort((short) 1); + mutNum.subtract((short) 1); + + assertEquals((short) 0, mutNum.shortValue()); + } + + public void testSubtractValueObject() { + MutableShort mutNum = new MutableShort((short) 1); + mutNum.subtract(new Short((short) 1)); + + assertEquals((short) 0, mutNum.shortValue()); + } + public void testToString() { assertEquals("0", new MutableShort((short) 0).toString()); assertEquals("10", new MutableShort((short) 10).toString());