Interface Ordered<T>

All Superinterfaces:
Arrangeable
All Known Implementing Classes:
CaseInsensitiveOrderedMap, CaseInsensitiveOrderedSet, EnumFloatOrderedMap, EnumIntOrderedMap, EnumLongOrderedMap, EnumOrderedMap, EnumOrderedSet, FilteredIterableOrderedMap, FilteredIterableOrderedSet, FilteredStringOrderedMap, FilteredStringOrderedSet, HolderOrderedSet, IdentityObjectOrderedMap, IdentityOrderedSet, NumberedSet, NumberedSet.InternalMap, ObjectBag, ObjectFloatOrderedMap, ObjectIntOrderedMap, ObjectList, ObjectLongOrderedMap, ObjectObjectOrderedMap, ObjectOrderedSet

public interface Ordered<T> extends Arrangeable
Ensures that implementors allow access to the order of T items as an ObjectList. This is meant to allow different (typically insertion-ordered) data structures to all have their order manipulated by the same methods. This interface extends Arrangeable, which itself is compatible both with primitive-backed collections like IntList and generic ones like the implementations of Ordered. This has default implementations of Arrangeable.swap(int, int) and Arrangeable.shuffle(Random).
  • Nested Class Summary

    Nested Classes
    Modifier and Type
    Interface
    Description
    static interface 
     
    static interface 
     
    static interface 
     
    static interface 
    A primitive specialization of Ordered for collections of double values instead of objects.
    static interface 
    A primitive specialization of Ordered for collections of float values instead of objects.
    static interface 
    A primitive specialization of Ordered for collections of int values instead of objects.
    static interface 
    A primitive specialization of Ordered for collections of long values instead of objects.
    static interface 
     

    Nested classes/interfaces inherited from interface com.github.tommyettinger.ds.Arrangeable

    Arrangeable.ArrangeableList<T>
  • Method Summary

    Modifier and Type
    Method
    Description
    default OrderType
     
    Gets the ObjectList of T items that this data structure holds, in the order it uses for iteration.
    default T
    Returns a random T value from this Ordered, where T is typically the key type for Maps and the item type for Lists and Sets, or null if the list is empty.
    default T
    Gets a random T value from this Ordered, where T is typically the key type for Maps and the item type for Lists and Sets, using the given random number generator.
    default void
    removeRange(int start, int end)
    Removes items from the ordering (and potentially only the ordering, depending on implementation) between start, inclusive, and end, exclusive.
    default void
    Reverses the order of this Ordered in-place.
    default T
    selectRanked(Comparator<T> comparator, int kthLowest)
    Selects the kth-lowest element from this Ordered according to Comparator ranking.
    default int
    selectRankedIndex(Comparator<T> comparator, int kthLowest)
    Gets the index of the kth-lowest element from this Ordered according to Comparator ranking.
    default void
    Pseudo-randomly shuffles the order of this Ordered in-place.
    default void
    sort(Comparator<? super T> comparator)
    Sorts this Ordered according to the order induced by the specified Comparator.
    default void
    swap(int first, int second)
    Switches the ordering of positions first and second, without changing any items beyond that.

    Methods inherited from interface com.github.tommyettinger.ds.Arrangeable

    rearrange, shuffle, size
  • Method Details

    • order

      ObjectList<T> order()
      Gets the ObjectList of T items that this data structure holds, in the order it uses for iteration. This should usually return a direct reference to an ObjectList used inside this object, so changes to the list will affect this.
      Returns:
      the ObjectList of T items that this data structure holds
    • swap

      default void swap(int first, int second)
      Switches the ordering of positions first and second, without changing any items beyond that.
      Specified by:
      swap in interface Arrangeable
      Parameters:
      first - the first position, must not be negative and must be less than Arrangeable.size()
      second - the second position, must not be negative and must be less than Arrangeable.size()
    • shuffle

      default void shuffle(Random rng)
      Pseudo-randomly shuffles the order of this Ordered in-place. You can seed rng, the random number generator, with an identical seed to reproduce a shuffle on two Ordered with the same Arrangeable.size().
      Specified by:
      shuffle in interface Arrangeable
      Parameters:
      rng - any Random, such as AlternateRandom or one from juniper
    • reverse

      default void reverse()
      Reverses the order of this Ordered in-place.
      Specified by:
      reverse in interface Arrangeable
    • random

      default T random()
      Returns a random T value from this Ordered, where T is typically the key type for Maps and the item type for Lists and Sets, or null if the list is empty. Uses ArrayTools.RANDOM as its random number generator, which is randomly seeded.
      Returns:
      a randomly selected item from this, or null if this is empty
    • random

      default T random(Random rng)
      Gets a random T value from this Ordered, where T is typically the key type for Maps and the item type for Lists and Sets, using the given random number generator.
      This should throw an IllegalStateException if the Ordered is empty.
      Parameters:
      rng - any Random class
      Returns:
      a random T value from this Ordered
    • sort

      default void sort(Comparator<? super T> comparator)
      Sorts this Ordered according to the order induced by the specified Comparator. The sort is stable: this method must not reorder equal elements.
      All elements in the order() must be mutually comparable using the specified comparator (that is, c.compare(e1, e2) must not throw a ClassCastException for any elements e1 and e2 in the list).
      If the specified comparator is null then all elements in this Ordered must implement the Comparable interface and the elements' natural ordering should be used.
      Parameters:
      comparator - used to sort the T items this contains; may be null if T implements Comparable
    • selectRanked

      default T selectRanked(Comparator<T> comparator, int kthLowest)
      Selects the kth-lowest element from this Ordered according to Comparator ranking. This might partially sort the Ordered, changing its order. The Ordered must have a size greater than 0, or a RuntimeException will be thrown.
      Parameters:
      comparator - used for comparison
      kthLowest - rank of desired object according to comparison; k is based on ordinal numbers, not array indices. For min value use 1, for max value use size of the Ordered; using 0 results in a runtime exception.
      Returns:
      the value of the kth lowest ranked object.
      See Also:
    • selectRankedIndex

      default int selectRankedIndex(Comparator<T> comparator, int kthLowest)
      Gets the index of the kth-lowest element from this Ordered according to Comparator ranking. This might partially sort the Ordered, changing its order. The Ordered must have a size greater than 0, or a RuntimeException will be thrown.
      Parameters:
      comparator - used for comparison
      kthLowest - rank of desired object according to comparison; k is based on ordinal numbers, not array indices. For min value use 1, for max value use size of the Ordered; using 0 results in a runtime exception.
      Returns:
      the index of the kth lowest ranked object.
      See Also:
    • removeRange

      default void removeRange(int start, int end)
      Removes items from the ordering (and potentially only the ordering, depending on implementation) between start, inclusive, and end, exclusive.
      Parameters:
      start - inclusive start of the range to remove from the ordering
      end - exclusive end of the range to remove from the ordering
    • getOrderType

      default OrderType getOrderType()