Class Utility

java.lang.Object
gnu.dtools.ritopt.Utility

public class Utility extends Object
This class provides static utility members for some basic string operations.
 Copyright (C) Damian Ryan Eads, 2001. All Rights Reserved.

 ritopt is free software; you can redistribute it and/or modify
 it under the terms of the GNU General Public License as published by
 the Free Software Foundation; either version 2 of the License, or
 (at your option) any later version.

 ritopt is distributed in the hope that it will be useful,
 but WITHOUT ANY WARRANTY; without even the implied warranty of
 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 GNU General Public License for more details.

 You should have received a copy of the GNU General Public License
 along with ritopt; if not, write to the Free Software
 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 
  • Constructor Summary

    Constructors
    Constructor
    Description
     
  • Method Summary

    Modifier and Type
    Method
    Description
    static boolean
    contains(char check, String list)
    Returns true if any of the characters in the list are equal to the check character.
    static boolean
    contains(String check, String list)
    Returns true if any of the characters in the list appear in the check string passed.
    static int
    count(String check, char spec)
    Returns the number of occurances the character specification appears in the check string passed.
    static String
    expandString(String s, int length)
    Returns a string with no more and no less than n characters where n is the length.
    static String
    getSpaces(int count)
    Returns a string containing the number of spaces passed as an argument.
    static boolean
    isAlpha(char check)
    Returns true if the character is a letter in the phonetic alphabetic.
    static boolean
    isAlpha(String check)
    Returns true if the string only contains letters in the phonetic alphabet.
    static boolean
    isAlphaLower(char check)
    Returns true if the character is a lower case letter in the phonetic alphabetic.
    static boolean
    Returns true if the string only contains lower case letters in the phonetic alphabet.
    static boolean
    isAlphaNumeric(char check)
    Returns true if the character is a letter in the phonetic alphabetic or is a decimal number.
    static boolean
    isAlphaUpper(char check)
    Returns true if the character is a upper case letter in the phonetic alphabetic.
    static boolean
    Returns true if the string only contains upper case letters in the phonetic alphabet.
    static boolean
    isNumeric(char check)
    Returns true if the character is a decimal number.
    static String
    Trim spaces off the left side of this string.
    static String
    repeat(char c, int count)
    Returns a string with a character repeated based on a count passed.
    static String
    repeat(String s, int count)
    Returns a string with the passed string repeated based on the integer count passed.
    static String
    Trim spaces off the right side of this string.
    static String
    stripComments(String s, char delim, char comment)
    Takes a line (presumably from a file) and removes a comment if one exists.
    static String
    Trim spaces off both sides of this string.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Constructor Details

    • Utility

      public Utility()
  • Method Details

    • contains

      public static boolean contains(String check, String list)
      Returns true if any of the characters in the list appear in the check string passed.
      Parameters:
      check - The string to check.
      list - The list of valid characters.
      Returns:
      true if the criteria of this method is satisfied.
    • count

      public static int count(String check, char spec)
      Returns the number of occurances the character specification appears in the check string passed.
      Parameters:
      check - The string to check.
      spec - The character specification.
      Returns:
      the number of occurances of the character specification.
    • contains

      public static boolean contains(char check, String list)
      Returns true if any of the characters in the list are equal to the check character.
      Parameters:
      check - The character to check.
      list - The list of valid characters.
      Returns:
      true if any of the characters in the list equal the check character.
    • isAlpha

      public static boolean isAlpha(String check)
      Returns true if the string only contains letters in the phonetic alphabet.
      Parameters:
      check - The string to check.
      Returns:
      If this method's criteria is matched.
    • isAlphaLower

      public static boolean isAlphaLower(String check)
      Returns true if the string only contains lower case letters in the phonetic alphabet.
      Parameters:
      check - The string to check.
      Returns:
      If this method's criteria is matched.
    • isAlphaUpper

      public static boolean isAlphaUpper(String check)
      Returns true if the string only contains upper case letters in the phonetic alphabet.
      Parameters:
      check - The string to check.
      Returns:
      If this method's criteria is matched.
    • isAlpha

      public static boolean isAlpha(char check)
      Returns true if the character is a letter in the phonetic alphabetic.
      Parameters:
      check - The character to check.
      Returns:
      true if this method's criteria is matched.
    • isAlphaLower

      public static boolean isAlphaLower(char check)
      Returns true if the character is a lower case letter in the phonetic alphabetic.
      Parameters:
      check - The character to check.
      Returns:
      true if this method's criteria is matched.
    • isAlphaUpper

      public static boolean isAlphaUpper(char check)
      Returns true if the character is a upper case letter in the phonetic alphabetic.
      Parameters:
      check - The character to check.
      Returns:
      true if this method's criteria is matched.
    • isAlphaNumeric

      public static boolean isAlphaNumeric(char check)
      Returns true if the character is a letter in the phonetic alphabetic or is a decimal number.
      Parameters:
      check - The character to check.
      Returns:
      true if this method's criteria is matched.
    • isNumeric

      public static boolean isNumeric(char check)
      Returns true if the character is a decimal number.
      Parameters:
      check - The character to check.
      Returns:
      true if this method's criteria is matched.
    • expandString

      public static String expandString(String s, int length)
      Returns a string with no more and no less than n characters where n is the length. If the string passed is less than this length, an appropriate number of spaces is concatenated. If the string is longer than the length passed, a substring of the length passed is returned.
      Parameters:
      s - The string to expand.
      length - The required length.
      Returns:
      The expanded string.
    • getSpaces

      public static String getSpaces(int count)
      Returns a string containing the number of spaces passed as an argument.
      Parameters:
      count - The number of spaces in the string returned.
      Returns:
      a string containing the number of spaces passed.
    • repeat

      public static String repeat(char c, int count)
      Returns a string with a character repeated based on a count passed.
      Parameters:
      c - The character to repeat.
      count - The number of times to repeat the character.
    • ltrim

      public static String ltrim(String s)
      Trim spaces off the left side of this string.
      Parameters:
      s - The string to trim.
      Returns:
      The trimmed string.
    • rtrim

      public static String rtrim(String s)
      Trim spaces off the right side of this string.
      Parameters:
      s - The string to trim.
      Returns:
      The trimmed string.
    • trim

      public static String trim(String s)
      Trim spaces off both sides of this string.
      Parameters:
      s - The string to trim.
      Returns:
      The trimmed string.
    • stripComments

      public static String stripComments(String s, char delim, char comment)
      Takes a line (presumably from a file) and removes a comment if one exists. If the comment character is enclosed within a literal string defined by the delimiter passed, then the character is ignored.
      Parameters:
      s - The string to strip comments off.
      delim - The string delimiter.
      comment - The comment character.
      Returns:
      A string stripped of comments.
    • repeat

      public static String repeat(String s, int count)
      Returns a string with the passed string repeated based on the integer count passed.
      Parameters:
      s - The string to repeat.
      count - The number of times to repeat the string.
      Returns:
      The repeated string.