Class STRING
java.lang.Object
com.github.gbenroscience.parser.STRING
- 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 -
Method Summary
Modifier and TypeMethodDescriptionstatic booleancontains allows you to verify if an input string contains a given substring.static intcountOccurences(char c, String str) Counts how many times a given single character string occurs in a given String object.static Stringmethod delete takes 2 arguments,the string to be modified and the index of the character to be deletedstatic Stringmethod 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 Stringmethod delete takes 2 arguments,the string to be modified and the substring to be removed from it.static StringdeleteCharsAfter(String str, int i, int num) method deleteCharsAfter 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 StringdoubleToString(double num) static charstatic Stringmethod firstElement takes one argument and that is the string to be modified.static intmethod getFirstIndexOfDigit takes a String object and returns the index of the first occurence of a number character in the String.static intmethod getFirstIndexOfDigit takes a String object and returns the index of the first occurence of a number character in the String.static StringReturns the first number-like substring starting at the first digit found in the input.static StringgetFirstOccurenceOfDigit(String value) method getFirstOccurenceOfDigit takes a String object and returns the first occurence of a number character in the String.static booleanstatic booleanisDecimalPoint(String val) static booleanboolean Method isDigit can be used to check for single digits i.e 0-9.static booleanisDigitChar(char c) ////////////////////////////////////////////////////////////////////////////static booleanChecks if a string can be parsed as a double.static booleanMethod isDouble1 is specially built for parsing number strings in my parser.Please do not use it for your own purposes.static booleanisEven(double a) Checks if a given number is evenstatic booleanisEven(float a) Checks if a given number is evenstatic booleanisEven(int a) Checks if a given number is evenstatic booleanstatic booleanisExponentOf10(String val) static booleanisFullyDouble(String num) isFullyDouble allows you to verify if an input string is in double number format or not.static booleanstatic booleanmethod isLowerCaseWord takes one argument and that is the string whose case we wish to know.static booleanisNumberComponent(String comp) Checks if a string is a valid number component.static booleanisOnlyDigits allows you to verify if an input string consists of just digits and the exponential symbol.static booleanstatic booleanmethod isUpperCaseWord takes one argument and that is the string whose case we wish to know.static booleanstatic charstatic Stringmethod lastElement takes one argument and that is the string to be modified.static voidstatic intnextIndexOf(String str, int index, String str2) nextIndexOf allows you to get the next occurence of a substring searching from a point in the string forwardsstatic intprevIndexOf(String str, int index, String str2) prevIndexOf allows you to get the previous occurence of a substring searching from a point in the string backwardsstatic Stringpurifier allows you to remove all white spaces in a given string,which it receives as its argumentstatic StringReturns a string where characters from index `fromIndex` onward are purified (spaces and newlines removed), while the prefix [0, fromIndex) is preserved exactly.static StringremoveAll allows you to remove all occurrences of an unwanted string from a given string, which it receives as its argumentstatic StringAllows you to remove commas from a string.static StringremoveNewLineChar(String input) static Stringstatic Stringmethod 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 StringreplaceAll(String str, String replaced, String replacing) Replace all literal occurrences of `replaced` in `str` with `replacing`.static Stringmethod reverse takes 1 argument and that is the string to be reversedThis is an optimized specialized substitute for String.split in the Java API.static String[]This is an highly optimized specialized substitute for String.split in the Java API.static String[]This is an highly optimized specialized substitute for String.split in the Java API.static Stringmethod toLowerCase takes one argument only and that is input string to be converted to lower casestatic Stringmethod toUpperCase takes one argument only and that is the input string to be converted to upper case
-
Constructor Details
-
STRING
public STRING()
-
-
Method Details
-
contains
contains allows you to verify if an input string contains a given substring.- Parameters:
str- : the string to checksubstr- : the substring to check for- Returns:
- true or false depending on if or not the input consists of digits alone or otherwise.
-
isOnlyDigits
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
- Parameters:
s- 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
-
repeating
-
isFullyDouble
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
-
firstChar
-
lastChar
-
firstElement
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:
StringIndexOutOfBoundsException
-
lastElement
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:
StringIndexOutOfBoundsException
-
nextIndexOf
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
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
- Parameters:
val- the entry being analyzed.- Returns:
- true if the entry is a + sign or a minus sign
-
isDecimalPoint
- Parameters:
val- the entry being analyzed.- Returns:
- true if the entry is a floating point
-
isExponentOf10
- Parameters:
val- the entry being analyzed.- Returns:
- true if the entry is the power of 10 symbol i.e E
-
getFirstOccurenceOfDigit
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:
StringIndexOutOfBoundsException
-
getFirstIndexOfDigit
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:
StringIndexOutOfBoundsException
-
getFirstIndexOfDigitOrPoint
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:
StringIndexOutOfBoundsException
-
countOccurences
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
Returns the first number-like substring starting at the first digit found in the input. Supports optional decimal point and exponent (E or e) with optional sign. Examples it will extract: "123", "0.45", ".78", "3.14E-10". Note: relies on getFirstIndexOfDigit(val) to return the index of the first digit in val, or -1 if none.- Parameters:
val- the string to analyze- Returns:
- the index of the first occurrence of a number character in the sequence.
- Throws:
StringIndexOutOfBoundsException
-
removeCommas
-
purifier
-
purifier
Returns a string where characters from index `fromIndex` onward are purified (spaces and newlines removed), while the prefix [0, fromIndex) is preserved exactly. Semantics match the original: only ' ' and '\n' are removed.- Parameters:
h- The string to remove white space from.fromIndex-- Returns:
- a string from which white space has been removed starting from index fromIndex.
-
removeAll
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:
IndexOutOfBoundsException
-
replaceAll
Replace all literal occurrences of `replaced` in `str` with `replacing`. This preserves the original behavior for occurrences at the start or end.- Parameters:
str- the input string (must not be null)replaced- the substring to replace (must not be null)replacing- the replacement string (must not be null)- Returns:
- a new string with all literal occurrences replaced
- Throws:
NullPointerException- if any argument is nullIndexOutOfBoundsException- if replaced is longer than str
-
delete
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:
StringIndexOutOfBoundsException
-
delete
method delete takes 2 arguments,the string to be modified and the substring to be removed from it.- Parameters:
u- the string to be modifiedstr- the substring to be removed from u- Returns:
- the string after the first instance of the specified substring has been removed
- Throws:
StringIndexOutOfBoundsException
-
delete
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:
StringIndexOutOfBoundsException
-
deleteCharsAfter
method deleteCharsAfter 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 stringi- ..The index at which we start deletingnum- 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:
StringIndexOutOfBoundsException
-
isDouble
Checks if a string can be parsed as a double.- Parameters:
s- the string to check- Returns:
- true if parsable as double, false otherwise
- Throws:
NumberFormatException
-
isNumberComponent
Checks if a string is a valid number component. Valid components: digits, '.', 'E', '-', '+' -
split
public static ArrayList<String> split(String stringTosplit, String splittingObject) throws 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:
stringTosplit- The string to be split.splittingObject- The substring on which the string is to be split.- Returns:
- an array containing substrings that the string has been split into.
- Throws:
ArrayIndexOutOfBoundsException
-
splits
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:
stringToSplit- The string to be split.splittingObject- The substring on which the string is to be split.- Returns:
- an array containing substrings that the string has been split into.
-
splits
public static String[] splits(String stringTosplit, String[] splittingObjects) throws 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:
NullPointerException- if the array of splitting objects contains a null value or is null.
-
isDigitChar
public static boolean isDigitChar(char c) //////////////////////////////////////////////////////////////////////////// -
isDigit
boolean Method isDigit can be used to check for single digits i.e 0-9.- Parameters:
s- the String to check.- Returns:
- true if the string is a valid digit.
-
isDouble1
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
-
isLowerCaseWord
method isLowerCaseWord takes one argument and that is the string whose case we wish to know.- Parameters:
s- The string to manipulate.- Returns:
- true if the string is a lowercase letter
-
isUpperCaseWord
method isUpperCaseWord takes one argument and that is the string whose case we wish to know.- Parameters:
s- The string to manipulate.- Returns:
- true if the string is an uppercase letter
-
toUpperCase
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:
StringIndexOutOfBoundsException
-
toLowerCase
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:
StringIndexOutOfBoundsException
-
reverse
-
replace
public static String replace(String u, String u1, Integer i, Integer j) throws 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 stringi- Index at which to begin replacingj- 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:
StringIndexOutOfBoundsException
-
isEven
-
doubleToString
-
hasChars
- Parameters:
s- 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
-