Package com.google.common.jimfs
Class Directory
java.lang.Object
com.google.common.jimfs.File
com.google.common.jimfs.Directory
- All Implemented Interfaces:
Iterable<DirectoryEntry>
A table of directory entries.
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate int
private DirectoryEntry
The entry linking to this directory in its parent directory.private static final int
private static final int
private int
private DirectoryEntry[]
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprivate static void
addToBucket
(int bucketIndex, DirectoryEntry[] table, DirectoryEntry entryToAdd) private static int
bucketIndex
(Name name, int tableLength) Returns the index of the bucket in the array where an entry for the given name should go.private static Name
checkNotReserved
(Name name, String action) Checks that the given name is not "." or "..".(package private) Directory
copyWithoutContent
(int id, FileTime creationTime) Creates a copy of this directory.static Directory
Creates a new normal directory with the given ID and creation time.static Directory
createRoot
(int id, FileTime creationTime, Name name) Creates a new root directory with the given ID, creation time, and name.(package private) int
Returns the number of entries in this directory.Returns the entry linking to this directory in its parent.private boolean
private void
forcePut
(DirectoryEntry entry) Adds the given entry to the directory, overwriting an existing entry with the same name if such an entry exists.@Nullable DirectoryEntry
Returns the entry for the given name in this table or null if no such entry exists.boolean
isEmpty()
Returns true if this directory has no entries other than those to itself and its parent.private static boolean
isReserved
(Name name) Returns true if the given name is "." or "..".iterator()
void
Links the given name to the given file in this directory.(package private) void
linked
(DirectoryEntry entry) Called when this file has been linked in a directory.parent()
Returns the parent of this directory.(package private) void
put
(DirectoryEntry entry) Adds the given entry to the directory.private void
put
(DirectoryEntry entry, boolean overwriteExisting) Adds the given entry to the directory.(package private) DirectoryEntry
Removes and returns the entry for the given name from the directory.com.google.common.collect.ImmutableSortedSet
<Name> snapshot()
Creates an immutable sorted snapshot of the names this directory contains, excluding "." and "..".void
Unlinks the given name from the file it is linked to.(package private) void
unlinked()
Called when this file has been unlinked from a directory, either for a move or delete.Methods inherited from class com.google.common.jimfs.File
closed, contentLock, copyAttributes, copyBasicAttributes, copyContentTo, decrementLinkCount, deleteAttribute, deleted, getAttribute, getAttributeKeys, getAttributeNames, getCreationTime, getLastAccessTime, getLastModifiedTime, id, incrementLinkCount, isDirectory, isRegularFile, isRootDirectory, isSymbolicLink, links, opened, setAttribute, setCreationTime, setLastAccessTime, setLastModifiedTime, size, toString
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
Methods inherited from interface java.lang.Iterable
forEach, spliterator
-
Field Details
-
entryInParent
The entry linking to this directory in its parent directory. -
INITIAL_CAPACITY
private static final int INITIAL_CAPACITY- See Also:
-
INITIAL_RESIZE_THRESHOLD
private static final int INITIAL_RESIZE_THRESHOLD- See Also:
-
table
-
resizeThreshold
private int resizeThreshold -
entryCount
private int entryCount
-
-
Constructor Details
-
Directory
-
Directory
-
-
Method Details
-
create
Creates a new normal directory with the given ID and creation time. -
createRoot
Creates a new root directory with the given ID, creation time, and name. -
copyWithoutContent
Creates a copy of this directory. The copy does not contain a copy of the entries in this directory.- Specified by:
copyWithoutContent
in classFile
-
entryInParent
Returns the entry linking to this directory in its parent. If this directory has been deleted, this returns the entry for it in the directory it was in when it was deleted. -
parent
Returns the parent of this directory. If this directory has been deleted, this returns the directory it was in when it was deleted. -
linked
Description copied from class:File
Called when this file has been linked in a directory. The given entry is the new directory entry that links to this file. -
unlinked
void unlinked()Description copied from class:File
Called when this file has been unlinked from a directory, either for a move or delete. -
entryCount
int entryCount()Returns the number of entries in this directory. -
isEmpty
public boolean isEmpty()Returns true if this directory has no entries other than those to itself and its parent. -
get
Returns the entry for the given name in this table or null if no such entry exists. -
link
Links the given name to the given file in this directory.- Throws:
IllegalArgumentException
- ifname
is a reserved name such as "." or if an entry already exists for the name
-
unlink
Unlinks the given name from the file it is linked to.- Throws:
IllegalArgumentException
- ifname
is a reserved name such as "." or no entry exists for the name
-
snapshot
Creates an immutable sorted snapshot of the names this directory contains, excluding "." and "..". -
checkNotReserved
Checks that the given name is not "." or "..". Those names cannot be set/removed by users. -
isReserved
Returns true if the given name is "." or "..". -
bucketIndex
Returns the index of the bucket in the array where an entry for the given name should go. -
put
Adds the given entry to the directory.- Throws:
IllegalArgumentException
- if an entry with the given entry's name already exists in the directory
-
put
Adds the given entry to the directory.overwriteExisting
determines whether an existing entry with the same name should be overwritten or an exception should be thrown. -
forcePut
Adds the given entry to the directory, overwriting an existing entry with the same name if such an entry exists. -
expandIfNeeded
private boolean expandIfNeeded() -
addToBucket
-
remove
Removes and returns the entry for the given name from the directory.- Throws:
IllegalArgumentException
- if there is no entry with the given name in the directory
-
iterator
- Specified by:
iterator
in interfaceIterable<DirectoryEntry>
-