Navigable & RedBlackTreeSet

This commit is contained in:
Speiger 2020-12-19 21:11:21 +01:00
parent c8fc84bf88
commit 4e89ec946f
5 changed files with 1433 additions and 1 deletions

View File

@ -56,6 +56,7 @@ public class GlobalVariables
addInjectMapper("EQUALS_NULL", type.getComparableValue()+" == "+(type.isPrimitiveBlocking() ? type.getEmptyValue() : (type.needsCast() ? type.getEmptyValue() : "0"))).removeBraces(); addInjectMapper("EQUALS_NULL", type.getComparableValue()+" == "+(type.isPrimitiveBlocking() ? type.getEmptyValue() : (type.needsCast() ? type.getEmptyValue() : "0"))).removeBraces();
addArgumentMapper("EQUALS_NOT", type.getEquals(true)).removeBraces(); addArgumentMapper("EQUALS_NOT", type.getEquals(true)).removeBraces();
addArgumentMapper("EQUALS", type.getEquals(false)).removeBraces(); addArgumentMapper("EQUALS", type.getEquals(false)).removeBraces();
addArgumentMapper("COMPARE_TO_KEY", type.isObject() ? "((Comparable<T>)%1$s).compareTo((T)%2$s)" : type.getClassType()+".compare(%1$s, %2$s)").removeBraces();
addArgumentMapper("COMPARE_TO", type.isObject() ? "%1$s.compareTo(%2$s)" : type.getClassType()+".compare(%1$s, %2$s)").removeBraces(); addArgumentMapper("COMPARE_TO", type.isObject() ? "%1$s.compareTo(%2$s)" : type.getClassType()+".compare(%1$s, %2$s)").removeBraces();
addInjectMapper("KEY_TO_OBJ", type.isObject() ? "%s" : type.getClassType()+".valueOf(%s)").removeBraces(); addInjectMapper("KEY_TO_OBJ", type.isObject() ? "%s" : type.getClassType()+".valueOf(%s)").removeBraces();
addInjectMapper("OBJ_TO_KEY", type.isObject() ? "%s" : "%s."+type.getKeyType()+"Value()").removeBraces(); addInjectMapper("OBJ_TO_KEY", type.isObject() ? "%s" : "%s."+type.getKeyType()+"Value()").removeBraces();
@ -77,6 +78,7 @@ public class GlobalVariables
addClassMapper("LINKED_HASH_SET", "LinkedOpenHashSet"); addClassMapper("LINKED_HASH_SET", "LinkedOpenHashSet");
addClassMapper("CUSTOM_HASH_SET", "OpenCustomHashSet"); addClassMapper("CUSTOM_HASH_SET", "OpenCustomHashSet");
addClassMapper("HASH_SET", "OpenHashSet"); addClassMapper("HASH_SET", "OpenHashSet");
addClassMapper("RB_TREE_SET", "RBTreeSet");
addClassMapper("ARRAY_SET", "ArraySet"); addClassMapper("ARRAY_SET", "ArraySet");
//Abstract Classes //Abstract Classes
@ -99,6 +101,7 @@ public class GlobalVariables
addClassMapper("COLLECTION", "Collection"); addClassMapper("COLLECTION", "Collection");
addClassMapper("LIST_ITER", "ListIter"); addClassMapper("LIST_ITER", "ListIter");
addClassMapper("LIST", "List"); addClassMapper("LIST", "List");
addClassMapper("NAVIGABLE_SET", "NavigableSet");
addClassMapper("SORTED_SET", "SortedSet"); addClassMapper("SORTED_SET", "SortedSet");
addClassMapper("SET", "Set"); addClassMapper("SET", "Set");
addClassMapper("STRATEGY", "Strategy"); addClassMapper("STRATEGY", "Strategy");
@ -115,7 +118,6 @@ public class GlobalVariables
addClassMapper("COMPARATOR", "Comparator"); addClassMapper("COMPARATOR", "Comparator");
addFunctionMappers("IARRAY", "I%sArray"); addFunctionMappers("IARRAY", "I%sArray");
} }
//Dependency
return this; return this;
} }

View File

@ -34,4 +34,26 @@ public interface COMPARATOR extends Comparator<CLASS_TYPE>
Objects.requireNonNull(c); Objects.requireNonNull(c);
return (K, V) -> c.compare(KEY_TO_OBJ(K), KEY_TO_OBJ(V)); return (K, V) -> c.compare(KEY_TO_OBJ(K), KEY_TO_OBJ(V));
} }
public default COMPARATOR reversed() {
return new Reversed(this);
}
static class Reversed implements COMPARATOR
{
COMPARATOR original;
public Reversed(COMPARATOR original) {
this.original = original;
}
public int compare(KEY_TYPE o1, KEY_TYPE o2) {
return original.compare(o2, o1);
}
@Override
public COMPARATOR reversed() {
return original;
}
}
} }

View File

@ -0,0 +1,127 @@
package speiger.src.collections.PACKAGE.sets;
import java.util.NavigableSet;
import speiger.src.collections.PACKAGE.collections.BI_ITERATOR;
public interface NAVIGABLE_SET KEY_GENERIC_TYPE extends NavigableSet<CLASS_TYPE>, SORTED_SET KEY_GENERIC_TYPE
{
#if !TYPE_OBJECT
public KEY_TYPE lower(KEY_TYPE e);
public KEY_TYPE floor(KEY_TYPE e);
public KEY_TYPE ceiling(KEY_TYPE e);
public KEY_TYPE higher(KEY_TYPE e);
public void setDefaultMaxValue(KEY_TYPE e);
public KEY_TYPE getDefaultMaxValue();
public void setDefaultMinValue(KEY_TYPE e);
public KEY_TYPE getDefaultMinValue();
@Override
public default NAVIGABLE_SET KEY_GENERIC_TYPE subSet(KEY_TYPE fromElement, KEY_TYPE toElement) { return subSet(fromElement, true, toElement, false); }
@Override
public default NAVIGABLE_SET KEY_GENERIC_TYPE headSet(KEY_TYPE toElement) { return headSet(toElement, false); }
@Override
public default NAVIGABLE_SET KEY_GENERIC_TYPE tailSet(KEY_TYPE fromElement) { return tailSet(fromElement, true); }
public NAVIGABLE_SET KEY_GENERIC_TYPE subSet(KEY_TYPE fromElement, boolean fromInclusive, KEY_TYPE toElement, boolean toInclusive);
public NAVIGABLE_SET KEY_GENERIC_TYPE headSet(KEY_TYPE toElement, boolean inclusive);
public NAVIGABLE_SET KEY_GENERIC_TYPE tailSet(KEY_TYPE fromElement, boolean inclusive);
#else
@Override
public default NAVIGABLE_SET KEY_GENERIC_TYPE subSet(KEY_TYPE fromElement, KEY_TYPE toElement) { return subSet(fromElement, true, toElement, false); }
@Override
public default NAVIGABLE_SET KEY_GENERIC_TYPE headSet(KEY_TYPE toElement) { return headSet(toElement, false); }
@Override
public default NAVIGABLE_SET KEY_GENERIC_TYPE tailSet(KEY_TYPE fromElement) { return tailSet(fromElement, true); }
@Override
public NAVIGABLE_SET KEY_GENERIC_TYPE subSet(KEY_TYPE fromElement, boolean fromInclusive, KEY_TYPE toElement, boolean toInclusive);
@Override
public NAVIGABLE_SET KEY_GENERIC_TYPE headSet(KEY_TYPE toElement, boolean inclusive);
@Override
public NAVIGABLE_SET KEY_GENERIC_TYPE tailSet(KEY_TYPE fromElement, boolean inclusive);
#endif
@Override
public BI_ITERATOR KEY_GENERIC_TYPE iterator();
@Override
public BI_ITERATOR KEY_GENERIC_TYPE descendingIterator();
@Override
public NAVIGABLE_SET KEY_GENERIC_TYPE descendingSet();
#if !TYPE_OBJECT
@Override
@Deprecated
public default CLASS_TYPE lower(CLASS_TYPE e) { return KEY_TO_OBJ(lower(OBJ_TO_KEY(e))); }
@Override
@Deprecated
public default CLASS_TYPE floor(CLASS_TYPE e) { return KEY_TO_OBJ(floor(OBJ_TO_KEY(e))); }
@Override
@Deprecated
public default CLASS_TYPE ceiling(CLASS_TYPE e) { return KEY_TO_OBJ(ceiling(OBJ_TO_KEY(e))); }
@Override
@Deprecated
public default CLASS_TYPE higher(CLASS_TYPE e) { return KEY_TO_OBJ(higher(OBJ_TO_KEY(e))); }
@Override
@Deprecated
default CLASS_TYPE first() { return SORTED_SET.super.first(); }
@Override
@Deprecated
default CLASS_TYPE last() { return SORTED_SET.super.last(); }
@Override
@Deprecated
public default CLASS_TYPE pollFirst() { return KEY_TO_OBJ(POLL_FIRST_KEY()); }
@Override
@Deprecated
public default CLASS_TYPE pollLast() { return KEY_TO_OBJ(POLL_LAST_KEY()); }
@Override
@Deprecated
public default NAVIGABLE_SET KEY_GENERIC_TYPE subSet(CLASS_TYPE fromElement, boolean fromInclusive, CLASS_TYPE toElement, boolean toInclusive) { return subSet(OBJ_TO_KEY(fromElement), fromInclusive, OBJ_TO_KEY(toElement), toInclusive); }
@Override
@Deprecated
public default NAVIGABLE_SET KEY_GENERIC_TYPE headSet(CLASS_TYPE toElement, boolean inclusive) { return headSet(OBJ_TO_KEY(toElement), inclusive); }
@Override
@Deprecated
public default NAVIGABLE_SET KEY_GENERIC_TYPE tailSet(CLASS_TYPE fromElement, boolean inclusive) { return tailSet(OBJ_TO_KEY(fromElement), inclusive); }
@Override
@Deprecated
public default SORTED_SET KEY_GENERIC_TYPE subSet(CLASS_TYPE fromElement, CLASS_TYPE toElement) { return SORTED_SET.super.subSet(fromElement, toElement); }
@Override
@Deprecated
public default SORTED_SET KEY_GENERIC_TYPE headSet(CLASS_TYPE toElement) { return SORTED_SET.super.headSet(toElement); }
@Override
@Deprecated
public default SORTED_SET KEY_GENERIC_TYPE tailSet(CLASS_TYPE fromElement) { return SORTED_SET.super.tailSet(fromElement); }
#endif
}

File diff suppressed because it is too large Load Diff

View File

@ -43,18 +43,23 @@ public interface SORTED_SET KEY_GENERIC_TYPE extends SET KEY_GENERIC_TYPE, Sorte
public KEY_TYPE POLL_LAST_KEY(); public KEY_TYPE POLL_LAST_KEY();
@Override @Override
@Deprecated
public default SORTED_SET KEY_GENERIC_TYPE subSet(CLASS_TYPE fromElement, CLASS_TYPE toElement) { return subSet(OBJ_TO_KEY(fromElement), OBJ_TO_KEY(toElement)); } public default SORTED_SET KEY_GENERIC_TYPE subSet(CLASS_TYPE fromElement, CLASS_TYPE toElement) { return subSet(OBJ_TO_KEY(fromElement), OBJ_TO_KEY(toElement)); }
@Override @Override
@Deprecated
public default SORTED_SET KEY_GENERIC_TYPE headSet(CLASS_TYPE toElement) { return headSet(OBJ_TO_KEY(toElement)); } public default SORTED_SET KEY_GENERIC_TYPE headSet(CLASS_TYPE toElement) { return headSet(OBJ_TO_KEY(toElement)); }
@Override @Override
@Deprecated
public default SORTED_SET KEY_GENERIC_TYPE tailSet(CLASS_TYPE fromElement) { return tailSet(OBJ_TO_KEY(fromElement)); } public default SORTED_SET KEY_GENERIC_TYPE tailSet(CLASS_TYPE fromElement) { return tailSet(OBJ_TO_KEY(fromElement)); }
@Override @Override
@Deprecated
public default CLASS_TYPE first() { return KEY_TO_OBJ(FIRST_KEY()); } public default CLASS_TYPE first() { return KEY_TO_OBJ(FIRST_KEY()); }
@Override @Override
@Deprecated
default CLASS_TYPE last() { return KEY_TO_OBJ(LAST_KEY()); } default CLASS_TYPE last() { return KEY_TO_OBJ(LAST_KEY()); }
#else #else
public CLASS_TYPE pollFirst(); public CLASS_TYPE pollFirst();