LANG-1189 Add

getAndIncrement/getAndDecrement/getAndAdd/incrementAndGet/decrementAndGet/addAndGet
in Mutable* classes
This commit is contained in:
Sebb 2016-06-02 11:46:11 +01:00
parent 17d6f2163d
commit e474263669
13 changed files with 1069 additions and 0 deletions

View File

@ -15,6 +15,30 @@
See the License for the specific language governing permissions and
limitations under the License.
-->
<!--
This file is also used by the maven-changes-plugin to generate the release notes.
Useful ways of finding items to add to this file are:
1. Add items when you fix a bug or add a feature (this makes the
release process easy :-).
2. Do a JIRA search for tickets closed since the previous release.
3. Use the report generated by the maven-changelog-plugin to see all
SVN commits. TBA how to use this with SVN.
To generate the release notes from this file:
mvn changes:announcement-generate -Prelease-notes [-Dchanges.version=nnn]
then tweak the formatting if necessary
and commit
The <action> type attribute can be add,update,fix,remove.
-->
<document>
<properties>
<title>Apache Commons Lang Changes</title>
@ -22,6 +46,7 @@
<body>
<release version="3.5" date="tba" description="tba">
<action issue="LANG-1189" type="add" dev="sebb" due-to="haiyang li / Matthew Bartenschlag ">Add getAndIncrement/getAndDecrement/getAndAdd/incrementAndGet/decrementAndGet/addAndGet in Mutable* classes</action>
<action issue="LANG-1240" type="update" dev="pschumacher" due-to="zhanhb">Optimize BitField constructor implementation</action>
<action issue="LANG-1206" type="update" dev="pschumacher" due-to="Mohammed Alfallaj">Improve CharSetUtils.squeeze() performance</action>
<action issue="LANG-1225" type="add" dev="pschumacher" due-to="Caleb Cushing">Add RandomStringUtils#randomGraph and #randomPrint which match corresponding regular expression class</action>

View File

@ -119,6 +119,29 @@ public void increment() {
value++;
}
/**
* Increments this instance's value by 1; this method returns the value associated with the instance
* immediately prior to the increment operation. This method is not thread safe.
*
* @return the value associated with the instance before it was incremented
*/
public byte getAndIncrement() {
byte last = value;
value++;
return last;
}
/**
* Increments this instance's value by 1; this method returns the value associated with the instance
* immediately after the increment operation. This method is not thread safe.
*
* @return the value associated with the instance after it is incremented
*/
public byte incrementAndGet() {
value++;
return value;
}
/**
* Decrements the value.
*
@ -128,6 +151,29 @@ public void decrement() {
value--;
}
/**
* Decrements this instance's value by 1; this method returns the value associated with the instance
* immediately prior to the decrement operation. This method is not thread safe.
*
* @return the value associated with the instance before it was decremented
*/
public byte getAndDecrement() {
byte last = value;
value--;
return last;
}
/**
* Decrements this instance's value by 1; this method returns the value associated with the instance
* immediately after the decrement operation. This method is not thread safe.
*
* @return the value associated with the instance after it is decremented
*/
public byte decrementAndGet() {
value--;
return value;
}
//-----------------------------------------------------------------------
/**
* Adds a value to the value of this instance.
@ -171,6 +217,58 @@ public void subtract(final Number operand) {
this.value -= operand.byteValue();
}
/**
* Increments this instance's value by {@code operand}; this method returns the value associated with the instance
* immediately after the addition operation. This method is not thread safe.
*
* @param operand the quantity to add, not null
* @return the value associated with this instance after adding the operand
*/
public byte addAndGet(final byte operand) {
this.value += operand;
return value;
}
/**
* Increments this instance's value by {@code operand}; this method returns the value associated with the instance
* immediately after the addition operation. This method is not thread safe.
*
* @param operand the quantity to add, not null
* @throws NullPointerException if {@code operand} is null
* @return the value associated with this instance after adding the operand
*/
public byte addAndGet(final Number operand) {
this.value += operand.byteValue();
return value;
}
/**
* Increments this instance's value by {@code operand}; this method returns the value associated with the instance
* immediately prior to the addition operation. This method is not thread safe.
*
* @param operand the quantity to add, not null
* @return the value associated with this instance immediately before the operand was added
*/
public byte getAndAdd(final byte operand) {
byte last = value;
this.value += operand;
return last;
}
/**
* Increments this instance's value by {@code operand}; this method returns the value associated with the instance
* immediately prior to the addition operation. This method is not thread safe.
*
* @param operand the quantity to add, not null
* @throws NullPointerException if {@code operand} is null
* @return the value associated with this instance immediately before the operand was added
*/
public byte getAndAdd(final Number operand) {
byte last = value;
this.value += operand.byteValue();
return last;
}
//-----------------------------------------------------------------------
// shortValue relies on Number implementation
/**

View File

@ -136,6 +136,29 @@ public void increment() {
value++;
}
/**
* Increments this instance's value by 1; this method returns the value associated with the instance
* immediately prior to the increment operation. This method is not thread safe.
*
* @return the value associated with the instance before it was incremented
*/
public double getAndIncrement() {
double last = value;
value++;
return last;
}
/**
* Increments this instance's value by 1; this method returns the value associated with the instance
* immediately after the increment operation. This method is not thread safe.
*
* @return the value associated with the instance after it is incremented
*/
public double incrementAndGet() {
value++;
return value;
}
/**
* Decrements the value.
*
@ -145,6 +168,29 @@ public void decrement() {
value--;
}
/**
* Decrements this instance's value by 1; this method returns the value associated with the instance
* immediately prior to the decrement operation. This method is not thread safe.
*
* @return the value associated with the instance before it was decremented
*/
public double getAndDecrement() {
double last = value;
value--;
return last;
}
/**
* Decrements this instance's value by 1; this method returns the value associated with the instance
* immediately after the decrement operation. This method is not thread safe.
*
* @return the value associated with the instance after it is decremented
*/
public double decrementAndGet() {
value--;
return value;
}
//-----------------------------------------------------------------------
/**
* Adds a value to the value of this instance.
@ -188,6 +234,58 @@ public void subtract(final Number operand) {
this.value -= operand.doubleValue();
}
/**
* Increments this instance's value by {@code operand}; this method returns the value associated with the instance
* immediately after the addition operation. This method is not thread safe.
*
* @param operand the quantity to add, not null
* @return the value associated with this instance after adding the operand
*/
public double addAndGet(final double operand) {
this.value += operand;
return value;
}
/**
* Increments this instance's value by {@code operand}; this method returns the value associated with the instance
* immediately after the addition operation. This method is not thread safe.
*
* @param operand the quantity to add, not null
* @throws NullPointerException if {@code operand} is null
* @return the value associated with this instance after adding the operand
*/
public double addAndGet(final Number operand) {
this.value += operand.doubleValue();
return value;
}
/**
* Increments this instance's value by {@code operand}; this method returns the value associated with the instance
* immediately prior to the addition operation. This method is not thread safe.
*
* @param operand the quantity to add, not null
* @return the value associated with this instance immediately before the operand was added
*/
public double getAndAdd(final double operand) {
double last = value;
this.value += operand;
return last;
}
/**
* Increments this instance's value by {@code operand}; this method returns the value associated with the instance
* immediately prior to the addition operation. This method is not thread safe.
*
* @param operand the quantity to add, not null
* @throws NullPointerException if {@code operand} is null
* @return the value associated with this instance immediately before the operand was added
*/
public double getAndAdd(final Number operand) {
double last = value;
this.value += operand.doubleValue();
return last;
}
//-----------------------------------------------------------------------
// shortValue and byteValue rely on Number implementation
/**

View File

@ -136,6 +136,29 @@ public void increment() {
value++;
}
/**
* Increments this instance's value by 1; this method returns the value associated with the instance
* immediately prior to the increment operation. This method is not thread safe.
*
* @return the value associated with the instance before it was incremented
*/
public float getAndIncrement() {
float last = value;
value++;
return last;
}
/**
* Increments this instance's value by 1; this method returns the value associated with the instance
* immediately after the increment operation. This method is not thread safe.
*
* @return the value associated with the instance after it is incremented
*/
public float incrementAndGet() {
value++;
return value;
}
/**
* Decrements the value.
*
@ -145,6 +168,29 @@ public void decrement() {
value--;
}
/**
* Decrements this instance's value by 1; this method returns the value associated with the instance
* immediately prior to the decrement operation. This method is not thread safe.
*
* @return the value associated with the instance before it was decremented
*/
public float getAndDecrement() {
float last = value;
value--;
return last;
}
/**
* Decrements this instance's value by 1; this method returns the value associated with the instance
* immediately after the decrement operation. This method is not thread safe.
*
* @return the value associated with the instance after it is decremented
*/
public float decrementAndGet() {
value--;
return value;
}
//-----------------------------------------------------------------------
/**
* Adds a value to the value of this instance.
@ -188,6 +234,58 @@ public void subtract(final Number operand) {
this.value -= operand.floatValue();
}
/**
* Increments this instance's value by {@code operand}; this method returns the value associated with the instance
* immediately after the addition operation. This method is not thread safe.
*
* @param operand the quantity to add, not null
* @return the value associated with this instance after adding the operand
*/
public float addAndGet(final float operand) {
this.value += operand;
return value;
}
/**
* Increments this instance's value by {@code operand}; this method returns the value associated with the instance
* immediately after the addition operation. This method is not thread safe.
*
* @param operand the quantity to add, not null
* @throws NullPointerException if {@code operand} is null
* @return the value associated with this instance after adding the operand
*/
public float addAndGet(final Number operand) {
this.value += operand.floatValue();
return value;
}
/**
* Increments this instance's value by {@code operand}; this method returns the value associated with the instance
* immediately prior to the addition operation. This method is not thread safe.
*
* @param operand the quantity to add, not null
* @return the value associated with this instance immediately before the operand was added
*/
public float getAndAdd(final float operand) {
float last = value;
this.value += operand;
return last;
}
/**
* Increments this instance's value by {@code operand}; this method returns the value associated with the instance
* immediately prior to the addition operation. This method is not thread safe.
*
* @param operand the quantity to add, not null
* @throws NullPointerException if {@code operand} is null
* @return the value associated with this instance immediately before the operand was added
*/
public float getAndAdd(final Number operand) {
float last = value;
this.value += operand.floatValue();
return last;
}
//-----------------------------------------------------------------------
// shortValue and byteValue rely on Number implementation
/**

View File

@ -119,6 +119,29 @@ public void increment() {
value++;
}
/**
* Increments this instance's value by 1; this method returns the value associated with the instance
* immediately prior to the increment operation. This method is not thread safe.
*
* @return the value associated with the instance before it was incremented
*/
public int getAndIncrement() {
int last = value;
value++;
return last;
}
/**
* Increments this instance's value by 1; this method returns the value associated with the instance
* immediately after the increment operation. This method is not thread safe.
*
* @return the value associated with the instance after it is incremented
*/
public int incrementAndGet() {
value++;
return value;
}
/**
* Decrements the value.
*
@ -128,6 +151,29 @@ public void decrement() {
value--;
}
/**
* Decrements this instance's value by 1; this method returns the value associated with the instance
* immediately prior to the decrement operation. This method is not thread safe.
*
* @return the value associated with the instance before it was decremented
*/
public int getAndDecrement() {
int last = value;
value--;
return last;
}
/**
* Decrements this instance's value by 1; this method returns the value associated with the instance
* immediately after the decrement operation. This method is not thread safe.
*
* @return the value associated with the instance after it is decremented
*/
public int decrementAndGet() {
value--;
return value;
}
//-----------------------------------------------------------------------
/**
* Adds a value to the value of this instance.
@ -171,6 +217,58 @@ public void subtract(final Number operand) {
this.value -= operand.intValue();
}
/**
* Increments this instance's value by {@code operand}; this method returns the value associated with the instance
* immediately after the addition operation. This method is not thread safe.
*
* @param operand the quantity to add, not null
* @return the value associated with this instance after adding the operand
*/
public int addAndGet(final int operand) {
this.value += operand;
return value;
}
/**
* Increments this instance's value by {@code operand}; this method returns the value associated with the instance
* immediately after the addition operation. This method is not thread safe.
*
* @param operand the quantity to add, not null
* @throws NullPointerException if {@code operand} is null
* @return the value associated with this instance after adding the operand
*/
public int addAndGet(final Number operand) {
this.value += operand.intValue();
return value;
}
/**
* Increments this instance's value by {@code operand}; this method returns the value associated with the instance
* immediately prior to the addition operation. This method is not thread safe.
*
* @param operand the quantity to add, not null
* @return the value associated with this instance immediately before the operand was added
*/
public int getAndAdd(final int operand) {
int last = value;
this.value += operand;
return last;
}
/**
* Increments this instance's value by {@code operand}; this method returns the value associated with the instance
* immediately prior to the addition operation. This method is not thread safe.
*
* @param operand the quantity to add, not null
* @throws NullPointerException if {@code operand} is null
* @return the value associated with this instance immediately before the operand was added
*/
public int getAndAdd(final Number operand) {
int last = value;
this.value += operand.intValue();
return last;
}
//-----------------------------------------------------------------------
// shortValue and byteValue rely on Number implementation
/**

View File

@ -119,6 +119,29 @@ public void increment() {
value++;
}
/**
* Increments this instance's value by 1; this method returns the value associated with the instance
* immediately prior to the increment operation. This method is not thread safe.
*
* @return the value associated with the instance before it was incremented
*/
public long getAndIncrement() {
long last = value;
value++;
return last;
}
/**
* Increments this instance's value by 1; this method returns the value associated with the instance
* immediately after the increment operation. This method is not thread safe.
*
* @return the value associated with the instance after it is incremented
*/
public long incrementAndGet() {
value++;
return value;
}
/**
* Decrements the value.
*
@ -128,6 +151,29 @@ public void decrement() {
value--;
}
/**
* Decrements this instance's value by 1; this method returns the value associated with the instance
* immediately prior to the decrement operation. This method is not thread safe.
*
* @return the value associated with the instance before it was decremented
*/
public long getAndDecrement() {
long last = value;
value--;
return last;
}
/**
* Decrements this instance's value by 1; this method returns the value associated with the instance
* immediately after the decrement operation. This method is not thread safe.
*
* @return the value associated with the instance after it is decremented
*/
public long decrementAndGet() {
value--;
return value;
}
//-----------------------------------------------------------------------
/**
* Adds a value to the value of this instance.
@ -171,6 +217,58 @@ public void subtract(final Number operand) {
this.value -= operand.longValue();
}
/**
* Increments this instance's value by {@code operand}; this method returns the value associated with the instance
* immediately after the addition operation. This method is not thread safe.
*
* @param operand the quantity to add, not null
* @return the value associated with this instance after adding the operand
*/
public long addAndGet(final long operand) {
this.value += operand;
return value;
}
/**
* Increments this instance's value by {@code operand}; this method returns the value associated with the instance
* immediately after the addition operation. This method is not thread safe.
*
* @param operand the quantity to add, not null
* @throws NullPointerException if {@code operand} is null
* @return the value associated with this instance after adding the operand
*/
public long addAndGet(final Number operand) {
this.value += operand.longValue();
return value;
}
/**
* Increments this instance's value by {@code operand}; this method returns the value associated with the instance
* immediately prior to the addition operation. This method is not thread safe.
*
* @param operand the quantity to add, not null
* @return the value associated with this instance immediately before the operand was added
*/
public long getAndAdd(final long operand) {
long last = value;
this.value += operand;
return last;
}
/**
* Increments this instance's value by {@code operand}; this method returns the value associated with the instance
* immediately prior to the addition operation. This method is not thread safe.
*
* @param operand the quantity to add, not null
* @throws NullPointerException if {@code operand} is null
* @return the value associated with this instance immediately before the operand was added
*/
public long getAndAdd(final Number operand) {
long last = value;
this.value += operand.longValue();
return last;
}
//-----------------------------------------------------------------------
// shortValue and byteValue rely on Number implementation
/**

View File

@ -119,6 +119,29 @@ public void increment() {
value++;
}
/**
* Increments this instance's value by 1; this method returns the value associated with the instance
* immediately prior to the increment operation. This method is not thread safe.
*
* @return the value associated with the instance before it was incremented
*/
public short getAndIncrement() {
short last = value;
value++;
return last;
}
/**
* Increments this instance's value by 1; this method returns the value associated with the instance
* immediately after the increment operation. This method is not thread safe.
*
* @return the value associated with the instance after it is incremented
*/
public short incrementAndGet() {
value++;
return value;
}
/**
* Decrements the value.
*
@ -128,6 +151,29 @@ public void decrement() {
value--;
}
/**
* Decrements this instance's value by 1; this method returns the value associated with the instance
* immediately prior to the decrement operation. This method is not thread safe.
*
* @return the value associated with the instance before it was decremented
*/
public short getAndDecrement() {
short last = value;
value--;
return last;
}
/**
* Decrements this instance's value by 1; this method returns the value associated with the instance
* immediately after the decrement operation. This method is not thread safe.
*
* @return the value associated with the instance after it is decremented
*/
public short decrementAndGet() {
value--;
return value;
}
//-----------------------------------------------------------------------
/**
* Adds a value to the value of this instance.
@ -171,6 +217,58 @@ public void subtract(final Number operand) {
this.value -= operand.shortValue();
}
/**
* Increments this instance's value by {@code operand}; this method returns the value associated with the instance
* immediately after the addition operation. This method is not thread safe.
*
* @param operand the quantity to add, not null
* @return the value associated with this instance after adding the operand
*/
public short addAndGet(final short operand) {
this.value += operand;
return value;
}
/**
* Increments this instance's value by {@code operand}; this method returns the value associated with the instance
* immediately after the addition operation. This method is not thread safe.
*
* @param operand the quantity to add, not null
* @throws NullPointerException if {@code operand} is null
* @return the value associated with this instance after adding the operand
*/
public short addAndGet(final Number operand) {
this.value += operand.shortValue();
return value;
}
/**
* Increments this instance's value by {@code operand}; this method returns the value associated with the instance
* immediately prior to the addition operation. This method is not thread safe.
*
* @param operand the quantity to add, not null
* @return the value associated with this instance immediately before the operand was added
*/
public short getAndAdd(final short operand) {
short last = value;
this.value += operand;
return last;
}
/**
* Increments this instance's value by {@code operand}; this method returns the value associated with the instance
* immediately prior to the addition operation. This method is not thread safe.
*
* @param operand the quantity to add, not null
* @throws NullPointerException if {@code operand} is null
* @return the value associated with this instance immediately before the operand was added
*/
public short getAndAdd(final Number operand) {
short last = value;
this.value += operand.shortValue();
return last;
}
//-----------------------------------------------------------------------
// byteValue relies on Number implementation
/**

View File

@ -142,6 +142,26 @@ public void testIncrement() {
assertEquals(2L, mutNum.longValue());
}
@Test
public void testIncrementAndGet() {
final MutableByte mutNum = new MutableByte((byte) 1);
byte result = mutNum.incrementAndGet();
assertEquals(2, result);
assertEquals(2, mutNum.intValue());
assertEquals(2L, mutNum.longValue());
}
@Test
public void testGetAndIncrement() {
final MutableByte mutNum = new MutableByte((byte) 1);
byte result = mutNum.getAndIncrement();
assertEquals(1, result);
assertEquals(2, mutNum.intValue());
assertEquals(2L, mutNum.longValue());
}
@Test
public void testDecrement() {
final MutableByte mutNum = new MutableByte((byte) 1);
@ -151,6 +171,26 @@ public void testDecrement() {
assertEquals(0L, mutNum.longValue());
}
@Test
public void testDecrementAndGet() {
final MutableByte mutNum = new MutableByte((byte) 1);
byte result = mutNum.decrementAndGet();
assertEquals(0, result);
assertEquals(0, mutNum.intValue());
assertEquals(0L, mutNum.longValue());
}
@Test
public void testGetAndDecrement() {
final MutableByte mutNum = new MutableByte((byte) 1);
byte result = mutNum.getAndDecrement();
assertEquals(1, result);
assertEquals(0, mutNum.intValue());
assertEquals(0L, mutNum.longValue());
}
@Test
public void testAddValuePrimitive() {
final MutableByte mutNum = new MutableByte((byte) 1);
@ -167,6 +207,42 @@ public void testAddValueObject() {
assertEquals((byte) 2, mutNum.byteValue());
}
@Test
public void testGetAndAddValuePrimitive() {
final MutableByte mutableByte = new MutableByte((byte)0);
byte result = mutableByte.getAndAdd((byte) 1);
assertEquals((byte) 0, result);
assertEquals((byte) 1, mutableByte.byteValue());
}
@Test
public void testGetAndAddValueObject() {
final MutableByte mutableByte = new MutableByte((byte)0);
byte result = mutableByte.getAndAdd(Byte.valueOf((byte) 1));
assertEquals((byte) 0, result);
assertEquals((byte) 1, mutableByte.byteValue());
}
@Test
public void testAddAndGetValuePrimitive() {
final MutableByte mutableByte = new MutableByte((byte)0);
byte result = mutableByte.addAndGet((byte) 1);
assertEquals((byte) 1, result);
assertEquals((byte) 1, mutableByte.byteValue());
}
@Test
public void testAddAndGetValueObject() {
final MutableByte mutableByte = new MutableByte((byte)0);
byte result = mutableByte.addAndGet(Byte.valueOf((byte) 1));
assertEquals((byte) 1, result);
assertEquals((byte) 1, mutableByte.byteValue());
}
@Test
public void testSubtractValuePrimitive() {
final MutableByte mutNum = new MutableByte((byte) 1);

View File

@ -154,6 +154,26 @@ public void testIncrement() {
assertEquals(2L, mutNum.longValue());
}
@Test
public void testIncrementAndGet() {
final MutableDouble mutNum = new MutableDouble(1d);
double result = mutNum.incrementAndGet();
assertEquals(2d, result, 0.01d);
assertEquals(2, mutNum.intValue());
assertEquals(2L, mutNum.longValue());
}
@Test
public void testGetAndIncrement() {
final MutableDouble mutNum = new MutableDouble(1d);
double result = mutNum.getAndIncrement();
assertEquals(1d, result, 0.01d);
assertEquals(2, mutNum.intValue());
assertEquals(2L, mutNum.longValue());
}
@Test
public void testDecrement() {
final MutableDouble mutNum = new MutableDouble(1);
@ -163,6 +183,26 @@ public void testDecrement() {
assertEquals(0L, mutNum.longValue());
}
@Test
public void testDecrementAndGet() {
final MutableDouble mutNum = new MutableDouble(1d);
double result = mutNum.decrementAndGet();
assertEquals(0d, result, 0.01d);
assertEquals(0, mutNum.intValue());
assertEquals(0L, mutNum.longValue());
}
@Test
public void testGetAndDecrement() {
final MutableDouble mutNum = new MutableDouble(1d);
double result = mutNum.getAndDecrement();
assertEquals(1d, result, 0.01d);
assertEquals(0, mutNum.intValue());
assertEquals(0L, mutNum.longValue());
}
@Test
public void testAddValuePrimitive() {
final MutableDouble mutNum = new MutableDouble(1);
@ -179,6 +219,42 @@ public void testAddValueObject() {
assertEquals(2.1d, mutNum.doubleValue(), 0.01d);
}
@Test
public void testGetAndAddValuePrimitive() {
final MutableDouble mutableDouble = new MutableDouble(0.5d);
double result = mutableDouble.getAndAdd(1d);
assertEquals(0.5d, result, 0.01d);
assertEquals(1.5d, mutableDouble.doubleValue(), 0.01d);
}
@Test
public void testGetAndAddValueObject() {
final MutableDouble mutableDouble = new MutableDouble(0.5d);
double result = mutableDouble.getAndAdd(Double.valueOf(2d));
assertEquals(0.5d, result, 0.01d);
assertEquals(2.5d, mutableDouble.doubleValue(), 0.01d);
}
@Test
public void testAddAndGetValuePrimitive() {
final MutableDouble mutableDouble = new MutableDouble(10.5d);
double result = mutableDouble.addAndGet(-0.5d);
assertEquals(10d, result, 0.01d);
assertEquals(10d, mutableDouble.doubleValue(), 0.01d);
}
@Test
public void testAddAndGetValueObject() {
final MutableDouble mutableDouble = new MutableDouble(7.5d);
double result = mutableDouble.addAndGet(Double.valueOf(-2.5d));
assertEquals(5d, result, 0.01d);
assertEquals(5d, mutableDouble.doubleValue(), 0.01d);
}
@Test
public void testSubtractValuePrimitive() {
final MutableDouble mutNum = new MutableDouble(1);

View File

@ -154,6 +154,26 @@ public void testIncrement() {
assertEquals(2L, mutNum.longValue());
}
@Test
public void testIncrementAndGet() {
final MutableFloat mutNum = new MutableFloat(1f);
float result = mutNum.incrementAndGet();
assertEquals(2f, result, 0.01f);
assertEquals(2, mutNum.intValue());
assertEquals(2L, mutNum.longValue());
}
@Test
public void testGetAndIncrement() {
final MutableFloat mutNum = new MutableFloat(1f);
float result = mutNum.getAndIncrement();
assertEquals(1f, result, 0.01f);
assertEquals(2, mutNum.intValue());
assertEquals(2L, mutNum.longValue());
}
@Test
public void testDecrement() {
final MutableFloat mutNum = new MutableFloat(1);
@ -163,6 +183,26 @@ public void testDecrement() {
assertEquals(0L, mutNum.longValue());
}
@Test
public void testDecrementAndGet() {
final MutableFloat mutNum = new MutableFloat(1f);
float result = mutNum.decrementAndGet();
assertEquals(0f, result, 0.01f);
assertEquals(0, mutNum.intValue());
assertEquals(0L, mutNum.longValue());
}
@Test
public void testGetAndDecrement() {
final MutableFloat mutNum = new MutableFloat(1f);
float result = mutNum.getAndDecrement();
assertEquals(1f, result, 0.01f);
assertEquals(0, mutNum.intValue());
assertEquals(0L, mutNum.longValue());
}
@Test
public void testAddValuePrimitive() {
final MutableFloat mutNum = new MutableFloat(1);
@ -179,6 +219,42 @@ public void testAddValueObject() {
assertEquals(2.1f, mutNum.floatValue(), 0.01f);
}
@Test
public void testGetAndAddValuePrimitive() {
final MutableFloat mutableFloat = new MutableFloat(1.25f);
float result = mutableFloat.getAndAdd(0.75f);
assertEquals(1.25f, result, 0.01f);
assertEquals(2f, mutableFloat.floatValue(), 0.01f);
}
@Test
public void testGetAndAddValueObject() {
final MutableFloat mutableFloat = new MutableFloat(7.75f);
float result = mutableFloat.getAndAdd(Float.valueOf(2.25f));
assertEquals(7.75f, result, 0.01f);
assertEquals(10f, mutableFloat.floatValue(), 0.01f);
}
@Test
public void testAddAndGetValuePrimitive() {
final MutableFloat mutableFloat = new MutableFloat(0.5f);
float result = mutableFloat.addAndGet(1f);
assertEquals(1.5f, result, 0.01f);
assertEquals(1.5f, mutableFloat.floatValue(), 0.01f);
}
@Test
public void testAddAndGetValueObject() {
final MutableFloat mutableFloat = new MutableFloat(5f);
float result = mutableFloat.addAndGet(Float.valueOf(2.5f));
assertEquals(7.5f, result, 0.01f);
assertEquals(7.5f, mutableFloat.floatValue(), 0.01f);
}
@Test
public void testSubtractValuePrimitive() {
final MutableFloat mutNum = new MutableFloat(1);

View File

@ -148,6 +148,26 @@ public void testIncrement() {
assertEquals(2L, mutNum.longValue());
}
@Test
public void testIncrementAndGet() {
final MutableInt mutNum = new MutableInt((int) 1);
int result = mutNum.incrementAndGet();
assertEquals(2, result);
assertEquals(2, mutNum.intValue());
assertEquals(2L, mutNum.longValue());
}
@Test
public void testGetAndIncrement() {
final MutableInt mutNum = new MutableInt((int) 1);
int result = mutNum.getAndIncrement();
assertEquals(1, result);
assertEquals(2, mutNum.intValue());
assertEquals(2L, mutNum.longValue());
}
@Test
public void testDecrement() {
final MutableInt mutNum = new MutableInt(1);
@ -157,6 +177,26 @@ public void testDecrement() {
assertEquals(0L, mutNum.longValue());
}
@Test
public void testDecrementAndGet() {
final MutableInt mutNum = new MutableInt((int) 1);
int result = mutNum.decrementAndGet();
assertEquals(0, result);
assertEquals(0, mutNum.intValue());
assertEquals(0L, mutNum.longValue());
}
@Test
public void testGetAndDecrement() {
final MutableInt mutNum = new MutableInt((int) 1);
int result = mutNum.getAndDecrement();
assertEquals(1, result);
assertEquals(0, mutNum.intValue());
assertEquals(0L, mutNum.longValue());
}
@Test
public void testAddValuePrimitive() {
final MutableInt mutNum = new MutableInt(1);
@ -175,6 +215,42 @@ public void testAddValueObject() {
assertEquals(2L, mutNum.longValue());
}
@Test
public void testGetAndAddValuePrimitive() {
final MutableInt mutableInteger = new MutableInt((int)0);
int result = mutableInteger.getAndAdd((int) 1);
assertEquals((int) 0, result);
assertEquals((int) 1, mutableInteger.intValue());
}
@Test
public void testGetAndAddValueObject() {
final MutableInt mutableInteger = new MutableInt((int)0);
int result = mutableInteger.getAndAdd(Integer.valueOf((int) 1));
assertEquals((int) 0, result);
assertEquals((int) 1, mutableInteger.intValue());
}
@Test
public void testAddAndGetValuePrimitive() {
final MutableInt mutableInteger = new MutableInt((int)0);
int result = mutableInteger.addAndGet((int) 1);
assertEquals((int) 1, result);
assertEquals((int) 1, mutableInteger.intValue());
}
@Test
public void testAddAndGetValueObject() {
final MutableInt mutableInteger = new MutableInt((int)0);
int result = mutableInteger.addAndGet(Integer.valueOf((int) 1));
assertEquals((int) 1, result);
assertEquals((int) 1, mutableInteger.intValue());
}
@Test
public void testSubtractValuePrimitive() {
final MutableInt mutNum = new MutableInt(1);

View File

@ -142,6 +142,26 @@ public void testIncrement() {
assertEquals(2L, mutNum.longValue());
}
@Test
public void testIncrementAndGet() {
final MutableLong mutNum = new MutableLong((long) 1);
long result = mutNum.incrementAndGet();
assertEquals(2, result);
assertEquals(2, mutNum.intValue());
assertEquals(2L, mutNum.longValue());
}
@Test
public void testGetAndIncrement() {
final MutableLong mutNum = new MutableLong((long) 1);
long result = mutNum.getAndIncrement();
assertEquals(1, result);
assertEquals(2, mutNum.intValue());
assertEquals(2L, mutNum.longValue());
}
@Test
public void testDecrement() {
final MutableLong mutNum = new MutableLong(1);
@ -151,6 +171,26 @@ public void testDecrement() {
assertEquals(0L, mutNum.longValue());
}
@Test
public void testDecrementAndGet() {
final MutableLong mutNum = new MutableLong((long) 1);
long result = mutNum.decrementAndGet();
assertEquals(0, result);
assertEquals(0, mutNum.intValue());
assertEquals(0L, mutNum.longValue());
}
@Test
public void testGetAndDecrement() {
final MutableLong mutNum = new MutableLong((long) 1);
long result = mutNum.getAndDecrement();
assertEquals(1, result);
assertEquals(0, mutNum.intValue());
assertEquals(0L, mutNum.longValue());
}
@Test
public void testAddValuePrimitive() {
final MutableLong mutNum = new MutableLong(1);
@ -169,6 +209,42 @@ public void testAddValueObject() {
assertEquals(2L, mutNum.longValue());
}
@Test
public void testGetAndAddValuePrimitive() {
final MutableLong mutableLong = new MutableLong((long)0);
long result = mutableLong.getAndAdd((long) 1);
assertEquals((long) 0, result);
assertEquals((long) 1, mutableLong.longValue());
}
@Test
public void testGetAndAddValueObject() {
final MutableLong mutableLong = new MutableLong((long)0);
long result = mutableLong.getAndAdd(Long.valueOf((long) 1));
assertEquals((long) 0, result);
assertEquals((long) 1, mutableLong.longValue());
}
@Test
public void testAddAndGetValuePrimitive() {
final MutableLong mutableLong = new MutableLong((long)0);
long result = mutableLong.addAndGet((long) 1);
assertEquals((long) 1, result);
assertEquals((long) 1, mutableLong.longValue());
}
@Test
public void testAddAndGetValueObject() {
final MutableLong mutableLong = new MutableLong((long)0);
long result = mutableLong.addAndGet(Long.valueOf((long) 1));
assertEquals((long) 1, result);
assertEquals((long) 1, mutableLong.longValue());
}
@Test
public void testSubtractValuePrimitive() {
final MutableLong mutNum = new MutableLong(1);

View File

@ -137,6 +137,26 @@ public void testIncrement() {
assertEquals(2L, mutNum.longValue());
}
@Test
public void testIncrementAndGet() {
final MutableShort mutNum = new MutableShort((short) 1);
short result = mutNum.incrementAndGet();
assertEquals(2, result);
assertEquals(2, mutNum.intValue());
assertEquals(2L, mutNum.longValue());
}
@Test
public void testGetAndIncrement() {
final MutableShort mutNum = new MutableShort((short) 1);
short result = mutNum.getAndIncrement();
assertEquals(1, result);
assertEquals(2, mutNum.intValue());
assertEquals(2L, mutNum.longValue());
}
@Test
public void testDecrement() {
final MutableShort mutNum = new MutableShort((short) 1);
@ -146,6 +166,26 @@ public void testDecrement() {
assertEquals(0L, mutNum.longValue());
}
@Test
public void testDecrementAndGet() {
final MutableShort mutNum = new MutableShort((short) 1);
short result = mutNum.decrementAndGet();
assertEquals(0, result);
assertEquals(0, mutNum.intValue());
assertEquals(0L, mutNum.longValue());
}
@Test
public void testGetAndDecrement() {
final MutableShort mutNum = new MutableShort((short) 1);
short result = mutNum.getAndDecrement();
assertEquals(1, result);
assertEquals(0, mutNum.intValue());
assertEquals(0L, mutNum.longValue());
}
@Test
public void testAddValuePrimitive() {
final MutableShort mutNum = new MutableShort((short) 1);
@ -162,6 +202,42 @@ public void testAddValueObject() {
assertEquals((short) 2, mutNum.shortValue());
}
@Test
public void testGetAndAddValuePrimitive() {
final MutableShort mutableShort = new MutableShort((short)0);
short result = mutableShort.getAndAdd((short) 1);
assertEquals((short) 0, result);
assertEquals((short) 1, mutableShort.shortValue());
}
@Test
public void testGetAndAddValueObject() {
final MutableShort mutableShort = new MutableShort((short)0);
short result = mutableShort.getAndAdd(Short.valueOf((short) 1));
assertEquals((short) 0, result);
assertEquals((short) 1, mutableShort.shortValue());
}
@Test
public void testAddAndGetValuePrimitive() {
final MutableShort mutableShort = new MutableShort((short) 0);
short result = mutableShort.addAndGet((short) 1);
assertEquals((short) 1, result);
assertEquals((short) 1, mutableShort.shortValue());
}
@Test
public void testAddAndGetValueObject() {
final MutableShort mutableShort = new MutableShort((short) 0);
short result = mutableShort.addAndGet(Short.valueOf((short) 1));
assertEquals((short) 1, result);
assertEquals((short) 1, mutableShort.shortValue());
}
@Test
public void testSubtractValuePrimitive() {
final MutableShort mutNum = new MutableShort((short) 1);