diff --git a/gradle.properties b/gradle.properties index d273149..8585e4a 100644 --- a/gradle.properties +++ b/gradle.properties @@ -1,2 +1,2 @@ -version=1.5 +version=1.6 release=false \ No newline at end of file diff --git a/src/main/java/com/dselent/bigarraylist/BigArrayList.java b/src/main/java/com/dselent/bigarraylist/BigArrayList.java index 5a23524..ae33bdc 100644 --- a/src/main/java/com/dselent/bigarraylist/BigArrayList.java +++ b/src/main/java/com/dselent/bigarraylist/BigArrayList.java @@ -22,6 +22,7 @@ import java.io.IOException; import java.io.Serializable; import java.util.ArrayList; +import java.util.Collection; import java.util.Comparator; import java.util.Iterator; import java.util.List; @@ -1001,8 +1002,7 @@ public E set(long index, E element) { * @return The new element at the specified index */ public E set(int index, E element) { - long longIndex = index; - return set(longIndex, element); + return set((long)index, element); } /** @@ -1011,49 +1011,36 @@ public E set(int index, E element) { * @return True is the list is empty, false otherwise */ public boolean isEmpty() { - boolean empty = true; - - if (size() > 0) { - empty = false; - } - - return empty; + return wholeListSize == 0; } //hashCode cannot be implemented correctly due to contents being on disk and out of sight from memory - /* (non-Javadoc) - * @see java.lang.Object#equals(java.lang.Object) - */ - @SuppressWarnings("rawtypes") @Override public boolean equals(Object otherObject) { - boolean isEqual = true; - - if (otherObject == null) { - isEqual = false; - } else if (this == otherObject) { - isEqual = true; - } else if (!(otherObject instanceof BigArrayList)) { - isEqual = false; - } else { - BigArrayList otherBigArrayList = (BigArrayList) otherObject; - - if (wholeListSize != otherBigArrayList.size()) { - isEqual = false; - } else if (liveObject != otherBigArrayList.isLive()) { - isEqual = false; - } else { - for (long i = 0; i < wholeListSize && isEqual; i++) { - if (!get(i).equals(otherBigArrayList.get(i))) { - isEqual = false; - } - } - } + if (!(otherObject instanceof BigArrayList)) { + return super.equals(otherObject); } + + BigArrayList otherBigArrayList = (BigArrayList) otherObject; - return isEqual; + if (wholeListSize != otherBigArrayList.size()) { + return false; + } + if (liveObject != otherBigArrayList.isLive()) { + return false; + } + + Iterator thisIterator = this.iterator(); + Iterator otherIterator = otherBigArrayList.iterator(); + while (thisIterator.hasNext() && otherIterator.hasNext()) { + E o1 = thisIterator.next(); + Object o2 = otherIterator.next(); + if (!(o1==null ? o2==null : o1.equals(o2))) + return false; + } + return !(thisIterator.hasNext() || otherIterator.hasNext()); } @Override @@ -1078,4 +1065,33 @@ public E next() { } }; } + + /** + * @param other The other BigArrayList + * @see ArrayList#addAll(Collection) + */ + public void addAll(BigArrayList other) { + for (E element : other) { + add(element); + } + } + + /** + * @param other The other collection + * @see ArrayList#addAll(Collection) + */ + public void addAll(Collection other) { + for (E element : other) { + add(element); + } + } + + /** + * Clears all elements without clearing the memory + */ + public void clear() { + for (long i = wholeListSize-1; i >= 0; i--) { + remove(i); + } + } } diff --git a/src/main/java/com/dselent/bigarraylist/CacheMapping.java b/src/main/java/com/dselent/bigarraylist/CacheMapping.java index 275fd65..a3aca94 100644 --- a/src/main/java/com/dselent/bigarraylist/CacheMapping.java +++ b/src/main/java/com/dselent/bigarraylist/CacheMapping.java @@ -499,4 +499,4 @@ protected void clearMemory() throws IOException { fileAccessor.clearMemory(); } -} \ No newline at end of file +} diff --git a/src/main/java/com/dselent/bigarraylist/FileAccessor.java b/src/main/java/com/dselent/bigarraylist/FileAccessor.java index 7b396e3..6677d20 100644 --- a/src/main/java/com/dselent/bigarraylist/FileAccessor.java +++ b/src/main/java/com/dselent/bigarraylist/FileAccessor.java @@ -368,9 +368,6 @@ protected void clearMemory() throws IOException } } } - //don't delete the folder, other things may be using it - } - -} \ No newline at end of file +} diff --git a/src/test/java/BigArrayListTest.java b/src/test/java/BigArrayListTest.java index 9019844..b69ee44 100644 --- a/src/test/java/BigArrayListTest.java +++ b/src/test/java/BigArrayListTest.java @@ -13,6 +13,7 @@ import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.fail; import static org.junit.jupiter.api.Assertions.assertIterableEquals; +import static org.junit.jupiter.api.Assertions.assertTrue; public class BigArrayListTest { @@ -27,7 +28,7 @@ public class BigArrayListTest private static int maxActions; private static Random random; - private BigArrayList bigArrayList; + private BigArrayList actualMonte; @BeforeAll static void setUp() throws Exception @@ -47,9 +48,9 @@ static void setUp() throws Exception @AfterEach protected void tearDown() throws Exception { - if(bigArrayList != null) + if(actualMonte != null) { - bigArrayList.clearMemory(); + actualMonte.clearMemory(); } } @@ -68,7 +69,7 @@ public void testBigArrayList() int cacheBlocks = random.nextInt(maxCacheBlocks- minCacheBlocks) + minCacheBlocks; int actions = random.nextInt(maxActions-minActions) + minActions; - bigArrayList = new BigArrayList(blockSize, cacheBlocks); + actualMonte = new BigArrayList(blockSize, cacheBlocks); List arrayList = new ArrayList<>(); for(int j=0; j