public class LogMessage extends Object implements Comparable<LogMessage>
| Constructor and Description |
|---|
LogMessage(long timestamp,
String message)
Constructs an instance from a simple string.
|
| Modifier and Type | Method and Description |
|---|---|
int |
compareTo(LogMessage that)
Compares instances based on their timestamp.
|
byte[] |
getBytes()
Returns the UTF-8 message bytes.
|
String |
getMessage()
Returns the original message string.
|
long |
getTimestamp()
Returns the timestamp.
|
int |
size()
Returns the size of the UTF-8 representation.
|
void |
truncate(int maxSize)
Ensures that the message has no more than the specified number of bytes,
truncating if necessary.
|
public LogMessage(long timestamp,
String message)
public long getTimestamp()
public int size()
public String getMessage()
public byte[] getBytes()
public void truncate(int maxSize)
public int compareTo(LogMessage that)
Note that an "equal" comparison is not consistent with equals(),
which uses default instance equality. This is intentional: one the one hand,
there's no reason to test equality for two instances; they should be considered
opaque. On the other, we don't want the comparision to do more than it should:
we're using a stable sort, and rely on that fact to order two messages with the
same timestamp in the order they were passed to append().
compareTo in interface Comparable<LogMessage>Copyright © 2023. All rights reserved.