Class DirectoryNodeStore<K extends java.io.Serializable,D extends java.io.Serializable>
- java.lang.Object
-
- com.github.basking2.sdsai.dsds.fs.DirectoryNodeStore<K,D>
-
- All Implemented Interfaces:
NodeStore<K,java.io.File,D>
public class DirectoryNodeStore<K extends java.io.Serializable,D extends java.io.Serializable> extends java.lang.Object implements NodeStore<K,java.io.File,D>
A trivial storage class that puts all nodes into a single directory with filenames represented by the hex-encoding of their key names.
-
-
Constructor Summary
Constructors Constructor Description DirectoryNodeStore(java.io.File directory)DirectoryNodeStore(java.lang.String directory)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description java.io.Fileconvert(K key)Convert user keys to store keys.java.io.FilegenerateKey(Node<K,java.io.File> node, D d)Generate a key to store a node or data element.DloadData(java.io.File key)Load the user's data.Node<K,java.io.File>loadNode(java.io.File key)Load a node object fromNodeStore.voidremoveData(java.io.File key)Remove the given data key.voidremoveNode(java.io.File key)Remove the given node key.voidstore(java.io.File key, Node<K,java.io.File> node)Store the given node.voidstore(java.io.File key, D data)Store user data.
-
-
-
Method Detail
-
removeNode
public void removeNode(java.io.File key) throws NodeStoreExceptionRemove the given node key. If the key does not exist, this should return without error.- Specified by:
removeNodein interfaceNodeStore<K extends java.io.Serializable,java.io.File,D extends java.io.Serializable>- Throws:
NodeStoreException
-
removeData
public void removeData(java.io.File key) throws NodeStoreExceptionRemove the given data key. If the key does not exist, this should return without error.- Specified by:
removeDatain interfaceNodeStore<K extends java.io.Serializable,java.io.File,D extends java.io.Serializable>- Throws:
NodeStoreException
-
loadNode
public Node<K,java.io.File> loadNode(java.io.File key) throws NodeStoreException
Load a node object fromNodeStore.- Specified by:
loadNodein interfaceNodeStore<K extends java.io.Serializable,java.io.File,D extends java.io.Serializable>- Throws:
NodeStoreExceptionNodeStoreNodeNotFoundException- When a node is not found.
-
loadData
public D loadData(java.io.File key) throws NodeStoreException
Load the user's data.- Specified by:
loadDatain interfaceNodeStore<K extends java.io.Serializable,java.io.File,D extends java.io.Serializable>- Returns:
- the user's data or null if it is not found.
- Throws:
NodeStoreException
-
store
public void store(java.io.File key, Node<K,java.io.File> node) throws NodeStoreExceptionStore the given node. If an object already exists at the key, it should be replaced.- Specified by:
storein interfaceNodeStore<K extends java.io.Serializable,java.io.File,D extends java.io.Serializable>- Throws:
NodeStoreException
-
store
public void store(java.io.File key, D data) throws NodeStoreExceptionStore user data. If an object already exists at the key, it should be replaced.- Specified by:
storein interfaceNodeStore<K extends java.io.Serializable,java.io.File,D extends java.io.Serializable>- Throws:
NodeStoreException
-
generateKey
public java.io.File generateKey(Node<K,java.io.File> node, D d)
Generate a key to store a node or data element. This key must be unique.- Specified by:
generateKeyin interfaceNodeStore<K extends java.io.Serializable,java.io.File,D extends java.io.Serializable>- Parameters:
node- This is provided to implementations for some context. If generateKey is being called for the purposes of storing a user key, this will be null.d- If a key is being generated for a user key value, it will be passed along. This is most useful when things like aPagedListare adding a value, but the List API does not provide a way to specify a key.
-
convert
public java.io.File convert(K key) throws NodeStoreException
Convert user keys to store keys. This method, given a user's key, must always produce the same store key.- Specified by:
convertin interfaceNodeStore<K extends java.io.Serializable,java.io.File,D extends java.io.Serializable>- Throws:
NodeStoreException- if any error occurs.
-
-