Class StringUtil

java.lang.Object
megamek.common.util.StringUtil

public class StringUtil extends Object
  • Constructor Details

    • StringUtil

      public StringUtil()
  • Method Details

    • splitString

      public static Vector<String> splitString(String s, String divider)
    • makeLength

      public static String makeLength(String s, int n)
    • makeLength

      public static String makeLength(int s, int n)
    • makeLength

      public static String makeLength(String s, int n, boolean bRightJustify)
      A utility for padding out a string with spaces.
      Parameters:
      s - the string to pad
      n - the desired length of the resultant string
      bRightJustify - true if the string should be right justified
    • addDateTimeStamp

      public static String addDateTimeStamp(String filename)
      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

      public static boolean isNumeric(String number)
      Returns TRUE if the passed string is a valid number.
      Parameters:
      number - The String to be evaluated.
      Returns:
      TRUE if the value can be parsed to a Double without throwing a NumberFormatException.
    • isPositiveInteger

      public static boolean isPositiveInteger(String number)
      Returns TRUE if the passed string is a positive integer value.
      Parameters:
      number - The String to be evaluated.
      Returns:
      TRUE if the value can be parsed to an Integer without throwing a NumberFormatException and the parsed value is greater than or equal to zero.
    • isInteger

      public static boolean isInteger(String number)
      Returns TRUE if the passed string is an integer value.
      Parameters:
      number - The String to be evaluated.
      Returns:
      TRUE if the value can be parsed to an Integer without throwing a NumberFormatException and the parsed value is greater than or equal to zero.
    • toInt

      public static int toInt(String s, int i)
      Returns integer value from the passed string or default value if conversion fails.
    • toFloat

      public static float toFloat(String s, float i)
      Returns float value from the passed string or default value if conversion fails.
    • isBetween

      public static boolean isBetween(double value, String sStart, String sEnd)
      Returns if value is between the start and end
    • wrapLines

      public static String wrapLines(String in, int length)
      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 string
      length - The maximum line length in characters
      Returns:
      The string, with lines wrapped to at most length