Class SortIndex<T>

  • Type Parameters:
    T - type of the items

    final class SortIndex<T>
    extends java.lang.Object
    A index on a list of items sorted with a given Comparator. The index does not change the list itself.
    • Nested Class Summary

      Nested Classes 
      Modifier and Type Class Description
      private class  SortIndex.Entry  
    • Constructor Summary

      Constructors 
      Constructor Description
      SortIndex​(java.util.Comparator<? super T> comparator)
      Creates a new index based in the given comparator.
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      int getPosition​(int idx)
      Returns the sorted position of the element with the given index in the items list provided to the init() method.
      void init​(java.util.List<? extends T> items)
      Initializes the index for the given list of items.
      • Methods inherited from class java.lang.Object

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

      • comparator

        private final java.util.Comparator<? super T> comparator
      • positions

        private int[] positions
    • Constructor Detail

      • SortIndex

        public SortIndex​(java.util.Comparator<? super T> comparator)
        Creates a new index based in the given comparator.
        Parameters:
        comparator - comparator to sort items
    • Method Detail

      • init

        public void init​(java.util.List<? extends T> items)
        Initializes the index for the given list of items.
        Parameters:
        items - list of items
      • getPosition

        public int getPosition​(int idx)
        Returns the sorted position of the element with the given index in the items list provided to the init() method.
        Parameters:
        idx - index of a element of the list
        Returns:
        its position in a sorted list