Package megamek.common.util
Class StringUtil
java.lang.Object
megamek.common.util.StringUtil
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic StringaddDateTimeStamp(String filename) Inserts a date/time stamp into the given filename string just before the last period.static booleanReturns if value is between the start and endstatic booleanReturns TRUE if the passed string is an integer value.static booleanReturns TRUE if the passed string is a valid number.static booleanisPositiveInteger(String number) Returns TRUE if the passed string is a positive integer value.static StringmakeLength(int s, int n) static StringmakeLength(String s, int n) static StringmakeLength(String s, int n, boolean bRightJustify) A utility for padding out a string with spaces.splitString(String s, String divider) static floatReturns float value from the passed string or default value if conversion fails.static intReturns integer value from the passed string or default value if conversion fails.static StringWrap an input string, inserting newlines such that line length will not exceed the given length.
-
Constructor Details
-
StringUtil
public StringUtil()
-
-
Method Details
-
splitString
-
makeLength
-
makeLength
-
makeLength
A utility for padding out a string with spaces.- Parameters:
s- the string to padn- the desired length of the resultant stringbRightJustify- true if the string should be right justified
-
addDateTimeStamp
Inserts a date/time stamp into the given filename string just before the last period. If there is no period in the filename, the stamp is added to the end. The format of the stamp is dictated by the client option "StampFormat", which must use the same formatting as Java's DateTimeFormatter class.- Parameters:
filename- the String containing the filename (with extension)- Returns:
- the filename with date/time stamp added
-
isNumeric
Returns TRUE if the passed string is a valid number.- Parameters:
number- TheStringto be evaluated.- Returns:
- TRUE if the value can be parsed to a
Doublewithout throwing aNumberFormatException.
-
isPositiveInteger
Returns TRUE if the passed string is a positive integer value.- Parameters:
number- TheStringto be evaluated.- Returns:
- TRUE if the value can be parsed to an
Integerwithout throwing aNumberFormatExceptionand the parsed value is greater than or equal to zero.
-
isInteger
Returns TRUE if the passed string is an integer value.- Parameters:
number- TheStringto be evaluated.- Returns:
- TRUE if the value can be parsed to an
Integerwithout throwing aNumberFormatExceptionand the parsed value is greater than or equal to zero.
-
toInt
Returns integer value from the passed string or default value if conversion fails. -
toFloat
Returns float value from the passed string or default value if conversion fails. -
isBetween
Returns if value is between the start and end -
wrapLines
Wrap an input string, inserting newlines such that line length will not exceed the given length. Used primarily for formatting tooltips with wrapping, because apparently Swing doesn't have a nice provision to automatically wordwrap tooltips.- Parameters:
in- Input stringlength- The maximum line length in characters- Returns:
- The string, with lines wrapped to at most length
-