### Question:
NibbleArray { public int getAndSet(int index, int value) { Validate.inclusiveBetween(0, maxEntryValue, value); int bitStartIndex = index * bitsPreEntry; int arrayStartIndex = bitStartIndex >>> 6; int arrayEndIndex = (bitStartIndex + bitsPreEntry - 1) >>> 6; Validate.inclusiveBetween(0, array.length - 1, arrayEndIndex); int offset = bitStartIndex & 63; long oldValue = array[arrayStartIndex] >>> offset; array[arrayStartIndex] = array[arrayStartIndex] & ~(maxEntryValue << offset) | (long) value << offset; if (arrayStartIndex != arrayEndIndex) { offset = 64 - offset; oldValue |= array[arrayEndIndex] << offset; int offsetEnd = bitsPreEntry - offset; this.array[arrayEndIndex] = this.array[arrayEndIndex] >>> offsetEnd << offsetEnd | (long) value >> offset; } return (int) (oldValue & maxEntryValue); } NibbleArray(int bitsPreEntry, int length); int getBitsPreEntry(); int length(); long getMaxEntryValue(); int get(int index); void set(int index, int value); int getAndSet(int index, int value); int[] toArray(); long[] getBackingArray();  }### Answer:
@Test public void getAndSet() { for (int i = 0; i < bit8Array.length(); i++) { assertEquals(bit8RawArray[i], bit8Array.getAndSet(i, bit8RawArray2[i])); } for (int i = 0; i < bit24Array.length(); i++) { assertEquals(bit24RawArray[i], bit24Array.getAndSet(i, bit24RawArray2[i])); } for (int i = 0; i < bit31Array.length(); i++) { assertEquals(bit31RawArray[i], bit31Array.getAndSet(i, bit31RawArray2[i])); } }