Interface Arrangeable

All Known Subinterfaces:
Arrangeable.ArrangeableList<T>, Ordered<T>, Ordered.OfBoolean, Ordered.OfByte, Ordered.OfChar, Ordered.OfDouble, Ordered.OfFloat, Ordered.OfInt, Ordered.OfLong, Ordered.OfShort
All Known Implementing Classes:
BooleanBag, BooleanDeque, BooleanList, ByteBag, ByteDeque, ByteList, CaseInsensitiveOrderedMap, CaseInsensitiveOrderedSet, CharBag, CharDeque, CharList, DoubleBag, DoubleDeque, DoubleList, EnumFloatOrderedMap, EnumIntOrderedMap, EnumLongOrderedMap, EnumOrderedMap, EnumOrderedSet, FilteredIterableOrderedMap, FilteredIterableOrderedSet, FilteredStringOrderedMap, FilteredStringOrderedSet, FloatBag, FloatDeque, FloatList, HolderOrderedSet, IdentityObjectOrderedMap, IdentityOrderedSet, IntBag, IntDeque, IntFloatOrderedMap, IntIntOrderedMap, IntList, IntLongOrderedMap, IntObjectOrderedMap, IntOrderedSet, LongBag, LongDeque, LongFloatOrderedMap, LongIntOrderedMap, LongList, LongLongOrderedMap, LongObjectOrderedMap, LongOrderedSet, NumberedSet, NumberedSet.InternalMap, ObjectBag, ObjectDeque, ObjectFloatOrderedMap, ObjectIntOrderedMap, ObjectList, ObjectLongOrderedMap, ObjectObjectOrderedMap, ObjectOrderedSet, ShortBag, ShortDeque, ShortList

public interface Arrangeable
Indicates that a type can have its contents change position, without specifying the type of contents. This can be used for primitive-backed collections as well as generic ones.
  • Nested Class Summary

    Nested Classes
    Modifier and Type
    Interface
    Description
    static interface 
    An empty interface that merges Arrangeable and java.util.List APIs.
  • Method Summary

    Modifier and Type
    Method
    Description
    default void
    rearrange(long seed)
    Rearranges this Arrangeable using the given seed to shuffle it.
    void
    Reverses this Arrangeable in-place.
    default void
    Pseudo-randomly shuffles the order of this Arrangeable in-place, using ArrayTools.RANDOM as the unseeded random number generator.
    default void
    shuffle(Random random)
    Pseudo-randomly shuffles the order of this Arrangeable in-place.
    int
    Returns the number of elements in this Arrangeable.
    void
    swap(int first, int second)
    Switches the ordering of positions first and second, without changing any items beyond that.
  • Method Details

    • swap

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

      default void shuffle()
      Pseudo-randomly shuffles the order of this Arrangeable in-place, using ArrayTools.RANDOM as the unseeded random number generator.
    • shuffle

      default void shuffle(Random random)
      Pseudo-randomly shuffles the order of this Arrangeable in-place.
      Parameters:
      random - any Random, such as AlternateRandom or one from juniper
    • reverse

      void reverse()
      Reverses this Arrangeable in-place.
    • size

      int size()
      Returns the number of elements in this Arrangeable. Often this is shared with Collection.size(), but isn't always.
      Returns:
      the number of elements in this Arrangeable
    • rearrange

      default void rearrange(long seed)
      Rearranges this Arrangeable using the given seed to shuffle it. The rearrangement is done in-place. You can reuse the seed on different calls to rearrange with Arrangeables of the same size, which will perform the same reordering steps on each Arrangeable (so if the first item in one Arrangeable became the fifth item after a call to rearrange(), reusing the seed in another same-size Arrangeable would also move its first item to become its fifth item).
      If you don't need to reuse a seed, you should consider shuffle(Random), which can be faster than this with a good enough Random subclass (likely not with Random).
      This uses Hasher.randomize2Bounded(long, int) to randomize the swap positions. If you want to use a stronger randomization method, such as Hasher.randomize3Bounded(long, int), use a faster one, such as Hasher.randomize1Bounded(long, int), or just to inline this method manually, the code used here fits in one line:
      for (int i = size() - 1; i > 0; i--) swap(i, Hasher.randomize2Bounded(++seed, i + 1));
      Parameters:
      seed - a (typically random) long seed to determine the shuffled order