Class LogRecord

java.lang.Object
  |
  +--LogRecord
All Implemented Interfaces:
java.lang.Comparable

public class LogRecord
extends java.lang.Object
implements java.lang.Comparable

A LogRecord describes a logged event. A LogRecord consists of an event name, an event identifier number, and the time at which the event took place. The identifier number is taken from an internal counter. LogRecords are immutable. That is, once created, they are never changed. LogRecord's implement the Comparable interface so that they can be sorted.


Constructor Summary
LogRecord(java.lang.String event)
          Constructor specifying a string description of an event; events are not allowed to contain "newlines" \n.
 
Method Summary
 int compareTo(java.lang.Object o)
          LogRecords are ordered based first on timestamp, then eventID, and finally event name.
 boolean equals(java.lang.Object o)
          One LogRecord is equal to another if all of its fields are themselves equal to (using the .equals method) the fields of the other object.
 void format(java.io.PrintWriter out)
          Creates a string representation of the LogRecord for later retrieval by fromFormat, below.
static LogRecord fromFormat(java.io.BufferedReader in)
          Creates a LogRecord from its format representation.
 java.lang.String getEvent()
          Returns the string event portion of the LogRecord.
 java.util.Date getTimestamp()
          Returns the time when this LogRecord was created.
 java.lang.String toString()
          Creates a string representation of the LogRecord suitable for printing.
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

LogRecord

public LogRecord(java.lang.String event)
Constructor specifying a string description of an event; events are not allowed to contain "newlines" \n. In addition to storing the string, it will store the current time (using the Date class) and a unique numeric ID, drawn from the internal counter.

Method Detail

getEvent

public java.lang.String getEvent()
Returns the string event portion of the LogRecord.


getTimestamp

public java.util.Date getTimestamp()
Returns the time when this LogRecord was created.


toString

public java.lang.String toString()
Creates a string representation of the LogRecord suitable for printing.

Overrides:
toString in class java.lang.Object

format

public void format(java.io.PrintWriter out)
Creates a string representation of the LogRecord for later retrieval by fromFormat, below. Each element of the LogRecord is printed on its own line (i.e., each is followed by a newline) in the following order: eventID, timestamp, and event. The timestamp is printed as the number of milliseconds since January 1, 1970, 00:00:00 GMT.


fromFormat

public static LogRecord fromFormat(java.io.BufferedReader in)
Creates a LogRecord from its format representation. That is, it reads each of the three fields separated by newlines---eventID, timestamp, and event---and creates the corresponding LogRecord using a private constructor.


equals

public boolean equals(java.lang.Object o)
One LogRecord is equal to another if all of its fields are themselves equal to (using the .equals method) the fields of the other object.

Overrides:
equals in class java.lang.Object

compareTo

public int compareTo(java.lang.Object o)
              throws java.lang.ClassCastException
LogRecords are ordered based first on timestamp, then eventID, and finally event name.

Specified by:
compareTo in interface java.lang.Comparable
java.lang.ClassCastException