Enum Class OrderType

java.lang.Object
java.lang.Enum<OrderType>
com.github.tommyettinger.ds.OrderType
All Implemented Interfaces:
Serializable, Comparable<OrderType>, Constable

public enum OrderType extends Enum<OrderType>
Used to determine what class Ordered objects will use for their Ordered.order() implementation. This is always a subclass of the type returned by order(), such as ObjectList for Ordered or LongList for Ordered.OfLong. ObjectList only has ObjectBag as its subclass here, but the primitive lists such as IntList have IntBag and IntDeque as subclasses that may be used.
Each ordering type has different advantages and disadvantages. Each variety offers constant-time ArrayList.get(int) performance, and amortized constant-time ArrayList.add(Object) to the end. DEQUE has slower get(int) performance in practice than the others, but not worse algorithmic complexity. Adding to the beginning of the iteration order is constant-time for DEQUE, but linear-time for LIST and BAG. Both LIST and DEQUE preserve insertion order, but BAG is permitted to rearrange items whenever an item is removed. Removal performs very differently. with LIST removing in constant time only for the last item in the iteration order, or linear time for any other item. DEQUE removes items at the start or end of the order in constant-time, and linear time for other positions. BAG has constant-time removal from any position by swapping the item at the end into the place of the removed item. All types permit sorting, but BAG only holds its sorted order until an item is removed. All types have faster iteration than an unordered set or map.
The reason to use LIST is to preserve iteration order and allow fast get() by index. DEQUE also preserves iteration order and makes insertion or removal at either end of the order faster. BAG allows sets and maps to keep or improve on the complexity of an unordered set or map for all operations, while speeding up iteration as long as the order doesn't need to be kept between iterations over the type/.
If a type of ordering isn't available for a given item type, this should default to LIST.
  • Enum Constant Details

    • LIST

      public static final OrderType LIST
      The order() method will return a list, such as ObjectList or IntList.
    • BAG

      public static final OrderType BAG
      The order() method will return a bag with non-persistent iteration order, such as ObjectBag or IntBag.
    • DEQUE

      public static final OrderType DEQUE
      The order() method will return a deque (which is also always a list here), such as LongDeque or IntDeque. This will not be valid for Object-based types, because ObjectDeque is not a subclass of ObjectList.
  • Method Details

    • values

      public static OrderType[] values()
      Returns an array containing the constants of this enum class, in the order they are declared.
      Returns:
      an array containing the constants of this enum class, in the order they are declared
    • valueOf

      public static OrderType valueOf(String name)
      Returns the enum constant of this class with the specified name. The string must match exactly an identifier used to declare an enum constant in this class. (Extraneous whitespace characters are not permitted.)
      Parameters:
      name - the name of the enum constant to be returned.
      Returns:
      the enum constant with the specified name
      Throws:
      IllegalArgumentException - if this enum class has no constant with the specified name
      NullPointerException - if the argument is null