Class NodeLedgerDocument

java.lang.Object
space.subkek.nodeledger.NodeLedgerDocument

public class NodeLedgerDocument extends Object
Mutable NodeLedger document rooted at a node tree.
  • Method Details

    • root

      public NodeLedgerNode root()
      Returns the root node.
      Returns:
      root node.
    • path

      public Optional<Path> path()
      Returns the source file path when this document was opened from a file.
      Returns:
      source path.
    • fileSize

      public long fileSize()
      Returns the file size observed when the document was opened or saved.
      Returns:
      file size in bytes.
    • lastTrimTimestamp

      public long lastTrimTimestamp()
      Returns the last trim timestamp stored in the NODELEDGER header.
      Returns:
      last trim timestamp.
    • set

      public <T> void set(String path, T value)
      Stores a value at a path.
      Type Parameters:
      T - Java value type.
      Parameters:
      path - document path.
      value - value to store.
    • get

      public <T> T get(String path, Class<T> javaType) throws NodeLedgerException
      Reads a value from a path.
      Type Parameters:
      T - Java value type.
      Parameters:
      path - document path.
      javaType - expected Java type.
      Returns:
      decoded value.
      Throws:
      NodeLedgerException - when the value cannot be read as the requested type.
    • remove

      public boolean remove(String path)
      Removes a value or node at a path.
      Parameters:
      path - document path.
      Returns:
      true when a value was removed.
    • contains

      public boolean contains(String path)
      Checks whether a path exists.
      Parameters:
      path - document path.
      Returns:
      true when the path exists.
    • isDirty

      public boolean isDirty()
      Returns whether this document has unsaved changes.
      Returns:
      true when the document is dirty.
    • save

      public void save(Path path) throws NodeLedgerException
      Saves this document to a file.
      Parameters:
      path - target file path.
      Throws:
      NodeLedgerException - when writing fails.
    • trim

      public void trim(Path path) throws NodeLedgerException
      Compacts this document into a new file.
      Parameters:
      path - target file path.
      Throws:
      NodeLedgerException - when trimming fails.