diff --git a/gdxapp4d-lib-bassboonyd/src/main/java/love/distributedrebirth/bassboon/jpp/lang/Iterableᴿᵈ.java b/gdxapp4d-lib-bassboonyd/src/main/java/love/distributedrebirth/bassboon/jpp/lang/Iterableᴿᵈ.java new file mode 100644 index 00000000..84223e88 --- /dev/null +++ b/gdxapp4d-lib-bassboonyd/src/main/java/love/distributedrebirth/bassboon/jpp/lang/Iterableᴿᵈ.java @@ -0,0 +1,22 @@ +package love.distributedrebirth.bassboon.jpp.lang; + +import java.util.Spliterator; +import java.util.Spliterators; +import java.util.function.Consumer; + +import love.distributedrebirth.bassboon.clazz.BãßBȍőnAuthor注; +import love.distributedrebirth.bassboon.jpp.util.Iteratorᴿᵈ; + +@BãßBȍőnAuthor注(name = "للَّٰهِilLצسُو", copyright = "©Δ∞ 仙上主天") +public interface Iterableᴿᵈ { + + Iteratorᴿᵈ iteratorᴿᵈ(); + + default void forEachᴿᵈ(Consumer action) { + iteratorᴿᵈ().forEachRemainingᴿᵈ(action); + } + + default Spliterator spliteratorᴿᵈ() { + return Spliterators.spliteratorUnknownSize(iteratorᴿᵈ().iteratorᴼᶠ(), Spliterator.ORDERED); + } +} diff --git a/gdxapp4d-lib-bassboonyd/src/main/java/love/distributedrebirth/bassboon/jpp/util/Appenderᵂʳ.java b/gdxapp4d-lib-bassboonyd/src/main/java/love/distributedrebirth/bassboon/jpp/util/Appenderᵂʳ.java index 36b447f3..43a8b7a6 100644 --- a/gdxapp4d-lib-bassboonyd/src/main/java/love/distributedrebirth/bassboon/jpp/util/Appenderᵂʳ.java +++ b/gdxapp4d-lib-bassboonyd/src/main/java/love/distributedrebirth/bassboon/jpp/util/Appenderᵂʳ.java @@ -5,13 +5,13 @@ import love.distributedrebirth.bassboon.clazz.BãßBȍőnAuthor注; @BãßBȍőnAuthor注(name = "للَّٰهِilLצسُو", copyright = "©Δ∞ 仙上主天") public interface Appenderᵂʳ { - boolean add(E value); + boolean addᵂʳ(E value); - default boolean addAll(Collectionᴿᵈ c) { + default boolean addAllᵂʳ(Collectionᴿᵈ c) { boolean result = false; Iteratorᴿᵈ iterator = c.iteratorᴿᵈ(); - while (iterator.hasNext()) { - if (add(iterator.next())) { + while (iterator.hasNextᴿᵈ()) { + if (addᵂʳ(iterator.nextᴿᵈ())) { result = true; } } diff --git a/gdxapp4d-lib-bassboonyd/src/main/java/love/distributedrebirth/bassboon/jpp/util/ArrayListᴿᵂ.java b/gdxapp4d-lib-bassboonyd/src/main/java/love/distributedrebirth/bassboon/jpp/util/ArrayListᴿᵂ.java index af22280c..05f87183 100644 --- a/gdxapp4d-lib-bassboonyd/src/main/java/love/distributedrebirth/bassboon/jpp/util/ArrayListᴿᵂ.java +++ b/gdxapp4d-lib-bassboonyd/src/main/java/love/distributedrebirth/bassboon/jpp/util/ArrayListᴿᵂ.java @@ -1,9 +1,11 @@ package love.distributedrebirth.bassboon.jpp.util; import java.util.ArrayList; +import java.util.Comparator; +import java.util.Iterator; import java.util.List; -public class ArrayListᴿᵂ implements Collectionᵂʳ { +public class ArrayListᴿᵂ implements Listᵂʳ,Iterable { private final List data; @@ -19,17 +21,42 @@ public class ArrayListᴿᵂ implements Collectionᵂʳ { } @Override - public Iteratorᴿᵈ iteratorᴿᵈ() { - return Iteratorᴿᵈ.wrap(data.iterator()); + public Iterator iterator() { + return data.iterator(); } - + @Override - public boolean add(E value) { + public Iteratorᴿᵈ iteratorᴿᵈ() { + return Iteratorᴿᵈ.wrapᴼᶠ(iterator()); + } + + @Override + public boolean addᵂʳ(E value) { return data.add(value); } - + @Override - public boolean remove(Object o) { + public boolean removeᵂʳ(Object o) { return data.remove(o); } + + @Override + public void addᵂʳ(int index, E element) { + data.add(index, element); + } + + @Override + public E removeᵂʳ(int index) { + return data.remove(index); + } + + @Override + public E setᵂʳ(int index, E element) { + return data.set(index, element); + } + + @Override + public void sortᵂʳ(Comparator c) { + data.sort(c); + } } diff --git a/gdxapp4d-lib-bassboonyd/src/main/java/love/distributedrebirth/bassboon/jpp/util/Collectionᴿᵈ.java b/gdxapp4d-lib-bassboonyd/src/main/java/love/distributedrebirth/bassboon/jpp/util/Collectionᴿᵈ.java index a16dc21f..32368100 100644 --- a/gdxapp4d-lib-bassboonyd/src/main/java/love/distributedrebirth/bassboon/jpp/util/Collectionᴿᵈ.java +++ b/gdxapp4d-lib-bassboonyd/src/main/java/love/distributedrebirth/bassboon/jpp/util/Collectionᴿᵈ.java @@ -1,31 +1,29 @@ package love.distributedrebirth.bassboon.jpp.util; import java.util.Spliterator; -import java.util.Spliterators; import java.util.stream.Collectors; import java.util.stream.Stream; import java.util.stream.StreamSupport; import love.distributedrebirth.bassboon.clazz.BãßBȍőnAuthor注; +import love.distributedrebirth.bassboon.jpp.lang.Iterableᴿᵈ; @BãßBȍőnAuthor注(name = "للَّٰهِilLצسُو", copyright = "©Δ∞ 仙上主天") -public interface Collectionᴿᵈ { +public interface Collectionᴿᵈ extends Iterableᴿᵈ { - Iteratorᴿᵈ iteratorᴿᵈ(); - - default int size() { + default int sizeᴿᵈ() { return (int) streamᴿᵈ().count(); } - default boolean isEmpty() { - return iteratorᴿᵈ().hasNext() == false; + default boolean isEmptyᴿᵈ() { + return iteratorᴿᵈ().hasNextᴿᵈ() == false; } - default boolean contains(Object obj) { + default boolean containsᴿᵈ(Object obj) { return streamᴿᵈ().collect(Collectors.toSet()).contains(obj); } - default boolean containsAll(Collectionᴿᵈ set) { + default boolean containsAllᴿᵈ(Collectionᴿᵈ set) { return streamᴿᵈ().collect(Collectors.toSet()).containsAll(set.streamᴿᵈ().collect(Collectors.toSet())); } @@ -33,19 +31,19 @@ public interface Collectionᴿᵈ { return streamᴿᵈ().parallel(); } - default Spliterator spliterator() { + default Spliterator spliteratorᴿᵈ() { return streamᴿᵈ().spliterator(); } - default Object[] toArray() { + default Object[] toArrayᴿᵈ() { return streamᴿᵈ().collect(Collectors.toList()).toArray(); } - default T[] toArray(T[] arr) { + default T[] toArrayᴿᵈ(T[] arr) { return streamᴿᵈ().collect(Collectors.toList()).toArray(arr); } default Stream streamᴿᵈ() { - return StreamSupport.stream(Spliterators.spliteratorUnknownSize(Iteratorᴿᵈ.wrap(iteratorᴿᵈ()), Spliterator.ORDERED), false); + return StreamSupport.stream(spliteratorᴿᵈ(), false); } } diff --git a/gdxapp4d-lib-bassboonyd/src/main/java/love/distributedrebirth/bassboon/jpp/util/Collectionᵂʳ.java b/gdxapp4d-lib-bassboonyd/src/main/java/love/distributedrebirth/bassboon/jpp/util/Collectionᵂʳ.java index 94fe2241..c2fe1cb5 100644 --- a/gdxapp4d-lib-bassboonyd/src/main/java/love/distributedrebirth/bassboon/jpp/util/Collectionᵂʳ.java +++ b/gdxapp4d-lib-bassboonyd/src/main/java/love/distributedrebirth/bassboon/jpp/util/Collectionᵂʳ.java @@ -8,17 +8,17 @@ import love.distributedrebirth.bassboon.clazz.BãßBȍőnAuthor注; @BãßBȍőnAuthor注(name = "للَّٰهِilLצسُو", copyright = "©Δ∞ 仙上主天") public interface Collectionᵂʳ extends Collectionᴿᵈ, Appenderᵂʳ { - boolean remove(Object o); + boolean removeᵂʳ(Object o); - default void clear() { - streamᴿᵈ().collect(Collectors.toList()).forEach(v -> remove(v)); + default void clearᵂʳ() { + streamᴿᵈ().collect(Collectors.toList()).forEach(v -> removeᵂʳ(v)); } default boolean removeAll(Collectionᴿᵈ set) { boolean result = false; Iteratorᴿᵈ iterator = set.iteratorᴿᵈ(); - while (iterator.hasNext()) { - if (remove(iterator.next())) { + while (iterator.hasNextᴿᵈ()) { + if (removeᵂʳ(iterator.nextᴿᵈ())) { result = true; } } @@ -29,7 +29,7 @@ public interface Collectionᵂʳ extends Collectionᴿᵈ, Appenderᵂʳ delete = new Collectionᴿᵈ<>() { @Override public Iteratorᴿᵈ iteratorᴿᵈ() { - return Iteratorᴿᵈ.wrap(streamᴿᵈ().filter(filter).collect(Collectors.toList()).iterator()); + return Iteratorᴿᵈ.wrapᴼᶠ(streamᴿᵈ().filter(filter).collect(Collectors.toList()).iterator()); } }; return removeAll(delete); @@ -38,8 +38,8 @@ public interface Collectionᵂʳ extends Collectionᴿᵈ, Appenderᵂʳ set) { boolean result = false; for (E e:streamᴿᵈ().collect(Collectors.toList())) { - if (!set.contains(e)) { - remove(e); + if (!set.containsᴿᵈ(e)) { + removeᵂʳ(e); result = true; } } diff --git a/gdxapp4d-lib-bassboonyd/src/main/java/love/distributedrebirth/bassboon/jpp/util/Iteratorᴿᵈ.java b/gdxapp4d-lib-bassboonyd/src/main/java/love/distributedrebirth/bassboon/jpp/util/Iteratorᴿᵈ.java index 8e463995..dbdb38be 100644 --- a/gdxapp4d-lib-bassboonyd/src/main/java/love/distributedrebirth/bassboon/jpp/util/Iteratorᴿᵈ.java +++ b/gdxapp4d-lib-bassboonyd/src/main/java/love/distributedrebirth/bassboon/jpp/util/Iteratorᴿᵈ.java @@ -1,47 +1,50 @@ package love.distributedrebirth.bassboon.jpp.util; import java.util.Iterator; -import java.util.Spliterator; -import java.util.Spliterators; import java.util.function.Consumer; -import java.util.stream.StreamSupport; import love.distributedrebirth.bassboon.clazz.BãßBȍőnAuthor注; @BãßBȍőnAuthor注(name = "للَّٰهِilLצسُو", copyright = "©Δ∞ 仙上主天") public interface Iteratorᴿᵈ { - boolean hasNext(); + boolean hasNextᴿᵈ(); - E next(); + E nextᴿᵈ(); - default void forEachRemaining(Consumer action) { - StreamSupport.stream(Spliterators.spliteratorUnknownSize(wrap(this), Spliterator.ORDERED), false).forEach(action); + default void forEachRemainingᴿᵈ(Consumer action) { + while (hasNextᴿᵈ()) { + action.accept(nextᴿᵈ()); + } } - static Iterator wrap(Iteratorᴿᵈ iterator) { + default Iterator iteratorᴼᶠ() { + return wrapᴼᶠ(this); + } + + static Iterator wrapᴼᶠ(Iteratorᴿᵈ iterator) { return new Iterator<>() { @Override public boolean hasNext() { - return iterator.hasNext(); + return iterator.hasNextᴿᵈ(); } - + @Override public T next() { - return iterator.next(); + return iterator.nextᴿᵈ(); } }; } - static Iteratorᴿᵈ wrap(Iterator iterator) { + static Iteratorᴿᵈ wrapᴼᶠ(Iterator iterator) { return new Iteratorᴿᵈ<>() { @Override - public boolean hasNext() { + public boolean hasNextᴿᵈ() { return iterator.hasNext(); } - + @Override - public T next() { + public T nextᴿᵈ() { return iterator.next(); } }; diff --git a/gdxapp4d-lib-bassboonyd/src/main/java/love/distributedrebirth/bassboon/jpp/util/Iteratorᵂʳ.java b/gdxapp4d-lib-bassboonyd/src/main/java/love/distributedrebirth/bassboon/jpp/util/Iteratorᵂʳ.java index 5006de49..7ab5d94a 100644 --- a/gdxapp4d-lib-bassboonyd/src/main/java/love/distributedrebirth/bassboon/jpp/util/Iteratorᵂʳ.java +++ b/gdxapp4d-lib-bassboonyd/src/main/java/love/distributedrebirth/bassboon/jpp/util/Iteratorᵂʳ.java @@ -1,10 +1,54 @@ package love.distributedrebirth.bassboon.jpp.util; +import java.util.Iterator; + import love.distributedrebirth.bassboon.clazz.BãßBȍőnAuthor注; @BãßBȍőnAuthor注(name = "للَّٰهِilLצسُو", copyright = "©Δ∞ 仙上主天") public interface Iteratorᵂʳ extends Iteratorᴿᵈ { - default void remove() { + default void removeᵂʳ() { + } + + default Iterator iteratorᴼᶠ() { + return wrapᴼᶠ(this); + } + + static Iterator wrapᴼᶠ(Iteratorᵂʳ iterator) { + return new Iterator<>() { + @Override + public boolean hasNext() { + return iterator.hasNextᴿᵈ(); + } + + @Override + public T next() { + return iterator.nextᴿᵈ(); + } + + @Override + public void remove() { + iterator.removeᵂʳ(); + } + }; + } + + static Iteratorᵂʳ wrapᴼᶠ(Iterator iterator) { + return new Iteratorᵂʳ<>() { + @Override + public boolean hasNextᴿᵈ() { + return iterator.hasNext(); + } + + @Override + public T nextᴿᵈ() { + return iterator.next(); + } + + @Override + public void removeᵂʳ() { + iterator.remove(); + } + }; } } diff --git a/gdxapp4d-lib-bassboonyd/src/main/java/love/distributedrebirth/bassboon/jpp/util/ListIteratorᴿᵈ.java b/gdxapp4d-lib-bassboonyd/src/main/java/love/distributedrebirth/bassboon/jpp/util/ListIteratorᴿᵈ.java new file mode 100644 index 00000000..ba79b0b6 --- /dev/null +++ b/gdxapp4d-lib-bassboonyd/src/main/java/love/distributedrebirth/bassboon/jpp/util/ListIteratorᴿᵈ.java @@ -0,0 +1,51 @@ +package love.distributedrebirth.bassboon.jpp.util; + +import java.util.ListIterator; + +import love.distributedrebirth.bassboon.clazz.BãßBȍőnAuthor注; + +@BãßBȍőnAuthor注(name = "للَّٰهِilLצسُو", copyright = "©Δ∞ 仙上主天") +public interface ListIteratorᴿᵈ extends Iteratorᴿᵈ { + + boolean hasPreviousᴿᵈ(); + + int nextIndexᴿᵈ(); + + E previousᴿᵈ(); + + int previousIndexᴿᵈ(); + + static ListIteratorᴿᵈ wrapᴼᶠ(ListIterator iterator) { + return new ListIteratorᴿᵈ<>() { + @Override + public boolean hasNextᴿᵈ() { + return iterator.hasNext(); + } + + @Override + public T nextᴿᵈ() { + return iterator.next(); + } + + @Override + public boolean hasPreviousᴿᵈ() { + return iterator.hasPrevious(); + } + + @Override + public int nextIndexᴿᵈ() { + return iterator.nextIndex(); + } + + @Override + public T previousᴿᵈ() { + return iterator.previous(); + } + + @Override + public int previousIndexᴿᵈ() { + return iterator.previousIndex(); + } + }; + } +} diff --git a/gdxapp4d-lib-bassboonyd/src/main/java/love/distributedrebirth/bassboon/jpp/util/ListIteratorᵂʳ.java b/gdxapp4d-lib-bassboonyd/src/main/java/love/distributedrebirth/bassboon/jpp/util/ListIteratorᵂʳ.java new file mode 100644 index 00000000..65c1df26 --- /dev/null +++ b/gdxapp4d-lib-bassboonyd/src/main/java/love/distributedrebirth/bassboon/jpp/util/ListIteratorᵂʳ.java @@ -0,0 +1,110 @@ +package love.distributedrebirth.bassboon.jpp.util; + +import java.util.ListIterator; + +import love.distributedrebirth.bassboon.clazz.BãßBȍőnAuthor注; + +@BãßBȍőnAuthor注(name = "للَّٰهِilLצسُو", copyright = "©Δ∞ 仙上主天") +public interface ListIteratorᵂʳ extends ListIteratorᴿᵈ,Iteratorᵂʳ { + + void addᵂʳ(E e); + + void setᵂʳ(E e); + + default ListIterator iteratorᴼᶠ() { + return wrapᴼᶠ(this); + } + + static ListIterator wrapᴼᶠ(ListIteratorᵂʳ iterator) { + return new ListIterator<>() { + @Override + public boolean hasNext() { + return iterator.hasNextᴿᵈ(); + } + + @Override + public T next() { + return iterator.nextᴿᵈ(); + } + + @Override + public void add(T arg0) { + iterator.addᵂʳ(arg0); + } + + @Override + public boolean hasPrevious() { + return iterator.hasPreviousᴿᵈ(); + } + + @Override + public int nextIndex() { + return iterator.nextIndexᴿᵈ(); + } + + @Override + public T previous() { + return iterator.previousᴿᵈ(); + } + + @Override + public int previousIndex() { + return iterator.previousIndexᴿᵈ(); + } + + @Override + public void remove() { + iterator.removeᵂʳ(); + } + + @Override + public void set(T arg0) { + iterator.setᵂʳ(arg0); + } + }; + } + + static ListIteratorᵂʳ wrapᴼᶠ(ListIterator iterator) { + return new ListIteratorᵂʳ<>() { + @Override + public boolean hasNextᴿᵈ() { + return iterator.hasNext(); + } + + @Override + public T nextᴿᵈ() { + return iterator.next(); + } + + @Override + public boolean hasPreviousᴿᵈ() { + return iterator.hasPrevious(); + } + + @Override + public int nextIndexᴿᵈ() { + return iterator.nextIndex(); + } + + @Override + public T previousᴿᵈ() { + return iterator.previous(); + } + + @Override + public int previousIndexᴿᵈ() { + return iterator.previousIndex(); + } + + @Override + public void addᵂʳ(T e) { + iterator.add(e); + } + + @Override + public void setᵂʳ(T e) { + iterator.set(e); + } + }; + } +} diff --git a/gdxapp4d-lib-bassboonyd/src/main/java/love/distributedrebirth/bassboon/jpp/util/Listᴿᵈ.java b/gdxapp4d-lib-bassboonyd/src/main/java/love/distributedrebirth/bassboon/jpp/util/Listᴿᵈ.java new file mode 100644 index 00000000..752a5c5f --- /dev/null +++ b/gdxapp4d-lib-bassboonyd/src/main/java/love/distributedrebirth/bassboon/jpp/util/Listᴿᵈ.java @@ -0,0 +1,41 @@ +package love.distributedrebirth.bassboon.jpp.util; + +import java.util.stream.Collectors; + +import love.distributedrebirth.bassboon.clazz.BãßBȍőnAuthor注; + +@BãßBȍőnAuthor注(name = "للَّٰهِilLצسُو", copyright = "©Δ∞ 仙上主天") +public interface Listᴿᵈ extends Collectionᴿᵈ { + + default E getᴿᵈ(int index) { + return streamᴿᵈ().skip(index).collect(Collectors.toList()).get(0); + } + + default int indexOfᴿᵈ(Object o) { + return streamᴿᵈ().collect(Collectors.toList()).indexOf(o); + } + + default int lastIndexOfᴿᵈ(Object o) { + return streamᴿᵈ().collect(Collectors.toList()).lastIndexOf(o); + } + + default ListIteratorᴿᵈ listIteratorᴿᵈ() { + return listIteratorᴿᵈ(0); + } + + default ListIteratorᴿᵈ listIteratorᴿᵈ(int index) { + return ListIteratorᴿᵈ.wrapᴼᶠ(streamᴿᵈ().collect(Collectors.toList()).listIterator(index)); + } + + default Listᴿᵈ subListᴿᵈ(int fromIndex, int toIndex) { + return new ArrayListᴿᵂ<>(streamᴿᵈ().collect(Collectors.toList()).subList(fromIndex, toIndex)); + } + + default Object[] toArrayᴿᵈ() { + return streamᴿᵈ().collect(Collectors.toList()).toArray(); + } + + default T[] toArrayᴿᵈ(T[] arr) { + return streamᴿᵈ().collect(Collectors.toList()).toArray(arr); + } +} diff --git a/gdxapp4d-lib-bassboonyd/src/main/java/love/distributedrebirth/bassboon/jpp/util/Listᵂʳ.java b/gdxapp4d-lib-bassboonyd/src/main/java/love/distributedrebirth/bassboon/jpp/util/Listᵂʳ.java new file mode 100644 index 00000000..a01998e6 --- /dev/null +++ b/gdxapp4d-lib-bassboonyd/src/main/java/love/distributedrebirth/bassboon/jpp/util/Listᵂʳ.java @@ -0,0 +1,46 @@ +package love.distributedrebirth.bassboon.jpp.util; + +import java.util.Comparator; +import java.util.function.UnaryOperator; +import java.util.stream.Collectors; + +import love.distributedrebirth.bassboon.clazz.BãßBȍőnAuthor注; + +@BãßBȍőnAuthor注(name = "للَّٰهِilLצسُو", copyright = "©Δ∞ 仙上主天") +public interface Listᵂʳ extends Listᴿᵈ, Collectionᵂʳ { + + void addᵂʳ(int index, E element); + + default boolean addAllᵂʳ(int index, Collectionᴿᵈ c) { + Iteratorᴿᵈ iterator = c.iteratorᴿᵈ(); + boolean result = iterator.hasNextᴿᵈ(); + while (iterator.hasNextᴿᵈ()) { + addᵂʳ(index, iterator.nextᴿᵈ()); + } + return result; + } + + E removeᵂʳ(int index); + + default void replaceAllᵂʳ(UnaryOperator operator) { + for (int i=0;i c); + + default ListIteratorᵂʳ listIteratorᵂʳ() { + return listIteratorᵂʳ(); + } + + default ListIteratorᵂʳ listIteratorᵂʳ(int index) { + return ListIteratorᵂʳ.wrapᴼᶠ(streamᴿᵈ().collect(Collectors.toList()).listIterator(index)); + } + + default Listᵂʳ subListᵂʳ(int fromIndex, int toIndex) { + return new ArrayListᴿᵂ<>(streamᴿᵈ().collect(Collectors.toList()).subList(fromIndex, toIndex)); + } +}