Class OctaveIO

    • Constructor Detail

      • OctaveIO

        public OctaveIO​(OctaveExec octaveExec)
        Parameters:
        octaveExec -
    • Method Detail

      • set

        public void set​(Map<String,​OctaveObject> name2val)
        Sets the variables named as keys in name2val to objects given by the mapped values.
        Parameters:
        name2val - a mapping from variable names to according objects.
      • get

        public OctaveObject get​(String name)
        Gets the value of the variable name or null if this variable does not exist according to existsVar(String).
        Parameters:
        name - the name of a variable
        Returns:
        the value of the variable name from octave or null if the variable does not exist.
        Throws:
        OctaveClassCastException - if the value can not be cast to T
      • existsVar

        private boolean existsVar​(String name)
        Returns whether the variable name exists.
        Parameters:
        name - the name of a variable
        Returns:
        whether the variable name exists.
      • readerReadLine

        public static String readerReadLine​(BufferedReader reader)
        Reads a line from reader into a string if possible. Returns null at the end of the stream and throws an exception in case of io problems.
        Parameters:
        reader - the reader to read a line from.
        Returns:
        next line from reader, null at end of stream
        Throws:
        OctaveIOException - in case of IOException reading from reader.
      • read

        public static OctaveObject read​(BufferedReader reader)
        Read a single object from Reader. The first line read determines the type of object and the rest of reading is delegated to the OctaveDataReader associated with that type given by OctaveDataReader.getOctaveDataReader(String).
        Parameters:
        reader - a reader starting with first line TYPE[global ]type, i.e. global is optional and type is the type of the object to be read.
        Returns:
        OctaveObject read from Reader
        Throws:
        OctaveParseException - **** appropriate type? if the type read before is not registered and so there is no appropriate reader.
      • readWithName

        public static Map<String,​OctaveObject> readWithName​(BufferedReader reader)
        Read a single variable - object pair from Reader. The variable is given by its name.
        Parameters:
        reader - a reader starting with first line NAMEname, where name is the name of the variable. the following lines represent the object stored in that variable.
        Returns:
        a singleton map with the name of a variable and object stored therein.
      • readWithName

        public static Map<String,​OctaveObject> readWithName​(String input)
        Read a single object from String, it is an error if there is data left after the object.
        Parameters:
        input -
        Returns:
        a singleton map with the name and object
        Throws:
        OctaveParseException - if there is data left after the object is read
      • writerWriteLine

        public static void writerWriteLine​(Writer writer,
                                           String strWithNl)
        Writes a line given by strWithNl to writer if possible.
        Parameters:
        writer -
        strWithNl -
        Throws:
        OctaveIOException - in case of IOException writing to writer.
      • write

        public static <T extends OctaveObject> void write​(Writer writer,
                                                          T octValue)
                                                   throws IOException
        ER: Writes the OctaveObject octaveType (****bad name) to the writer writer. To that end, fetch an OctaveDataWriter of the appropriate type given by octaveType and use this writer to write octaveType onto writer.
        Type Parameters:
        T - the type of OctaveObject to be written.
        Parameters:
        writer - the writer to write the object octValue onto.
        octValue - the object to write to writer.
        Throws:
        OctaveParseException - **** appropriate type? if the type of octValue is not registered and so there is no appropriate writer.
        IOException - if the process of writing fails.
      • write

        public static void write​(Writer writer,
                                 String name,
                                 OctaveObject octValue)
                          throws IOException
        ER: Writes the name name and the OctaveObject octValue to the writer writer using write(Writer, OctaveObject).
        Parameters:
        writer - the writer to write the object octaveType onto.
        name - the name, **** of a variable
        octValue - the object to write to writer.
        Throws:
        OctaveParseException - **** appropriate type? if the type of octaveType is not registered and so there is no appropriate writer.
        IOException - if the process of writing fails.
      • toText

        public static String toText​(String name,
                                    OctaveObject octValue)
        Returns as a string how the variable name and the OctaveObject octaveType (****bad name) are written.
        Parameters:
        name - the name, **** of a variable
        octValue - the object to write to writer.
        Returns:
        The result from saving the value octaveType in octave -text format
      • toText

        public static String toText​(OctaveObject octValue)
        Returns as a string how the OctaveObject octaveType (****bad name) is written without variable, i.e. with variable "ans".
        Parameters:
        octValue -
        Returns:
        toText("ans", octValue)