Added list interfaces

This commit is contained in:
Willem Cazander 2022-10-24 07:28:15 +02:00
parent aa98c3b15f
commit 107435ec13
11 changed files with 390 additions and 48 deletions

View file

@ -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ᴿᵈ<E> {
Iteratorᴿᵈ<E> iteratorᴿᵈ();
default void forEachᴿᵈ(Consumer<? super E> action) {
iteratorᴿᵈ().forEachRemainingᴿᵈ(action);
}
default Spliterator<E> spliteratorᴿᵈ() {
return Spliterators.spliteratorUnknownSize(iteratorᴿᵈ().iteratorᴼᶠ(), Spliterator.ORDERED);
}
}

View file

@ -5,13 +5,13 @@ import love.distributedrebirth.bassboon.clazz.BãßBȍőnAuthor注;
@BãßBȍőnAuthor注(name = "للَّٰهِilLצسُو", copyright = "©Δ∞ 仙上主天") @BãßBȍőnAuthor注(name = "للَّٰهِilLצسُو", copyright = "©Δ∞ 仙上主天")
public interface Appenderᵂʳ<E> { public interface Appenderᵂʳ<E> {
boolean add(E value); boolean addᵂʳ(E value);
default boolean addAll(Collectionᴿᵈ<? extends E> c) { default boolean addAllᵂʳ(Collectionᴿᵈ<? extends E> c) {
boolean result = false; boolean result = false;
Iteratorᴿᵈ<? extends E> iterator = c.iteratorᴿᵈ(); Iteratorᴿᵈ<? extends E> iterator = c.iteratorᴿᵈ();
while (iterator.hasNext()) { while (iterator.hasNextᴿᵈ()) {
if (add(iterator.next())) { if (addᵂʳ(iterator.nextᴿᵈ())) {
result = true; result = true;
} }
} }

View file

@ -1,9 +1,11 @@
package love.distributedrebirth.bassboon.jpp.util; package love.distributedrebirth.bassboon.jpp.util;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Comparator;
import java.util.Iterator;
import java.util.List; import java.util.List;
public class ArrayListᴿᵂ<E> implements Collectionᵂʳ<E> { public class ArrayListᴿᵂ<E> implements Listᵂʳ<E>,Iterable<E> {
private final List<E> data; private final List<E> data;
@ -19,17 +21,42 @@ public class ArrayListᴿᵂ<E> implements Collectionᵂʳ<E> {
} }
@Override @Override
public Iteratorᴿᵈ<E> iteratorᴿᵈ() { public Iterator<E> iterator() {
return Iteratorᴿᵈ.wrap(data.iterator()); return data.iterator();
} }
@Override @Override
public boolean add(E value) { public Iteratorᴿᵈ<E> iteratorᴿᵈ() {
return Iteratorᴿᵈ.wrapᴼᶠ(iterator());
}
@Override
public boolean addᵂʳ(E value) {
return data.add(value); return data.add(value);
} }
@Override @Override
public boolean remove(Object o) { public boolean removeᵂʳ(Object o) {
return data.remove(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<? super E> c) {
data.sort(c);
}
} }

View file

@ -1,31 +1,29 @@
package love.distributedrebirth.bassboon.jpp.util; package love.distributedrebirth.bassboon.jpp.util;
import java.util.Spliterator; import java.util.Spliterator;
import java.util.Spliterators;
import java.util.stream.Collectors; import java.util.stream.Collectors;
import java.util.stream.Stream; import java.util.stream.Stream;
import java.util.stream.StreamSupport; import java.util.stream.StreamSupport;
import love.distributedrebirth.bassboon.clazz.BãßBȍőnAuthor注; import love.distributedrebirth.bassboon.clazz.BãßBȍőnAuthor注;
import love.distributedrebirth.bassboon.jpp.lang.Iterableᴿᵈ;
@BãßBȍőnAuthor注(name = "للَّٰهِilLצسُو", copyright = "©Δ∞ 仙上主天") @BãßBȍőnAuthor注(name = "للَّٰهِilLצسُو", copyright = "©Δ∞ 仙上主天")
public interface Collectionᴿᵈ<E> { public interface Collectionᴿᵈ<E> extends Iterableᴿᵈ<E> {
Iteratorᴿᵈ<E> iteratorᴿᵈ(); default int sizeᴿᵈ() {
default int size() {
return (int) streamᴿᵈ().count(); return (int) streamᴿᵈ().count();
} }
default boolean isEmpty() { default boolean isEmptyᴿᵈ() {
return iteratorᴿᵈ().hasNext() == false; return iteratorᴿᵈ().hasNextᴿᵈ() == false;
} }
default boolean contains(Object obj) { default boolean containsᴿᵈ(Object obj) {
return streamᴿᵈ().collect(Collectors.toSet()).contains(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())); return streamᴿᵈ().collect(Collectors.toSet()).containsAll(set.streamᴿᵈ().collect(Collectors.toSet()));
} }
@ -33,19 +31,19 @@ public interface Collectionᴿᵈ<E> {
return streamᴿᵈ().parallel(); return streamᴿᵈ().parallel();
} }
default Spliterator<E> spliterator() { default Spliterator<E> spliteratorᴿᵈ() {
return streamᴿᵈ().spliterator(); return streamᴿᵈ().spliterator();
} }
default Object[] toArray() { default Object[] toArrayᴿᵈ() {
return streamᴿᵈ().collect(Collectors.toList()).toArray(); return streamᴿᵈ().collect(Collectors.toList()).toArray();
} }
default <T> T[] toArray(T[] arr) { default <T> T[] toArrayᴿᵈ(T[] arr) {
return streamᴿᵈ().collect(Collectors.toList()).toArray(arr); return streamᴿᵈ().collect(Collectors.toList()).toArray(arr);
} }
default Stream<E> streamᴿᵈ() { default Stream<E> streamᴿᵈ() {
return StreamSupport.stream(Spliterators.spliteratorUnknownSize(Iteratorᴿᵈ.wrap(iteratorᴿᵈ()), Spliterator.ORDERED), false); return StreamSupport.stream(spliteratorᴿᵈ(), false);
} }
} }

View file

@ -8,17 +8,17 @@ import love.distributedrebirth.bassboon.clazz.BãßBȍőnAuthor注;
@BãßBȍőnAuthor注(name = "للَّٰهِilLצسُو", copyright = "©Δ∞ 仙上主天") @BãßBȍőnAuthor注(name = "للَّٰهِilLצسُو", copyright = "©Δ∞ 仙上主天")
public interface Collectionᵂʳ<E> extends Collectionᴿᵈ<E>, Appenderᵂʳ<E> { public interface Collectionᵂʳ<E> extends Collectionᴿᵈ<E>, Appenderᵂʳ<E> {
boolean remove(Object o); boolean removeᵂʳ(Object o);
default void clear() { default void clearᵂʳ() {
streamᴿᵈ().collect(Collectors.toList()).forEach(v -> remove(v)); streamᴿᵈ().collect(Collectors.toList()).forEach(v -> removeᵂʳ(v));
} }
default boolean removeAll(Collectionᴿᵈ<?> set) { default boolean removeAll(Collectionᴿᵈ<?> set) {
boolean result = false; boolean result = false;
Iteratorᴿᵈ<?> iterator = set.iteratorᴿᵈ(); Iteratorᴿᵈ<?> iterator = set.iteratorᴿᵈ();
while (iterator.hasNext()) { while (iterator.hasNextᴿᵈ()) {
if (remove(iterator.next())) { if (removeᵂʳ(iterator.nextᴿᵈ())) {
result = true; result = true;
} }
} }
@ -29,7 +29,7 @@ public interface Collectionᵂʳ<E> extends Collectionᴿᵈ<E>, Appenderᵂʳ<E
Collectionᴿᵈ<E> delete = new Collectionᴿᵈ<>() { Collectionᴿᵈ<E> delete = new Collectionᴿᵈ<>() {
@Override @Override
public Iteratorᴿᵈ<E> iteratorᴿᵈ() { public Iteratorᴿᵈ<E> iteratorᴿᵈ() {
return Iteratorᴿᵈ.wrap(streamᴿᵈ().filter(filter).collect(Collectors.toList()).iterator()); return Iteratorᴿᵈ.wrapᴼᶠ(streamᴿᵈ().filter(filter).collect(Collectors.toList()).iterator());
} }
}; };
return removeAll(delete); return removeAll(delete);
@ -38,8 +38,8 @@ public interface Collectionᵂʳ<E> extends Collectionᴿᵈ<E>, Appenderᵂʳ<E
default boolean retainAll(Collectionᴿᵈ<?> set) { default boolean retainAll(Collectionᴿᵈ<?> set) {
boolean result = false; boolean result = false;
for (E e:streamᴿᵈ().collect(Collectors.toList())) { for (E e:streamᴿᵈ().collect(Collectors.toList())) {
if (!set.contains(e)) { if (!set.containsᴿᵈ(e)) {
remove(e); removeᵂʳ(e);
result = true; result = true;
} }
} }

View file

@ -1,47 +1,50 @@
package love.distributedrebirth.bassboon.jpp.util; package love.distributedrebirth.bassboon.jpp.util;
import java.util.Iterator; import java.util.Iterator;
import java.util.Spliterator;
import java.util.Spliterators;
import java.util.function.Consumer; import java.util.function.Consumer;
import java.util.stream.StreamSupport;
import love.distributedrebirth.bassboon.clazz.BãßBȍőnAuthor注; import love.distributedrebirth.bassboon.clazz.BãßBȍőnAuthor注;
@BãßBȍőnAuthor注(name = "للَّٰهِilLצسُو", copyright = "©Δ∞ 仙上主天") @BãßBȍőnAuthor注(name = "للَّٰهِilLצسُو", copyright = "©Δ∞ 仙上主天")
public interface Iteratorᴿᵈ<E> { public interface Iteratorᴿᵈ<E> {
boolean hasNext(); boolean hasNextᴿᵈ();
E next(); E nextᴿᵈ();
default void forEachRemaining(Consumer<? super E> action) { default void forEachRemainingᴿᵈ(Consumer<? super E> action) {
StreamSupport.stream(Spliterators.spliteratorUnknownSize(wrap(this), Spliterator.ORDERED), false).forEach(action); while (hasNextᴿᵈ()) {
action.accept(nextᴿᵈ());
}
} }
static <T> Iterator<T> wrap(Iteratorᴿᵈ<T> iterator) { default Iterator<E> iteratorᴼᶠ() {
return wrapᴼᶠ(this);
}
static <T> Iterator<T> wrapᴼᶠ(Iteratorᴿᵈ<T> iterator) {
return new Iterator<>() { return new Iterator<>() {
@Override @Override
public boolean hasNext() { public boolean hasNext() {
return iterator.hasNext(); return iterator.hasNextᴿᵈ();
} }
@Override @Override
public T next() { public T next() {
return iterator.next(); return iterator.nextᴿᵈ();
} }
}; };
} }
static <T> Iteratorᴿᵈ<T> wrap(Iterator<T> iterator) { static <T> Iteratorᴿᵈ<T> wrapᴼᶠ(Iterator<T> iterator) {
return new Iteratorᴿᵈ<>() { return new Iteratorᴿᵈ<>() {
@Override @Override
public boolean hasNext() { public boolean hasNextᴿᵈ() {
return iterator.hasNext(); return iterator.hasNext();
} }
@Override @Override
public T next() { public T nextᴿᵈ() {
return iterator.next(); return iterator.next();
} }
}; };

View file

@ -1,10 +1,54 @@
package love.distributedrebirth.bassboon.jpp.util; package love.distributedrebirth.bassboon.jpp.util;
import java.util.Iterator;
import love.distributedrebirth.bassboon.clazz.BãßBȍőnAuthor注; import love.distributedrebirth.bassboon.clazz.BãßBȍőnAuthor注;
@BãßBȍőnAuthor注(name = "للَّٰهِilLצسُو", copyright = "©Δ∞ 仙上主天") @BãßBȍőnAuthor注(name = "للَّٰهِilLצسُو", copyright = "©Δ∞ 仙上主天")
public interface Iteratorᵂʳ<E> extends Iteratorᴿᵈ<E> { public interface Iteratorᵂʳ<E> extends Iteratorᴿᵈ<E> {
default void remove() { default void removeᵂʳ() {
}
default Iterator<E> iteratorᴼᶠ() {
return wrapᴼᶠ(this);
}
static <T> Iterator<T> wrapᴼᶠ(Iteratorᵂʳ<T> 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 <T> Iteratorᵂʳ<T> wrapᴼᶠ(Iterator<T> iterator) {
return new Iteratorᵂʳ<>() {
@Override
public boolean hasNextᴿᵈ() {
return iterator.hasNext();
}
@Override
public T nextᴿᵈ() {
return iterator.next();
}
@Override
public void removeᵂʳ() {
iterator.remove();
}
};
} }
} }

View file

@ -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ᴿᵈ<E> extends Iteratorᴿᵈ<E> {
boolean hasPreviousᴿᵈ();
int nextIndexᴿᵈ();
E previousᴿᵈ();
int previousIndexᴿᵈ();
static <T> ListIteratorᴿᵈ<T> wrapᴼᶠ(ListIterator<T> 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();
}
};
}
}

View file

@ -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ᵂʳ<E> extends ListIteratorᴿᵈ<E>,Iteratorᵂʳ<E> {
void addᵂʳ(E e);
void setᵂʳ(E e);
default ListIterator<E> iteratorᴼᶠ() {
return wrapᴼᶠ(this);
}
static <T> ListIterator<T> wrapᴼᶠ(ListIteratorᵂʳ<T> 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 <T> ListIteratorᵂʳ<T> wrapᴼᶠ(ListIterator<T> 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);
}
};
}
}

View file

@ -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ᴿᵈ<E> extends Collectionᴿᵈ<E> {
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ᴿᵈ<E> listIteratorᴿᵈ() {
return listIteratorᴿᵈ(0);
}
default ListIteratorᴿᵈ<E> listIteratorᴿᵈ(int index) {
return ListIteratorᴿᵈ.wrapᴼᶠ(streamᴿᵈ().collect(Collectors.toList()).listIterator(index));
}
default Listᴿᵈ<E> 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> T[] toArrayᴿᵈ(T[] arr) {
return streamᴿᵈ().collect(Collectors.toList()).toArray(arr);
}
}

View file

@ -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ᵂʳ<E> extends Listᴿᵈ<E>, Collectionᵂʳ<E> {
void addᵂʳ(int index, E element);
default boolean addAllᵂʳ(int index, Collectionᴿᵈ<? extends E> c) {
Iteratorᴿᵈ<? extends E> iterator = c.iteratorᴿᵈ();
boolean result = iterator.hasNextᴿᵈ();
while (iterator.hasNextᴿᵈ()) {
addᵂʳ(index, iterator.nextᴿᵈ());
}
return result;
}
E removeᵂʳ(int index);
default void replaceAllᵂʳ(UnaryOperator<E> operator) {
for (int i=0;i<sizeᴿᵈ();i++) {
setᵂʳ(i, operator.apply(getᴿᵈ(i)));
}
}
E setᵂʳ(int index, E element);
/* default */ void sortᵂʳ(Comparator<? super E> c);
default ListIteratorᵂʳ<E> listIteratorᵂʳ() {
return listIteratorᵂʳ();
}
default ListIteratorᵂʳ<E> listIteratorᵂʳ(int index) {
return ListIteratorᵂʳ.wrapᴼᶠ(streamᴿᵈ().collect(Collectors.toList()).listIterator(index));
}
default Listᵂʳ<E> subListᵂʳ(int fromIndex, int toIndex) {
return new ArrayListᴿᵂ<>(streamᴿᵈ().collect(Collectors.toList()).subList(fromIndex, toIndex));
}
}