Package parser

Class STRING


  • public class STRING
    extends java.lang.Object
    Author:
    JIBOYE OLUWAGBEMIRO OLAOLUWA. This class has many methods. Method delete provides 2 constructors.The at takes 2 arguments,the string to manipulate and the index to be deleted from the string.It returns the original string without the element at the specified index. Method delete takes 3 arguments.The string,the index from which deletion is to begin and the index where deletion ends.The returned string is the original string without the characters from the starting index to one index behind the ending index.So the character at the ending index is not deleted. So if we write At( u,0,u.length() ),the whole string is deleted. Method isDouble1 takes a single argument;that is the number string which we wish to know if it is of type double or not. It is a bold attempt by the author to devise a means of checking if a number entry qualifies as a double number string. This checking is done at much higher speeds in comparison to method isDouble.
    • Constructor Summary

      Constructors 
      Constructor Description
      STRING()  
    • Method Summary

      Modifier and Type Method Description
      static boolean contains​(java.lang.String str, java.lang.String substr)
      contains allows you to verify if an input string contains a given substring.
      static int countOccurences​(java.lang.String c, java.lang.String str)
      Counts how many times a given single character string occurs in a given String object.
      static java.lang.String delete​(java.lang.String u, int i)
      method delete takes 2 arguments,the string to be modified and the index of the character to be deleted
      static java.lang.String delete​(java.lang.String u, int i, int j)
      method delete takes 3 arguments,the string to be modified, the index at which deleting is to begin and the index one after the point where deletion is to end.
      static java.lang.String delete​(java.lang.String u, java.lang.String str)
      method delete takes 2 arguments,the string to be modified and the substring to be removed from it.
      static java.lang.String deleteCharsAfter​(java.lang.String str, int i, int num)
      method delete takes 3 arguments,the string to be modified, the index at which deleting is to begin and the index one after the point where deletion is to end.
      static java.lang.String doubleToString​(double num)  
      static java.lang.String firstElement​(java.lang.String u)
      method firstElement takes one argument and that is the string to be modified.
      static int getFirstIndexOfDigit​(java.lang.String val)
      method getFirstIndexOfDigit takes a String object and returns the index of the first occurence of a number character in the String.
      static int getFirstIndexOfDigitOrPoint​(java.lang.String val)
      method getFirstIndexOfDigit takes a String object and returns the index of the first occurence of a number character in the String.
      static java.lang.String getFirstNumberSubstring​(java.lang.String val)
      method getFirstNumberSubstring takes a String object and returns the first number string in the String.
      static java.lang.String getFirstOccurenceOfDigit​(java.lang.String value)
      method getFirstOccurenceOfDigit takes a String object and returns the first occurence of a number character in the String.
      static boolean hasChars​(java.lang.String str)  
      static boolean isDecimalPoint​(java.lang.String val)  
      static boolean isDigit​(java.lang.String a)
      boolean Method isDigit can be used to check for single digits i.e 0-9.
      static boolean isDouble​(java.lang.String a)
      boolean Method isDouble(Object a) detects if a string entry is in double number format or not.
      static boolean isDouble1​(java.lang.String a)
      Method isDouble1 is specially built for parsing number strings in my parser.Please do not use it for your own purposes.
      static boolean isEven​(double a)
      Checks if a given number is even
      static boolean isEven​(float a)
      Checks if a given number is even
      static boolean isEven​(int a)
      Checks if a given number is even
      static boolean isEven​(java.lang.String a)  
      static boolean isExponentOf10​(java.lang.String val)  
      static boolean isfullyDouble​(java.lang.String num)
      isfullyDouble allows you to verify if an input string is in double number format or not.
      static boolean isLetter​(java.lang.String aChar)  
      static boolean isLowerCaseWord​(java.lang.String a)
      method isLowerCaseWord takes one argument and that is the string whose case we wish to know.
      static boolean isNumberComponent​(java.lang.String comp)
      boolean Method isNumberComponent(args) detects if a string entry is a buiding block for a valid number or not For our purposes,the building blocks are the digits,the "." symbol,the E symbol,the - symbol,but not the addition one.
      static boolean isOnlyDigits​(java.lang.String h)
      isOnlyDigits allows you to verify if an input string consists of just digits and the exponential symbol.
      static boolean isSign​(java.lang.String val)  
      static boolean isUpperCaseWord​(java.lang.String a)
      method isUpperCaseWord takes one argument and that is the string whose case we wish to know.
      static boolean isWord​(java.lang.String a)  
      static java.lang.String lastElement​(java.lang.String u)
      method lastElement takes one argument and that is the string to be modified.
      static void main​(java.lang.String[] args)  
      static int nextIndexOf​(java.lang.String str, int index, java.lang.String str2)
      nextIndexOf allows you to get the next occurence of a substring searching from a point in the string forwards
      static int prevIndexOf​(java.lang.String str, int index, java.lang.String str2)
      prevIndexOf allows you to get the previous occurence of a substring searching from a point in the string backwards
      static java.lang.String purifier​(java.lang.String h)
      purifier allows you to remove all white spaces in a given string,which it receives as its argument
      static java.lang.String purifier​(java.lang.String h, int fromIndex)
      purifier allows you to remove all white spaces in a given string,which it receives as its argument
      static java.lang.String removeAll​(java.lang.String str, java.lang.String unwanted)
      removeAll allows you to remove all occurrences of an unwanted string from a given string, which it receives as its argument
      static java.lang.String removeCommas​(java.lang.String h)
      Allows you to remove commas from a string.
      static java.lang.String removeNewLineChar​(java.lang.String input)  
      static java.lang.String replace​(java.lang.String u, java.lang.String u1, java.lang.Integer i, java.lang.Integer j)
      method replace takes 4 arguments,the string to be modified, the replacing string, the index at which replacement is to begin and the index where replacement ends plus one i.e replacement ends at index j-1.
      static java.lang.String replaceAll​(java.lang.String str, java.lang.String replaced, java.lang.String replacing)
      The Technology: 1.
      static java.lang.String reverse​(java.lang.String u1)
      method reverse takes 1 argument and that is the string to be reversed
      static java.util.ArrayList<java.lang.String> split​(java.lang.String stringTosplit, java.lang.String splittingObject)
      This is an optimized specialized substitute for String.split in the Java API.
      static java.lang.String[] splits​(java.lang.String stringTosplit, java.lang.String splittingObject)
      This is an highly optimized specialized substitute for String.split in the Java API.
      static java.lang.String[] splits​(java.lang.String stringTosplit, java.lang.String[] splittingObjects)
      This is an highly optimized specialized substitute for String.split in the Java API.
      static java.lang.String toLowerCase​(java.lang.String m)
      method toLowerCase takes one argument only and that is input string to be converted to lower case
      static java.lang.String toUpperCase​(java.lang.String m)
      method toUpperCase takes one argument only and that is the input string to be converted to upper case
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • STRING

        public STRING()
    • Method Detail

      • contains

        public static boolean contains​(java.lang.String str,
                                       java.lang.String substr)
        contains allows you to verify if an input string contains a given substring.
        Parameters:
        str - : the string to check
        substr - : the substring to check for
        Returns:
        true or false depending on if or not the input consists of digits alone or otherwise.
      • isOnlyDigits

        public static boolean isOnlyDigits​(java.lang.String h)
        isOnlyDigits allows you to verify if an input string consists of just digits and the exponential symbol. So the method will return true for 32000 but not for 3.2E4.It will also return true for 32E3.No decimal points are allowed
        Parameters:
        h - ..The string to be analyzed.
        Returns:
        true or false depending on if or not the input consists of digits alone or otherwise.
      • isLetter

        public static boolean isLetter​(java.lang.String aChar)
        Parameters:
        aChar - The single character string to be examined if it is a letter of the alphabet or not.
        Returns:
        true if the parameter is a valid letter of the English alphabet.
      • removeNewLineChar

        public static java.lang.String removeNewLineChar​(java.lang.String input)
        Parameters:
        input - The string from which we wish to remove all new line characters.
        Returns:
        a string like the input but free of all new line characters.
      • isfullyDouble

        public static boolean isfullyDouble​(java.lang.String num)
        isfullyDouble allows you to verify if an input string is in double number format or not.
        Parameters:
        num - ..The string to be analyzed.
        Returns:
        true or false depending on if or not the input represents a valid double number
      • firstElement

        public static java.lang.String firstElement​(java.lang.String u)
        method firstElement takes one argument and that is the string to be modified.
        Parameters:
        u - the string to be modified
        Returns:
        the first element of the string
        Throws:
        java.lang.StringIndexOutOfBoundsException
      • lastElement

        public static java.lang.String lastElement​(java.lang.String u)
        method lastElement takes one argument and that is the string to be modified.
        Parameters:
        u - the string to be modified
        Returns:
        the last element of the string
        Throws:
        java.lang.StringIndexOutOfBoundsException
      • nextIndexOf

        public static int nextIndexOf​(java.lang.String str,
                                      int index,
                                      java.lang.String str2)
        nextIndexOf allows you to get the next occurence of a substring searching from a point in the string forwards
        Parameters:
        str - ..The String being analyzed.
        index - ..The starting point of the search.
        str2 - ..The string whose next occurence we desire.
        Returns:
        the next index of the str2 if found or -1 if not found
      • prevIndexOf

        public static int prevIndexOf​(java.lang.String str,
                                      int index,
                                      java.lang.String str2)
        prevIndexOf allows you to get the previous occurence of a substring searching from a point in the string backwards
        Parameters:
        str - ..The String being analyzed.
        index - ..The starting point of the search.
        str2 - ..The string whose previous occurence we desire.
        Returns:
        the previous index of the str2 if found or -1 if not found
      • isSign

        public static boolean isSign​(java.lang.String val)
        Parameters:
        val - the entry being analyzed.
        Returns:
        true if the entry is a + sign or a minus sign
      • isDecimalPoint

        public static boolean isDecimalPoint​(java.lang.String val)
        Parameters:
        val - the entry being analyzed.
        Returns:
        true if the entry is a floating point
      • isExponentOf10

        public static boolean isExponentOf10​(java.lang.String val)
        Parameters:
        val - the entry being analyzed.
        Returns:
        true if the entry is the power of 10 symbol i.e E
      • getFirstOccurenceOfDigit

        public static java.lang.String getFirstOccurenceOfDigit​(java.lang.String value)
                                                         throws java.lang.StringIndexOutOfBoundsException
        method getFirstOccurenceOfDigit takes a String object and returns the first occurence of a number character in the String.
        Parameters:
        value - the string to analyze
        Returns:
        the first occurence of a number character in the sequence.
        Throws:
        java.lang.StringIndexOutOfBoundsException
      • getFirstIndexOfDigit

        public static int getFirstIndexOfDigit​(java.lang.String val)
                                        throws java.lang.StringIndexOutOfBoundsException
        method getFirstIndexOfDigit takes a String object and returns the index of the first occurence of a number character in the String.
        Parameters:
        val - the string to analyze
        Returns:
        the index of the first occurence of a number character in the sequence.
        Throws:
        java.lang.StringIndexOutOfBoundsException
      • getFirstIndexOfDigitOrPoint

        public static int getFirstIndexOfDigitOrPoint​(java.lang.String val)
                                               throws java.lang.StringIndexOutOfBoundsException
        method getFirstIndexOfDigit takes a String object and returns the index of the first occurence of a number character in the String.
        Parameters:
        val - the string to analyze
        Returns:
        the index of the first occurence of a number character in the sequence.
        Throws:
        java.lang.StringIndexOutOfBoundsException
      • countOccurences

        public static int countOccurences​(java.lang.String c,
                                          java.lang.String str)
        Counts how many times a given single character string occurs in a given String object.
        Parameters:
        c - A single character String value whose occurences in another string we wish to count.
        str - The String object that we will search through.
        Returns:
        The number of times c occurs in str
      • getFirstNumberSubstring

        public static java.lang.String getFirstNumberSubstring​(java.lang.String val)
                                                        throws java.lang.StringIndexOutOfBoundsException
        method getFirstNumberSubstring takes a String object and returns the first number string in the String.
        Parameters:
        val - the string to analyze
        Returns:
        the index of the first occurrence of a number character in the sequence.
        Throws:
        java.lang.StringIndexOutOfBoundsException
      • removeCommas

        public static java.lang.String removeCommas​(java.lang.String h)
        Allows you to remove commas from a string.
        Parameters:
        h -
        Returns:
        a string in which the contents of the original have been freed from all commas.
      • purifier

        public static java.lang.String purifier​(java.lang.String h)
        purifier allows you to remove all white spaces in a given string,which it receives as its argument
        Parameters:
        h - The string to free from white space.
        Returns:
        a string devoid of all white space.
      • purifier

        public static java.lang.String purifier​(java.lang.String h,
                                                int fromIndex)
        purifier allows you to remove all white spaces in a given string,which it receives as its argument
        Parameters:
        h - The string to remove white space from.
        Returns:
        a string from which white space has been removed starting from index fromIndex.
      • removeAll

        public static java.lang.String removeAll​(java.lang.String str,
                                                 java.lang.String unwanted)
                                          throws java.lang.IndexOutOfBoundsException
        removeAll allows you to remove all occurrences of an unwanted string from a given string, which it receives as its argument
        Parameters:
        str - The string to remove the unwanted substring from.
        unwanted - The unwanted substring.
        Returns:
        a string from which all instance of unwanted has been removed.
        Throws:
        java.lang.IndexOutOfBoundsException
      • replaceAll

        public static java.lang.String replaceAll​(java.lang.String str,
                                                  java.lang.String replaced,
                                                  java.lang.String replacing)
        The Technology: 1. Split the string into an array on the replaced string. For example, if the string is Shohkhohlhohkhohbanhghohshoh, and the replaced string is hoh and the replacing string is now. Stage 1 generates: [S,k,l,k,banhg,s,] 2. Create a string object and loop through the array, appending to this object in each index, the contents of that index and the replacing string replaceAll allows you to replace all occurrences of an unwanted string in a given string with a new string, which it receives as its argument
        Parameters:
        str - The string on which replacement is to be done.
        replaced - The replaced string.
        replacing - The replacing string.
        Returns:
        a string from which all instance of unwanted has been removed.
      • delete

        public static java.lang.String delete​(java.lang.String u,
                                              int i)
                                       throws java.lang.StringIndexOutOfBoundsException
        method delete takes 2 arguments,the string to be modified and the index of the character to be deleted
        Parameters:
        u -
        i -
        Returns:
        the string after the character at index i has been removed
        Throws:
        java.lang.StringIndexOutOfBoundsException
      • delete

        public static java.lang.String delete​(java.lang.String u,
                                              java.lang.String str)
        method delete takes 2 arguments,the string to be modified and the substring to be removed from it.
        Parameters:
        u - the string to be modified
        str - the substring to be removed from u
        Returns:
        the string after the first instance of the specified substring has been removed
        Throws:
        java.lang.StringIndexOutOfBoundsException
      • delete

        public static java.lang.String delete​(java.lang.String u,
                                              int i,
                                              int j)
                                       throws java.lang.StringIndexOutOfBoundsException
        method delete takes 3 arguments,the string to be modified, the index at which deleting is to begin and the index one after the point where deletion is to end. STRING.delete("Corinthian", 2,4)returns "Conthian"
        Parameters:
        u -
        i -
        j -
        Returns:
        Throws:
        java.lang.StringIndexOutOfBoundsException
      • deleteCharsAfter

        public static java.lang.String deleteCharsAfter​(java.lang.String str,
                                                        int i,
                                                        int num)
                                                 throws java.lang.StringIndexOutOfBoundsException
        method delete takes 3 arguments,the string to be modified, the index at which deleting is to begin and the index one after the point where deletion is to end. STRING.delete("Corinthian", 2,4)returns "Conthian"
        Parameters:
        str - ..The original string
        i - ..The index at which we start deleting
        num - The number of characters to delete after the index.
        Returns:
        the resulting string after the chars between i and i+num-1 have been deleted.
        Throws:
        java.lang.StringIndexOutOfBoundsException
      • isDouble

        public static boolean isDouble​(java.lang.String a)
                                throws java.lang.NumberFormatException
        boolean Method isDouble(Object a) detects if a string entry is in double number format or not.
        Parameters:
        a -
        Returns:
        Throws:
        java.lang.NumberFormatException
      • isNumberComponent

        public static boolean isNumberComponent​(java.lang.String comp)
        boolean Method isNumberComponent(args) detects if a string entry is a buiding block for a valid number or not For our purposes,the building blocks are the digits,the "." symbol,the E symbol,the - symbol,but not the addition one.
        Parameters:
        comp - the String object to check
        Returns:
        true if the analyzed object is a valid component of a real number
      • split

        public static java.util.ArrayList<java.lang.String> split​(java.lang.String stringTosplit,
                                                                  java.lang.String splittingObject)
                                                           throws java.lang.ArrayIndexOutOfBoundsException
        This is an optimized specialized substitute for String.split in the Java API. It runs about 10-20 times or more faster than the split method in the Java API and it returns an ArrayList of values, instead of an array. Splits a string on all instances of the splitting object
        Parameters:
        splittingObject - The substring on which the string is to be split.
        stringTosplit - The string to be split.
        Returns:
        an array containing substrings that the string has been split into.
        Throws:
        java.lang.ArrayIndexOutOfBoundsException
      • splits

        public static java.lang.String[] splits​(java.lang.String stringTosplit,
                                                java.lang.String splittingObject)
        This is an highly optimized specialized substitute for String.split in the Java API. It runs about 40-100 times faster than the split method in the Java API and it returns an array, too. Splits a string on all instances of the splitting object
        Parameters:
        splittingObject - The substring on which the string is to be split.
        stringTosplit - The string to be split.
        Returns:
        an array containing substrings that the string has been split into.
      • splits

        public static java.lang.String[] splits​(java.lang.String stringTosplit,
                                                java.lang.String[] splittingObjects)
                                         throws java.lang.NullPointerException
        This is an highly optimized specialized substitute for String.split in the Java API. It runs about 5-10 times faster than the split method in the Java API and it returns an Array object, too. If the array of splitting objects contains nothing or contains elements that are not found in the string, then an Array object containing the original string is returned. But if the array of splitting objects contains an empty string, it chops or slices the string into pieces, and so returns an Array object containing the individual characters of the string. Splits a string on all instances of the splitting object
        Parameters:
        stringTosplit - The string to be split.
        splittingObjects - An array containing substrings on which the string should be split.
        Returns:
        an array containing substrings that the string has been split into.
        Throws:
        java.lang.NullPointerException - if the array of splitting objects contains a null value or is null.
      • isDigit

        public static boolean isDigit​(java.lang.String a)
        boolean Method isDigit can be used to check for single digits i.e 0-9.
        Parameters:
        a - the String to check.
        Returns:
        true if the string is a valid digit.
      • isDouble1

        public static boolean isDouble1​(java.lang.String a)
        Method isDouble1 is specially built for parsing number strings in my parser.Please do not use it for your own purposes. Its purpose is to detect already scanned number strings in a List object that contains many kinds of string objects
        Parameters:
        a -
        Returns:
        true if the string represents a number string( this in reality is true if the number has already being scanned and proven to be a valid number)
      • isWord

        public static boolean isWord​(java.lang.String a)
      • isLowerCaseWord

        public static boolean isLowerCaseWord​(java.lang.String a)
        method isLowerCaseWord takes one argument and that is the string whose case we wish to know.
        Parameters:
        a - The string to manipulate.
        Returns:
        true if the string is a lowercase letter
      • isUpperCaseWord

        public static boolean isUpperCaseWord​(java.lang.String a)
        method isUpperCaseWord takes one argument and that is the string whose case we wish to know.
        Parameters:
        a - The string to manipulate.
        Returns:
        true if the string is an uppercase letter
      • toUpperCase

        public static java.lang.String toUpperCase​(java.lang.String m)
        method toUpperCase takes one argument only and that is the input string to be converted to upper case
        Parameters:
        m - the single length string to be converted to upper case
        Returns:
        the upper case version of the input
        Throws:
        java.lang.StringIndexOutOfBoundsException
      • toLowerCase

        public static java.lang.String toLowerCase​(java.lang.String m)
        method toLowerCase takes one argument only and that is input string to be converted to lower case
        Parameters:
        m - the single length string to be converted to lower case
        Returns:
        the lower case version of the input
        Throws:
        java.lang.StringIndexOutOfBoundsException
      • reverse

        public static java.lang.String reverse​(java.lang.String u1)
        method reverse takes 1 argument and that is the string to be reversed
        Parameters:
        u1 - The string to be reversed.
        Returns:
        The reversed string.
      • replace

        public static java.lang.String replace​(java.lang.String u,
                                               java.lang.String u1,
                                               java.lang.Integer i,
                                               java.lang.Integer j)
                                        throws java.lang.StringIndexOutOfBoundsException
        method replace takes 4 arguments,the string to be modified, the replacing string, the index at which replacement is to begin and the index where replacement ends plus one i.e replacement ends at index j-1. STRING.replace("Corinthian","The" 3,6)returns "CorThehians"
        Parameters:
        u - The string to manipulate.
        u1 - The replacing string
        i - Index at which to begin replacing
        j - Index at which replacement ends plus one
        Returns:
        A string in which the characters between index i and j-1 have been replaced with the replacing string
        Throws:
        java.lang.StringIndexOutOfBoundsException
      • isEven

        public static boolean isEven​(java.lang.String a)
      • doubleToString

        public static java.lang.String doubleToString​(double num)
      • hasChars

        public static boolean hasChars​(java.lang.String str)
        Parameters:
        str - The String object to check.
        Returns:
        true if it contains at least one non-white space characters.
      • isEven

        public static boolean isEven​(double a)
        Checks if a given number is even
        Parameters:
        a - the number
        Returns:
        true if a is even
      • isEven

        public static boolean isEven​(float a)
        Checks if a given number is even
        Parameters:
        a - the number
        Returns:
        true if a is even
      • isEven

        public static boolean isEven​(int a)
        Checks if a given number is even
        Parameters:
        a - the number
        Returns:
        true if a is even
      • main

        public static void main​(java.lang.String[] args)