Package space.subkek.nodeledger
Class NodeLedgerDocument
java.lang.Object
space.subkek.nodeledger.NodeLedgerDocument
Mutable NodeLedger document rooted at a node tree.
-
Method Summary
Modifier and TypeMethodDescriptionbooleanChecks whether a path exists.longfileSize()Returns the file size observed when the document was opened or saved.<T> TReads a value from a path.booleanisDirty()Returns whether this document has unsaved changes.longReturns the last trim timestamp stored in the NODELEDGER header.path()Returns the source file path when this document was opened from a file.booleanRemoves a value or node at a path.root()Returns the root node.voidSaves this document to a file.<T> voidStores a value at a path.voidCompacts this document into a new file.
-
Method Details
-
root
Returns the root node.- Returns:
- root node.
-
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
Stores a value at a path.- Type Parameters:
T- Java value type.- Parameters:
path- document path.value- value to store.
-
get
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
Removes a value or node at a path.- Parameters:
path- document path.- Returns:
truewhen a value was removed.
-
contains
Checks whether a path exists.- Parameters:
path- document path.- Returns:
truewhen the path exists.
-
isDirty
public boolean isDirty()Returns whether this document has unsaved changes.- Returns:
truewhen the document is dirty.
-
save
Saves this document to a file.- Parameters:
path- target file path.- Throws:
NodeLedgerException- when writing fails.
-
trim
Compacts this document into a new file.- Parameters:
path- target file path.- Throws:
NodeLedgerException- when trimming fails.
-