Class Rule


  • public class Rule
    extends java.lang.Object
    Creates an object that can be used to change text based on a target, replacement, environment, and exception.
    • Field Summary

      Fields 
      Modifier and Type Field Description
      protected static char[] whitespaces  
    • Constructor Summary

      Constructors 
      Constructor Description
      Rule​(java.lang.String ruleStr)
      Creates a rule based on an input string
      Rule​(java.lang.String target, java.lang.String replacement, java.lang.String environment)
      Creates a rule with a given target, replacement, and environment
      Rule​(java.lang.String target, java.lang.String replacement, java.lang.String environment, java.lang.String exception)
      Creates a rule with a given target, replacement, environment, and exception
      Rule​(java.lang.String target, java.lang.String replacement, java.lang.String environment, java.lang.String exception, java.util.ArrayList<Category> categories)
      Creates a rule with a given target, replacement, environment, and exception, along with a list of categories
      Rule​(java.lang.String target, java.lang.String replacement, java.lang.String environment, java.util.ArrayList<Category> categories)
      Creates a rule with a given target, replacement, and environment, along with a category list
      Rule​(java.lang.String ruleStr, java.util.ArrayList<Category> categories)
      Creates a rule based on an input string and a list of categories
    • Method Summary

      All Methods Static Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      java.lang.String parse​(java.lang.String input)
      Takes a string, runs it through the rule, and gives an output.
      static java.util.ArrayList<Rule> parseFromList​(java.lang.String ruleList)
      Parses a list of rules, and makes it an ArrayList
      static java.lang.String parseList​(java.util.ArrayList<Rule> list, java.lang.String input)
      Parses a list of rules on one string
      java.lang.String toString()  
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
    • Field Detail

      • whitespaces

        protected static char[] whitespaces
    • Constructor Detail

      • Rule

        public Rule​(java.lang.String ruleStr)
             throws InvalidRuleSyntaxException
        Creates a rule based on an input string
        Parameters:
        ruleStr - The string to make the rule from
        Throws:
        InvalidRuleSyntaxException - Thrown when ruleStr does not follow the expected X/Y/Z/A format
      • Rule

        public Rule​(java.lang.String ruleStr,
                    java.util.ArrayList<Category> categories)
             throws InvalidRuleSyntaxException
        Creates a rule based on an input string and a list of categories
        Parameters:
        ruleStr - The string to make the rule from
        categories - The list of categories to use
        Throws:
        InvalidRuleSyntaxException - Thrown when ruleStr does not follow the expected X/Y/Z/A format
      • Rule

        public Rule​(java.lang.String target,
                    java.lang.String replacement,
                    java.lang.String environment,
                    java.util.ArrayList<Category> categories)
        Creates a rule with a given target, replacement, and environment, along with a category list
        Parameters:
        target - The target for the rule
        replacement - The replacement for the rule
        environment - The environment for the rule
        categories - The list of categories to use
      • Rule

        public Rule​(java.lang.String target,
                    java.lang.String replacement,
                    java.lang.String environment)
        Creates a rule with a given target, replacement, and environment
        Parameters:
        target - The target for the rule
        replacement - The replacement for the rule
        environment - The environment for the rule
      • Rule

        public Rule​(java.lang.String target,
                    java.lang.String replacement,
                    java.lang.String environment,
                    java.lang.String exception)
        Creates a rule with a given target, replacement, environment, and exception
        Parameters:
        target - The target for the rule
        replacement - The replacement for the rule
        environment - The environment for the rule
        exception - The exception for the rule; when the rule should not apply
      • Rule

        public Rule​(java.lang.String target,
                    java.lang.String replacement,
                    java.lang.String environment,
                    java.lang.String exception,
                    java.util.ArrayList<Category> categories)
        Creates a rule with a given target, replacement, environment, and exception, along with a list of categories
        Parameters:
        target - The target for the rule
        replacement - The replacement for the rule
        environment - The environment for the rule
        exception - The exception for the rule; when the rule should not apply
        categories - The list of categories to use
    • Method Detail

      • parse

        public java.lang.String parse​(java.lang.String input)
        Takes a string, runs it through the rule, and gives an output.
        Parameters:
        input - The string to run through the rule
        Returns:
        The output of the rule on the given string
      • parseList

        public static java.lang.String parseList​(java.util.ArrayList<Rule> list,
                                                 java.lang.String input)
        Parses a list of rules on one string
        Parameters:
        list - The list of rules to use
        input - The input to be processed
        Returns:
        The output of every rule on the input
      • parseFromList

        public static java.util.ArrayList<Rule> parseFromList​(java.lang.String ruleList)
        Parses a list of rules, and makes it an ArrayList
        Parameters:
        ruleList - A list of rules, separated by newlines
        Returns:
        an ArrayList of each rule specified
      • toString

        public java.lang.String toString()
        Overrides:
        toString in class java.lang.Object