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 intprivate DirectoryEntryThe entry linking to this directory in its parent directory.private static final intprivate static final intprivate intprivate DirectoryEntry[] -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprivate static voidaddToBucket(int bucketIndex, DirectoryEntry[] table, DirectoryEntry entryToAdd) private static intbucketIndex(Name name, int tableLength) Returns the index of the bucket in the array where an entry for the given name should go.private static NamecheckNotReserved(Name name, String action) Checks that the given name is not "." or "..".(package private) DirectorycopyWithoutContent(int id, FileTime creationTime) Creates a copy of this directory.static DirectoryCreates a new normal directory with the given ID and creation time.static DirectorycreateRoot(int id, FileTime creationTime, Name name) Creates a new root directory with the given ID, creation time, and name.(package private) intReturns the number of entries in this directory.Returns the entry linking to this directory in its parent.private booleanprivate voidforcePut(DirectoryEntry entry) Adds the given entry to the directory, overwriting an existing entry with the same name if such an entry exists.@Nullable DirectoryEntryReturns the entry for the given name in this table or null if no such entry exists.booleanisEmpty()Returns true if this directory has no entries other than those to itself and its parent.private static booleanisReserved(Name name) Returns true if the given name is "." or "..".iterator()voidLinks the given name to the given file in this directory.(package private) voidlinked(DirectoryEntry entry) Called when this file has been linked in a directory.parent()Returns the parent of this directory.(package private) voidput(DirectoryEntry entry) Adds the given entry to the directory.private voidput(DirectoryEntry entry, boolean overwriteExisting) Adds the given entry to the directory.(package private) DirectoryEntryRemoves 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 "..".voidUnlinks the given name from the file it is linked to.(package private) voidunlinked()Called when this file has been unlinked from a directory, either for a move or delete.Methods inherited from class 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, toStringMethods inherited from class Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, waitMethods inherited from interface 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
-
createRoot
-
copyWithoutContent
Creates a copy of this directory. The copy does not contain a copy of the entries in this directory.- Specified by:
copyWithoutContentin 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:FileCalled when this file has been linked in a directory. The given entry is the new directory entry that links to this file. -
unlinked
-
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- ifnameis 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- ifnameis 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
-
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.overwriteExistingdetermines 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:
iteratorin interfaceIterable<DirectoryEntry>
-