Creates a substring of the given text. If the expression has an ellipsis defined, and the given start
position and length are greater than the string's length, the ellipsis-text will be appended to indicate
that this substring result is only a partial match.
A similiar functionality can be achived using the built-in formula support.
| Method from org.jfree.report.function.strings.SubStringExpression Detail: |
public String getEllipsis() {
return ellipsis;
}
Returns the ellipsis-text that indicates partial values. |
public String getField() {
return field;
}
Returns the name of the datarow-column from where to read the string value. |
public int getLength() {
return length;
}
Returns the sub-string's length. |
public int getStart() {
return start;
}
Returns the sub-string's start position. |
public Object getValue() {
final Object raw = getDataRow().get(getField());
if (raw == null)
{
return null;
}
final String text = String.valueOf(raw);
// the text is not large enough to fit the start-bounds. Return nothing,
// but indicate that there would have been some more content ...
if (start >= text.length())
{
return appendEllipsis(null);
}
// the text fully fits into the given range. No clipping needed ...
if ((start + length) > text.length())
{
return appendEllipsis(text.substring(start));
}
return text.substring(start, start + length);
}
|
public void setEllipsis(String ellipsis) {
this.ellipsis = ellipsis;
}
Defines the ellipsis-text that indicates partial values. |
public void setField(String field) {
this.field = field;
}
Defines the name of the datarow-column from where to read the string value. |
public void setLength(int length) {
if (length < 0)
{
throw new IndexOutOfBoundsException("String length cannot be negative.");
}
this.length = length;
}
Defines the sub-string's length. The length cannot be negative. |
public void setStart(int start) {
if (length < 0)
{
throw new IndexOutOfBoundsException ("String start position cannot be negative.");
}
this.start = start;
}
Defines the sub-string's start position. The start position cannot be negative. |