Class StringSort

  • All Implemented Interfaces:
    java.io.Closeable, java.lang.AutoCloseable, java.lang.Iterable<java.lang.String>

    public class StringSort
    extends java.lang.Object
    implements java.lang.Iterable<java.lang.String>, java.io.Closeable
    Utility class to store a list of string and perform sort on that. For small size the list would be maintained in memory. If the size crosses the required threshold then the sorting would be performed externally
    • Field Summary

      Fields 
      Modifier and Type Field Description
      static int BATCH_SIZE  
    • Constructor Summary

      Constructors 
      Constructor Description
      StringSort​(int overflowToDiskThreshold, java.util.Comparator<java.lang.String> comparator)  
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      void add​(java.lang.String id)  
      void close()  
      java.util.Iterator<java.lang.String> getIds()  
      long getSize()  
      boolean isEmpty()  
      java.util.Iterator<java.lang.String> iterator()  
      void sort()  
      boolean usingFile()  
      • Methods inherited from class java.lang.Object

        equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
      • Methods inherited from interface java.lang.Iterable

        forEach, spliterator
    • Constructor Detail

      • StringSort

        public StringSort​(int overflowToDiskThreshold,
                          java.util.Comparator<java.lang.String> comparator)
    • Method Detail

      • add

        public void add​(java.lang.String id)
                 throws java.io.IOException
        Throws:
        java.io.IOException
      • sort

        public void sort()
                  throws java.io.IOException
        Throws:
        java.io.IOException
      • getIds

        public java.util.Iterator<java.lang.String> getIds()
                                                    throws java.io.IOException
        Throws:
        java.io.IOException
      • getSize

        public long getSize()
      • isEmpty

        public boolean isEmpty()
      • usingFile

        public boolean usingFile()
      • close

        public void close()
                   throws java.io.IOException
        Specified by:
        close in interface java.lang.AutoCloseable
        Specified by:
        close in interface java.io.Closeable
        Throws:
        java.io.IOException
      • iterator

        public java.util.Iterator<java.lang.String> iterator()
        Specified by:
        iterator in interface java.lang.Iterable<java.lang.String>