edu.cuny.cat.comm
Class Message

java.lang.Object
  extended by edu.cuny.cat.comm.Message
Direct Known Subclasses:
CatpMessage, TelnetMessage

public abstract class Message
extends java.lang.Object

An abstract class representing a plain-text message.

Version:
$Revision: 1.2 $
Author:
Jinzhong Niu

Field Summary
static java.lang.String CRLF
           
static java.lang.String VALUE_SEPARATOR
          the string separating items in a list.
 
Constructor Summary
Message()
           
 
Method Summary
static java.lang.String concatenate(double[] numbers)
          concatenates the string representations of doubles in an array.
static java.lang.String concatenate(int[] numbers)
          concatenates the string representations of integers in an array.
static java.lang.String concatenate(java.lang.String[] texts)
          concatenates an array of strings with the default VALUE_SEPARATOR, and return its string representation.
static java.lang.String concatenate(java.lang.String[] texts, java.lang.String separator)
          concatenates an array of strings with the separator, and return its string representation.
static double[] parseDoubles(java.lang.String s)
          parses a String into a list of doubles.
static int[] parseIntegers(java.lang.String s)
          parses a String into a list of integers.
static java.lang.String[] parseStrings(java.lang.String s)
          parses a list of plain-text words, separated by VALUE_SEPARATOR.
abstract  java.lang.String toString()
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

CRLF

public static java.lang.String CRLF

VALUE_SEPARATOR

public static java.lang.String VALUE_SEPARATOR
the string separating items in a list.

Constructor Detail

Message

public Message()
Method Detail

toString

public abstract java.lang.String toString()
Overrides:
toString in class java.lang.Object
Returns:
the plain-text presentation of this message.

parseStrings

public static java.lang.String[] parseStrings(java.lang.String s)
parses a list of plain-text words, separated by VALUE_SEPARATOR.

Parameters:
s - a word list
Returns:
the list of words in an array

parseDoubles

public static double[] parseDoubles(java.lang.String s)
                             throws MessageException
parses a String into a list of doubles.

Parameters:
s - a double list
Returns:
the list of doubles in an array
Throws:
MessageException - if an entry in the list fails to be parsed into double.
See Also:
parseStrings(String)

parseIntegers

public static int[] parseIntegers(java.lang.String s)
                           throws MessageException
parses a String into a list of integers.

Parameters:
s - an integer list
Returns:
the list of integers in an array
Throws:
CatException - if an entry in the list fails to be parsed into integer.
MessageException
See Also:
parseStrings(String)

concatenate

public static java.lang.String concatenate(java.lang.String[] texts)
concatenates an array of strings with the default VALUE_SEPARATOR, and return its string representation.

See Also:
concatenate(String[], String)

concatenate

public static java.lang.String concatenate(java.lang.String[] texts,
                                           java.lang.String separator)
concatenates an array of strings with the separator, and return its string representation. Null strings are overlooked, while empty string is considered as valid item.

Parameters:
texts - the array of strings.
separator - the string to separate the strings.
Returns:
a String instance for this representation.

concatenate

public static java.lang.String concatenate(double[] numbers)
concatenates the string representations of doubles in an array.

Parameters:
numbers - an array of doubles
Returns:
a String instance for this representation.
See Also:
concatenate(String[])

concatenate

public static java.lang.String concatenate(int[] numbers)
concatenates the string representations of integers in an array.

Parameters:
numbers - an array of intergers
Returns:
a String instance for this representation.
See Also:
concatenate(String[])