org.opensolaris.os.dtrace
Class PrintfRecord

java.lang.Object
  extended by org.opensolaris.os.dtrace.PrintfRecord
All Implemented Interfaces:
java.io.Serializable, java.lang.Comparable<PrintfRecord>, Record

public final class PrintfRecord
extends java.lang.Object
implements Record, java.io.Serializable, java.lang.Comparable<PrintfRecord>

A formatted string generated by the DTrace printf() action.

Immutable. Supports persistence using XMLEncoder.

See Also:
Serialized Form

Constructor Summary
PrintfRecord(java.util.List<ValueRecord> v, java.lang.String s)
          Creates a record with the unformatted elements passed to the DTrace printf() action and the resulting formatted output.
 
Method Summary
 int compareTo(PrintfRecord r)
          Compares the formatted string value of this record with that of the given record.
 boolean equals(java.lang.Object o)
          Compares the specified object with this PrintfRecord for equality.
 java.lang.String getFormattedString()
          Gets the formatted string output of the DTrace printf() action.
 ValueRecord getRecord(int i)
          Gets the unformatted element passed to the DTrace printf() action at the given offset in the printf() argument list after the format string, starting at offset zero for the first unformatted element.
 int getRecordCount()
          Gets the number of DTrace printf() unformatted elements (arguments following the format string).
 java.util.List<ValueRecord> getRecords()
          Gets the unfomatted elements passed to the DTrace printf() action after the format string.
 int hashCode()
          Overridden to ensure that equal instances have equal hash codes.
 java.lang.String toString()
          Gets the formatted string output of the DTrace printf() action.
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Constructor Detail

PrintfRecord

public PrintfRecord(java.util.List<ValueRecord> v,
                    java.lang.String s)
Creates a record with the unformatted elements passed to the DTrace printf() action and the resulting formatted output. Supports XML persistence.

Parameters:
v - variable number of unformatted elements passed to the DTrace printf() action
s - formatted printf() output
Throws:
java.lang.NullPointerException - if the given list or any of its elements is null, or if the given formatted string is null
Method Detail

getFormattedString

public java.lang.String getFormattedString()
Gets the formatted string output of the DTrace printf() action.

Returns:
non-null formatted string output of the DTrace printf() action

getRecords

public java.util.List<ValueRecord> getRecords()
Gets the unfomatted elements passed to the DTrace printf() action after the format string.

Returns:
non-null, unmodifiable list of unformatted elements passed to the DTrace printf() action that generated this record, in the order they appear in the argument list after the format string

getRecordCount

public int getRecordCount()
Gets the number of DTrace printf() unformatted elements (arguments following the format string). For example, the following action

    printf("%s %d\n", "cat", 9);
 
generates a PrintfRecord with a record count of two.

Returns:
the number of unformatted elements passed to the DTrace printf() action that generated this record.

getRecord

public ValueRecord getRecord(int i)
Gets the unformatted element passed to the DTrace printf() action at the given offset in the printf() argument list after the format string, starting at offset zero for the first unformatted element.

Returns:
non-null record representing the unformatted printf() element at the given index (using the same order that they appear in the printf() argument list)
Throws:
java.lang.ArrayIndexOutOfBoundsException - if the given index is out of range (index < 0 || index >= getRecordCount())

equals

public boolean equals(java.lang.Object o)
Compares the specified object with this PrintfRecord for equality. Returns true if and only if the specified object is also a PrintfRecord and both records have the same formatted string and underlying data elements.

Overrides:
equals in class java.lang.Object
Returns:
true if and only if the specified object is also a PrintfRecord and both the formatted strings and the underlying data elements of both records are equal

hashCode

public int hashCode()
Overridden to ensure that equal instances have equal hash codes.

Overrides:
hashCode in class java.lang.Object

compareTo

public int compareTo(PrintfRecord r)
Compares the formatted string value of this record with that of the given record. Note that ordering printf records by their string values is incompatible with equals(), which also checks the underlying data elements for equality.

Specified by:
compareTo in interface java.lang.Comparable<PrintfRecord>
Returns:
a negative number, 0, or a positive number as this record's formatted string is lexicographically less than, equal to, or greater than the given record's formatted string

toString

public java.lang.String toString()
Gets the formatted string output of the DTrace printf() action.

Overrides:
toString in class java.lang.Object