public class DirCacheEditor extends BaseDirCacheEditor
DirCache
by supplying discrete
edit commands.
An editor updates a DirCache by taking a list of
DirCacheEditor.PathEdit
commands and
executing them against the entries of the destination cache to produce a new
cache. This edit style allows applications to insert a few commands and then
have the editor compute the proper entry indexes necessary to perform an
efficient in-order update of the index records. This can be easier to use
than DirCacheBuilder
.
DirCacheBuilder
Modifier and Type | Class and Description |
---|---|
static class |
DirCacheEditor.DeletePath
Deletes a single file entry from the index.
|
static class |
DirCacheEditor.DeleteTree
Recursively deletes all paths under a subtree.
|
static class |
DirCacheEditor.PathEdit
Any index record update.
|
Modifier and Type | Field and Description |
---|---|
private static java.util.Comparator<DirCacheEditor.PathEdit> |
EDIT_CMP |
private int |
editIdx |
private java.util.List<DirCacheEditor.PathEdit> |
edits |
cache, entries, entryCnt
Modifier | Constructor and Description |
---|---|
protected |
DirCacheEditor(DirCache dc,
int ecnt)
Construct a new editor.
|
Modifier and Type | Method and Description |
---|---|
void |
add(DirCacheEditor.PathEdit edit)
Append one edit command to the list of commands to be applied.
|
private void |
applyEdits() |
boolean |
commit()
Finish, write, commit this change, and release the index lock.
|
private int |
deleteOverlappingSubtree(DirCacheEntry ent,
int eIdx) |
private int |
findEntry(byte[] p,
int pLen) |
void |
finish()
Finish this builder and update the destination
DirCache . |
private static boolean |
inDir(DirCacheEntry e,
byte[] path,
int pLen) |
private void |
insertEdit(DirCacheEditor.DeleteTree d) |
private static int |
pdir(byte[] path,
int e) |
fastAdd, fastKeep, getDirCache, replace
private static final java.util.Comparator<DirCacheEditor.PathEdit> EDIT_CMP
private final java.util.List<DirCacheEditor.PathEdit> edits
private int editIdx
protected DirCacheEditor(DirCache dc, int ecnt)
dc
- the cache this editor will eventually update.ecnt
- estimated number of entries the editor will have upon
completion. This sizes the initial entry table.public void add(DirCacheEditor.PathEdit edit)
Edit commands may be added in any order chosen by the application. They are automatically rearranged by the builder to provide the most efficient update possible.
edit
- another edit command.public boolean commit() throws java.io.IOException
If this method fails (returns false) the lock is still released.
This is a utility method for applications as the finish-write-commit pattern is very common after using a builder to update entries.
commit
in class BaseDirCacheEditor
java.io.IOException
- the output file could not be created. The caller no longer
holds the lock.public void finish()
DirCache
.
When this method completes this builder instance is no longer usable by the calling application. A new builder must be created to make additional changes to the index entries.
After completion the DirCache returned by BaseDirCacheEditor.getDirCache()
will
contain all modifications.
Note to implementors: Make sure BaseDirCacheEditor.entries
is fully sorted
then invoke BaseDirCacheEditor.replace()
to update the DirCache with the new table.
finish
in class BaseDirCacheEditor
private void applyEdits()
private int deleteOverlappingSubtree(DirCacheEntry ent, int eIdx)
private int findEntry(byte[] p, int pLen)
private void insertEdit(DirCacheEditor.DeleteTree d)
private static boolean inDir(DirCacheEntry e, byte[] path, int pLen)
private static int pdir(byte[] path, int e)