Package com.google.common.jimfs
Class Directory
- java.lang.Object
-
- com.google.common.jimfs.File
-
- com.google.common.jimfs.Directory
-
- All Implemented Interfaces:
java.lang.Iterable<DirectoryEntry>
final class Directory extends File implements java.lang.Iterable<DirectoryEntry>
A table of directory entries.
-
-
Field Summary
Fields Modifier and Type Field Description private intentryCountprivate DirectoryEntryentryInParentThe entry linking to this directory in its parent directory.private static intINITIAL_CAPACITYprivate static intINITIAL_RESIZE_THRESHOLDprivate intresizeThresholdprivate DirectoryEntry[]table
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description private 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, java.lang.String action)Checks that the given name is not "." or "..".(package private) DirectorycopyWithoutContent(int id, java.nio.file.attribute.FileTime creationTime)Creates a copy of this directory.static Directorycreate(int id, java.nio.file.attribute.FileTime creationTime)Creates a new normal directory with the given ID and creation time.static DirectorycreateRoot(int id, java.nio.file.attribute.FileTime creationTime, Name name)Creates a new root directory with the given ID, creation time, and name.(package private) intentryCount()Returns the number of entries in this directory.DirectoryEntryentryInParent()Returns the entry linking to this directory in its parent.private booleanexpandIfNeeded()private voidforcePut(DirectoryEntry entry)Adds the given entry to the directory, overwriting an existing entry with the same name if such an entry exists.@Nullable DirectoryEntryget(Name name)Returns 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 "..".java.util.Iterator<DirectoryEntry>iterator()voidlink(Name name, File file)Links 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.Directoryparent()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) DirectoryEntryremove(Name name)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 "..".voidunlink(Name name)Unlinks 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 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
-
-
-
-
Field Detail
-
entryInParent
private DirectoryEntry entryInParent
The entry linking to this directory in its parent directory.
-
INITIAL_CAPACITY
private static final int INITIAL_CAPACITY
- See Also:
- Constant Field Values
-
INITIAL_RESIZE_THRESHOLD
private static final int INITIAL_RESIZE_THRESHOLD
- See Also:
- Constant Field Values
-
table
private DirectoryEntry[] table
-
resizeThreshold
private int resizeThreshold
-
entryCount
private int entryCount
-
-
Constructor Detail
-
Directory
private Directory(int id, java.nio.file.attribute.FileTime creationTime)
-
Directory
private Directory(int id, java.nio.file.attribute.FileTime creationTime, Name rootName)
-
-
Method Detail
-
create
public static Directory create(int id, java.nio.file.attribute.FileTime creationTime)
Creates a new normal directory with the given ID and creation time.
-
createRoot
public static Directory createRoot(int id, java.nio.file.attribute.FileTime creationTime, Name name)
Creates a new root directory with the given ID, creation time, and name.
-
copyWithoutContent
Directory copyWithoutContent(int id, java.nio.file.attribute.FileTime creationTime)
Creates a copy of this directory. The copy does not contain a copy of the entries in this directory.- Specified by:
copyWithoutContentin classFile
-
entryInParent
public DirectoryEntry 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
public Directory 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
void linked(DirectoryEntry entry)
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
void unlinked()
Description copied from class:FileCalled 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
public @Nullable DirectoryEntry get(Name name)
Returns the entry for the given name in this table or null if no such entry exists.
-
link
public void link(Name name, File file)
Links the given name to the given file in this directory.- Throws:
java.lang.IllegalArgumentException- ifnameis a reserved name such as "." or if an entry already exists for the name
-
unlink
public void unlink(Name name)
Unlinks the given name from the file it is linked to.- Throws:
java.lang.IllegalArgumentException- ifnameis a reserved name such as "." or no entry exists for the name
-
snapshot
public com.google.common.collect.ImmutableSortedSet<Name> snapshot()
Creates an immutable sorted snapshot of the names this directory contains, excluding "." and "..".
-
checkNotReserved
private static Name checkNotReserved(Name name, java.lang.String action)
Checks that the given name is not "." or "..". Those names cannot be set/removed by users.
-
isReserved
private static boolean isReserved(Name name)
Returns true if the given name is "." or "..".
-
bucketIndex
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.
-
put
void put(DirectoryEntry entry)
Adds the given entry to the directory.- Throws:
java.lang.IllegalArgumentException- if an entry with the given entry's name already exists in the directory
-
put
private void put(DirectoryEntry entry, boolean overwriteExisting)
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
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.
-
expandIfNeeded
private boolean expandIfNeeded()
-
addToBucket
private static void addToBucket(int bucketIndex, DirectoryEntry[] table, DirectoryEntry entryToAdd)
-
remove
@CanIgnoreReturnValue DirectoryEntry remove(Name name)
Removes and returns the entry for the given name from the directory.- Throws:
java.lang.IllegalArgumentException- if there is no entry with the given name in the directory
-
iterator
public java.util.Iterator<DirectoryEntry> iterator()
- Specified by:
iteratorin interfacejava.lang.Iterable<DirectoryEntry>
-
-