Package jme3utilities
Class MyString
java.lang.Object
jme3utilities.MyString
Utility methods for char sequences, strings, and collections of strings.
-
Method Summary
Modifier and TypeMethodDescriptionaddMatchPrefix(Collection<String> collection, String prefix, List<String> addResult) Find all strings in the input collection that begin with the specified prefix and add them to the result.static intDetermine the index of the named coordinate axis.static StringaxisName(int axisIndex) Describe a coordinate axis.static voidDe-duplicate a list of strings by appending distinguishing suffixes as needed.static Stringdescribe(float fValue) Generate a textual description of a single-precision floating-point value.static StringdescribeAngle(float fValue) Generate a textual description of a single-precision floating-point value using at most 2 decimal places.static StringdescribeFraction(float fValue) Generate a textual description of a single-precision floating-point value using at most 3 decimal places.static StringdescribeMatrix(com.jme3.math.Matrix3f matrix) Generate a textual description of a Matrix3f value.static Stringescape(CharSequence unescaped) Replace all tab, quote, newline, and backslash characters in the specified text with escape sequences.static intFind the specified string value in an array, using a linear search.static StringfindLongestPrefix(Collection<String> collection) Find the longest repeated prefix in a collection of strings.static StringfirstToLower(String input) Convert the first character of the specified text to lower case.Invert the specified String-to-String map.static booleanTest whether the specified List is lexicographically sorted in ascending order with no duplicates.static Stringjoin(CharSequence separator, Iterable objects) Join a collection of objects into a text string using the specified separator, ignoring any empties/nulls.static StringJoin a collection of objects into a text string using spaces for separators and ignoring any empties/nulls.static StringJoin an array of objects into a text string using spaces for separators and ignoring any empties/nulls.static voidmatchPrefix(Collection<String> collection, String prefix) Filter a collection of strings, keeping only those that begin with the specified prefix.static Stringquote(CharSequence text) Enclose the specified text in quotation marks and escape all tab, quote, newline, and backslash characters.static StringquoteName(CharSequence name) Enclose the specified name in quotation marks and escape all tab, quote, newline, and backslash characters.static voidreduce(Collection<String> collection, int sizeGoal) Reduce a collection of strings using common prefixes.static StringExtract the remainder of the specified string after removing the specified prefix.static StringremoveSuffix(String input, String suffix) Extract the remainder of the specified string after removing the specified suffix.static Stringrepeat(CharSequence sequence, int numTimes) Generate a String consisting of a specified character sequence repeated a specified number of times.static intFind the length of the shared prefix of 2 text sequences.static String[]toArray(Collection<String> collection) Convert a collection of strings into an array.static StringTrim any trailing zeros and one trailing decimal point from a string representation of a float.static StringunEscape(CharSequence escaped) Undo character escape sequences added byescape(CharSequence).
-
Method Details
-
addMatchPrefix
public static List<String> addMatchPrefix(Collection<String> collection, String prefix, List<String> addResult) Find all strings in the input collection that begin with the specified prefix and add them to the result.- Parameters:
collection- input collection (not null, unaffected)prefix- (not null)addResult- (added to if not null)- Returns:
- an expanded list (either addResult or a new instance)
-
axisIndex
Determine the index of the named coordinate axis.- Parameters:
axisName- the name of the axis (not null, not empty)- Returns:
- the index of the axis: 0→X, 1→Y, 2→Z
- See Also:
-
axisName
Describe a coordinate axis.- Parameters:
axisIndex- the index of the axis: 0→X, 1→Y, 2→Z- Returns:
- a textual description (not null, not empty)
- See Also:
-
dedup
De-duplicate a list of strings by appending distinguishing suffixes as needed. The number of strings and their order remains unchanged.- Parameters:
list- input (not null, modified)separator- text to separate original name from suffix (not null)
-
describe
Generate a textual description of a single-precision floating-point value.- Parameters:
fValue- the value to describe- Returns:
- a description (not null, not empty)
-
describeAngle
Generate a textual description of a single-precision floating-point value using at most 2 decimal places.- Parameters:
fValue- the value to describe- Returns:
- a description (not null, not empty)
-
describeFraction
Generate a textual description of a single-precision floating-point value using at most 3 decimal places.- Parameters:
fValue- the value to describe- Returns:
- a description (not null, not empty)
-
describeMatrix
Generate a textual description of a Matrix3f value.- Parameters:
matrix- the value to describe (may be null, unaffected)- Returns:
- a description (not null, not empty)
-
escape
Replace all tab, quote, newline, and backslash characters in the specified text with escape sequences.- Parameters:
unescaped- the input text to escape (not null)- Returns:
- the escaped text (not null)
- See Also:
-
findIndex
Find the specified string value in an array, using a linear search. UnlikeArrays.binarySearch(java.lang.Object[], java.lang.Object), the array need not be sorted.- Parameters:
array- the array to search (not null, unaffected)value- the value to find (not null)- Returns:
- the index of the first match (≥0, <length) or -1 if not found
-
findLongestPrefix
Find the longest repeated prefix in a collection of strings.- Parameters:
collection- (not null, unaffected)- Returns:
- prefix (not null)
-
firstToLower
Convert the first character of the specified text to lower case.- Parameters:
input- the input text to convert (not null)- Returns:
- the converted text (not null)
-
invert
Invert the specified String-to-String map.- Parameters:
input- (not null, unaffected)- Returns:
- a new String-to-String map
-
isSorted
Test whether the specified List is lexicographically sorted in ascending order with no duplicates.- Parameters:
list- the List to analyze (not null, unaffected)- Returns:
- true if sorted, otherwise false
-
join
Join a collection of objects into a text string using the specified separator, ignoring any empties/nulls. Note that Java 8 providesString.join(java.lang.CharSequence, java.lang.Iterable), which doesn't ignore nulls.- Parameters:
separator- text string (not null)objects- objects to join (not null, unaffected, may contain nulls)- Returns:
- joined string (not null)
-
join
Join a collection of objects into a text string using spaces for separators and ignoring any empties/nulls.Note that Java 8 provides
String.join(java.lang.CharSequence, java.lang.Iterable), which doesn't ignore nulls.- Parameters:
objects- objects to join (not null, unaffected, may contain nulls)- Returns:
- joined string (not null)
-
join
Join an array of objects into a text string using spaces for separators and ignoring any empties/nulls.- Parameters:
array- objects to join (not null, unaffected, may contain nulls)- Returns:
- joined string (not null)
-
matchPrefix
Filter a collection of strings, keeping only those that begin with the specified prefix.- Parameters:
collection- collection to filter (not null, modified)prefix- (not null)
-
quote
Enclose the specified text in quotation marks and escape all tab, quote, newline, and backslash characters.- Parameters:
text- the input text to quote- Returns:
- the quoted text, or "null" if the input was null
-
quoteName
Enclose the specified name in quotation marks and escape all tab, quote, newline, and backslash characters.- Parameters:
name- the name to quote- Returns:
- a quoted string, or "(no name)" if the name was null
-
reduce
Reduce a collection of strings using common prefixes.- Parameters:
collection- (not null, modified)sizeGoal- (>0)
-
remainder
Extract the remainder of the specified string after removing the specified prefix.- Parameters:
input- the input string (not null)prefix- the prefix string (not null)- Returns:
- the remainder of the input (not null)
-
removeSuffix
Extract the remainder of the specified string after removing the specified suffix.- Parameters:
input- the input string (not null)suffix- the suffix string (not null)- Returns:
- the remainder of the input (not null)
-
repeat
Generate a String consisting of a specified character sequence repeated a specified number of times.- Parameters:
sequence- the sequence to use (not null)numTimes- the number of times (≥0)- Returns:
- a repetitious String
-
toArray
Convert a collection of strings into an array. This is more convenient than Collection.toArray() because the elements of the resulting array will all be strings.- Parameters:
collection- the collection to convert (not null)- Returns:
- a new array containing the same strings in the same order
-
trimFloat
Trim any trailing zeros and one trailing decimal point from a string representation of a float. Also remove any leading minus sign from zero.- Parameters:
input- the String to trim (not null)- Returns:
- a trimmed String (not null)
-
unEscape
Undo character escape sequences added byescape(CharSequence).- Parameters:
escaped- the input sequence (not null)- Returns:
- an unescaped string (not null)
-