/* XBN Java: Generically useful, non-GUI Java code. http://sourceforge.net/projects/xbnjava Copyright (C) 1997-2003, Jeff Epstein All rights reserved. Modifications: No Redistribution in binary form, with or without modifications, are permitted provided that the following conditions are met: * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. * If modifications are made to source code then this license should indicate that fact in the "Modifications" section above. * Neither the author, nor the contributors may be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. [NOTE: This license contains NO advertising clause.] */ package xbn.string; import xbn.placeholder.i_i_i; import java.util.Date; import java.text.SimpleDateFormat; import java.text.ParseException; /**

Random functions for java.lang.Strings. See String.

Source code:  UtilString.java.  Unit tests:  xbn_junit.string.JUTUtilString.java and also see the unit tests for UtilSOB..

@version 0.9b @author Jeff Epstein, http://sourceforge.net/projects/xbnjava. **/ public class UtilString extends UtilSOB { /**

To shorten code and Javadoc.

Equal to "xbn.string.UtilString."

**/ public static final String sUS = "xbn.string.UtilString."; /**

Create a UtilString. This constructor does nothing.

**/ public UtilString() { } private UtilChar uChar = new UtilChar(); public final String[] getAOHexDigitAsStr(String s_tr) { String[] as = new String[s_tr.length()]; try { for(int i = 0; i < s_tr.length(); i++) { as[i] = uChar.getHexDigitAsString(s_tr.charAt(i)); } } catch(NullPointerException npx) { throwAX("getAOHexDigitAsStr: s_tr is null."); } return as; } /**

Get a random hex number with the requested number of digits.

@param i_digits The number of digits in length the returned value should be. Must be greater than -1. @return "" If i_digits is zero.
[A hex digit of i_digits length] If i_digits is anything but zero. **/ public String getRandomHex(int i_digits) { if(i_digits < 0) { throwAX("getRandomHexDigit: i_digits must be equal to or greater than zero."); } StringBuffer sb = new StringBuffer(sES); for(int i = 0; i < i_digits; i++) { int j = (new Double(Math.random() * 1000000)).intValue(); sb.append(UtilChar.getAOCHexLetters()[j % 16]); } return sb.toString(); } /**

Conditionally get the string, if it's not null.

Equal to getConditional(s_value, "")

**/ public String getConditional(String s_value) { return getConditional(s_value, sES); } /**

Conditionally get the string, if it's not null.

Equal to getConditional(null, s_value, null, s_whenObjectNull)

**/ public String getConditional(String s_value, String s_whenObjectNull) { return getConditional(null, s_value, null, s_whenObjectNull); } /**

Convenience function to conditionally display a variable when non-null.

Equal to getConditional(s_prefix, s_value, s_postfix, "")

**/ public String getConditional(String s_prefix, String s_value, String s_postfix) { return getConditional(s_prefix, s_value, s_postfix, sES); } /**

Convenience function to conditionally display a variable when non-null.

Equal to getConditional(s_prefix, s_value, s_postfix, s_whenValueNull, "")

**/ public String getConditional(String s_prefix, String s_value, String s_postfix, String s_whenValueNull) { return getConditional(s_prefix, s_value, s_postfix, s_whenValueNull, sES); } /**

Get the string value (plus prefix and postfix) only when not-null. When null, get the alternative ("when-null") value.

@param s_prefix The string to put before the non-null value. When null, no prefix is used (which is the same behavior as when this is equal to empty string). @param s_value The value. When null, all parameters except s_whenValueNull are ignored. When not null, (only) s_whenValueNull is ignored. @param s_prefix The string to put after the non-null value. When null, no postfix is used (which is the same behavior as when this is equal to empty string). @param s_whenValueNull When s_value is null, then this is the entire text that is returned (no prefix or postfix). When s_value is not null, this parameter is ignored. May be null or any number of characters in length. To emphasize, if both an s_value are null, then 'null' is returned. @param s_whenValueEmpty When s_value is zero characters in length, then this is the entire text that is returned (no prefix or postfix). When s_value is not empty, this parameter is ignored. May be null or any number of characters in length. This behaves in the same manner as s_whenValueNull, when s_value is empty. @return s_whenValueNull If s_value is null.
s_prefix + s_value + s_postfix If s_value is not null. Note that if s_prefix is null, it is omitted. If s_postfix is null, it is omitted. **/ public String getConditional(String s_prefix, String s_value, String s_postfix, String s_whenValueNull, String s_whenValueEmpty) { if(s_value == null) { return s_whenValueNull; } if(s_value.length() < 1) { return s_whenValueEmpty; } StringBuffer sb = new StringBuffer(s_value); if(s_prefix != null) { //There is a prefix, and it goes first, before //everything else. sb.insert(0, s_prefix); } if(s_postfix != null) { //There is a prefix, and it goes last, after //everything else. sb.append(s_postfix); } return sb.toString(); } /**

Get a boolean from the value in the string.

@param s_potentialBoolean The string containing a boolean value. @return true If s_potentialBoolean equals "true" (case sensitive).
false If s_potentialBoolean equals "false" (case sensitive). @exception AssertException If s_potentialBoolean is null, or contains a value other than "true" or "false". **/ public boolean getBoolean(String s_potentialBoolean) { throwAXIfNull(s_potentialBoolean, "s_potentialBoolean", "getBoolean"); if(s_potentialBoolean.equals("true")) { return true; } if(s_potentialBoolean.equals("false")) { return false; } throwAX("getBoolean: s_potentialBoolean is not null, but is also not equal to 'true' or 'false'. Currently '" + s_potentialBoolean + "'"); //Never reached. Required for compile. return false; } /**

Get an int from the value in the string.

Equal to getInt(s_potentialInt, false)

**/ public int getInt(String s_potentialInt) { return getInt(s_potentialInt, false); } /**

Get an int from the value in the string.

TODO: A critical difference between this and isNumber: This function uses Integer.valueOf, and therefore a huge number (like 8374018734087120847104387208472784) is considered invalid according to this function, but valid according to isNumber (would return true).

@param s_potentialInt The string containing an int value. @param b_nfxInsteadOfax If the s_potentialInt is null, or contains an illegal value, according to Integer.valueOf(s_potentialInt).intValue() **/ public int getInt(String s_potentialInt, boolean b_nfxInsteadOfax) { throwAXIfNull(s_potentialInt, "s_potentialInt", "getInt"); try { return Integer.valueOf(s_potentialInt).intValue(); } catch(NumberFormatException nfx) { String sMsg = "ERROR in UtilString.getInt: s_potentialInt ('" + s_potentialInt + "') is not null, but is also not a valid int according Integer.valueOf('" + s_potentialInt + "').intValue()."; if(b_nfxInsteadOfax) { throw new NumberFormatException(sMsg); } //They want ax and not nfx throwAX(sMsg); } //Never reached. Required for compile. return -1; } /**

Get an long from the value in the string.

Equal to getLong(s_potentialLong, false)

**/ public long getLong(String s_potentialLong) { return getLong(s_potentialLong, false); } /**

Get an long from the value in the string.

@param s_potentialLong The string containing an long value. @param b_nfxInsteadOfax If the s_potentialLong is null, or contains an illegal value, according to Long.valueOf(s_potentialLong).longValue() **/ public long getLong(String s_potentialLong, boolean b_nfxInsteadOfax) { throwAXIfNull(s_potentialLong, "s_potentialLong", "getLong"); try { return Long.valueOf(s_potentialLong).longValue(); } catch(NumberFormatException nfx) { String sMsg = "ERROR in UtilString.getLong: s_potentialLong ('" + s_potentialLong + "') is not null, but is also not a valid long according Long.valueOf('" + s_potentialLong + "').longValue()."; if(b_nfxInsteadOfax) { throw new NumberFormatException(sMsg); } //They want ax and not nfx throwAX(sMsg); } //Never reached. Required for compile. return -1; } /**

Get a Date object from the potential date string and date format.

@return getDate(s_potentialDate, new SimpleDateFormat(s_dateFormat)) **/ public Date getDate(String s_potentialDate, String s_dateFormat) { try { getDate(s_potentialDate, new SimpleDateFormat(s_dateFormat)); } catch(NullPointerException npx) { throwAX("getDate: s_dateFormat is null."); } catch(IllegalArgumentException iax) { throwAX("getDate: s_dateFormat ('" + s_dateFormat + "') is illegal according to SimpleDateFormat.constructor: " + iax.toString()); } //Never reached. Required for compile. return null; } /**

Get a Date object from the potential date string and SimpleDateFormat.

@param s_potentialDate String containing a date that conforms to s_dateFormat. May not be null. @param simple_dateFormat The SimpleDateFormat that s_potentialDate must conform to. May not be null. @return simple_dateFormat.parse(s_potentialDate) **/ public Date getDate(String s_potentialDate, SimpleDateFormat simple_dateFormat) { try { return simple_dateFormat.parse(s_potentialDate); } catch(ParseException px) { throwAX("getDate: s_potentialDate ('" + s_potentialDate + "') does not conform to simple_dateFormat [" + simple_dateFormat.toString() + "]: " + px.toString()); } //Never reached. Required for compile. return null; } /**

Is the string a legally formatted email address?

@param s_potentialEmail The string to analyze. @return false If any of the following conditions are met:
true If otherwise. **/ public boolean isEmail(String s_potentialEmail) { if(s_potentialEmail == null || s_potentialEmail.length() < 1) { return false; } int iAt = s_potentialEmail.indexOf("@"); if(iAt == -1 || iAt == 0 || iAt == s_potentialEmail.length() - 1 || iAt!= s_potentialEmail.lastIndexOf("@")) { //It does not have any '@', contains more than one '@', or //starts or ends with '@'. return false; } if(s_potentialEmail.startsWith(".") || s_potentialEmail.endsWith(".")) { return false; } if(s_potentialEmail.indexOf(" ") != -1 || s_potentialEmail.indexOf(",") != -1 || s_potentialEmail.indexOf("\\") != -1 || s_potentialEmail.indexOf("/") != -1) { return false; } if(s_potentialEmail.indexOf(".@") != -1 || s_potentialEmail.indexOf("@.") != -1 || s_potentialEmail.indexOf("..") != -1) { return false; } if(s_potentialEmail.lastIndexOf(".") < iAt) { //The *last* period is found before the at sign. return false; } return true; } /**

Does the string contain a valid boolean value?. Note that the behavior of this function is distinct from java.lang.Boolean.valueOf.

@param s_potentialBoolean The string to analyze. @return true If s_potentialBoolean equals "true" or "false".
false If s_potentialBoolean is null, or does not equal "true" or "false". **/ public boolean isBoolean(String s_potentialBoolean) { if(s_potentialBoolean == null || s_potentialBoolean.length() < 1) { //The string is either null, or empty string. Either way, //it ain't a boolean. return false; } //If it's equal to "true" or equal to "false", return true. //Otherwise, return false. return (s_potentialBoolean.equals("true") || s_potentialBoolean.equals("false")); } /**

Is the string a valid integer?. An integer is a number without a decimal point.

Equal to isNumber(s_potentialDigit, false)

**/ public boolean isInteger(String s_potentialInteger) { return isNumber(s_potentialInteger, false); } /**

Is the string a valid decimal number?. A decimal number may or may not have a decimal point.

Equal to isNumber(s_potentialDigit, true)

**/ public boolean isDecimal(String s_potentialDigit) { return isNumber(s_potentialDigit, true); } /**

Is the string a valid digit?

A digit is defined with the following rules:

TODO: A critical difference between this and getInt: This function does string analysis, and therefore a huge number (8374018734087120847104387208472784) is considered valid according to this function, while invalid according to getInt (would throw an exception)

@param s_potentialDigit The string to analyze. @param b_decimalAllowed If true, then the digit is allowed to have (exactly one) decimal point. If false, the digit is not allowed to have a decimal point, and therefore must be an integer. @return true If the string conforms to the rules.
false If the string breaks any of the rules. **/ public boolean isNumber(String s_potentialDigit, boolean b_decimalAllowed) { if(s_potentialDigit == null || s_potentialDigit.length() < 1) { //The string is either null, or empty string. Either way, //it ain't a digit. return false; } int iPosition = 0; //The decimal point has not yet been found. boolean bDecimalFound = false; //Get the first character in this string char c = s_potentialDigit.charAt(0); //Only the first character is allowed to be a //dash, a negative symbol... if(c == '-') { //...and it is. if(s_potentialDigit.length() == 1) { //There is only one character in this string. //The first and last character in this string is //a dash. This is not a valid digit. return false; } else { //Increment the position to the second character. //We know the first character is a dash, so it's //definitely not a decimal or digit. iPosition = 1; } } //If the first character is not a dash, then i equals 0. //Otherwise, the first character *is* a dash, and i equals 1, //AND the length of the string is greater than 1 (there are //at least two characters in the string). for(; iPosition < s_potentialDigit.length(); iPosition++) { c = s_potentialDigit.charAt(iPosition); if(c == '.') { if(!b_decimalAllowed) { return false; } if(bDecimalFound) { //A decimal point was already found before this character. //There cannot be more than one decimal point in a digit. return false; } else if(s_potentialDigit.length() == (iPosition + 1)) { //This is the first decimal point found, but it's also //the last character in the string. A decimal poboolean belongs //before the last character in the string. return false; } else { //This is the first decimal point found, but is //also the last character in the string. bDecimalFound = true; } } else if(!Character.isDigit(c)) { //Not only is this character not a decimal or dash, //it's not even a number. return false; } //So far, the string is a valid digit... } //This string is definitely a valid digit. return true; } private static final String sGCI = "getContainedIdx"; /**

If either string is contained in or equal to the other, get information describing the containment.

@return getContainedIdx(getSOBS(s_x, "getContainedIdx"), getSOBS(s_y, "getContainedIdx")) **/ public final i_i_i getContainedIdxs(String s_x, String s_y) { return getContainedIdxs(getSOBS(s_x, sGCI), getSOBS(s_y, sGCI)); } /**

If either string is contained in (or equal to) the other, get information describing the containment.

@return getContainedIdx(getSOBS(s_x, "getContainedIdx"), getSOBS(s_y, "getContainedIdx"), gcic_two)

The array is created only once, and populated in this function repeatedly.

**/ public final i_i_i getContainedIdxs(String s_x, String s_y, GCICTwo gcic_two) { return getContainedIdxs(getSOBS(s_x, sGCI), getSOBS(s_y, sGCI), gcic_two); } /**

If any string is contained in (or equal to) any other, get information describing the containment.

Equal to getContainedIdxs(getAOSOBS(a_string), (new GCIConfig()))

**/ public final i_i_i getContainedIdxs(String[] a_string) { return getContainedIdxs(getAOSOBS(a_string)); } /**

If any string is contained in any other, get information describing the containment.

Equal to getContainedIdxs(getAOSOBS(a_string), (new GCIConfig()))

**/ public final i_i_i getContainedIdxs(String[] a_string, GCIConfig gci_config) { return getContainedIdxs(getAOSOBS(a_string), gci_config); } private static final String sGQL = "getQuotedLines"; /**

Get a copy of the String where each line is quoted.

@return getQuotedLines(getSOBSB(s_tr, sUS + "getQuotedLines")).toString() **/ public final String getQuotedLines(String s_tr) { return getQuotedLines(getSOBSB(s_tr, sUS + sGQL)).toString(); } /**

Get a copy of the String where each line is quoted.

@return getQuotedLines(getSOBSB(s_tr, sUS + "getQuotedLines"), s_quote).toString() **/ public final String getQuotedLines(String s_tr, String s_quote) { return getQuotedLines(getSOBSB(s_tr, sUS + sGQL), s_quote).toString(); } /**

Get a copy of the String where each line is quoted.

@return getQuotedLines(getSOBSB(s_tr, sUS + "getQuotedLines"), s_quoteStart, s_quoteEnd).toString() **/ public final String getQuotedLines(String s_tr, String s_quoteStart, String s_quoteEnd) { return getQuotedLines(getSOBSB(s_tr, sUS + sGQL), s_quoteStart, s_quoteEnd).toString(); } /**

Get a copy of the String where each line is quoted.

@return getQuotedLines(getSOBSB(s_tr, sUS + "getQuotedLines"), s_quoteStart, s_quoteEnd, s_lineSep).toString() **/ public final String getQuotedLines(String s_tr, String s_quoteStart, String s_quoteEnd, String s_lineSep) { return getQuotedLines(getSOBSB(s_tr, sUS + sGQL), s_quoteStart, s_quoteEnd, s_lineSep).toString(); } /**

Is the value of the String a valid hexidecimal number?

@return isHexidecimal(getSOBS(s_potentialHex, "s_potentialHex", sUS + ".isHexidecimal")) **/ public boolean isHexidecimal(String s_potentialHex) { return isHexidecimal(getSOBS(s_potentialHex, "s_potentialHex", sUS + ".isHexidecimal")); } /**

Does the String contain only whitespace?

@param s_potentialTabSpace The String analyzed, to see if it contains only whitespace characters. May not be null or zero characters in length. @return isTabSpace(getSOBS(s_potentialTabSpace, "s_potentialTabSpace", sUS + ".isTabSpace"))

**/ public boolean isTabSpace(String s_potentialTabSpace) { return isTabSpace(getSOBS(s_potentialTabSpace, "s_potentialTabSpace", "isTabSpace")); } /**

Does the String not contain any whitespace characters?

@param s_tr The String analyzed, to see if it contains only non-whitespace characters. May not be null or zero characters in length. @return hasNoTabSpace(getSOBS(s_tr, sUS + ".hasNoTabSpace"))

**/ public boolean hasNoTabSpace(String s_tr) { return hasNoTabSpace(getSOBS(s_tr, sUS + "hasNoTabSpace")); } /**

Get a copy of the String, after appending a duplicated string onto it.

@return dupAppend(getSOBSB(s_tr, sUS + ".getDupAppend"), s_toDuplicate, i_dupCount).toString() **/ public final String getDupAppend(String s_tr, String s_toDuplicate, int i_dupCount) { return getDupAppend(getSOBSB(s_tr, sUS + "getDupAppend"), s_toDuplicate, i_dupCount).toString(); } /**

Get the priovided string, duplicated.

@return getDupAppend("", s_tr, i_dupCount) **/ public String getDuped(String s_tr, int i_dupCount) { return getDupAppend(sES, s_tr, i_dupCount); } /**

Get the array index of the first non-white-space character.

@return getIdxOf1stNonWS(getSOBS(s_tr, sUS + ".getIdxOf1stNonWS"))

**/ public final int getIdxOf1stNonWS(String s_tr) { return getIdxOf1stNonWS(getSOBS(s_tr, sUS + "getIdxOf1stNonWS")); } /**

Get the array index of the last non-white-space character.

@return getIdxOfLastNonWS(getSOBS(s_tr, sUS + ".getIdxOfLastNonWS")) **/ public final int getIdxOfLastNonWS(String s_tr) { return getIdxOfLastNonWS(getSOBS(s_tr, sUS + "getIdxOfLastNonWS")); } private static final String sGIO1CNIA = "getIdxOf1stCharNIA"; /**

Get the array index of the first character that is not a member of the array.

@return getIdxOf1stCharNIA(getSOBS(s_tr, sUS + "getIdxOf1stCharNIA"), a_char) **/ public final int getIdxOf1stCharNIA(String s_tr, char[] a_char) { return getIdxOf1stCharNIA(getSOBS(s_tr, sUS + sGIO1CNIA), a_char); } /**

Get the array index of the first character that is not a member of the array.

@return getIdxOf1stCharNIA(getSOBS(s_tr, sUS + "getIdxOf1stCharNIA"), a_char, 0, s_tr.length(), b_validateAOC) **/ public final int getIdxOf1stCharNIA(String s_tr, char[] a_char, boolean b_validateAOC) { try { return getIdxOf1stCharNIA(getSOBS(s_tr, sUS + sGIO1CNIA), a_char, 0, s_tr.length(), b_validateAOC); } catch(NullPointerException npx) { throwAX("getIdxOf1stCharNIA: s_tr is null."); } //Never reached. Required for compile. return -1; } /**

Get the array index of the first character that is not a member of the array.

@return getIdxOf1stCharNIA(getSOBS(s_tr, sUS + "getIdxOf1stCharNIA"), a_char, i_idxStart, i_idxAfterEnd) **/ public final int getIdxOf1stCharNIA(String s_tr, char[] a_char, int i_idxStart, int i_idxAfterEnd) { return getIdxOf1stCharNIA(getSOBS(s_tr, sUS + sGIO1CNIA), a_char, i_idxStart, i_idxAfterEnd); } /**

Get the array index of the first character that does not exist in the array.

@return getIdxOf1stCharNIA(getSOBS(s_tr, sUS + "getIdxOf1stCharNIA"), a_char, i_idxStart, i_idxAfterEnd, b_validateAOC) **/ public final int getIdxOf1stCharNIA(String s_tr, char[] a_char, int i_idxStart, int i_idxAfterEnd, boolean b_validateAOC) { return getIdxOf1stCharNIA(getSOBS(s_tr, sUS + sGIO1CNIA), a_char, i_idxStart, i_idxAfterEnd, b_validateAOC); } private static final String sGIOLCNIA = "getIdxOfLastCharNIA"; /**

Get the array index of the last character that is not a member of the array.

@return getIdxOfLastCharNIA(getSOBS(s_tr, sUS + "getIdxOfLastCharNIA"), a_char) **/ public final int getIdxOfLastCharNIA(String s_tr, char[] a_char) { return getIdxOfLastCharNIA(getSOBS(s_tr, sUS + sGIOLCNIA), a_char); } /**

Get the array index of the last character that is not a member of the array.

@return getIdxOfLastCharNIA(getSOBS(s_tr, sUS + "getIdxOfLastCharNIA"), a_char, 0, length(), b_validateAOC) **/ public final int getIdxOfLastCharNIA(String s_tr, char[] a_char, boolean b_validateAOC) { try { return getIdxOfLastCharNIA(getSOBS(s_tr, sUS + sGIOLCNIA), a_char, 0, s_tr.length(), b_validateAOC); } catch(NullPointerException npx) { throwAX("getIdxOf1stCharNIA: s_tr is null."); } //Never reached. Required for compile. return -1; } /**

Get the array index of the last character that is not a member of the array.

@return getIdxOfLastCharNIA(getSOBS(s_tr, sUS + "getIdxOfLastCharNIA"), a_char, i_idxStart, i_idxAfterEnd) **/ public final int getIdxOfLastCharNIA(String s_tr, char[] a_char, int i_idxStart, int i_idxAfterEnd) { return getIdxOfLastCharNIA(getSOBS(s_tr, sUS + sGIOLCNIA), a_char, i_idxStart, i_idxAfterEnd); } /**

Get the array index of the last character that does not exist in the array.

@return getIdxOfLastCharNIA(getSOBS(s_tr, sUS + "getIdxOfLastCharNIA"), a_char, i_idxStart, i_idxAfterEnd, b_validateAOC) **/ public final int getIdxOfLastCharNIA(String s_tr, char[] a_char, int i_idxStart, int i_idxAfterEnd, boolean b_validateAOC) { return getIdxOfLastCharNIA(getSOBS(s_tr, sUS + sGIOLCNIA), a_char, i_idxStart, i_idxAfterEnd, b_validateAOC); } /**

Get a copy of the String, where the contents' invisible characters are made visible.

@return getVisible(getSOBSB(s_tr, sUS + ".getVisible").toString() **/ public final String getVisible(String s_tr) { return getVisible(getSOBSB(s_tr, sUS + "getVisible")).toString(); } /**

Does the string contain only letters, digits and underscores?

@return isLetterDigitUnderscore(getSOBS(s_tr, sUS + ".isLetterDigitUnderscore")) **/ public boolean isLetterDigitUnderscore(String s_tr) { return isLetterDigitUnderscore(getSOBS(s_tr, sUS + "isLetterDigitUnderscore")); } /**

Does the string contain only letters and (other provided) legal characters?

@return hasLettersOrInAOC(getSOBS(s_tr, sUS + ".hasLettersOrInAOC"), b_digitsOkOpt, ac_legal) **/ public boolean hasLettersOrInAOC(String s_tr, boolean b_digitsOkOpt, char[] ac_legal) { return hasLettersOrInAOC(getSOBS(s_tr, sUS + "hasLettersOrInAOC"), b_digitsOkOpt, ac_legal); } /**

Does the string contain only letters and (other provided) legal characters?

@return hasLettersOrInAOC(getSOBS(s_tr, sUS + ".hasLettersOrInAOC"), b_digitsOkOpt, ac_legal, b_validateAOC) **/ public boolean hasLettersOrInAOC(String s_tr, boolean b_digitsOkOpt, char[] ac_legal, boolean b_validateAOC) { return hasLettersOrInAOC(getSOBS(s_tr, sUS + "hasLettersOrInAOC"), b_digitsOkOpt, ac_legal, b_validateAOC); } /**

Does the string contain only digits and (other provided) legal characters?

@return hasDigitsOrInAOC(getSOBS(s_tr, sUS + ".hasDigitsOrInAOC"), b_lettersOkOpt, ac_legal) **/ public boolean hasDigitsOrInAOC(String s_tr, boolean b_lettersOkOpt, char[] ac_legal) { return hasDigitsOrInAOC(getSOBS(s_tr, sUS + "hasDigitsOrInAOC"), b_lettersOkOpt, ac_legal); } /**

Does the string contain only digits and (other provided) legal characters?

@return hasDigitsOrInAOC(getSOBS(s_tr, sUS + ".hasDigitsOrInAOC"), b_lettersOkOpt, ac_legal, b_validateAOC) **/ public boolean hasDigitsOrInAOC(String s_tr, boolean b_lettersOkOpt, char[] ac_legal, boolean b_validateAOC) { return hasDigitsOrInAOC(getSOBS(s_tr, sUS + "hasDigitsOrInAOC"), b_lettersOkOpt, ac_legal, b_validateAOC); } /**

Does the string contain only letters, digits and (other provided) legal characters?

@return hasLDOrInAOC(getSOBS(s_tr, sUS + ".hasLDOrInAOC"), ac_legal) **/ public boolean hasLDOrInAOC(String s_tr, char[] ac_legal) { return hasLDOrInAOC(getSOBS(s_tr, sUS + "hasLDOrInAOC"), ac_legal); } /**

Does the string contain only letters, digits and (other provided) legal characters?

@return hasLDOrInAOC(getSOBS(s_tr, sUS + ".hasLDOrInAOC"), ac_legal, b_validateAOC) **/ public boolean hasLDOrInAOC(String s_tr, char[] ac_legal, boolean b_validateAOC) { return hasLDOrInAOC(getSOBS(s_tr, sUS + "hasLDOrInAOC"), ac_legal, b_validateAOC); } /**

Does the string contain only legal characters?

@return hasLegalChars(getSOBS(s_tr, sUS + ".hasLegalChars"), ac_legal) **/ public boolean hasLegalChars(String s_tr, char[] ac_legal) { return hasLegalChars(getSOBS(s_tr, sUS + "hasLegalChars"), ac_legal); } /**

Does the string contain only legal characters?

@return isLegal(getSOBS(s_tr, sUS + ".hasLegalChars"), false, false, ac_legal, b_validateAOC) **/ public boolean hasLegalChars(String s_tr, char[] ac_legal, boolean b_validateAOC) { return isLegal(getSOBS(s_tr, sUS + "hasLegalChars"), false, false, ac_legal, b_validateAOC); } /**

Does the string contain only legal characters?

@return isLegal(getSOBS(s_tr, sUS + ".isLegal"), b_lettersOkOpt, b_digitsOkOpt, ac_legal) **/ public boolean isLegal(String s_tr, boolean b_lettersOkOpt, boolean b_digitsOkOpt, char[] ac_legal) { return isLegal(getSOBS(s_tr, sUS + "isLegal"), b_lettersOkOpt, b_digitsOkOpt, ac_legal); } /**

Does the string contain only legal characters?

@return isLegal(getSOBS(s_tr, sUS + ".isLegal"), b_lettersOkOpt, b_digitsOkOpt, ac_legal, b_validateAOC) **/ public boolean isLegal(String s_tr, boolean b_lettersOkOpt, boolean b_digitsOkOpt, char[] ac_legal, boolean b_validateAOC) { return isLegal(getSOBS(s_tr, sUS + "isLegal"), b_lettersOkOpt, b_digitsOkOpt, ac_legal, b_validateAOC); } /**

Does the string not contain any letters or (other provided) illegal characters?

@return isNotLettersOrInAOC(getSOBS(s_tr, sUS + ".isNotLettersOrInAOC"), b_digitsBadOpt, ac_legal) **/ public boolean isNotLettersOrInAOC(String s_tr, boolean b_digitsBadOpt, char[] ac_legal) { return isNotLettersOrInAOC(getSOBS(s_tr, sUS + "isNotLettersOrInAOC"), b_digitsBadOpt, ac_legal); } /**

Does the string not contain any letters or (other provided) illegal characters?

@return isNotLettersOrInAOC(getSOBS(s_tr, sUS + ".isNotLettersOrInAOC"), b_digitsBadOpt, ac_legal, b_validateAOC) **/ public boolean isNotLettersOrInAOC(String s_tr, boolean b_digitsBadOpt, char[] ac_legal, boolean b_validateAOC) { return isNotLettersOrInAOC(getSOBS(s_tr, sUS + "isNotLettersOrInAOC"), b_digitsBadOpt, ac_legal, b_validateAOC); } /**

Does the string not contain any digits or (other provided) illegal characters?

@return isNotDigitsOrInAOC(getSOBS(s_tr, sUS + ".isNotDigitsOrInAOC"), b_digitsBadOpt, ac_legal) **/ public boolean isNotDigitsOrInAOC(String s_tr, boolean b_lettersBadOpt, char[] ac_legal) { return isNotDigitsOrInAOC(getSOBS(s_tr, sUS + "isNotDigitsOrInAOC"), b_lettersBadOpt, ac_legal); } /**

Does the string not contain any digits or (other provided) illegal characters?

@return isNotDigitsOrInAOC(getSOBS(s_tr, sUS + ".isNotDigitsOrInAOC"), b_lettersBadOpt, ac_legal, b_validateAOC) **/ public boolean isNotDigitsOrInAOC(String s_tr, boolean b_lettersBadOpt, char[] ac_legal, boolean b_validateAOC) { return isNotDigitsOrInAOC(getSOBS(s_tr, sUS + "isNotDigitsOrInAOC"), b_lettersBadOpt, ac_legal, b_validateAOC); } /**

Does the string not contain any letters, digits or (other provided) illegal characters?

@return isNotLDOrInAOC(getSOBS(s_tr, sUS + ".isNotLDOrInAOC"), ac_legal) **/ public boolean isNotLDOrInAOC(String s_tr, char[] ac_legal) { return isNotLDOrInAOC(getSOBS(s_tr, sUS + "isNotLDOrInAOC"), ac_legal); } /**

Does the string not contain any letters, digits or (other provided) illegal characters?

@return isNotLDOrInAOC(getSOBS(s_tr, sUS + ".isNotLDOrInAOC"), ac_legal, b_validateAOC) **/ public boolean isNotLDOrInAOC(String s_tr, char[] ac_legal, boolean b_validateAOC) { return isNotLDOrInAOC(getSOBS(s_tr, sUS + "isNotLDOrInAOC"), ac_legal, b_validateAOC); } /**

Does the string not contain any illegal characters?

@return hasNoIllegalChars(getSOBS(s_tr, sUS + ".hasNoIllegalChars"), ac_illegal) **/ public boolean hasNoIllegalChars(String s_tr, char[] ac_illegal) { return hasNoIllegalChars(getSOBS(s_tr, sUS + "hasNoIllegalChars"), ac_illegal); } /**

Does the string not contain any illegal characters?

@return isNotIllegal(getSOBS(s_tr, sUS + ".hasNoIllegalChars"), false, false, ac_illegal, b_validateAOC) **/ public boolean hasNoIllegalChars(String s_tr, char[] ac_illegal, boolean b_validateAOC) { return isLegal(getSOBS(s_tr, sUS + "hasNoIllegalChars"), false, false, ac_illegal, b_validateAOC); } /**

Does the string not contain any illegal characters?

@return isNotIllegal(getSOBS(s_tr, sUS + ".isNotIllegal"), b_lettersBadOpt, b_digitsBadOpt, ac_illegal) **/ public boolean isNotIllegal(String s_tr, boolean b_lettersBadOpt, boolean b_digitsBadOpt, char[] ac_illegal) { return isNotIllegal(getSOBS(s_tr, sUS + "isNotIllegal"), b_lettersBadOpt, b_digitsBadOpt, ac_illegal); } /**

Does the string not contain any illegal characters?

@return isNotIllegal(getSOBS(s_tr, sUS + ".isNotLegal"), b_lettersBadOpt, b_digitsBadOpt, ac_illegal, b_validateAOC) **/ public boolean isNotIllegal(String s_tr, boolean b_lettersBadOpt, boolean b_digitsBadOpt, char[] ac_illegal, boolean b_validateAOC) { return isNotIllegal(getSOBS(s_tr, sUS + "isNotLegal"), b_lettersBadOpt, b_digitsBadOpt, ac_illegal, b_validateAOC); } /**

Create an SOBStringBuffer with the String.

@return null If s_tr is null.
(new StringBuffer(s_tr)) If s_tr is non-null. **/ public StringBuffer getSB(String s_tr) { if(s_tr == null) { return null; } return (new StringBuffer(s_tr)); } /**

Return a copy of the provided string, in which all occurances are replaced.

@return getReplaceAll(getSOBSB(s_tr, sUS + ".getReplaceAll"), s_replaceWhat, s_replaceWith) **/ public final String getReplaceAll(String s_tr, String s_replaceWhat, String s_replaceWith) { return getReplaceAll(getSOBSB(s_tr, sUS + "getReplaceAll"), s_replaceWhat, s_replaceWith).toString(); } /**

Replace all occurances, with multiple passes, until no instances of the search string remain.

@return getReplaceUntil(getSOBSB(s_tr, sUS + ".getReplaceUntil"), s_replaceWhat, s_replaceWith) **/ public final String getReplaceUntil(String s_tr, String s_replaceWhat, String s_replaceWith) { return getReplaceUntil(getSOBSB(s_tr, sUS + "replaceUntil"), s_replaceWhat, s_replaceWith).toString(); } /**

What is the first array index containing an int not equal to element zero?

This is useful in unit tests that tests multiple versions of the same function, when you want to ensure that each returns the same value.

@param a_int The int array to analyze. May not be null or equal to zero elements in length. Element zero may not be null. @return -1 If a_int.length is one element in length, or every element in the array is equal.
The array index representing the first element in a_int whose value is different than element zero. Will definitely be greater than zero. **/ public final int getIdxNEToLmnt0(String[] a_string) { try { for(int i = 1; i < a_string.length; i++) { try { if(!a_string[0].equals(a_string[i])) { return i; } } catch(NullPointerException npx) { if(a_string.length == 0) { throwAX("getIdxNEToLmnt0: a_string.length equals zero."); } else { throwAX("getIdxNEToLmnt0: a_string[0] is null."); } } } } catch(NullPointerException npx) { throwAX("getIdxNEToLmnt0: a_string is null."); } return -1; } /**

Create an SOBString from the String.

@return getSOBS(s_tr, sUS + ".s_tr", s_callingClsFnc) **/ public final SOBString getSOBS(String s_tr, String s_callingClsFnc) { return getSOBS(s_tr, "s_tr", s_callingClsFnc); } /**

Create an SOBString from the String.

@param s_tr The String to create a new SOBString with. May not be null. @param s_sDescription The descriptive name of s_tr, for potential error messages. @param s_callingClsFnc The function from which the potential error message should appear as if it is coming from. @return (new SOBString(s_tr)) **/ public final SOBString getSOBS(String s_tr, String s_sDescription, String s_callingClsFnc) { try { return new SOBString(s_tr); } catch(NullPointerException npx) { throwAX(s_callingClsFnc + ": " + s_sDescription + " is null."); } //Never reached. Required for compile. return null; } /**

Create an SOBStringBuffer from the String.

@return getSOBSB(s_tr, "s_tr", s_callingClsFnc) **/ public final SOBStringBuffer getSOBSB(String s_tr, String s_callingClsFnc) { return getSOBSB(s_tr, "s_tr", s_callingClsFnc); } /**

Create an SOBStringBuffer from the String.

@param s_tr The String to create a new SOBStringBuffer with. May not be null. @param s_sDescription The descriptive name of s_tr, for potential error messages. @param s_callingClsFnc The function from which the potential error message should appear as if it is coming from. @return (new SOBStringBuffer(s_tr)) **/ public final SOBStringBuffer getSOBSB(String s_tr, String s_sDescription, String s_callingClsFnc) { try { return (new SOBStringBuffer(s_tr)); } catch(NullPointerException npx) { throwAX(s_callingClsFnc + ": " + s_sDescription + " is null."); } //Never reached. Required for compile. return null; } /**

Get an array of SOBStrings from the array of strings.

@param a_string The array of strings to create an array of SOBStrings from. @return null If a_string is null.
An array of SOBStrings where each element has contents equalling that in the corresponding member of a_string. Note: If a_string[X] is null then the X-th element in the returned array is also null (it is not possible to have the contents of an SOBString equal null). **/ public final SOBString[] getAOSOBS(String[] a_string) { if(a_string == null) { return null; } SOBString[] ass = new SOBString[a_string.length]; for(int i = 0; i < a_string.length; i++) { if(a_string[i] == null) { ass[i] = null; } else { ass[i] = new SOBString(a_string[i].toString()); } } return ass; } /**

Get an array of SOBStringBuffers from the array of strings.

@param a_string The array of strings to create an array of SOBStringBuffers from. @return null If a_string is null.
An array of SOBStringBuffers where each element has contents equalling that in the corresponding member of a_string. Note: If a_string[X] is null then the X-th element in the returned array is also null (it is not possible to have the contents of an SOBStringBuffer equal null). **/ public final SOBStringBuffer[] getAOSOBSB(String[] a_string) { if(a_string == null) { return null; } SOBStringBuffer[] assb = new SOBStringBuffer[a_string.length]; for(int i = 0; i < a_string.length; i++) { if(a_string[i] == null) { assb[i] = null; } else { assb[i] = new SOBStringBuffer(a_string[i]); } } return assb; } }