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)
    Instances are ordered firstly by utc, secondly by hash.
    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 java.lang.Object

    clone, finalize, getClass, notify, notifyAll, wait, wait, wait
  • Field Details

  • 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 long
      firstUtc - the min utc in the tree
      lastUtc - the max utc in the tree
      out - 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 bytes
      firstUtc - the min utc in the tree
      lastUtc - the max utc in the tree
      out - 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 for HashUtc.utc().
    • maxUtc

      public long maxUtc()
      Returns the maximum crum utc in the tree.
    • compareTo

      public int compareTo​(TreeRef o)
      Instances are ordered firstly by utc, secondly by hash. Consistent with HashUtc.equals(Object).
      Specified by:
      compareTo in interface java.lang.Comparable<TreeRef>
    • serialForm

      public java.nio.ByteBuffer serialForm()
      Returns the instance's serialized representation as a read-only buffer.
      Overrides:
      serialForm in class HashUtc
      Returns:
      a buffer with HashUtc.DATA_SIZE remaining bytes.
      See Also:
      #TreeRef(ByteBuffer)