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 int
entryCount
private DirectoryEntry
entryInParent
The entry linking to this directory in its parent directory.private static int
INITIAL_CAPACITY
private static int
INITIAL_RESIZE_THRESHOLD
private int
resizeThreshold
private DirectoryEntry[]
table
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description private 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, java.lang.String action)
Checks that the given name is not "." or "..".(package private) Directory
copyWithoutContent(int id, java.nio.file.attribute.FileTime creationTime)
Creates a copy of this directory.static Directory
create(int id, java.nio.file.attribute.FileTime creationTime)
Creates a new normal directory with the given ID and creation time.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.(package private) int
entryCount()
Returns the number of entries in this directory.DirectoryEntry
entryInParent()
Returns the entry linking to this directory in its parent.private boolean
expandIfNeeded()
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
get(Name name)
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 "..".java.util.Iterator<DirectoryEntry>
iterator()
void
link(Name name, File file)
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.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
remove(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 "..".void
unlink(Name name)
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
-
-
-
-
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:
copyWithoutContent
in 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: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
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
- ifname
is 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
- ifname
is 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.overwriteExisting
determines 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:
iterator
in interfacejava.lang.Iterable<DirectoryEntry>
-
-