package speiger.src.collections.PACKAGE.sets; #if JAVA_VERSION>=21 import java.util.SequencedSet; #endif import speiger.src.collections.PACKAGE.collections.BI_ITERATOR; import speiger.src.collections.PACKAGE.collections.ORDERED_COLLECTION; #if SPLIT_ITERATOR_FEATURE import speiger.src.collections.PACKAGE.collections.SPLIT_ITERATOR; import speiger.src.collections.PACKAGE.utils.SPLIT_ITERATORS; #endif import speiger.src.collections.PACKAGE.sets.ABSTRACT_SET.REVERSED_ORDERED_SET; #if SETS_FEATURE import speiger.src.collections.PACKAGE.utils.SETS; #endif /** * A Special Set Interface giving Access to some really usefull functions * The Idea behind this interface is to allow access to functions that give control to the Order of elements. * Since Linked implementations as examples can be reordered outside of the Insertion Order. * This interface provides basic access to such functions while also providing some Sorted/NaivgableSet implementations that still fit into here. * * @Type(T) */ #if JAVA_VERSION>=21 public interface ORDERED_SET KEY_GENERIC_TYPE extends SET KEY_GENERIC_TYPE, ORDERED_COLLECTION KEY_GENERIC_TYPE, SequencedSet #else public interface ORDERED_SET KEY_GENERIC_TYPE extends SET KEY_GENERIC_TYPE, ORDERED_COLLECTION KEY_GENERIC_TYPE #endif { /** * A customized add method that allows you to insert into the first index. * @param o the element that should be inserted * @return true if it was added * @see java.util.Set#add(Object) */ public boolean addAndMoveToFirst(KEY_TYPE o); /** * A customized add method that allows you to insert into the last index. * @param o the element that should be inserted * @return true if it was added * @see java.util.Set#add(Object) */ public boolean addAndMoveToLast(KEY_TYPE o); /** * A specific move method to move a given key to the first index. * @param o that should be moved to the first index * @return true if the value was moved. * @note returns false if the value was not present in the first place */ public boolean moveToFirst(KEY_TYPE o); /** * A specific move method to move a given key to the last index. * @param o that should be moved to the first last * @return true if the value was moved. * @note returns false if the value was not present in the first place */ public boolean moveToLast(KEY_TYPE o); @Override public ORDERED_SET KEY_GENERIC_TYPE copy(); @Override public BI_ITERATOR KEY_GENERIC_TYPE iterator(); public BI_ITERATOR KEY_GENERIC_TYPE reverseIterator(); /** * A type Specific Iterator starting from a given key * @param fromElement the element the iterator should start from * @return a iterator starting from the given element * @throws java.util.NoSuchElementException if fromElement isn't found */ public BI_ITERATOR KEY_GENERIC_TYPE iterator(KEY_TYPE fromElement); #if SPLIT_ITERATOR_FEATURE /** * A Type Specific Type Splititerator to reduce boxing/unboxing * @return type specific splititerator */ @Override default SPLIT_ITERATOR KEY_GENERIC_TYPE spliterator() { return SPLIT_ITERATORS.createSplititerator(this, 0); } #endif /** * A method to get the first element in the set * @return first element in the set */ public KEY_TYPE GET_FIRST_KEY(); /** * A method to get and remove the first element in the set * @return first element in the set */ public KEY_TYPE REMOVE_FIRST_KEY(); /** * A method to get the last element in the set * @return last element in the set */ public KEY_TYPE GET_LAST_KEY(); /** * A method to get and remove the last element in the set * @return last element in the set */ public KEY_TYPE REMOVE_LAST_KEY(); #if JAVA_VERSION>=21 && !TYPE_OBJECT /** {@inheritDoc} *

This default implementation delegates to the corresponding type-specific function. * @deprecated Please use the corresponding type-specific function instead. */ @Override @Deprecated default void addFirst(CLASS_TYPE e) { addAndMoveToFirst(OBJ_TO_KEY(e)); } /** {@inheritDoc} *

This default implementation delegates to the corresponding type-specific function. * @deprecated Please use the corresponding type-specific function instead. */ @Override @Deprecated default void addLast(CLASS_TYPE e) { addAndMoveToLast(OBJ_TO_KEY(e)); } /** {@inheritDoc} *

This default implementation delegates to the corresponding type-specific function. * @deprecated Please use the corresponding type-specific function instead. */ @Override @Deprecated default CLASS_TYPE getFirst() { return GET_FIRST_KEY(); } /** {@inheritDoc} *

This default implementation delegates to the corresponding type-specific function. * @deprecated Please use the corresponding type-specific function instead. */ @Override @Deprecated default CLASS_TYPE getLast() { return GET_LAST_KEY(); } /** {@inheritDoc} *

This default implementation delegates to the corresponding type-specific function. * @deprecated Please use the corresponding type-specific function instead. */ @Override @Deprecated default CLASS_TYPE removeFirst() { return REMOVE_FIRST_KEY(); } /** {@inheritDoc} *

This default implementation delegates to the corresponding type-specific function. * @deprecated Please use the corresponding type-specific function instead. */ @Override @Deprecated default CLASS_TYPE removeLast() { return REMOVE_LAST_KEY(); } #endif @Java21 public default ORDERED_SET KEY_GENERIC_TYPE reversed() { return new REVERSED_ORDERED_SETBRACES(this); } #if SETS_FEATURE /** * Creates a Wrapped OrderedSet that is Synchronized * @return a new OrderedSet that is synchronized * @see SETS#synchronize */ public default ORDERED_SET KEY_GENERIC_TYPE synchronize() { return SETS.synchronize(this); } /** * Creates a Wrapped OrderedSet that is Synchronized * @param mutex is the controller of the synchronization block * @return a new OrderedSet Wrapper that is synchronized * @see SETS#synchronize */ public default ORDERED_SET KEY_GENERIC_TYPE synchronize(Object mutex) { return SETS.synchronize(this, mutex); } /** * Creates a Wrapped OrderedSet that is unmodifiable * @return a new OrderedSet Wrapper that is unmodifiable * @see SETS#unmodifiable */ public default ORDERED_SET KEY_GENERIC_TYPE unmodifiable() { return SETS.unmodifiable(this); } #endif }