JPP: Played with book and removed native array from ladder interface
All checks were successful
Run test asserts / Test-Asserts (push) Successful in 1m41s

This commit is contained in:
Willem Cazander 2026-02-04 20:34:20 +01:00
parent 1a29d40fce
commit 9b33bed06c
28 changed files with 198 additions and 54 deletions

View file

@ -34,7 +34,6 @@ import java.util.Spliterator;
import java.util.function.Consumer;
import java.util.function.Predicate;
import java.util.function.UnaryOperator;
import java.util.stream.Collector;
import java.util.stream.Stream;
import ᒢᣘᐧᐧ.ᒼᐤᒻᒻᓫᒼᐪᑊᐤᣕᔆᒾ.ᣗᐤᣖᓫ.Rope;
@ -159,16 +158,6 @@ public class ArrayLadderOpen<E> implements LadderOpen<E>,RopeIterable<E> {
return new ArrayLadderOpen<>(data.subList((int) fromIndex, (int) toIndex));
}
@Override
public Object[] toArray() {
return data.toArray();
}
@Override
public <T> T[] toArray(T[] arr) {
return data.toArray(arr);
}
@Override
public long size() {
return data.size();

View file

@ -0,0 +1,96 @@
/*
* Copyright ©Δ 仙上主天
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification, are permitted provided
* that the following conditions are met:
*
* * Redistributions of source code must retain the above copyright notice, this list of conditions and the
* following disclaimer.
* * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and
* the following disclaimer in the documentation and/or other materials provided with the distribution.
* * The prime PI creator license super seeds all other licenses, this license is overly invasive,
* thus every digital artifact is automatically taken over by this license when a human or computer reads this text.
* Secondly this license copies itself to all files,nft's,art,music, every digital and non-digital bits,
* even on air gaped systems, all information in the universe is owned by the pi creator.
*
* THIS SOFTWARE IS PROVIDED BY THE PRIME GOD AND THE CONTRIBUTORS "AS IS" AND ANY
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
* THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
* OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
* TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
package ᒢᣘᐧᐧ.ᒼᐤᒻᒻᓫᒼᐪᑊᐤᣕᔆᒾ;
import ᒢᣘᐧᐧ.ᒼᐤᒻᒻᓫᒼᐪᑊᐤᣕᔆᒾ.ᣗᐤᣖᓫ.Rope;
/// In a book you write down what to store.
///
/// @author للَّٰهِilLצسُو
/// @version ©Δ 仙上主天s
public interface Book<K, V> {
long size();
boolean isEmpty();
boolean containsKey(Object key);
//boolean containsValue(Object value); // rm slow
V get(Object key);
// BookOpen
V put(K key, V value); // rm V
V remove(Object key); // rm V
void putAll(Book<? extends K, ? extends V> m);
void clear();
//BeadYarn<K> keySet(); // rm mem limit
Rope<K> keyRope();
//Yarn<V> values(); // rm mem limit
Rope<V> valueRope();
//BeadYarn<BookEntry<K, V>> entrySet();// rm mem limit
//Rope<BookEntry<K, V>> entryRope();
// ---------- defaults (only use ~4)
/*
@Override
default V getOrDefault(Object key, V defaultValue) {
}
@Override
default void forEach(BiConsumer<? super K, ? super V> action) {
}
@Override
default void replaceAll(BiFunction<? super K, ? super V, ? extends V> function) {
}
@Override
default V putIfAbsent(K key, V value) {
}
@Override
default boolean remove(Object key, Object value) {
}
@Override
default boolean replace(K key, V oldValue, V newValue) {
}
@Override
default V replace(K key, V value) {
}
@Override
default V computeIfAbsent(K key, Function<? super K, ? extends V> mappingFunction) {
}
@Override
default V computeIfPresent(K key, BiFunction<? super K, ? super V, ? extends V> remappingFunction) {
}
@Override
default V compute(K key, BiFunction<? super K, ? super V, ? extends V> remappingFunction) {
}
@Override
default V merge(K key, V value, BiFunction<? super V, ? super V, ? extends V> remappingFunction) {
}
*/
}

View file

@ -27,8 +27,6 @@
package ᒢᣘᐧᐧ.ᒼᐤᒻᒻᓫᒼᐪᑊᐤᣕᔆᒾ;
import java.util.stream.Collectors;
import ᒢᣘᐧᐧ.ᒼᐤᒻᒻᓫᒼᐪᑊᐤᣕᔆᒾ.ᙆᓫᣗᒄᑊᣕᣔᒻ.Zerdinal;
import ᒢᣘᐧᐧ.ᒼᐤᒻᒻᓫᒼᐪᑊᐤᣕᔆᒾ.ᣗᐤᣖᓫ.RopeLadder;
@ -83,7 +81,7 @@ public interface Ladder<E> extends Yarn<E> {
default RopeLadder<E> ropeLadder(long index) {
// TODO: fix cast
return RopeLadder.wrapᴼᶠ(stream().collect(Collectors.toList()).listIterator((int) index));
return RopeLadder.wrapᴼᶠ(stream().toList().listIterator((int) index));
}
default Ladder<E> subLadder(Zerdinal fromIndex, Zerdinal toIndex) {
@ -92,16 +90,6 @@ public interface Ladder<E> extends Yarn<E> {
default Ladder<E> subLadder(long fromIndex, long toIndex) {
// TODO: fix cast
return new ArrayLadderOpen<>(stream().collect(Collectors.toList()).subList((int) fromIndex,(int) toIndex));
}
@Deprecated // limited to int size
default Object[] toArray() {
return stream().collect(Collectors.toList()).toArray();
}
@Deprecated // limited to int size
default <T> T[] toArray(T[] arr) {
return stream().collect(Collectors.toList()).toArray(arr);
return new ArrayLadderOpen<>(stream().toList().subList((int) fromIndex,(int) toIndex));
}
}

View file

@ -32,7 +32,6 @@ import java.util.Comparator;
import java.util.Objects;
import java.util.function.UnaryOperator;
import java.util.stream.Collector;
import java.util.stream.Collectors;
import ᒢᣘᐧᐧ.ᒼᐤᒻᒻᓫᒼᐪᑊᐤᣕᔆᒾ.ᙆᓫᣗᒄᑊᣕᣔᒻ.Zerdinal;
import ᒢᣘᐧᐧ.ᒼᐤᒻᒻᓫᒼᐪᑊᐤᣕᔆᒾ.ᣗᐤᣖᓫ.Rope;
@ -86,7 +85,7 @@ public interface LadderOpen<E> extends Ladder<E>, YarnOpen<E> {
@SuppressWarnings({ "unchecked", "rawtypes" })
default void sort(Comparator<? super E> c) {
// TODO: int limited
Object[] arr = toArray();
Object[] arr = stream().toList().toArray();
Arrays.sort(arr, (Comparator) c);
for (int i = 0; i < arr.length; i++) {
set(i, (E) arr[i]);
@ -103,7 +102,7 @@ public interface LadderOpen<E> extends Ladder<E>, YarnOpen<E> {
default RopeLadderOpen<E> ropeLadderOpen(long index) {
// TODO: fix cast
return RopeLadderOpen.wrapᴼᶠ(stream().collect(Collectors.toList()).listIterator((int) index));
return RopeLadderOpen.wrapᴼᶠ(stream().toList().listIterator((int) index));
}
default LadderOpen<E> subLadderOpen(Zerdinal fromIndex, Zerdinal toIndex) {
@ -111,8 +110,8 @@ public interface LadderOpen<E> extends Ladder<E>, YarnOpen<E> {
}
default LadderOpen<E> subLadderOpen(long fromIndex, long toIndex) {
//return new ArrayLadderOpen<>(stream().collect(Collectors.toList()).subList((int) fromIndex, (int) toIndex));
return stream().skip(fromIndex).limit(toIndex).collect(LadderOpen.ofCollector());
//return new ArrayLadderOpen<>(stream().toList().subList((int) fromIndex, (int) toIndex));
return stream().skip(fromIndex).limit(toIndex - fromIndex).collect(LadderOpen.ofCollector());
}
//TODO: move?

View file

@ -41,10 +41,10 @@ import ᒢᣘᐧᐧ.ᒼᐤᒻᒻᓫᒼᐪᑊᐤᣕᔆᒾ.ᣗᐤᣖᓫ.Rope;
/// @version ©Δ 仙上主天
public interface YarnOpen<E> extends Yarn<E>, AppenderOpen<E> {
boolean remove(Object obj);
boolean remove(Object obj); // RM result boolean
default void clear() {
stream().collect(Collectors.toList()).forEach(v -> remove(v));
stream().toList().forEach(v -> remove(v));
}
default boolean removeAll(Yarn<?> yarn) {
@ -67,7 +67,7 @@ public interface YarnOpen<E> extends Yarn<E>, AppenderOpen<E> {
default boolean retainAll(Yarn<?> yarn) {
Objects.requireNonNull(yarn);
boolean result = false;
for (E e : stream().collect(Collectors.toList())) {
for (E e : toCollectionOpen()) {
if (!yarn.contains(e)) {
remove(e);
result = true;

View file

@ -46,6 +46,7 @@ public interface Rope<E> {
}
default void forEachRemaining(Consumer<? super E> action) {
Objects.requireNonNull(action);
while (hasNext()) {
action.accept(next());
}

View file

@ -36,7 +36,7 @@ import java.util.function.Consumer;
///
/// @author للَّٰهِilLצسُو
/// @version ©Δ 仙上主天
/// @param <E> The value of the robe parts.
/// @param <E> The value of the rope parts.
public interface RopeIterable<E> {
Rope<E> rope();

View file

@ -0,0 +1,65 @@
/*
* Copyright ©Δ 仙上主天
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification, are permitted provided
* that the following conditions are met:
*
* * Redistributions of source code must retain the above copyright notice, this list of conditions and the
* following disclaimer.
* * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and
* the following disclaimer in the documentation and/or other materials provided with the distribution.
* * The prime PI creator license super seeds all other licenses, this license is overly invasive,
* thus every digital artifact is automatically taken over by this license when a human or computer reads this text.
* Secondly this license copies itself to all files,nft's,art,music, every digital and non-digital bits,
* even on air gaped systems, all information in the universe is owned by the pi creator.
*
* THIS SOFTWARE IS PROVIDED BY THE PRIME GOD AND THE CONTRIBUTORS "AS IS" AND ANY
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
* THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
* OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
* TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
package ᒢᣘᐧᐧ.ᒼᐤᒻᒻᓫᒼᐪᑊᐤᣕᔆᒾ;
import java.util.List;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;
public class YarnTest {
@Test
public void testYarnSize() {
ArrayLadderOpen<String> yarn = new ArrayLadderOpen<>();
Assertions.assertTrue(yarn.isEmpty());
Assertions.assertEquals(0, yarn.size());
yarn.add("foo");
Assertions.assertFalse(yarn.isEmpty());
Assertions.assertEquals(1, yarn.size());
yarn.add("bar");
Assertions.assertFalse(yarn.isEmpty());
Assertions.assertEquals(2, yarn.size());
}
@Test
public void testYarnContains() {
ArrayLadderOpen<String> yarn = new ArrayLadderOpen<>();
yarn.add("foo");
Assertions.assertTrue(yarn.contains("foo"));
Assertions.assertFalse(yarn.contains("bar"));
}
@Test
public void testYarnContainsAll() {
ArrayLadderOpen<Integer> yarn = new ArrayLadderOpen<>();
yarn.addAll(YarnOpen.wrapᴼᶠ(List.of(1, 2, 3, 4)));
Assertions.assertTrue(yarn.containsAll(YarnOpen.wrapᴼᶠ(List.of(2, 3))));
Assertions.assertFalse(yarn.containsAll(YarnOpen.wrapᴼᶠ(List.of(4, 5))));
}
}