mome.ext
Class Utils

java.lang.Object
  extended by mome.ext.Utils

public class Utils
extends Object

Collection of useful static utils for parsing strings.

Version:
1.0
Author:
Sergio Morozov

Field Summary
static char[] testSeparators
          Array of separators.
 
Constructor Summary
protected Utils()
          Protects constructor.
 
Method Summary
static boolean isTestSeparator(char c)
          Checks if the given character is separator.
static boolean parseBoolean(String arg)
          Parses given string and returns true if string is "on" or "true" false otherwise.
static int parseColor(String arg)
          Parses string as hexadecimal integer representation and returns color as integer or -1 if string is null or can't be parsed.
static Font parseFont(String arg)
          Parses string and returns font.
static int parseFontFace(String face)
          Parses string and returns fonts face as integer.
static int parseFontSize(String size)
          Parses string and returns fonts size as integer.
static int parseFontStyle(String style)
          Parses string and returns fonts style as integer.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

testSeparators

public static char[] testSeparators
Array of separators.

Constructor Detail

Utils

protected Utils()
Protects constructor.

Method Detail

parseBoolean

public static boolean parseBoolean(String arg)
Parses given string and returns true if string is "on" or "true" false otherwise. Tests are case insensitive.

Parameters:
arg - string to parse.
Returns:
true if string is "on" or "true" false otherwise.

parseColor

public static int parseColor(String arg)
Parses string as hexadecimal integer representation and returns color as integer or -1 if string is null or can't be parsed.

Parameters:
arg - string to be parsed.
Returns:
color as integer or -1 if string is null or can't be parsed

parseFontFace

public static int parseFontFace(String face)
Parses string and returns fonts face as integer. String must be of form
 PROPRTIONAL | MONOSPACE | SYSTEM
 
to be parsed. Test are case insensitive. Spaces are not allowed.

Parameters:
face - string to be parsed.
Returns:
font's face as integer.
Throws:
NullPointerException - if face is null.
IllegalArgumentException - if face is not of valid form.

parseFontStyle

public static int parseFontStyle(String style)
Parses string and returns fonts style as integer. String must be of form
             (PLAIN|BOLD|ITALIC|UNDERLINED)(;(PLAIN|BOLD|ITALIC|UNDERLINED))*
 
to be parsed. Test are case insensitive. Spaces are not allowed.

Parameters:
style - string to be parsed.
Returns:
font's style as integer.
Throws:
NullPointerException - if style is null.
IllegalArgumentException - if style is not of valid form.

parseFontSize

public static int parseFontSize(String size)
Parses string and returns fonts size as integer. String must be of form
 LARGE | MEDIUM | SMALL
 
to be parsed. Test are case insensitive. Spaces are not allowed.

Parameters:
size - string to be parsed.
Returns:
font's size as integer.
Throws:
NullPointerException - if style is null;
IllegalArgumentException - if style is not of valid form.

parseFont

public static Font parseFont(String arg)
Parses string and returns font. String must be of form
       <Face>,<Style>,<Size>
         Face = PROPRTIONAL|MONOSPACE|SYSTEM
         Style = (PLAIN|BOLD|ITALIC|UNDERLINED)(;(PLAIN|BOLD|ITALIC|UNDERLINED))*
         Size = LARGE|MEDIUM|SMALL
 
to be parsed. Test are case insensitive. Spaces are not allowed.

Parameters:
arg - string to be parsed.
Returns:
font or null if string is null or not of valid form.

isTestSeparator

public static boolean isTestSeparator(char c)
Checks if the given character is separator.

Parameters:
c - character to be tested.
Returns:
true if character is separator, false otherwise.