Class ConsecutivelyNumberedFilenames

  • All Implemented Interfaces:
    java.lang.Iterable<java.io.File>

    public class ConsecutivelyNumberedFilenames
    extends java.lang.Object
    implements java.lang.Iterable<java.io.File>
    This class is used to produce file names based on a given format string and an internal counter which increments every time a new file name is produced.
    • Field Summary

      Fields 
      Modifier and Type Field Description
      private java.util.Iterator<java.io.File> iter
      The iterator to return upon the iterator() method being called.
    • Constructor Summary

      Constructors 
      Constructor Description
      ConsecutivelyNumberedFilenames()
      Instantiates an ConsecutivelyNumberedFilenames object which returns Files with file names which are consecutively numbered beginning from 0.
      ConsecutivelyNumberedFilenames​(int start)
      Instantiates an ConsecutivelyNumberedFilenames object which returns Files with file names which are consecutively numbered beginning from the given value.
      ConsecutivelyNumberedFilenames​(java.io.File dir)
      Instantiates an ConsecutivelyNumberedFilenames object which returns Files with file names which are consecutively numbered beginning from 0, with the directory specified.
      ConsecutivelyNumberedFilenames​(java.io.File dir, int start)
      Instantiates an ConsecutivelyNumberedFilenames object which returns Files with file names which are consecutively numbered beginning from from the given value, with the directory specified.
      ConsecutivelyNumberedFilenames​(java.io.File dir, java.lang.String format)
      Instantiates an ConsecutivelyNumberedFilenames object which returns Files with file names which are based on a format string, located in the directory specified.
      ConsecutivelyNumberedFilenames​(java.io.File dir, java.lang.String format, int start)
      Instantiates an ConsecutivelyNumberedFilenames object which returns Files with file names which are based on a format string, located in the directory specified.
      ConsecutivelyNumberedFilenames​(java.lang.String format)
      Instantiates an ConsecutivelyNumberedFilenames object which returns Files with file names which are based on a format string.
      ConsecutivelyNumberedFilenames​(java.lang.String format, int start)
      Instantiates an ConsecutivelyNumberedFilenames object which returns Files with file names which are based on a format string.
    • Method Summary

      All Methods Static Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      private static void checkDirectory​(java.io.File dir)  
      java.util.Iterator<java.io.File> iterator()
      Returns an iterator which generates file names according to the rules specified by this object.
      • Methods inherited from class java.lang.Object

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

        forEach, spliterator
    • Field Detail

      • iter

        private final java.util.Iterator<java.io.File> iter
        The iterator to return upon the iterator() method being called.
    • Constructor Detail

      • ConsecutivelyNumberedFilenames

        public ConsecutivelyNumberedFilenames()

        Instantiates an ConsecutivelyNumberedFilenames object which returns Files with file names which are consecutively numbered beginning from 0.

        File name sequence

        1. 0
        2. 1
        3. 2
        4. 3

        and so on.

      • ConsecutivelyNumberedFilenames

        public ConsecutivelyNumberedFilenames​(int start)

        Instantiates an ConsecutivelyNumberedFilenames object which returns Files with file names which are consecutively numbered beginning from the given value.

        File name sequence

        For a case where the given value is 5:

        1. 5
        2. 6
        3. 7
        4. 8

        and so on.

        Parameters:
        start - The value from which to start counting.
      • ConsecutivelyNumberedFilenames

        public ConsecutivelyNumberedFilenames​(java.io.File dir)
                                       throws java.io.IOException

        Instantiates an ConsecutivelyNumberedFilenames object which returns Files with file names which are consecutively numbered beginning from 0, with the directory specified.

        File name sequence

        For a case where the parent directory is /foo/bar/:

        1. /foo/bar/0
        2. /foo/bar/1
        3. /foo/bar/2
        4. /foo/bar/3

        and so on.

        Parameters:
        dir - The directory in which the files are to be located.
        Throws:
        java.io.IOException - If the specified directory path is not a directory, or if does not exist.
      • ConsecutivelyNumberedFilenames

        public ConsecutivelyNumberedFilenames​(java.lang.String format)

        Instantiates an ConsecutivelyNumberedFilenames object which returns Files with file names which are based on a format string. The numbering will be consecutive from 0.

        The format string should contain the string %d which will be replaced with a consecutively counted number. Additional formatting can be applied. For more details, please refer to the section on Numeric formatting in the Java API specification for the Formatter class.

        File name sequence

        For a case where the format string is image-%d:

        1. image-0
        2. image-1
        3. image-2
        4. image-3

        and so on.

        Parameters:
        format - The format string to use.
      • ConsecutivelyNumberedFilenames

        public ConsecutivelyNumberedFilenames​(java.io.File dir,
                                              int start)
                                       throws java.io.IOException

        Instantiates an ConsecutivelyNumberedFilenames object which returns Files with file names which are consecutively numbered beginning from from the given value, with the directory specified.

        File name sequence

        For a case where the parent directory is /foo/bar/, and the specified value is 5:

        1. /foo/bar/5
        2. /foo/bar/6
        3. /foo/bar/7
        4. /foo/bar/8

        and so on.

        Parameters:
        dir - The directory in which the files are to be located.
        start - The value from which to start counting.
        Throws:
        java.io.IOException - If the specified directory path is not a directory, or if does not exist.
      • ConsecutivelyNumberedFilenames

        public ConsecutivelyNumberedFilenames​(java.io.File dir,
                                              java.lang.String format)
                                       throws java.io.IOException

        Instantiates an ConsecutivelyNumberedFilenames object which returns Files with file names which are based on a format string, located in the directory specified. The numbering will be consecutively counted from 0.

        The format string should contain the string %d which will be replaced with a consecutively counted number. Additional formatting can be applied. For more details, please refer to the section on Numeric formatting in the Java API specification for the Formatter class.

        File name sequence

        For a case where the parent directory is /foo/bar/, with the format string image-%d:

        1. /foo/bar/image-0
        2. /foo/bar/image-1
        3. /foo/bar/image-2
        4. /foo/bar/image-3

        and so on.

        Parameters:
        dir - The directory in which the files are to be located.
        format - The format string to use.
        Throws:
        java.io.IOException - If the specified directory path is not a directory, or if does not exist.
      • ConsecutivelyNumberedFilenames

        public ConsecutivelyNumberedFilenames​(java.lang.String format,
                                              int start)

        Instantiates an ConsecutivelyNumberedFilenames object which returns Files with file names which are based on a format string. The numbering will be consecutive from the specified value.

        The format string should contain the string %d which will be replaced with a consecutively counted number. Additional formatting can be applied. For more details, please refer to the section on Numeric formatting in the Java API specification for the Formatter class.

        File name sequence

        For a case where the parent directory is /foo/bar/, and the specified value is 5, with the format string image-%d:

        1. image-5
        2. image-6
        3. image-7
        4. image-8

        and so on.

        Parameters:
        format - The format string to use.
        start - The value from which to start counting.
      • ConsecutivelyNumberedFilenames

        public ConsecutivelyNumberedFilenames​(java.io.File dir,
                                              java.lang.String format,
                                              int start)
                                       throws java.io.IOException

        Instantiates an ConsecutivelyNumberedFilenames object which returns Files with file names which are based on a format string, located in the directory specified. The numbering will be consecutive from the specified value.

        The format string should contain the string %d which will be replaced with a consecutively counted number. Additional formatting can be applied. For more details, please refer to the section on Numeric formatting in the Java API specification for the Formatter class.

        File name sequence

        For a case where the parent directory is /foo/bar/, and the specified value is 5, with format string image-%d:

        1. /foo/bar/image-5
        2. /foo/bar/image-6
        3. /foo/bar/image-7
        4. /foo/bar/image-8

        and so on.

        Parameters:
        dir - The directory in which the files are to be located.
        format - The format string to use.
        start - The value from which to start counting.
        Throws:
        java.io.IOException - If the specified directory path is not a directory, or if does not exist.
    • Method Detail

      • checkDirectory

        private static void checkDirectory​(java.io.File dir)
                                    throws java.io.IOException
        Throws:
        java.io.IOException
      • iterator

        public java.util.Iterator<java.io.File> iterator()
        Returns an iterator which generates file names according to the rules specified by this object.
        Specified by:
        iterator in interface java.lang.Iterable<java.io.File>
        Returns:
        An iterator which generates file names.