Methods Summary |
---|
public static java.lang.String | format(java.lang.String base, java.lang.Object[] toInsert)This is the workhorse method of all of these overloaded methods.
The array of Objects' toString() methods are called one at a time. The
resulting Strings are used to replace numbered tokens. I.e. replacement
String #0 replaces this token: {1} and replacement String #1
replaces this token: {2}.
Avoid messy calling code by dedicating methods to the common cases of
1-3 inserts.
// the only "format" method that actually does much work!
// let's be gentle with nulls & empty Strings...
//ArgChecker.checkValid(base, "base");
if(toInsert == null || toInsert.length <= 0)
return null;
String ret = base;
for(int i = 0; i < toInsert.length; i++)
{
String token = makeToken(i + 1);
String replace = toInsert[i].toString();
ret = replaceToken(ret, token, replace);
if(ret == null || ret.length() <= 0)
return null;
}
return ret;
|
public static java.lang.String | format(java.lang.String base, java.lang.Object o1)Version of format with one token to replace
return format(base, new Object[] {o1});
|
public static java.lang.String | format(java.lang.String base, java.lang.Object o1, java.lang.Object o2)Version of format with two tokens to replace
return format(base, new Object[] {o1, o2});
|
public static java.lang.String | format(java.lang.String base, java.lang.Object o1, java.lang.Object o2, java.lang.Object o3)Version of format with three tokens to replace
return format(base, new Object[] {o1, o2, o3});
|
public java.lang.String | getAndFormat(java.lang.String key, java.lang.Object o1, java.lang.Object o2)Get the String from the member IStringSource object -- then call
format using that String.
return getAndFormat(key, new Object[] { o1, o2} );
|
public java.lang.String | getAndFormat(java.lang.String key, java.lang.Object o1, java.lang.Object o2, java.lang.Object o3)Get the String from the member IStringSource object -- then call
format using that String.
return getAndFormat(key, new Object[] { o1, o2, o3} );
|
public java.lang.String | getAndFormat(java.lang.String key, java.lang.Object[] toInsert)Get the String from the member IStringSource object -- then call
format using that String.
return format(getString(key), toInsert);
|
public java.lang.String | getAndFormat(java.lang.String key, java.lang.Object o1)Get the String from the member IStringSource object -- then call
format using that String.
return getAndFormat(key, new Object[] { o1} );
|
public IStringSource | getSource()Get the IStringSource object
Assert.assertit((mSource!=null), "mSource");
return mSource;
|
public java.lang.String | getString(java.lang.String lookupKey)IStringSource signature method. In this case it asks the IStringSource
member variable to get the String.
//ArgChecker.check(lookupKey, "lookupKey");
return(mSource.getString(lookupKey));
|
public static void | main(java.lang.String[] notUsed)TEMPORARY -- until unit testing code is created...
String test2A = "hello {1}, How are {2}?";
String test2AResult = format(test2A, "Carbon-based lifeform", "you");
Debug.println("INPUT: " + test2A + "\nOUTPUT: " + test2AResult);
|
private static java.lang.String | makeToken(int num)
/* this is the one and only place where the specifics of how tokens
* are represented are kept.
* It would have been easy (and nice!) to change this token
* programmatically. But unfortunately, impossible, because we
* have static methods
*/
return "{" + num + "}";
|
private static java.lang.String | replaceToken(java.lang.String s, java.lang.String token, java.lang.String replace)
/* look for the token, 'token', inside the String, 's', and replace
* with the String, 'replace'
*/
if(s == null || s.length() <= 0 || token == null || token.length() <= 0)
return s;
int index = s.indexOf(token);
if(index < 0)
return s;
int tokenLength = token.length();
String ret = s.substring(0, index);
ret += replace;
ret += s.substring(index + tokenLength);
return ret;
|
public void | setSource(IStringSource source)Set the IStringSource object
//ArgChecker.check(source, "source");
//ArgChecker.check(source != this, "Can't setSource to self!");
mSource = source;
|