Class NestedFormatHelper


  • public class NestedFormatHelper
    extends Object
    A helper class for the nested option format.
    Author:
    fracpete (fracpete at waikato dot ac dot nz)
    • Constructor Detail

      • NestedFormatHelper

        public NestedFormatHelper()
    • Method Detail

      • removeComments

        public static int removeComments​(List<String> lines)
        Removes all comments from the start of the list of (raw) lines.
        Parameters:
        lines - the raw lines
        Returns:
        the number of comment lines
      • getIndentationLevel

        protected static int getIndentationLevel​(String s,
                                                 char indentChar)
        Determines the indentation level of the given string.
        Parameters:
        s - the string to analyze
        indentChar - the character used for indentation
        Returns:
        the level
      • linesToNested

        protected static ArrayList linesToNested​(List<String> lines,
                                                 int[] index,
                                                 int[] levels,
                                                 int offset)
        Turns the nested lines into a nested structure to be used by option handlers.
        Parameters:
        lines - the lines to turn into a nested structure
        index - the index in the lines
        levels - all the indentation levels in the lines
        offset - the offset in lines, i.e., the number of comments removed
        Returns:
        the nested structure
      • linesToNested

        public static ArrayList linesToNested​(List<String> lines,
                                              char indentChar)
        Turns the nested lines into a nested structure to be used by option handlers.
        Parameters:
        lines - the lines to turn into a nested structure
        indentChar - the character used for indentation
        Returns:
        the nested structure
      • linesToNested

        public static ArrayList linesToNested​(List<String> lines,
                                              int offset,
                                              char indentChar)
        Turns the nested lines into a nested structure to be used by option handlers.
        Parameters:
        lines - the lines to turn into a nested structure
        offset - the offset in lines, i.e., the number of comments removed
        indentChar - the character used for indentation
        Returns:
        the nested structure
      • getIndentation

        protected static String getIndentation​(int level)
        Returns the indentation string for the given level.
        Parameters:
        level - the level to generate the indentation string for
        Returns:
        the generated string
      • nestedToLines

        protected static void nestedToLines​(List nested,
                                            boolean lineNo,
                                            List<String> lines,
                                            int level)
        Turns the nested options from an option handler into indentated lines.
        Parameters:
        nested - the nested structure to turn into indentated lines
        lineNo - whether to add the line numbers
        lines - the lines so far
        level - the current level of indentation
      • nestedToLines

        public static List<String> nestedToLines​(List nested)
        Turns the nested options from an option handler into indentated lines.
        Parameters:
        nested - the nested structure to turn into indentated lines
        Returns:
        the indentated lines
      • nestedToLines

        public static List<String> nestedToLines​(List nested,
                                                 boolean lineNo)
        Turns the nested options from an option handler into indentated lines.
        Parameters:
        nested - the nested structure to turn into indentated lines
        lineNo - whether to add the line numbers
        Returns:
        the indentated lines
      • renumber

        protected static int renumber​(List nested,
                                      int offset)
        Updates the line numbering.
        Parameters:
        nested - the nested lines to updated
        offset - the current offset
        Returns:
        the last line number updated
      • renumber

        public static void renumber​(List nested)
        Updates the line numbering.
        Parameters:
        nested - the nested lines to updated
      • getModules

        public static List<String> getModules​(List<String> lines)
        Extracts the modules from the comments, if available.
        Parameters:
        lines - the raw lines of the flow
        Returns:
        the modules, if any
      • checkModules

        public static String checkModules​(List<String> modules)
        Checks whether there are any modules missing in the current environment compared to the provided list of module names.
        Parameters:
        modules - the list of modules to check
        Returns:
        null if everything OK, otherwise error message