You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Calling BigArrayImpl.removeBeforeIndex with the headIndex seems a valid use case to remove all elements from the big array, even tough you could achieve the same thing with a call to removeAll.
The following code:
publicstaticvoidmain(String[] args) throwsException {
StringbasePath = newFile(System.getProperty("java.io.tmpdir"), "test").getPath();
IBigArraybigArray = newBigArrayImpl(basePath, "demo");
try {
// append some items into the arrayfor(inti = 0; i < 2; ++i) {
bigArray.append(String.valueOf(i).getBytes());
}
// get current size of the arraySystem.out.println("size: " + bigArray.size());
for (longindex = bigArray.getTailIndex(); index != bigArray.getHeadIndex(); index = (index == Long.MAX_VALUE ? 0 : index + 1)) {
Stringitem = newString(bigArray.get(index));
System.out.println("item[" + index + "]=" + item);
}
bigArray.removeBeforeIndex(bigArray.getHeadIndex());
System.out.println("size: " + bigArray.size());
for (longindex = bigArray.getTailIndex(); index != bigArray.getHeadIndex(); index = (index == Long.MAX_VALUE ? 0 : index + 1)) {
Stringitem = newString(bigArray.get(index));
System.out.println("item[" + index + "]=" + item);
}
// empty the big arraybigArray.removeAll();
} finally {
bigArray.close();
}
}
outputs to the console:
size: 2
item[0]=0
item[1]=1
Exception in thread "main" java.lang.IndexOutOfBoundsException
at com.leansoft.bigqueue.BigArrayImpl.validateIndex(BigArrayImpl.java:458)
at com.leansoft.bigqueue.BigArrayImpl.removeBeforeIndex(BigArrayImpl.java:198)
at com.jorge.test.BigArrayMain.main(BigArrayMain.java:27)
Perhaps removeBeforeIndex should be changed to something like:
Calling BigArrayImpl.removeBeforeIndex with the headIndex seems a valid use case to remove all elements from the big array, even tough you could achieve the same thing with a call to removeAll.
The following code:
outputs to the console:
Perhaps removeBeforeIndex should be changed to something like:
The text was updated successfully, but these errors were encountered: