Added toString interface

This commit is contained in:
Willem Cazander 2022-10-24 09:16:24 +02:00
parent 107435ec13
commit be3f1a9476
7 changed files with 83 additions and 13 deletions

View file

@ -0,0 +1,21 @@
package love.distributedrebirth.bassboon.jpp.lang;
import love.distributedrebirth.bassboon.clazz.BãßBȍőnAuthor注;
/**
* Mark objects which need a English latin1 human output.
*
* Human output can't be defined.
*/
@BãßBȍőnAuthor注(name = "للَّٰهِilLצسُو", copyright = "©Δ∞ 仙上主天")
public interface ObjectToHuman {
// it looks like this was JMX in java version 1.0
String toString(); // the biggest mistake in java
// thus for who in what format and which details...
// Every computer needs brahmi support on strings
default StringUnicode toStringUnicode() {
return StringUnicode.valueOf(toString());
}
}

View file

@ -11,11 +11,11 @@ import love.distributedrebirth.bassboon.clazz.BãßBȍőnAuthor注;
* String without any char or byte methods.
*/
@BãßBȍőnAuthor注(name = "للَّٰهِilLצسُو", copyright = "©Δ∞ 仙上主天")
public interface StringTypeConst<T extends StringTypeConst<T>> extends Comparable<T>, Iterable<Integer> /*, CharSequence */ {
// ---- Local
public interface StringTypeConst<T extends StringTypeConst<T>> extends Comparable<T>, Iterable<Integer>, ObjectToHuman /*, CharSequence */ {
String toString();
//int[] values();
// ---- Local
default long lengthBytes() {
return toString().length() + toString().length();

View file

@ -5,6 +5,9 @@ import java.util.Comparator;
import java.util.Iterator;
import java.util.List;
import love.distributedrebirth.bassboon.clazz.BãßBȍőnAuthor注;
@BãßBȍőnAuthor注(name = "للَّٰهِilLצسُو", copyright = "©Δ∞ 仙上主天")
public class ArrayListᴿᵂ<E> implements Listᵂʳ<E>,Iterable<E> {
private final List<E> data;
@ -30,6 +33,11 @@ public class ArrayListᴿᵂ<E> implements Listᵂʳ<E>,Iterable<E> {
return Iteratorᴿᵈ.wrapᴼᶠ(iterator());
}
@Override
public Iteratorᵂʳ<E> iteratorᵂʳ() {
return Iteratorᵂʳ.wrapᴼᶠ(iterator());
}
@Override
public boolean addᵂʳ(E value) {
return data.add(value);

View file

@ -6,7 +6,6 @@ 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ᴿᵈ<E> extends Iterableᴿᵈ<E> {

View file

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

View file

@ -1,11 +1,10 @@
package love.distributedrebirth.bassboon.jpp.lang;
package love.distributedrebirth.bassboon.jpp.util;
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> {

View file

@ -0,0 +1,39 @@
package love.distributedrebirth.bassboon.jpp.lang;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;
import love.distributedrebirth.bassboon.clazz.BãßBȍőnAuthor注;
@BãßBȍőnAuthor注(name = "للَّٰهِilLצسُو", copyright = "©Δ∞ 仙上主天")
public class ObjectToHumanTest {
@Test
public void testObjectToHuman() {
class HumanObjectSimple implements ObjectToHuman {
@Override
public String toString() {
return "ik probeer mens te zijn...";
}
}
HumanObjectSimple object = new HumanObjectSimple();
Assertions.assertTrue(object != null);
Assertions.assertTrue(object.toString() != null);
Assertions.assertTrue(object.toStringUnicode() != null);
Assertions.assertEquals(object.toString().length(), object.toStringUnicode().lengthChars());
Assertions.assertTrue(object.toString().contains("mens"));
Assertions.assertTrue(object.toStringUnicode().contains(StringUnicode.valueOf("mens")));
}
@Test
public void testObjectToObject2() {
StringUnicode str = new StringUnicode("0123456789");
for (int i=0;i<10;i++) {
str = str.toStringUnicode();
}
Assertions.assertTrue(str != null);
Assertions.assertEquals(20, str.toStringUnicode().lengthBytes());
Assertions.assertEquals(10, str.toStringUnicode().lengthChars());
Assertions.assertEquals(10, str.toStringUnicode().lengthCodePoints());
}
}