Class NaturalRanking.IntList

  • Enclosing class:
    NaturalRanking

    private static class NaturalRanking.IntList
    extends java.lang.Object
    An expandable list of int values. This allows tracking array positions without using boxed values in a List<Integer>.
    • Field Summary

      Fields 
      Modifier and Type Field Description
      private int[] data
      The list data.
      private int max
      The maximum size of array to allocate.
      private int size
      The size of the list.
    • Constructor Summary

      Constructors 
      Constructor Description
      IntList​(int max)  
    • Method Summary

      All Methods Static Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      (package private) void add​(int value)
      Adds the value to the list.
      (package private) void clear()
      Clear the list.
      (package private) int get​(int index)
      Gets the element at the specified index.
      (package private) void shuffle​(java.util.function.IntUnaryOperator randomIntFunction)
      Shuffle the list.
      (package private) int size()
      Gets the number of elements in the list.
      private static void swap​(int[] array, int i, int j)
      Swaps the two specified elements in the specified array.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Field Detail

      • max

        private final int max
        The maximum size of array to allocate.
      • size

        private int size
        The size of the list.
      • data

        private int[] data
        The list data. Initialised with space to store a tie of 2 values.
    • Constructor Detail

      • IntList

        IntList​(int max)
        Parameters:
        max - Maximum size of array to allocate. Can use the length of the parent array for which this is used to track indices.
    • Method Detail

      • add

        void add​(int value)
        Adds the value to the list.
        Parameters:
        value - the value
      • get

        int get​(int index)
        Gets the element at the specified index.
        Parameters:
        index - Element index
        Returns:
        the element
      • size

        int size()
        Gets the number of elements in the list.
        Returns:
        the size
      • clear

        void clear()
        Clear the list.
      • shuffle

        void shuffle​(java.util.function.IntUnaryOperator randomIntFunction)
        Shuffle the list.
        Parameters:
        randomIntFunction - Function maps positive x randomly to [0, x).
      • swap

        private static void swap​(int[] array,
                                 int i,
                                 int j)
        Swaps the two specified elements in the specified array.
        Parameters:
        array - Data array
        i - First index
        j - Second index