2222import java .io .IOException ;
2323import java .io .Serializable ;
2424import java .util .ArrayList ;
25+ import java .util .Collection ;
2526import java .util .Comparator ;
2627import java .util .Iterator ;
2728import java .util .List ;
@@ -1001,8 +1002,7 @@ public E set(long index, E element) {
10011002 * @return The new element at the specified index
10021003 */
10031004 public E set (int index , E element ) {
1004- long longIndex = index ;
1005- return set (longIndex , element );
1005+ return set ((long )index , element );
10061006 }
10071007
10081008 /**
@@ -1011,49 +1011,36 @@ public E set(int index, E element) {
10111011 * @return True is the list is empty, false otherwise
10121012 */
10131013 public boolean isEmpty () {
1014- boolean empty = true ;
1015-
1016- if (size () > 0 ) {
1017- empty = false ;
1018- }
1019-
1020- return empty ;
1014+ return wholeListSize == 0 ;
10211015 }
10221016
10231017 //hashCode cannot be implemented correctly due to contents being on disk and out of sight from memory
10241018
1025- /* (non-Javadoc)
1026- * @see java.lang.Object#equals(java.lang.Object)
1027- */
1028- @ SuppressWarnings ("rawtypes" )
10291019 @ Override
10301020 public boolean equals (Object otherObject ) {
10311021
1032- boolean isEqual = true ;
1033-
1034- if (otherObject == null ) {
1035- isEqual = false ;
1036- } else if (this == otherObject ) {
1037- isEqual = true ;
1038- } else if (!(otherObject instanceof BigArrayList )) {
1039- isEqual = false ;
1040- } else {
1041- BigArrayList otherBigArrayList = (BigArrayList ) otherObject ;
1042-
1043- if (wholeListSize != otherBigArrayList .size ()) {
1044- isEqual = false ;
1045- } else if (liveObject != otherBigArrayList .isLive ()) {
1046- isEqual = false ;
1047- } else {
1048- for (long i = 0 ; i < wholeListSize && isEqual ; i ++) {
1049- if (!get (i ).equals (otherBigArrayList .get (i ))) {
1050- isEqual = false ;
1051- }
1052- }
1053- }
1022+ if (!(otherObject instanceof BigArrayList )) {
1023+ return super .equals (otherObject );
10541024 }
1025+
1026+ BigArrayList <?> otherBigArrayList = (BigArrayList <?>) otherObject ;
10551027
1056- return isEqual ;
1028+ if (wholeListSize != otherBigArrayList .size ()) {
1029+ return false ;
1030+ }
1031+ if (liveObject != otherBigArrayList .isLive ()) {
1032+ return false ;
1033+ }
1034+
1035+ Iterator <E > thisIterator = this .iterator ();
1036+ Iterator <?> otherIterator = otherBigArrayList .iterator ();
1037+ while (thisIterator .hasNext () && otherIterator .hasNext ()) {
1038+ E o1 = thisIterator .next ();
1039+ Object o2 = otherIterator .next ();
1040+ if (!(o1 ==null ? o2 ==null : o1 .equals (o2 )))
1041+ return false ;
1042+ }
1043+ return !(thisIterator .hasNext () || otherIterator .hasNext ());
10571044 }
10581045
10591046 @ Override
@@ -1078,4 +1065,33 @@ public E next() {
10781065 }
10791066 };
10801067 }
1068+
1069+ /**
1070+ * @param other The other BigArrayList
1071+ * @see ArrayList#addAll(Collection)
1072+ */
1073+ public void addAll (BigArrayList <? extends E > other ) {
1074+ for (E element : other ) {
1075+ add (element );
1076+ }
1077+ }
1078+
1079+ /**
1080+ * @param other The other collection
1081+ * @see ArrayList#addAll(Collection)
1082+ */
1083+ public void addAll (Collection <? extends E > other ) {
1084+ for (E element : other ) {
1085+ add (element );
1086+ }
1087+ }
1088+
1089+ /**
1090+ * Clears all elements without clearing the memory
1091+ */
1092+ public void clear () {
1093+ for (long i = wholeListSize -1 ; i >= 0 ; i --) {
1094+ remove (i );
1095+ }
1096+ }
10811097}
0 commit comments