Package org.apache.sis.internal.util
Class Strings
java.lang.Object
org.apache.sis.util.Static
org.apache.sis.internal.util.Strings
Miscellaneous utilities which should not be put in public API.
Most of those methods are for
Object.toString()
implementations.- Since:
- 0.3
- Version:
- 1.2
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final char
The character to write at the beginning of lines that are continuation of a single log record.static final String
Characters for a new item in a block illustrated byCONTINUATION_MARK
.static final char
The character to write at the beginning of lines that are continuation of a single log record. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprivate static void
append
(Object value, StringBuilder buffer) Appends the given value in the given buffer, using quotes if the value is a character sequence.static boolean
appendUnicodeIdentifier
(StringBuilder appendTo, char separator, String text, String accepted, boolean toLowerCase) Appends to the given buffer only the characters that are valid for a Unicode identifier.static String
Formats"classname[index]"
.static String
Formats"name[index]"
.static boolean
equalsIgnoreCase
(String a, String b) Returns whether the given strings are equal, ignoring case.static void
Formats the given character sequence to the given formatter.static void
insertLineInLeftMargin
(StringBuilder buffer, String lineSeparator) Inserts a continuation character after each line separator except the last one.static String
Returns the given text if non-null, or the empty string otherwise.static String
Formats"classname[lower … upper]"
.static String
singleLine
(String delimiter, CharSequence text) Concatenates a potentially multi-lines text to a single line.static String
Appends"[index]"
to the given name.static String
Returns a string representation of an instance of the given class having the given properties.static String
toUpperCase
(String text, Characters.Filter filter, boolean all) Returns a string with the same content than the given string, but in upper case and containing only the filtered characters.static String
trimOrNull
(String text) Trims the leading and trailing spaces of the given string.
-
Field Details
-
CONTINUATION_MARK
public static final char CONTINUATION_MARKThe character to write at the beginning of lines that are continuation of a single log record. This constant is defined here only for a little bit more uniformtoString()
in SIS.- See Also:
-
CONTINUATION_END
public static final char CONTINUATION_ENDThe character to write at the beginning of lines that are continuation of a single log record. This constant is defined here only for a little bit more uniformtoString()
in SIS.- See Also:
-
CONTINUATION_ITEM
Characters for a new item in a block illustrated byCONTINUATION_MARK
. This constant is defined here only for a little bit more uniformtoString()
in SIS.- See Also:
-
-
Constructor Details
-
Strings
private Strings()Do not allow instantiation of this class.
-
-
Method Details
-
equalsIgnoreCase
Returns whether the given strings are equal, ignoring case. This method accepts null arguments.- Parameters:
a
- first string.b
- another string to be compared witha
.- Returns:
- whether the given strings are equal, ignoring case.
- See Also:
-
orEmpty
Returns the given text if non-null, or the empty string otherwise.- Parameters:
text
- text or null.- Returns:
- given text or empty string (never null).
-
trimOrNull
Trims the leading and trailing spaces of the given string. If the string is null, empty or contains only spaces, then this method returnsnull
.Note that this method strips white spaces too, including no-break spaces. In some cases this is not wanted, for example if the text is a programmatic identifier (maybe the developer really wanted no-break spaces). To preserve no-break spaces, the following can be used instead:
- Parameters:
text
- the text to trim, ornull
.- Returns:
- the trimmed text, or
null
if the given text was null or blank. - Since:
- 1.1
-
appendUnicodeIdentifier
public static boolean appendUnicodeIdentifier(StringBuilder appendTo, char separator, String text, String accepted, boolean toLowerCase) Appends to the given buffer only the characters that are valid for a Unicode identifier. The given separator character is append before the giventext
only if the buffer is not empty and at least onetext
character is valid.Relationship with
This method may be invoked for buildinggml:id
gml:id
values. Strictly speaking this is not appropriate since thexs:ID
type defines valid identifiers as containing only letters, digits, underscores, hyphens, and periods. This differ from Unicode identifier in two ways:- Unicode identifiers accept Japanese or Chinese ideograms for instance, which are considered as letters.
- Unicode identifiers do not accept the
'-'
and':'
characters. However, this restriction fits well our need, since those characters are typical values for theseparator
argument. - Note that
'_'
is valid both inxs:ID
and Unicode identifier.
- Parameters:
appendTo
- the buffer where to append the valid characters.separator
- the separator to append before the valid characters, or 0 if none.text
- the text from which to get the valid character to append in the given buffer.accepted
- additional characters to accept (e.g."-."
), or an empty string if none.toLowerCase
-true
for converting the characters to lower case.- Returns:
true
if at least one character has been added to the buffer.
-
toIndexed
Appends"[index]"
to the given name. This is used for formatting error messages.- Parameters:
name
- the variable name to which to append "[index]".index
- value to write between brackets.- Returns:
"name[index]"
.
-
bracket
Formats"name[index]"
.- Parameters:
name
- the variable name to which to append "[index]".index
- value to write between brackets.- Returns:
"name[index]"
.
-
bracket
Formats"classname[index]"
.- Parameters:
type
- the type to which to append "[index]".index
- value to write between brackets.- Returns:
"classname[index]"
.
-
range
Formats"classname[lower … upper]"
.- Parameters:
type
- the type to which to append "[lower … upper]".lower
- first value to write between brackets.upper
- second value to write between brackets.- Returns:
"classname[lower … upper]"
.
-
toUpperCase
Returns a string with the same content than the given string, but in upper case and containing only the filtered characters. If the given string already matches the criterion, then it is returned unchanged without creation of any temporary object.This method is useful before call to an
Enum.valueOf(String)
method, for making the search a little bit more tolerant.This method is not in public API because conversion to upper-cases should be locale-dependent.
- Parameters:
text
- the text to filter.filter
- the filter to apply.all
-true
for making all the string in upper-cases, orfalse
for changing only the first character.- Returns:
- the filtered text.
-
insertLineInLeftMargin
Inserts a continuation character after each line separator except the last one. The intent is to show that a block of lines are part of the same element. The characters are the same thanMonolineFormatter
.- Parameters:
buffer
- the buffer where to insert a continuation character in the left margin.lineSeparator
- the line separator.
-
singleLine
Concatenates a potentially multi-lines text to a single line. White spaces at the beginning and end of each line are removed.- Parameters:
delimiter
- the separator to insert between lines.text
- the multi-lines text to convert to single line, ornull
.- Returns:
- the the text on a single line text, or
null
if none.
-
toString
Returns a string representation of an instance of the given class having the given properties. This is a convenience method for implementation ofObject.toString()
methods that are used mostly for debugging purpose.The content is specified by (key=value) pairs. If a value is
null
, the whole entry is omitted. If a key isnull
, the value is written without the"key="
part. The latter happens typically when the first value is the object name.- Parameters:
classe
- the class to format.properties
- the (key=value) pairs.- Returns:
- a string representation of an instance of the given class having the given properties.
-
append
Appends the given value in the given buffer, using quotes if the value is a character sequence. -
formatTo
Formats the given character sequence to the given formatter. This method takes in account theFormattableFlags.UPPERCASE
andFormattableFlags.LEFT_JUSTIFY
flags.- Parameters:
formatter
- the formatter in which to format the value.flags
- the formatting flags.width
- minimal number of characters to write, padding with' '
if necessary.precision
- number of characters to keep before truncation, or -1 if no limit.value
- the text to format.
-