From a70a8c6c1684beaf6f65a8db6f59840a27054d29 Mon Sep 17 00:00:00 2001 From: bartimaeusnek <33183715+bartimaeusnek@users.noreply.github.com> Date: Sun, 15 Dec 2019 19:18:01 +0100 Subject: worked on AccessPriorityList + switching now works fine + toArray() now works as expected + added Exceptions Signed-off-by: bartimaeusnek <33183715+bartimaeusnek@users.noreply.github.com> Former-commit-id: b4707dfa63c6239a70f2ae829fef1b19d6ea7a58 --- .../accessprioritylist/AccessPriorityList.java | 74 ++++++++++++---------- 1 file changed, 42 insertions(+), 32 deletions(-) (limited to 'src/main') diff --git a/src/main/java/com/github/bartimaeusnek/bartworks/util/accessprioritylist/AccessPriorityList.java b/src/main/java/com/github/bartimaeusnek/bartworks/util/accessprioritylist/AccessPriorityList.java index bd4482741d..a1067b051e 100644 --- a/src/main/java/com/github/bartimaeusnek/bartworks/util/accessprioritylist/AccessPriorityList.java +++ b/src/main/java/com/github/bartimaeusnek/bartworks/util/accessprioritylist/AccessPriorityList.java @@ -22,6 +22,8 @@ package com.github.bartimaeusnek.bartworks.util.accessprioritylist; +import org.apache.commons.lang3.NotImplementedException; + import java.util.*; public class AccessPriorityList implements List, Deque, Set { @@ -30,7 +32,7 @@ public class AccessPriorityList implements List, Deque, Set { transient AccessPriorityListNode head; transient AccessPriorityListNode tail; - public static AccessPriorityList create(){ + public static AccessPriorityList create() { return new AccessPriorityList(); } @@ -62,32 +64,32 @@ public class AccessPriorityList implements List, Deque, Set { @Override public boolean offerFirst(E e) { - return false; + throw new NotImplementedException(""); } @Override public boolean offerLast(E e) { - return false; + throw new NotImplementedException(""); } @Override public E removeFirst() { - return null; + throw new NotImplementedException(""); } @Override public E removeLast() { - return null; + throw new NotImplementedException(""); } @Override public E pollFirst() { - return null; + throw new NotImplementedException(""); } @Override public E pollLast() { - return null; + throw new NotImplementedException(""); } @Override @@ -112,12 +114,12 @@ public class AccessPriorityList implements List, Deque, Set { @Override public boolean removeFirstOccurrence(Object o) { - return false; + throw new NotImplementedException(""); } @Override public boolean removeLastOccurrence(Object o) { - return false; + throw new NotImplementedException(""); } @Override @@ -132,7 +134,7 @@ public class AccessPriorityList implements List, Deque, Set { @Override public boolean contains(Object o) { - return false; + throw new NotImplementedException(""); } @Override @@ -148,16 +150,18 @@ public class AccessPriorityList implements List, Deque, Set { @Override public Object[] toArray() { Object[] ret = new Object[size]; - while (listIterator().hasNext()) - ret[listIterator().nextIndex()-1] = listIterator().next(); + int index = 0; + for (Iterator it = iterator(); it.hasNext(); index++) + ret[index] = it.next(); return ret; } @Override public T[] toArray(T[] a) { T[] ret = (T[]) new Object[size]; - while (listIterator().hasNext()) - ret[listIterator().nextIndex()-1] = (T) listIterator().next(); + int index = 0; + for (Iterator it = (Iterator) iterator(); it.hasNext(); index++) + ret[index] = it.next(); return ret; } @@ -181,6 +185,8 @@ public class AccessPriorityList implements List, Deque, Set { if (beforeBefore != null) beforeBefore.setNext(node); + else + head = node; // <0,1,3> <1,2,3> N<0,3,4> <3,4,5> before.setBefore(node); @@ -191,6 +197,8 @@ public class AccessPriorityList implements List, Deque, Set { if (next != null) next.setBefore(before); + else + tail = before; // <0,1,3> N<0,3,4> <3,2,4> <2,4,5> node.setNext(before); @@ -213,26 +221,28 @@ public class AccessPriorityList implements List, Deque, Set { @Override public boolean offer(E e) { - return false; + throw new NotImplementedException(""); } private boolean isValidIndex(int index) { - return index >= 0 && index < size; + if (index >= 0 && index < size) + return true; + throw new ArrayIndexOutOfBoundsException("NOT A VAILD INDEX!"); } @Override public E remove() { - return null; + throw new NotImplementedException(""); } @Override public E poll() { - return null; + throw new NotImplementedException(""); } @Override public E element() { - return null; + throw new NotImplementedException(""); } @Override @@ -247,17 +257,17 @@ public class AccessPriorityList implements List, Deque, Set { @Override public E pop() { - return null; + throw new NotImplementedException(""); } @Override public boolean remove(Object o) { - return false; + throw new NotImplementedException(""); } @Override public boolean containsAll(Collection c) { - return false; + throw new NotImplementedException(""); } @Override @@ -270,17 +280,17 @@ public class AccessPriorityList implements List, Deque, Set { @Override public boolean addAll(int index, Collection c) { - return false; + throw new NotImplementedException(""); } @Override public boolean removeAll(Collection c) { - return false; + throw new NotImplementedException(""); } @Override public boolean retainAll(Collection c) { - return false; + throw new NotImplementedException(""); } @Override @@ -323,27 +333,27 @@ public class AccessPriorityList implements List, Deque, Set { @Override public E set(int index, E element) { - return null; + throw new NotImplementedException(""); } @Override public void add(int index, E element) { - + throw new NotImplementedException(""); } @Override public E remove(int index) { - return null; + throw new NotImplementedException(""); } @Override public int indexOf(Object o) { - return 0; + throw new NotImplementedException(""); } @Override public int lastIndexOf(Object o) { - return 0; + throw new NotImplementedException(""); } @Override @@ -358,11 +368,11 @@ public class AccessPriorityList implements List, Deque, Set { @Override public List subList(int fromIndex, int toIndex) { - return null; + throw new NotImplementedException(""); } @Override public Spliterator spliterator() { - return null; + throw new NotImplementedException(""); } } -- cgit