diff --git a/.gitignore b/.gitignore
index 0683b2b..6c6a87b 100644
--- a/.gitignore
+++ b/.gitignore
@@ -28,4 +28,5 @@ bin/
### Mac OS ###
.DS_Store
-.idea
\ No newline at end of file
+.idea/workspace.xml
+.idea/shelf/
\ No newline at end of file
diff --git a/.idea/misc.xml b/.idea/misc.xml
new file mode 100644
index 0000000..3d3ab27
--- /dev/null
+++ b/.idea/misc.xml
@@ -0,0 +1,6 @@
+
+
+
+
+
+
\ No newline at end of file
diff --git a/.idea/modules.xml b/.idea/modules.xml
new file mode 100644
index 0000000..6cd1894
--- /dev/null
+++ b/.idea/modules.xml
@@ -0,0 +1,8 @@
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/.idea/uiDesigner.xml b/.idea/uiDesigner.xml
new file mode 100644
index 0000000..2b63946
--- /dev/null
+++ b/.idea/uiDesigner.xml
@@ -0,0 +1,124 @@
+
+
+
+
+ -
+
+
+ -
+
+
+ -
+
+
+ -
+
+
+ -
+
+
+
+
+
+ -
+
+
+
+
+
+ -
+
+
+
+
+
+ -
+
+
+
+
+
+ -
+
+
+
+
+ -
+
+
+
+
+ -
+
+
+
+
+ -
+
+
+
+
+ -
+
+
+
+
+ -
+
+
+
+
+ -
+
+
+ -
+
+
+
+
+ -
+
+
+
+
+ -
+
+
+
+
+ -
+
+
+
+
+ -
+
+
+
+
+ -
+
+
+ -
+
+
+ -
+
+
+ -
+
+
+ -
+
+
+
+
+ -
+
+
+ -
+
+
+
+
+
\ No newline at end of file
diff --git a/.idea/vcs.xml b/.idea/vcs.xml
new file mode 100644
index 0000000..35eb1dd
--- /dev/null
+++ b/.idea/vcs.xml
@@ -0,0 +1,6 @@
+
+
+
+
+
+
\ No newline at end of file
diff --git a/src/dev/asdf00/general/utils/list/PrimitiveList.java b/src/dev/asdf00/general/utils/list/PrimitiveList.java
index 9be2b45..a955b43 100644
--- a/src/dev/asdf00/general/utils/list/PrimitiveList.java
+++ b/src/dev/asdf00/general/utils/list/PrimitiveList.java
@@ -5,13 +5,9 @@ import dev.asdf00.general.utils.list.internal.ByteList;
public abstract class PrimitiveList extends AbstractBaseList {
- public static PrimitiveList create(Class type) {
- return create(type, 8);
- }
-
- public static PrimitiveList create(Class boxedType, int initial) {
+ public static PrimitiveList create(Class boxedType) {
if (Byte.class == boxedType) {
- return (PrimitiveList) new ByteList(initial);
+ return (PrimitiveList) new ByteList();
} else if (Short.class.equals(boxedType)) {
return null;
} else if (Integer.class.equals(boxedType)) {
diff --git a/src/dev/asdf00/general/utils/list/internal/AbstractBaseList.java b/src/dev/asdf00/general/utils/list/internal/AbstractBaseList.java
index 2205115..087eba9 100644
--- a/src/dev/asdf00/general/utils/list/internal/AbstractBaseList.java
+++ b/src/dev/asdf00/general/utils/list/internal/AbstractBaseList.java
@@ -65,12 +65,6 @@ public abstract class AbstractBaseList implements List {
return true;
}
- @Override
- public T remove(int index) {
- Objects.checkIndex(index, size);
- return remove(index, 0, size);
- }
-
@Override
public boolean remove(Object o) {
int index = indexOf(o);
@@ -149,15 +143,15 @@ public abstract class AbstractBaseList implements List {
protected abstract T1[] toArray(T1[] a, int start, int len);
- protected abstract T remove(Object o, int start, int len);
-
protected abstract int indexOf(Object o, int start, int len);
protected abstract int lastIndexOf(Object o, int start, int len);
protected abstract T directSet(int index, T element);
- protected abstract void removeRange(int start, int len);
+ protected abstract void createGap(int start, int len);
+
+ protected abstract void closeGap(int start, int len);
private static class ListItr implements ListIterator {
@@ -291,7 +285,7 @@ public abstract class AbstractBaseList implements List {
public void clear() {
checkConcurrentModification();
modCnt++;
- base.removeRange(start, size);
+ base.closeGap(start, size);
size = 0;
}
@@ -310,6 +304,11 @@ public abstract class AbstractBaseList implements List {
base.add(start + index, element);
}
+ @Override
+ public E remove(int index) {
+ return null;
+ }
+
@Override
public ListIterator listIterator() {
return new SubListItr<>(base, start, start, start + (size - 1));
@@ -340,34 +339,32 @@ public abstract class AbstractBaseList implements List {
return base.toArray(a, this.start + start, len);
}
- @Override
- protected E remove(Object o, int start, int len) {
- checkConcurrentModification();
- modCnt++;
- return base.remove(o, this.start + start, len);
- }
-
@Override
protected int indexOf(Object o, int start, int len) {
checkConcurrentModification();
- return base.indexOf(o, this.start + start, len);
+ return base.indexOf(o, this.start + start, len) - start;
}
@Override
protected int lastIndexOf(Object o, int start, int len) {
checkConcurrentModification();
- return base.lastIndexOf(o, this.start + start, len);
+ return base.lastIndexOf(o, this.start + start, len) - start;
}
@Override
protected E directSet(int index, E element) {
checkConcurrentModification();
modCnt++;
- return base.directSet(index, element);
+ return base.directSet(start + index, element);
}
@Override
- protected void removeRange(int start, int len) {
+ protected void createGap(int start, int len) {
+ throw new UnsupportedOperationException();
+ }
+
+ @Override
+ protected void closeGap(int start, int len) {
throw new UnsupportedOperationException();
}
diff --git a/src/dev/asdf00/general/utils/list/internal/ByteList.java b/src/dev/asdf00/general/utils/list/internal/ByteList.java
index 2567f85..70d905e 100644
--- a/src/dev/asdf00/general/utils/list/internal/ByteList.java
+++ b/src/dev/asdf00/general/utils/list/internal/ByteList.java
@@ -2,14 +2,18 @@ package dev.asdf00.general.utils.list.internal;
import dev.asdf00.general.utils.list.PrimitiveList;
+import java.util.Arrays;
import java.util.Collection;
+import java.util.Objects;
-public class ByteList extends PrimitiveList {
+public class ByteList extends PrimitiveList {
private byte[] data;
- public ByteList(int initial) {
-
+ public ByteList() {
+ data = new byte[8];
+ size = 0;
+ modCnt = 0;
}
@Override
@@ -19,59 +23,118 @@ public class ByteList extends PrimitiveList {
@Override
protected T1[] toArray(T1[] a, int start, int len) {
- return null;
- }
-
- @Override
- protected Boolean remove(Object o, int start, int len) {
- return null;
+ Object[] result = Arrays.copyOf(a, len, a.getClass());
+ for (int i = 0, j = start; i < len; i++, j++) {
+ result[i] = Byte.valueOf(data[j]);
+ }
+ return (T1[]) result;
}
@Override
protected int indexOf(Object o, int start, int len) {
- return 0;
+ if (!(o instanceof Byte)) {
+ return -1;
+ }
+ byte target = ((Byte) o).byteValue();
+ for (int i = start; i < start + len; i++) {
+ if (data[i] == target) {
+ return i;
+ }
+ }
+ return -1;
}
@Override
protected int lastIndexOf(Object o, int start, int len) {
- return 0;
+ if (!(o instanceof Byte)) {
+ return -1;
+ }
+ byte target = ((Byte) o).byteValue();
+ for (int i = (start + len) - 1; i >= start; i++) {
+ if (data[i] == target) {
+ return i;
+ }
+ }
+ return -1;
}
@Override
- protected Boolean directSet(int index, Boolean element) {
- return null;
+ protected Byte directSet(int index, Byte element) {
+ byte result = data[index];
+ data[index] = element.byteValue();
+ return result;
}
@Override
- protected void removeRange(int start, int len) {
-
+ protected void createGap(int start, int len) {
+ size += len;
+ if (size > data.length) {
+ if (Integer.bitCount(size) == 1) {
+ data = Arrays.copyOf(data, size);
+ } else {
+ data = Arrays.copyOf(data, Integer.highestOneBit(size) + 1);
+ }
+ }
+ System.arraycopy(data, start, data, start + len, (size - len) - start);
}
@Override
- public boolean addAll(Collection extends Boolean> c) {
- return false;
+ protected void closeGap(int start, int len) {
+ System.arraycopy(data, start + len, data, start, size - (start + len));
+ size -= len;
}
@Override
- public boolean addAll(int index, Collection extends Boolean> c) {
- return false;
+ public boolean addAll(Collection extends Byte> c) {
+ modCnt++;
+ int i = size;
+ createGap(size, c.size());
+ for (Byte b : c) {
+ data[i] = b.byteValue();
+ i++;
+ }
+ return true;
+ }
+
+ @Override
+ public boolean addAll(int index, Collection extends Byte> c) {
+ Objects.checkIndex(index, size);
+ modCnt++;
+ int i = index;
+ createGap(index, c.size());
+ for (Byte b : c) {
+ data[i] = b.byteValue();
+ i++;
+ }
+ return true;
}
@Override
public void clear() {
+ if (data == null) {
+ throw new NullPointerException();
+ }
+ modCnt++;
+ data = new byte[8];
+ size = 0;
+ }
+
+ @Override
+ public Byte get(int index) {
+ Objects.checkIndex(index, size);
+ return data[index];
+ }
+
+ @Override
+ public void add(int index, Byte element) {
}
@Override
- public Boolean get(int index) {
+ public Byte remove(int index) {
return null;
}
- @Override
- public void add(int index, Boolean element) {
-
- }
-
@Override
public void addByte(byte value) {
@@ -94,4 +157,8 @@ public class ByteList extends PrimitiveList {
AbstractBaseList.UNSAFE.putInt(data, AbstractBaseList.OFFSET_LEN, size);
return res;
}
+
+ private void reallocateWithLen(int newLen) {
+ data = Arrays.copyOf(data, newLen);
+ }
}