public class CSN extends Object implements Serializable, Comparable<CSN>
Modifier and Type | Class and Description |
---|---|
static class |
CSN.CsnVersion
The version of a CSN to ask for a particular representation.
|
Modifier and Type | Field and Description |
---|---|
static int |
BYTE_ENCODING_V1_LENGTH
The number of bytes used by the byte string representation of a change number v0.
|
static CSN |
MIN_VALUE
The minimum possible value for a CSN.
|
static int |
REPLICA_NAME_POSITION
The position of the replica name in a string representation of a CSN.
|
static int |
STRING_ENCODING_V1_LENGTH
The number of characters used by the string representation of a change number v0.
|
Constructor and Description |
---|
CSN(long timeStamp,
int seqNum,
int replicaId)
Create a new
CSN . |
CSN(long timeStamp,
int seqNum,
ReplicaId replicaId)
Create a new
CSN . |
Modifier and Type | Method and Description |
---|---|
static int |
compare(CSN csn1,
CSN csn2)
Compares this CSN with the provided CSN for order and returns a negative number if
csn1 is older than
csn2 , zero if they have the same age, or a positive number if csn1 is newer than csn2 . |
int |
compareTo(CSN csn)
Compares this CSN with the provided CSN for order and returns a negative number if this CSN is older than
csn , zero if they have the same age, or a positive number if this CSN is newer than csn . |
static int |
diffSeqNum(CSN csn1,
CSN csn2)
Computes the difference in number of changes between 2 CSNs.
|
boolean |
equals(Object obj) |
ReplicaId |
getReplicaId()
Getter for the replica ID.
|
int |
getSeqnum()
Getter for the sequence number.
|
long |
getTime()
Getter for the time.
|
long |
getTimeSec()
Get the timestamp associated to this
CSN in seconds. |
int |
hashCode() |
boolean |
isNewerThan(CSN csn)
Returns
true if this CSN is newer than the provided CSN. |
boolean |
isNewerThanOrEqualTo(CSN csn)
Returns
true if this CSN is newer than or equal to the provided CSN. |
boolean |
isOlderThan(CSN csn)
Returns
true if this CSN is older than the provided CSN. |
boolean |
isOlderThanOrEqualTo(CSN csn)
Returns
true if this CSN is older than or equal to the provided CSN. |
static CSN |
newestCsn(long timeStamp)
Return the newest possible CSN for the given time.
|
static CSN |
newestCsn(ReplicaId replicaId)
Returns the newest possible CSN for a replica.
|
static CSN |
oldestCsn(long timeStamp)
Returns the oldest possible CSN for the given time.
|
static CSN |
oldestCsn(ReplicaId replicaId)
Returns the oldest possible CSN for a replica.
|
static void |
skipCsn(ByteSequenceReader reader)
Advances reading the provided reader to the end of the CSN representation, by skipping over it.
|
ByteString |
toByteString()
Encodes this CSN as a byte string.
|
void |
toByteString(ByteStringBuilder builder)
Encodes this CSN into the provided byte string builder.
|
void |
toByteString(ByteStringBuilder builder,
CSN.CsnVersion version)
Encodes this CSN into the provided byte string builder according to the given CSN version.
|
ByteString |
toByteString(CSN.CsnVersion version)
Encodes this CSN as a byte string according to the given CSN version.
|
String |
toString()
Convert the
CSN to a printable String. |
String |
toString(CSN.CsnVersion version)
Convert the
CSN to a printable String according to the given CSN version. |
String |
toStringUI()
Convert the
CSN to a printable String with a user friendly format. |
static CSN |
valueOf(ByteSequence bs)
Decodes the provided
toByteString(CsnVersion) representation of a CSN. |
static CSN |
valueOf(ByteSequenceReader reader)
Decodes the provided
toByteString(CsnVersion) representation of a CSN, possibly embedded in a larger
sequence. |
static CSN |
valueOf(String str)
Parses the provided
toString() representation of a CSN. |
public static final int BYTE_ENCODING_V1_LENGTH
public static final int STRING_ENCODING_V1_LENGTH
valueOf(String)
,
toString()
,
Constant Field Valuespublic static final CSN MIN_VALUE
public static final int REPLICA_NAME_POSITION
public CSN(long timeStamp, int seqNum, int replicaId)
CSN
.timeStamp
- timeStamp for the CSN
seqNum
- sequence numberreplicaId
- identity of replicapublic static CSN valueOf(String str)
toString()
representation of a CSN.str
- The string to be parsed.toString()
public static CSN valueOf(ByteSequence bs)
toByteString(CsnVersion)
representation of a CSN.bs
- The byte sequence to be parsed.toByteString(CsnVersion)
public static void skipCsn(ByteSequenceReader reader)
reader
- The reader to advancepublic static CSN valueOf(ByteSequenceReader reader)
toByteString(CsnVersion)
representation of a CSN, possibly embedded in a larger
sequence.reader
- The reader of the byte sequence to be parsed.public long getTime()
public long getTimeSec()
CSN
in seconds.CSN
in secondspublic int getSeqnum()
public ReplicaId getReplicaId()
public ByteString toByteString()
The returned representation is according to the most recent CSN version.
Use toByteString(CsnVersion)
to get a representation compatible with earlier protocol versions.
valueOf(ByteSequence)
public void toByteString(ByteStringBuilder builder)
The returned representation is according to the most recent CSN version.
Use toByteString(ByteStringBuilder, CsnVersion)
to get a representation compatible with earlier
protocol versions.
builder
- The byte string builder.valueOf(ByteSequence)
public ByteString toByteString(CSN.CsnVersion version)
version
- The required representation versionpublic void toByteString(ByteStringBuilder builder, CSN.CsnVersion version)
builder
- The byte string builder.version
- The required representation versionvalueOf(ByteSequence)
public String toString()
CSN
to a printable String.
The returned representation is according to the most recent CSN version.
Use toString(CsnVersion)
to get a representation compatible with earlier protocol versions.
public String toString(CSN.CsnVersion version)
CSN
to a printable String according to the given CSN version.
version
- The required representation versionpublic String toStringUI()
CSN
to a printable String with a user friendly format.public static int compare(CSN csn1, CSN csn2)
csn1
is older than
csn2
, zero if they have the same age, or a positive number if csn1
is newer than csn2
.csn1
- The first CSN to be compared, which may be null
.csn2
- The second CSN to be compared, which may be null
.csn1
is older than csn2
, zero if they have the same age, or a
positive number if csn1
is newer than csn2
.public static int diffSeqNum(CSN csn1, CSN csn2)
public boolean isOlderThan(CSN csn)
true
if this CSN is older than the provided CSN.csn
- The CSN to be compared.true
if this CSN is older than the provided CSN.public boolean isOlderThanOrEqualTo(CSN csn)
true
if this CSN is older than or equal to the provided CSN.csn
- The CSN to be compared.true
if this CSN is older than or equal to the provided CSN.public boolean isNewerThanOrEqualTo(CSN csn)
true
if this CSN is newer than or equal to the provided CSN.csn
- The CSN to be compared.true
if this CSN is newer than or equal to the provided CSN.public boolean isNewerThan(CSN csn)
true
if this CSN is newer than the provided CSN.csn
- The CSN to be compared.true
if this CSN is newer than the provided CSN.public int compareTo(CSN csn)
csn
, zero if they have the same age, or a positive number if this CSN is newer than csn
.compareTo
in interface Comparable<CSN>
csn
- The CSN to be compared.csn
, zero if they have the same age, or a positive
number if this CSN is newer than csn
.public static CSN oldestCsn(long timeStamp)
timeStamp
- the time of the CSNpublic static CSN oldestCsn(ReplicaId replicaId)
replicaId
- the replicapublic static CSN newestCsn(long timeStamp)
timeStamp
- the time of the CSNCopyright 2010-2022 ForgeRock AS.