Stay always connected!
  1. Beth Paul
  2. Sierra/ Millennium/ Encore
  3. Tuesday, 31 January 2017
  4.  Subscribe via email
Cross-posted to the IUG listserv. I am creating spine label templates in Jaspersoft. While what I have works, I would like to know what it means.

I have figured out some, like .trim eliminates leading and trailing spaces, but I have not figured out others. Can any of you tell me what these mean?

What does .equals mean/do?
($F{callAlphaStart}.equals("" ) ? "" : " " )

What does .matches mean/do?
($F{callSuba}.matches("(?s)[A-Z].*" ) ? "." : "" )

In this expression, my understanding is .replaceAll replaces everything after the comma with what is before the comma. Correct?
$F{itemv}.trim().replaceAll("[ :]"," " ).replaceAll("\\.\\s","." ).replaceAll(",\\s"," " )

What then is the info inside the parenths? What do each of these represent?
• "[ :]"
• " "
• \\.\\s
• "."
• ",\\s"

Thanks in advance,
There are no comments made yet.
Accepted Answer
Accepted Answer Pending Moderation
It looks like you are using a variation on the Java expression that I wrote a number of years ago for the Print Templates wiki. There is a full explanation of how I wrote the expression and what it means on the Monographic Spine Label Print Templates wiki on CSDirect. Here are the answers to your specific questions:

($F{callAlphaStart}.equals("" ) ? "" : " " )
The expression "A ? B : C" means, "If A is true, return B, otherwise return C." This particular expression asks, "does callAlphaStart equal blank?" If true, it prints nothing, if false (i.e. callAlphaStart exists and is not blank), it prints a space character. You have to enclose literal strings inside double quotes, so a blank or missing character is "" and a space character is " ". Basically, this expression will add a space between callAlphaStart and the rest of the output, but only if there is a callAlphaStart.

($F{callSuba}.matches("(?s)[A-Z].*" ) ? "." : "" )
This uses a regular expression, or regex, as part of the true/false test. A regular expression tests whether the input string matches a pattern. This expression asks, "If callSuba looks like a capital letter followed by anything, then print a period, otherwise print nothing." In a regular expression, "[A-Z]" means any character in the range A to Z, i.e. all capital letters. A period, ".", is a wildcard character that matches any one character. An asterisk means "match any number of the preceding character", so "a*" would mean "match any number of a's in a row", while ".*" means "match any number of characters of any type." The (?s) is a special regex construct which tells the matching algorithm to go to single line mode, which means that the wildcard character "." will match line breaks, which it does not normally do.

$F{itemv}.trim().replaceAll("[ :]"," " ).replaceAll("\\.\\s","." ).replaceAll(",\\s"," " )
Your understanding of this code is correct. The function .replaceAll(A,B) will replace all instances of A with B. Like matches, replaceAll uses a regular expression as the matching pattern. The expression "[ :]" will match either a space or a colon. Normally, a "\." means a literal period (remember that a plain period is a wildcard character) and "\s" means any whitespace. But the replace function requires an extra level of escaping, so "\\.\\s" means a literal period followed by any whitespace character, while ",\\s" means a comma followed by any whitespace character.
  1. Beth Paul
  2. 3 years ago
  3. #655
Thanks, Stephen.
There are no comments made yet.

There are replies in this post but you are not allowed to view the replies from this post.