Interface SvetovidReader

  • All Superinterfaces:
    java.lang.AutoCloseable, java.io.Closeable
    All Known Implementing Classes:
    AbstractSvetovidReader, DefaultSvetovidReader, StandardSvetovidReader

    public interface SvetovidReader
    extends java.io.Closeable
    This interface provides methods that simplify reading the program input data for beginner programmers. Exception handling is not necessary as when it is turned off by setThrowingExceptions(boolean) many operations are returning default values on any errors. If necessary, the last raised exception can be retrieved using getLastException() method.
    • Method Summary

      All Methods Instance Methods Abstract Methods 
      Modifier and Type Method Description
      void close()
      Closes this reader and releases any resources associated with the underlying source.
      java.lang.Throwable getLastException()
      Returns the exception raised in the last operation; if the operation was successful and no exception was raised, returns null.
      java.util.regex.Pattern getWhitespace()
      Returns the currently used pattern for recognizing whitespace.
      boolean hasMore()
      Checks whether this reader has data to be read.
      boolean isEmpty()
      Checks whether this reader has no more data to be read.
      boolean isThrowingExceptions()
      Returns the indicator whether this reader will throw exceptions on I/O operation errors or just return default values.
      java.lang.String readAll()
      Reads all remaining content and returns it as a string.
      java.lang.String[] readAllLines()
      Read all remaining lines and returns them as an array of strings.
      boolean readBool()
      Reads one token and converts it to a boolean value.
      boolean[] readBoolArray()
      Reads one line, separates it into tokens and converts them to boolean values.
      java.lang.Boolean[] readBoolArrayBoxed()
      Reads one line, separates it into tokens and converts them to boolean values.
      java.lang.Boolean readBoolBoxed()
      Reads one token and converts it to a boolean value.
      boolean[][] readBoolMatrix()
      Reads multiple lines and converts the data to a boolean matrix.
      java.lang.Boolean[][] readBoolMatrixBoxed()
      Reads multiple lines and converts the data to a boolean matrix.
      byte readByte()
      Reads one token and converts it to a byte value.
      byte[] readByteArray()
      Reads one line, separates it into tokens and converts them to byte values.
      java.lang.Byte[] readByteArrayBoxed()
      Reads one line, separates it into tokens and converts them to byte values.
      java.lang.Byte readByteBoxed()
      Reads one token and converts it to a byte value.
      byte[][] readByteMatrix()
      Reads multiple lines and converts the data to a byte matrix.
      java.lang.Byte[][] readByteMatrixBoxed()
      Reads multiple lines and converts the data to a byte matrix.
      char readChar()
      Reads one token and converts it to a character value.
      char[] readCharArray()
      Reads one line, separates it into tokens and converts them to character values.
      java.lang.Character[] readCharArrayBoxed()
      Reads one line, separates it into tokens and converts them to character values.
      java.lang.Character readCharBoxed()
      Reads one token and converts it to a character value.
      char[][] readCharMatrix()
      Reads multiple lines and converts the data to a character matrix.
      java.lang.Character[][] readCharMatrixBoxed()
      Reads multiple lines and converts the data to a character matrix.
      double readDouble()
      Reads one token and converts it to a double-precision floating-point value.
      double[] readDoubleArray()
      Reads one line, separates it into tokens and converts them to double-precision floating-point values.
      java.lang.Double[] readDoubleArrayBoxed()
      Reads one line, separates it into tokens and converts them to double-precision floating-point values.
      java.lang.Double readDoubleBoxed()
      Reads one token and converts it to a double-precision floating-point value.
      double[][] readDoubleMatrix()
      Reads multiple lines and converts the data to a double-precision floating-point matrix.
      java.lang.Double[][] readDoubleMatrixBoxed()
      Reads multiple lines and converts the data to a double-precision floating-point matrix.
      float readFloat()
      Reads one token and converts it to a floating-point value.
      float[] readFloatArray()
      Reads one line, separates it into tokens and converts them to floating-point values.
      java.lang.Float[] readFloatArrayBoxed()
      Reads one line, separates it into tokens and converts them to floating-point values.
      java.lang.Float readFloatBoxed()
      Reads one token and converts it to a floating-point value.
      float[][] readFloatMatrix()
      Reads multiple lines and converts the data to a floating-point matrix.
      java.lang.Float[][] readFloatMatrixBoxed()
      Reads multiple lines and converts the data to a floating-point matrix.
      int readInt()
      Reads one token and converts it to an integer value.
      int[] readIntArray()
      Reads one line, separates it into tokens and converts them to integer values.
      java.lang.Integer[] readIntArrayBoxed()
      Reads one line, separates it into tokens and converts them to integer values.
      java.lang.Integer readIntBoxed()
      Reads one token and converts it to an integer value.
      int[][] readIntMatrix()
      Reads multiple lines and converts the data to an integer matrix.
      java.lang.Integer[][] readIntMatrixBoxed()
      Reads multiple lines and converts the data to an integer matrix.
      java.lang.String readLine()
      Reads a line of text and returns it as a string.
      long readLong()
      Reads one token and converts it to a long integer value.
      long[] readLongArray()
      Reads one line, separates it into tokens and converts them to long integer values.
      java.lang.Long[] readLongArrayBoxed()
      Reads one line, separates it into tokens and converts them to long integer values.
      java.lang.Long readLongBoxed()
      Reads one token and converts it to a long integer value.
      long[][] readLongMatrix()
      Reads multiple lines and converts the data to a long integer matrix.
      java.lang.Long[][] readLongMatrixBoxed()
      Reads multiple lines and converts the data to a long integer matrix.
      java.lang.Object readObject()
      Reads a JSON (JavaScript Object Notation) formatted object.
      short readShort()
      Reads one token and converts it to a short integer value.
      short[] readShortArray()
      Reads one line, separates it into tokens and converts them to short integer values.
      java.lang.Short[] readShortArrayBoxed()
      Reads one line, separates it into tokens and converts them to short integer values.
      java.lang.Short readShortBoxed()
      Reads one token and converts it to a short integer value.
      short[][] readShortMatrix()
      Reads multiple lines and converts the data to a shot integer matrix.
      java.lang.Short[][] readShortMatrixBoxed()
      Reads multiple lines and converts the data to a shot integer matrix.
      java.lang.String readToken()
      Reads one token and returns it as a string value.
      java.lang.String[] readTokenArray()
      Reads one line, separates it into tokens and returns them as string values.
      java.lang.String[][] readTokenMatrix()
      Reads multiple lines and converts the data to a string matrix.
      void setThrowingExceptions​(boolean shouldThrow)
      Configures whether this reader should throw exceptions on I/O operation errors or just return default values.
      void setWhitespace​(java.util.regex.Pattern whitespace)
      Sets the pattern used to recognize whitespace.
    • Method Detail

      • getWhitespace

        java.util.regex.Pattern getWhitespace()
        Returns the currently used pattern for recognizing whitespace. This pattern is used to separate tokens when reading form the underlying source. For more on patterns see Pattern.
        Returns:
        the pattern currently used to recognize whitespace.
        See Also:
        Pattern
      • setWhitespace

        void setWhitespace​(java.util.regex.Pattern whitespace)
        Sets the pattern used to recognize whitespace. This pattern is used to separate tokens when reading form the underlying source. For more on patterns see Pattern.
        Parameters:
        whitespace - the pattern to use recognize whitespace
        See Also:
        Pattern
      • isThrowingExceptions

        boolean isThrowingExceptions()
        Returns the indicator whether this reader will throw exceptions on I/O operation errors or just return default values.
        Returns:
        true if this reader throws exceptions on failed I/O operations; false otherwise.
      • setThrowingExceptions

        void setThrowingExceptions​(boolean shouldThrow)
        Configures whether this reader should throw exceptions on I/O operation errors or just return default values.
        Parameters:
        shouldThrow - true if this reader should throw exceptions on failed I/O operations in the future; false if it should return default values.
      • getLastException

        java.lang.Throwable getLastException()
        Returns the exception raised in the last operation; if the operation was successful and no exception was raised, returns null.
        Returns:
        the exception raised in the last operation or null it the operation was successful.
      • isEmpty

        boolean isEmpty()
        Checks whether this reader has no more data to be read.
        Returns:
        true if this reader has no more data to be read; false otherwise.
      • hasMore

        boolean hasMore()
        Checks whether this reader has data to be read.
        Returns:
        true if this reader has data to be read; false otherwise.
      • close

        void close()
            throws SvetovidIOException
        Closes this reader and releases any resources associated with the underlying source. The general contract of close is that it closes the input source. A closed source cannot perform input operations and cannot be reopened.
        Specified by:
        close in interface java.lang.AutoCloseable
        Specified by:
        close in interface java.io.Closeable
        Throws:
        SvetovidIOException - if an error occurred during the operation.
      • readTokenArray

        java.lang.String[] readTokenArray()
                                   throws SvetovidIOException
        Reads one line, separates it into tokens and returns them as string values.
        Returns:
        an array of String values read.
        Throws:
        SvetovidIOException - if an error occurred during the operation.
      • readLine

        java.lang.String readLine()
                           throws SvetovidIOException
        Reads a line of text and returns it as a string. A line is considered to be terminated by any one of a line feed ('\n'), a carriage return ('\r'), or a carriage return followed immediately by a line feed.
        Returns:
        A String containing the contents of the line, not including any line-termination characters, or null if the end of the source has been reached.
        Throws:
        SvetovidIOException - if an error occurred during the operation.
      • readAllLines

        java.lang.String[] readAllLines()
                                 throws SvetovidIOException
        Read all remaining lines and returns them as an array of strings. A line is considered to be terminated by any one of a line feed ('\n'), a carriage return ('\r'), or a carriage return followed immediately by a line feed.
        Returns:
        A String array containing the contents of the remaining lines, not including any line-termination characters, or an empty array if the end of the source has been reached.
        Throws:
        SvetovidIOException - if an error occurred during the operation.
      • readAll

        java.lang.String readAll()
                          throws SvetovidIOException
        Reads all remaining content and returns it as a string.
        Returns:
        A String containing all the remaining contents of the source, or null if the end of the source has been reached.
        Throws:
        SvetovidIOException - if an error occurred during the operation.
      • readBoolMatrix

        boolean[][] readBoolMatrix()
                            throws SvetovidFormatException,
                                   SvetovidIOException
        Reads multiple lines and converts the data to a boolean matrix. The matrix is read row by row until an empty row is found or the end of input is reached.
        Returns:
        a matrix of boolean values read.
        Throws:
        SvetovidFormatException - if one of the read values is not a parsable boolean.
        SvetovidIOException - if an error occurred during the operation.
      • readByteMatrix

        byte[][] readByteMatrix()
                         throws SvetovidFormatException,
                                SvetovidIOException
        Reads multiple lines and converts the data to a byte matrix. The matrix is read row by row until an empty row is found or the end of input is reached.
        Returns:
        a matrix of byte values read.
        Throws:
        SvetovidFormatException - if one of the read values is not a parsable byte.
        SvetovidIOException - if an error occurred during the operation.
      • readShortMatrix

        short[][] readShortMatrix()
                           throws SvetovidFormatException,
                                  SvetovidIOException
        Reads multiple lines and converts the data to a shot integer matrix. The matrix is read row by row until an empty row is found or the end of input is reached.
        Returns:
        a matrix of short values read.
        Throws:
        SvetovidFormatException - if one of the read values is not a parsable short.
        SvetovidIOException - if an error occurred during the operation.
      • readIntMatrix

        int[][] readIntMatrix()
                       throws SvetovidFormatException,
                              SvetovidIOException
        Reads multiple lines and converts the data to an integer matrix. The matrix is read row by row until an empty row is found or the end of input is reached.
        Returns:
        a matrix of int values read.
        Throws:
        SvetovidFormatException - if one of the read values is not a parsable integer.
        SvetovidIOException - if an error occurred during the operation.
      • readLongMatrix

        long[][] readLongMatrix()
                         throws SvetovidFormatException,
                                SvetovidIOException
        Reads multiple lines and converts the data to a long integer matrix. The matrix is read row by row until an empty row is found or the end of input is reached.
        Returns:
        a matrix of long values read.
        Throws:
        SvetovidFormatException - if one of the read values is not a parsable long.
        SvetovidIOException - if an error occurred during the operation.
      • readFloatMatrix

        float[][] readFloatMatrix()
                           throws SvetovidFormatException,
                                  SvetovidIOException
        Reads multiple lines and converts the data to a floating-point matrix. The matrix is read row by row until an empty row is found or the end of input is reached.
        Returns:
        a matrix of float values read.
        Throws:
        SvetovidFormatException - if one of the read values is not a parsable float.
        SvetovidIOException - if an error occurred during the operation.
      • readDoubleMatrix

        double[][] readDoubleMatrix()
                             throws SvetovidFormatException,
                                    SvetovidIOException
        Reads multiple lines and converts the data to a double-precision floating-point matrix. The matrix is read row by row until an empty row is found or the end of input is reached.
        Returns:
        a matrix of double values read.
        Throws:
        SvetovidFormatException - if one of the read values is not a parsable double.
        SvetovidIOException - if an error occurred during the operation.
      • readCharMatrix

        char[][] readCharMatrix()
                         throws SvetovidFormatException,
                                SvetovidIOException
        Reads multiple lines and converts the data to a character matrix. The matrix is read row by row until an empty row is found or the end of input is reached.
        Returns:
        a matrix of char values read.
        Throws:
        SvetovidFormatException - if one of the read values is not a parsable character.
        SvetovidIOException - if an error occurred during the operation.
      • readTokenMatrix

        java.lang.String[][] readTokenMatrix()
                                      throws SvetovidIOException
        Reads multiple lines and converts the data to a string matrix. The matrix is read row by row until an empty row is found or the end of input is reached.
        Returns:
        a matrix of String values read.
        Throws:
        SvetovidIOException - if an error occurred during the operation.
      • readBoolMatrixBoxed

        java.lang.Boolean[][] readBoolMatrixBoxed()
                                           throws SvetovidFormatException,
                                                  SvetovidIOException
        Reads multiple lines and converts the data to a boolean matrix. The matrix is read row by row until an empty row is found or the end of input is reached.
        Returns:
        a matrix of Boolean values read.
        Throws:
        SvetovidFormatException - if one of the read values is not a parsable boolean.
        SvetovidIOException - if an error occurred during the operation.
      • readByteMatrixBoxed

        java.lang.Byte[][] readByteMatrixBoxed()
                                        throws SvetovidFormatException,
                                               SvetovidIOException
        Reads multiple lines and converts the data to a byte matrix. The matrix is read row by row until an empty row is found or the end of input is reached.
        Returns:
        a matrix of Byte values read.
        Throws:
        SvetovidFormatException - if one of the read values is not a parsable byte.
        SvetovidIOException - if an error occurred during the operation.
      • readShortMatrixBoxed

        java.lang.Short[][] readShortMatrixBoxed()
                                          throws SvetovidFormatException,
                                                 SvetovidIOException
        Reads multiple lines and converts the data to a shot integer matrix. The matrix is read row by row until an empty row is found or the end of input is reached.
        Returns:
        a matrix of Short values read.
        Throws:
        SvetovidFormatException - if one of the read values is not a parsable short.
        SvetovidIOException - if an error occurred during the operation.
      • readIntMatrixBoxed

        java.lang.Integer[][] readIntMatrixBoxed()
                                          throws SvetovidFormatException,
                                                 SvetovidIOException
        Reads multiple lines and converts the data to an integer matrix. The matrix is read row by row until an empty row is found or the end of input is reached.
        Returns:
        a matrix of Integer values read.
        Throws:
        SvetovidFormatException - if one of the read values is not a parsable integer.
        SvetovidIOException - if an error occurred during the operation.
      • readLongMatrixBoxed

        java.lang.Long[][] readLongMatrixBoxed()
                                        throws SvetovidFormatException,
                                               SvetovidIOException
        Reads multiple lines and converts the data to a long integer matrix. The matrix is read row by row until an empty row is found or the end of input is reached.
        Returns:
        a matrix of Long values read.
        Throws:
        SvetovidFormatException - if one of the read values is not a parsable long.
        SvetovidIOException - if an error occurred during the operation.
      • readFloatMatrixBoxed

        java.lang.Float[][] readFloatMatrixBoxed()
                                          throws SvetovidFormatException,
                                                 SvetovidIOException
        Reads multiple lines and converts the data to a floating-point matrix. The matrix is read row by row until an empty row is found or the end of input is reached.
        Returns:
        a matrix of Float values read.
        Throws:
        SvetovidFormatException - if one of the read values is not a parsable float.
        SvetovidIOException - if an error occurred during the operation.
      • readDoubleMatrixBoxed

        java.lang.Double[][] readDoubleMatrixBoxed()
                                            throws SvetovidFormatException,
                                                   SvetovidIOException
        Reads multiple lines and converts the data to a double-precision floating-point matrix. The matrix is read row by row until an empty row is found or the end of input is reached.
        Returns:
        a matrix of Double values read.
        Throws:
        SvetovidFormatException - if one of the read values is not a parsable double.
        SvetovidIOException - if an error occurred during the operation.
      • readCharMatrixBoxed

        java.lang.Character[][] readCharMatrixBoxed()
                                             throws SvetovidFormatException,
                                                    SvetovidIOException
        Reads multiple lines and converts the data to a character matrix. The matrix is read row by row until an empty row is found or the end of input is reached.
        Returns:
        a matrix of Character values read.
        Throws:
        SvetovidFormatException - if one of the read values is not a parsable character.
        SvetovidIOException - if an error occurred during the operation.
      • readObject

        java.lang.Object readObject()
                             throws SvetovidFormatException,
                                    SvetovidIOException
        Reads a JSON (JavaScript Object Notation) formatted object.

        The object is converted to Java types using the following rules:

        • literal null is converted to Java null,
        • literals true and false are converted to Boolean.TRUE and Boolean.FALSE respectively,
        • numbers are converted to an instance of the first numeric type from the following list that can hold the value read: Byte, Short, Integer, Long, Float, Double, BigInteger, BigDecimal,
        • strings are converted to String values,
        • arrays are converted to Lists containing the held values in the same order
        • and objects are converted to Maps that can be iterated in the order in which its members were defined. Each member's value is registered in the map under its name.
        Returns:
        a Java Object parsed form the JSON format according to the above rules.
        Throws:
        SvetovidFormatException - if the object to be read is not in the JSON format.
        SvetovidIOException - if an error occurred during the operation.