aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/java/com/jogamp/common/util/Bitfield.java2
-rw-r--r--src/java/jogamp/common/util/Int32ArrayBitfield.java14
-rw-r--r--src/java/jogamp/common/util/Int32Bitfield.java14
-rw-r--r--src/java/jogamp/common/util/SyncedBitfield.java4
-rw-r--r--src/junit/com/jogamp/common/util/TestBitfield00.java8
5 files changed, 27 insertions, 15 deletions
diff --git a/src/java/com/jogamp/common/util/Bitfield.java b/src/java/com/jogamp/common/util/Bitfield.java
index d7ada5a..4b2b9d5 100644
--- a/src/java/com/jogamp/common/util/Bitfield.java
+++ b/src/java/com/jogamp/common/util/Bitfield.java
@@ -173,7 +173,7 @@ public interface Bitfield {
* @param bitnum bit number, restricted to [0..{@link #size()}-1].
* @throws IndexOutOfBoundsException if {@code bitnum} is out of bounds
*/
- void put(final int bitnum, final boolean bit) throws IndexOutOfBoundsException;
+ boolean put(final int bitnum, final boolean bit) throws IndexOutOfBoundsException;
/**
* Set the bit at position <code>bitnum</code> according to <code>bit</code>.
diff --git a/src/java/jogamp/common/util/Int32ArrayBitfield.java b/src/java/jogamp/common/util/Int32ArrayBitfield.java
index 3dcb9ae..5bc95eb 100644
--- a/src/java/jogamp/common/util/Int32ArrayBitfield.java
+++ b/src/java/jogamp/common/util/Int32ArrayBitfield.java
@@ -142,16 +142,20 @@ public class Int32ArrayBitfield implements Bitfield {
}
@Override
- public final void put(final int bitnum, final boolean bit) throws IndexOutOfBoundsException {
+ public final boolean put(final int bitnum, final boolean bit) throws IndexOutOfBoundsException {
check(bitSize, bitnum);
final int u = bitnum >>> UNIT_SHIFT;
final int b = bitnum - ( u << UNIT_SHIFT );
final int m = 1 << b;
- if( bit ) {
- storage[u] |= m;
- } else {
- storage[u] &= ~m;
+ final boolean prev = 0 != ( storage[u] & m ) ;
+ if( prev != bit ) {
+ if( bit ) {
+ storage[u] |= m;
+ } else {
+ storage[u] &= ~m;
+ }
}
+ return prev;
}
@Override
public final void set(final int bitnum) throws IndexOutOfBoundsException {
diff --git a/src/java/jogamp/common/util/Int32Bitfield.java b/src/java/jogamp/common/util/Int32Bitfield.java
index 9bf2117..7b55a59 100644
--- a/src/java/jogamp/common/util/Int32Bitfield.java
+++ b/src/java/jogamp/common/util/Int32Bitfield.java
@@ -115,14 +115,18 @@ public class Int32Bitfield implements Bitfield {
return 0 != ( storage & ( 1 << bitnum ) ) ;
}
@Override
- public final void put(final int bitnum, final boolean bit) throws IndexOutOfBoundsException {
+ public final boolean put(final int bitnum, final boolean bit) throws IndexOutOfBoundsException {
check(UNIT_SIZE, bitnum);
final int m = 1 << bitnum;
- if( bit ) {
- storage |= m;
- } else {
- storage &= ~m;
+ final boolean prev = 0 != ( storage & m ) ;
+ if( prev != bit ) {
+ if( bit ) {
+ storage |= m;
+ } else {
+ storage &= ~m;
+ }
}
+ return prev;
}
@Override
public final void set(final int bitnum) throws IndexOutOfBoundsException {
diff --git a/src/java/jogamp/common/util/SyncedBitfield.java b/src/java/jogamp/common/util/SyncedBitfield.java
index c23d7ea..49c27b0 100644
--- a/src/java/jogamp/common/util/SyncedBitfield.java
+++ b/src/java/jogamp/common/util/SyncedBitfield.java
@@ -70,8 +70,8 @@ public class SyncedBitfield implements Bitfield {
}
@Override
- public final synchronized void put(final int bitnum, final boolean bit) throws IndexOutOfBoundsException {
- impl.put(bitnum, bit);
+ public final synchronized boolean put(final int bitnum, final boolean bit) throws IndexOutOfBoundsException {
+ return impl.put(bitnum, bit);
}
@Override
diff --git a/src/junit/com/jogamp/common/util/TestBitfield00.java b/src/junit/com/jogamp/common/util/TestBitfield00.java
index a2d5d73..bb8ca37 100644
--- a/src/junit/com/jogamp/common/util/TestBitfield00.java
+++ b/src/junit/com/jogamp/common/util/TestBitfield00.java
@@ -320,12 +320,16 @@ public class TestBitfield00 extends SingletonJunitCase {
assertEquals(bf, lowBitnum+1, d.val, d.pattern, oneBitCount);
}
+ // test put() return value (previous value)
+ bf.clearField(false);
+ Assert.assertEquals(msg+", bitpos "+0, false, bf.put(lowBitnum+0, true));
+ Assert.assertEquals(msg+", bitpos "+0, true, bf.put(lowBitnum+0, false));
+
//
// via put
//
- bf.clearField(false);
for(int i=0; i<d.bitSize; i++) {
- bf.put(lowBitnum+i, 0 != ( d.val & ( 1 << i ) ));
+ Assert.assertEquals(msg+", bitpos "+i, false, bf.put(lowBitnum+i, 0 != ( d.val & ( 1 << i ) )));
}
Assert.assertEquals(msg, d.val, bf.get32(lowBitnum, d.bitSize));
for(int i=0; i<d.bitSize; i++) {