Package io.crums.model
Class TreeRef
java.lang.Object
io.crums.model.HashUtc
io.crums.model.TreeRef
- All Implemented Interfaces:
java.lang.Comparable<TreeRef>
public class TreeRef extends HashUtc implements java.lang.Comparable<TreeRef>
A stub to a crum Merkle tree identified by its root hash. Additional info provided
by this stub type include the tree number,
the tree's minimum and maximum UTCs.
-
Field Summary
Fields Modifier and Type Field Description static int
TREE_REF_SIZE
Fields inherited from class io.crums.model.HashUtc
data, DATA_SIZE, HASH_COMPARATOR, INCEPTION_UTC, RUN_MAX_UTC
-
Constructor Summary
Constructors Constructor Description TreeRef(java.nio.ByteBuffer data, int treeNumber)
Creates a new instance. -
Method Summary
Modifier and Type Method Description int
compareTo(TreeRef o)
long
maxUtc()
Returns the maximum crum utc in the tree.long
minUtc()
Returns the minimum crum utc in the tree.java.nio.ByteBuffer
serialForm()
Returns the instance's serialized representation as a read-only buffer.int
treeNumber()
Returns the zero-based tree number.static java.nio.ByteBuffer
writeTreeRefToBuffer(byte[] hash, long firstUtc, long lastUtc, java.nio.ByteBuffer out)
Writes the specified fields to the given out buffer.static java.nio.ByteBuffer
writeTreeRefToBuffer(java.nio.ByteBuffer hash, long firstUtc, long lastUtc, java.nio.ByteBuffer out)
Writes the specified fields to the given out buffer.Methods inherited from class io.crums.model.HashUtc
equals, equalsHashUtc, hash, hashCode, hashEquals, hashHex, sanityCheckUtc, toString, utc, writeToBuffer, writeToBuffer
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
-
Field Details
-
TREE_REF_SIZE
public static final int TREE_REF_SIZE- See Also:
- Constant Field Values
-
-
Constructor Details
-
TreeRef
public TreeRef(java.nio.ByteBuffer data, int treeNumber)Creates a new instance.- Parameters:
data
- at least TREE_REF_SIZE remaining bytes. The caller agrees not to modify in any way.
-
-
Method Details
-
writeTreeRefToBuffer
public static java.nio.ByteBuffer writeTreeRefToBuffer(byte[] hash, long firstUtc, long lastUtc, java.nio.ByteBuffer out)Writes the specified fields to the given out buffer. The buffer's position is advanced by TREE_REF_SIZE-many bytes.- Parameters:
hash
- Constants.HASH_WIDTH bytes longfirstUtc
- the min utc in the treelastUtc
- the max utc in the treeout
- the output buffer- Returns:
- out
-
writeTreeRefToBuffer
public static java.nio.ByteBuffer writeTreeRefToBuffer(java.nio.ByteBuffer hash, long firstUtc, long lastUtc, java.nio.ByteBuffer out)Writes the specified fields to the given out buffer. The buffer's position is advanced by TREE_REF_SIZE-many bytes.- Parameters:
hash
- Constants.HASH_WIDTH remaining bytesfirstUtc
- the min utc in the treelastUtc
- the max utc in the treeout
- the output buffer- Returns:
- out
-
treeNumber
public int treeNumber()Returns the zero-based tree number. -
minUtc
public long minUtc()Returns the minimum crum utc in the tree. Synonym forHashUtc.utc()
. -
maxUtc
public long maxUtc()Returns the maximum crum utc in the tree. -
compareTo
- Specified by:
compareTo
in interfacejava.lang.Comparable<TreeRef>
-
serialForm
public java.nio.ByteBuffer serialForm()Returns the instance's serialized representation as a read-only buffer.- Overrides:
serialForm
in classHashUtc
- Returns:
- a buffer with HashUtc.DATA_SIZE remaining bytes.
- See Also:
#TreeRef(ByteBuffer)
-