From 1cdf28deca74e6cc222e435f972ec2481acd4d36 Mon Sep 17 00:00:00 2001 From: bartimaeusnek <33183715+bartimaeusnek@users.noreply.github.com> Date: Sun, 15 Dec 2019 02:38:59 +0100 Subject: Renamed SSList -> AccessPriorityList + implemented clear() Signed-off-by: bartimaeusnek <33183715+bartimaeusnek@users.noreply.github.com> Former-commit-id: 56a7fd3f407454fb1eee55ec8e02a255267fbce8 --- .../ASM/BWCoreStaticReplacementMethodes.java | 4 +- .../accessprioritylist/AccessPriorityList.java | 368 +++++++++++++++++++++ .../AccessPriorityListIterators.java | 146 ++++++++ .../accessprioritylist/AccessPriorityListNode.java | 75 +++++ .../bartworks/util/selfsortinglist/SSList.java | 357 -------------------- .../util/selfsortinglist/SSListIterators.java | 146 -------- .../bartworks/util/selfsortinglist/SSListNode.java | 75 ----- 7 files changed, 591 insertions(+), 580 deletions(-) create mode 100644 src/main/java/com/github/bartimaeusnek/bartworks/util/accessprioritylist/AccessPriorityList.java create mode 100644 src/main/java/com/github/bartimaeusnek/bartworks/util/accessprioritylist/AccessPriorityListIterators.java create mode 100644 src/main/java/com/github/bartimaeusnek/bartworks/util/accessprioritylist/AccessPriorityListNode.java delete mode 100644 src/main/java/com/github/bartimaeusnek/bartworks/util/selfsortinglist/SSList.java delete mode 100644 src/main/java/com/github/bartimaeusnek/bartworks/util/selfsortinglist/SSListIterators.java delete mode 100644 src/main/java/com/github/bartimaeusnek/bartworks/util/selfsortinglist/SSListNode.java (limited to 'src/main') diff --git a/src/main/java/com/github/bartimaeusnek/ASM/BWCoreStaticReplacementMethodes.java b/src/main/java/com/github/bartimaeusnek/ASM/BWCoreStaticReplacementMethodes.java index d5d35e50a5..53a0fff182 100644 --- a/src/main/java/com/github/bartimaeusnek/ASM/BWCoreStaticReplacementMethodes.java +++ b/src/main/java/com/github/bartimaeusnek/ASM/BWCoreStaticReplacementMethodes.java @@ -22,7 +22,7 @@ package com.github.bartimaeusnek.ASM; -import com.github.bartimaeusnek.bartworks.util.selfsortinglist.SSList; +import com.github.bartimaeusnek.bartworks.util.accessprioritylist.AccessPriorityList; import net.minecraft.inventory.InventoryCrafting; import net.minecraft.item.Item; import net.minecraft.item.ItemStack; @@ -35,7 +35,7 @@ import java.util.Optional; public class BWCoreStaticReplacementMethodes { - public static final SSList RECENTLYUSEDRECIPES = new SSList<>(); + public static final AccessPriorityList RECENTLYUSEDRECIPES = new AccessPriorityList<>(); @SuppressWarnings("ALL") public static ItemStack findCachedMatchingRecipe(InventoryCrafting inventoryCrafting, World world) { 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 new file mode 100644 index 0000000000..8f0cd8dd41 --- /dev/null +++ b/src/main/java/com/github/bartimaeusnek/bartworks/util/accessprioritylist/AccessPriorityList.java @@ -0,0 +1,368 @@ +/* + * Copyright (c) 2018-2019 bartimaeusnek + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +package com.github.bartimaeusnek.bartworks.util.accessprioritylist; + +import java.util.*; + +public class AccessPriorityList implements List, Deque, Set { + + transient int size = 0; + transient AccessPriorityListNode head; + transient AccessPriorityListNode tail; + + public static AccessPriorityList create(){ + return new AccessPriorityList(); + } + + public AccessPriorityList() {} + + @Override + public void addFirst(E t) { + final AccessPriorityListNode first = head; + final AccessPriorityListNode newNode = new AccessPriorityListNode<>(null, t, first); + head = newNode; + if (first == null) + tail = newNode; + else + first.setBefore(newNode); + size++; + } + + @Override + public void addLast(E t) { + final AccessPriorityListNode last = tail; + final AccessPriorityListNode newNode = new AccessPriorityListNode<>(last, t, null); + tail = newNode; + if (last == null) + head = newNode; + else + last.setNext(newNode); + size++; + } + + @Override + public boolean offerFirst(E e) { + return false; + } + + @Override + public boolean offerLast(E e) { + return false; + } + + @Override + public E removeFirst() { + return null; + } + + @Override + public E removeLast() { + return null; + } + + @Override + public E pollFirst() { + return null; + } + + @Override + public E pollLast() { + return null; + } + + @Override + public E getFirst() { + return peekFirst(); + } + + @Override + public E getLast() { + return peekLast(); + } + + @Override + public E peekFirst() { + return head != null ? head.getELEMENT() : null; + } + + @Override + public E peekLast() { + return tail != null ? tail.getELEMENT() : null; + } + + @Override + public boolean removeFirstOccurrence(Object o) { + return false; + } + + @Override + public boolean removeLastOccurrence(Object o) { + return false; + } + + @Override + public int size() { + return size; + } + + @Override + public boolean isEmpty() { + return size == 0; + } + + @Override + public boolean contains(Object o) { + return false; + } + + @Override + public Iterator iterator() { + return new AccessPriorityListIterators.AccessPriorityListIterator<>(head); + } + + @Override + public Iterator descendingIterator() { + return new AccessPriorityListIterators.AccessPriorityListReverseIterator<>(tail); + } + + @Override + public Object[] toArray() { + Object[] ret = new Object[size]; + while (listIterator().hasNext()) + ret[listIterator().nextIndex()-1] = listIterator().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(); + return ret; + } + + @Override + public boolean add(E e) { + addLast(e); + return true; + } + + private void moveNodeUp(AccessPriorityListNode node){ + if (node == head || node.getBefore() == null) + return; + final AccessPriorityListNode before = node.getBefore(); + final AccessPriorityListNode beforeBefore = before.getBefore(); + final AccessPriorityListNode next = node.getNext(); + + // <0,1,2> <1,2,3> N<2,3,4> <3,4,5> + + node.setBefore(beforeBefore); + // <0,1,2> <1,2,3> N<0,3,4> <3,4,5> + + if (beforeBefore != null) + beforeBefore.setNext(node); + // <0,1,3> <1,2,3> N<0,3,4> <3,4,5> + + before.setBefore(node); + // <0,1,3> <3,2,3> N<0,3,4> <3,4,5> + + before.setNext(next); + // <0,1,3> <3,2,4> N<0,3,4> <3,4,5> + + if (next != null) + next.setBefore(before); + // <0,1,3> N<0,3,4> <3,2,4> <2,4,5> + + node.setNext(before); + // <0,1,3> N<0,3,2> <3,2,4> <2,4,5> + } + + AccessPriorityListNode getNode(int index) { + if (index <= (size / 2)) { + AccessPriorityListNode x = head; + for (int i = 0; i < index; i++) + x = x.getNext(); + return x; + } else { + AccessPriorityListNode x = tail; + for (int i = size - 1; i > index; i--) + x = x.getBefore(); + return x; + } + } + + @Override + public boolean offer(E e) { + return false; + } + + private boolean isValidIndex(int index) { + return index >= 0 && index < size; + } + + @Override + public E remove() { + return null; + } + + @Override + public E poll() { + return null; + } + + @Override + public E element() { + return null; + } + + @Override + public E peek() { + return getFirst(); + } + + @Override + public void push(E e) { + addFirst(e); + } + + @Override + public E pop() { + return null; + } + + @Override + public boolean remove(Object o) { + return false; + } + + @Override + public boolean containsAll(Collection c) { + return false; + } + + @Override + public boolean addAll(Collection c) { + for (E e : c) { + this.addLast(e); + } + return true; + } + + @Override + public boolean addAll(int index, Collection c) { + return false; + } + + @Override + public boolean removeAll(Collection c) { + return false; + } + + @Override + public boolean retainAll(Collection c) { + return false; + } + + @Override + public void clear() { + if (tail != null) { + AccessPriorityListNode node = tail; + while (node.getBefore() != null) { + node.setNext(null); + node.setPriority(0L); + node = node.getBefore(); + node.getNext().setBefore(null); + } + this.size = 0; + this.head = null; + this.tail = null; + } + } + + public void addPrioToNode(int index, long prio){ + if (!isValidIndex(index)) + return; + AccessPriorityListNode node = getNode(index); + node.setPriority(node.getPriority()+prio); + while (node.getBefore() != null && node.getPriority() > node.getBefore().getPriority()){ + moveNodeUp(node); + } + } + + public void addPrioToNode(int index){ + addPrioToNode(index,1L); + } + + @Override + public E get(int index) { + if (!isValidIndex(index)) + return null; + AccessPriorityListNode node = getNode(index); + return node.getELEMENT(); + } + + @Override + public E set(int index, E element) { + return null; + } + + @Override + public void add(int index, E element) { + + } + + @Override + public E remove(int index) { + return null; + } + + @Override + public int indexOf(Object o) { + return 0; + } + + @Override + public int lastIndexOf(Object o) { + return 0; + } + + @Override + public ListIterator listIterator() { + return new AccessPriorityListIterators.AccessPriorityListListIterator<>(head,tail,false); + } + + @Override + public ListIterator listIterator(int index) { + return new AccessPriorityListIterators.AccessPriorityListListIterator<>(this,index); + } + + @Override + public List subList(int fromIndex, int toIndex) { + return null; + } + + @Override + public Spliterator spliterator() { + return null; + } +} diff --git a/src/main/java/com/github/bartimaeusnek/bartworks/util/accessprioritylist/AccessPriorityListIterators.java b/src/main/java/com/github/bartimaeusnek/bartworks/util/accessprioritylist/AccessPriorityListIterators.java new file mode 100644 index 0000000000..3b85030d1e --- /dev/null +++ b/src/main/java/com/github/bartimaeusnek/bartworks/util/accessprioritylist/AccessPriorityListIterators.java @@ -0,0 +1,146 @@ +/* + * Copyright (c) 2018-2019 bartimaeusnek + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +package com.github.bartimaeusnek.bartworks.util.accessprioritylist; + +import org.apache.commons.lang3.NotImplementedException; + +import java.util.Iterator; +import java.util.ListIterator; + +public class AccessPriorityListIterators { + + + public static class AccessPriorityListListIterator implements ListIterator { + final AccessPriorityListNode head; + final AccessPriorityListNode tail; + AccessPriorityListNode current; + int counter = 0; + boolean reverse; + public AccessPriorityListListIterator(AccessPriorityListNode head, AccessPriorityListNode tail, boolean reverse) { + this.head = head; + this.tail = tail; + current = reverse ? tail : head; + this.reverse = reverse; + } + + public AccessPriorityListListIterator(AccessPriorityList list, int index) { + this.head = list.head; + this.tail = list.tail; + current = list.getNode(index); + counter = index; + } + + @Override + public boolean hasNext() { + return reverse ? head != current : tail != current; + } + + @Override + public E next() { + counter++; + E ret = current.getELEMENT(); + current = current.getNext(); + return ret; + } + + @Override + public boolean hasPrevious() { + return !reverse ? head != current : tail != current; + } + + @Override + public E previous() { + counter--; + E ret = current.getELEMENT(); + current = current.getBefore(); + return ret; + } + + @Override + public int nextIndex() { + return counter+1; + } + + @Override + public int previousIndex() { + return counter-1; + } + + @Override + public void remove() { + throw new NotImplementedException("Not Implemented"); + } + + @Override + public void set(E e) { + throw new NotImplementedException("Not Implemented"); + } + + @Override + public void add(E e) { + throw new NotImplementedException("Not Implemented"); + } + } + + public static class AccessPriorityListIterator implements Iterator { + final AccessPriorityListNode head; + AccessPriorityListNode current; + public AccessPriorityListIterator(AccessPriorityListNode head) { + this.head = this.current = head; + } + + @Override + public boolean hasNext() { + return current != null; + } + + @Override + public E next() { + E ret = current.getELEMENT(); + current = current.getNext(); + return ret; + } + } + + public static class AccessPriorityListReverseIterator implements Iterator { + final AccessPriorityListNode tail; + AccessPriorityListNode current; + + public AccessPriorityListReverseIterator(AccessPriorityListNode tail) { + this.tail = this.current = tail; + } + + @Override + public boolean hasNext() { + return current != null; + } + + @Override + public E next() { + E ret = current.getELEMENT(); + current = current.getBefore(); + return ret; + } + } + +} diff --git a/src/main/java/com/github/bartimaeusnek/bartworks/util/accessprioritylist/AccessPriorityListNode.java b/src/main/java/com/github/bartimaeusnek/bartworks/util/accessprioritylist/AccessPriorityListNode.java new file mode 100644 index 0000000000..b8fd357027 --- /dev/null +++ b/src/main/java/com/github/bartimaeusnek/bartworks/util/accessprioritylist/AccessPriorityListNode.java @@ -0,0 +1,75 @@ +/* + * Copyright (c) 2018-2019 bartimaeusnek + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +package com.github.bartimaeusnek.bartworks.util.accessprioritylist; + +public class AccessPriorityListNode { + + public final static AccessPriorityListNode EMPTY_NODE = new AccessPriorityListNode(null); + + private final E ELEMENT; + private long priority = Long.MIN_VALUE; + private AccessPriorityListNode next; + private AccessPriorityListNode before; + + public AccessPriorityListNode(E element) { + ELEMENT = element; + } + + public AccessPriorityListNode(AccessPriorityListNode before, E element, AccessPriorityListNode next) { + this.ELEMENT = element; + connect(next, before); + } + + public void connect(AccessPriorityListNode next, AccessPriorityListNode before){ + this.setNext(next); + this.setBefore(before); + } + + public E getELEMENT() { + return ELEMENT; + } + + public long getPriority() { + return priority; + } + + public void setPriority(long priority) { + this.priority = priority; + } + + public AccessPriorityListNode getNext() { + return next; + } + + public void setNext(AccessPriorityListNode next) { + this.next = next; + } + + public AccessPriorityListNode getBefore() { + return before; + } + + public void setBefore(AccessPriorityListNode before) { + this.before = before; + } +} diff --git a/src/main/java/com/github/bartimaeusnek/bartworks/util/selfsortinglist/SSList.java b/src/main/java/com/github/bartimaeusnek/bartworks/util/selfsortinglist/SSList.java deleted file mode 100644 index 769b32638d..0000000000 --- a/src/main/java/com/github/bartimaeusnek/bartworks/util/selfsortinglist/SSList.java +++ /dev/null @@ -1,357 +0,0 @@ -/* - * Copyright (c) 2018-2019 bartimaeusnek - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ - -package com.github.bartimaeusnek.bartworks.util.selfsortinglist; - -import java.util.*; - -public class SSList implements List, Deque, Set { - - transient int size = 0; - transient SSListNode head; - transient SSListNode tail; - - public static SSList create(){ - return new SSList(); - } - - public SSList() {} - - @Override - public void addFirst(E t) { - final SSListNode first = head; - final SSListNode newNode = new SSListNode<>(null, t, first); - head = newNode; - if (first == null) - tail = newNode; - else - first.setBefore(newNode); - size++; - } - - @Override - public void addLast(E t) { - final SSListNode last = tail; - final SSListNode newNode = new SSListNode<>(last, t, null); - tail = newNode; - if (last == null) - head = newNode; - else - last.setNext(newNode); - size++; - } - - @Override - public boolean offerFirst(E e) { - return false; - } - - @Override - public boolean offerLast(E e) { - return false; - } - - @Override - public E removeFirst() { - return null; - } - - @Override - public E removeLast() { - return null; - } - - @Override - public E pollFirst() { - return null; - } - - @Override - public E pollLast() { - return null; - } - - @Override - public E getFirst() { - return peekFirst(); - } - - @Override - public E getLast() { - return peekLast(); - } - - @Override - public E peekFirst() { - return head != null ? head.getELEMENT() : null; - } - - @Override - public E peekLast() { - return tail != null ? tail.getELEMENT() : null; - } - - @Override - public boolean removeFirstOccurrence(Object o) { - return false; - } - - @Override - public boolean removeLastOccurrence(Object o) { - return false; - } - - @Override - public int size() { - return size; - } - - @Override - public boolean isEmpty() { - return size == 0; - } - - @Override - public boolean contains(Object o) { - return false; - } - - @Override - public Iterator iterator() { - return new SSListIterators.SSListIterator<>(head); - } - - @Override - public Iterator descendingIterator() { - return new SSListIterators.SSListReverseIterator<>(tail); - } - - @Override - public Object[] toArray() { - Object[] ret = new Object[size]; - while (listIterator().hasNext()) - ret[listIterator().nextIndex()-1] = listIterator().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(); - return ret; - } - - @Override - public boolean add(E e) { - addLast(e); - return true; - } - - private void moveNodeUp(SSListNode node){ - if (node == head || node.getBefore() == null) - return; - final SSListNode before = node.getBefore(); - final SSListNode beforeBefore = before.getBefore(); - final SSListNode next = node.getNext(); - - // <0,1,2> <1,2,3> N<2,3,4> <3,4,5> - - node.setBefore(beforeBefore); - // <0,1,2> <1,2,3> N<0,3,4> <3,4,5> - - if (beforeBefore != null) - beforeBefore.setNext(node); - // <0,1,3> <1,2,3> N<0,3,4> <3,4,5> - - before.setBefore(node); - // <0,1,3> <3,2,3> N<0,3,4> <3,4,5> - - before.setNext(next); - // <0,1,3> <3,2,4> N<0,3,4> <3,4,5> - - if (next != null) - next.setBefore(before); - // <0,1,3> N<0,3,4> <3,2,4> <2,4,5> - - node.setNext(before); - // <0,1,3> N<0,3,2> <3,2,4> <2,4,5> - } - - SSListNode getNode(int index) { - if (index <= (size / 2)) { - SSListNode x = head; - for (int i = 0; i < index; i++) - x = x.getNext(); - return x; - } else { - SSListNode x = tail; - for (int i = size - 1; i > index; i--) - x = x.getBefore(); - return x; - } - } - - @Override - public boolean offer(E e) { - return false; - } - - private boolean isValidIndex(int index) { - return index >= 0 && index < size; - } - - @Override - public E remove() { - return null; - } - - @Override - public E poll() { - return null; - } - - @Override - public E element() { - return null; - } - - @Override - public E peek() { - return null; - } - - @Override - public void push(E e) { - addFirst(e); - } - - @Override - public E pop() { - return null; - } - - @Override - public boolean remove(Object o) { - return false; - } - - @Override - public boolean containsAll(Collection c) { - return false; - } - - @Override - public boolean addAll(Collection c) { - for (E e : c) { - this.addLast(e); - } - return true; - } - - @Override - public boolean addAll(int index, Collection c) { - return false; - } - - @Override - public boolean removeAll(Collection c) { - return false; - } - - @Override - public boolean retainAll(Collection c) { - return false; - } - - @Override - public void clear() { - - } - - public void addPrioToNode(int index, long prio){ - if (!isValidIndex(index)) - return; - SSListNode node = getNode(index); - node.setPriority(node.getPriority()+prio); - while (node.getBefore() != null && node.getPriority() > node.getBefore().getPriority()){ - moveNodeUp(node); - } - } - - public void addPrioToNode(int index){ - addPrioToNode(index,1L); - } - - @Override - public E get(int index) { - if (!isValidIndex(index)) - return null; - SSListNode node = getNode(index); - return node.getELEMENT(); - } - - @Override - public E set(int index, E element) { - return null; - } - - @Override - public void add(int index, E element) { - - } - - @Override - public E remove(int index) { - return null; - } - - @Override - public int indexOf(Object o) { - return 0; - } - - @Override - public int lastIndexOf(Object o) { - return 0; - } - - @Override - public ListIterator listIterator() { - return new SSListIterators.SSListListIterator<>(head,tail,false); - } - - @Override - public ListIterator listIterator(int index) { - return new SSListIterators.SSListListIterator<>(this,index); - } - - @Override - public List subList(int fromIndex, int toIndex) { - return null; - } - - @Override - public Spliterator spliterator() { - return null; - } -} diff --git a/src/main/java/com/github/bartimaeusnek/bartworks/util/selfsortinglist/SSListIterators.java b/src/main/java/com/github/bartimaeusnek/bartworks/util/selfsortinglist/SSListIterators.java deleted file mode 100644 index 83b3c66046..0000000000 --- a/src/main/java/com/github/bartimaeusnek/bartworks/util/selfsortinglist/SSListIterators.java +++ /dev/null @@ -1,146 +0,0 @@ -/* - * Copyright (c) 2018-2019 bartimaeusnek - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ - -package com.github.bartimaeusnek.bartworks.util.selfsortinglist; - -import org.apache.commons.lang3.NotImplementedException; - -import java.util.Iterator; -import java.util.ListIterator; - -public class SSListIterators { - - - public static class SSListListIterator implements ListIterator { - final SSListNode head; - final SSListNode tail; - SSListNode current; - int counter = 0; - boolean reverse; - public SSListListIterator(SSListNode head,SSListNode tail, boolean reverse) { - this.head = head; - this.tail = tail; - current = reverse ? tail : head; - this.reverse = reverse; - } - - public SSListListIterator(SSList list, int index) { - this.head = list.head; - this.tail = list.tail; - current = list.getNode(index); - counter = index; - } - - @Override - public boolean hasNext() { - return reverse ? head != current : tail != current; - } - - @Override - public E next() { - counter++; - E ret = current.getELEMENT(); - current = current.getNext(); - return ret; - } - - @Override - public boolean hasPrevious() { - return !reverse ? head != current : tail != current; - } - - @Override - public E previous() { - counter--; - E ret = current.getELEMENT(); - current = current.getBefore(); - return ret; - } - - @Override - public int nextIndex() { - return counter+1; - } - - @Override - public int previousIndex() { - return counter-1; - } - - @Override - public void remove() { - throw new NotImplementedException("Not Implemented"); - } - - @Override - public void set(E e) { - throw new NotImplementedException("Not Implemented"); - } - - @Override - public void add(E e) { - throw new NotImplementedException("Not Implemented"); - } - } - - public static class SSListIterator implements Iterator { - final SSListNode head; - SSListNode current; - public SSListIterator(SSListNode head) { - this.head = this.current = head; - } - - @Override - public boolean hasNext() { - return current != null; - } - - @Override - public E next() { - E ret = current.getELEMENT(); - current = current.getNext(); - return ret; - } - } - - public static class SSListReverseIterator implements Iterator { - final SSListNode tail; - SSListNode current; - - public SSListReverseIterator(SSListNode tail) { - this.tail = this.current = tail; - } - - @Override - public boolean hasNext() { - return current != null; - } - - @Override - public E next() { - E ret = current.getELEMENT(); - current = current.getBefore(); - return ret; - } - } - -} diff --git a/src/main/java/com/github/bartimaeusnek/bartworks/util/selfsortinglist/SSListNode.java b/src/main/java/com/github/bartimaeusnek/bartworks/util/selfsortinglist/SSListNode.java deleted file mode 100644 index f9c509019e..0000000000 --- a/src/main/java/com/github/bartimaeusnek/bartworks/util/selfsortinglist/SSListNode.java +++ /dev/null @@ -1,75 +0,0 @@ -/* - * Copyright (c) 2018-2019 bartimaeusnek - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ - -package com.github.bartimaeusnek.bartworks.util.selfsortinglist; - -public class SSListNode { - - public final static SSListNode EMPTY_NODE = new SSListNode(null); - - private final E ELEMENT; - private long priority = Long.MIN_VALUE; - private SSListNode next; - private SSListNode before; - - public SSListNode(E element) { - ELEMENT = element; - } - - public SSListNode(SSListNode before, E element, SSListNode next) { - this.ELEMENT = element; - connect(next, before); - } - - public void connect(SSListNode next, SSListNode before){ - this.setNext(next); - this.setBefore(before); - } - - public E getELEMENT() { - return ELEMENT; - } - - public long getPriority() { - return priority; - } - - public void setPriority(long priority) { - this.priority = priority; - } - - public SSListNode getNext() { - return next; - } - - public void setNext(SSListNode next) { - this.next = next; - } - - public SSListNode getBefore() { - return before; - } - - public void setBefore(SSListNode before) { - this.before = before; - } -} -- cgit