Class Directory

java.lang.Object
com.google.common.jimfs.File
com.google.common.jimfs.Directory
All Implemented Interfaces:
Iterable<DirectoryEntry>

final class Directory extends File implements Iterable<DirectoryEntry>
A table of directory entries.
  • Field Details

    • entryInParent

      private DirectoryEntry 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

      private DirectoryEntry[] table
    • resizeThreshold

      private int resizeThreshold
    • entryCount

      private int entryCount
  • Constructor Details

    • Directory

      private Directory(int id, FileTime creationTime)
    • Directory

      private Directory(int id, FileTime creationTime, Name rootName)
  • Method Details

    • create

      public static Directory create(int id, FileTime creationTime)
      Creates a new normal directory with the given ID and creation time.
    • createRoot

      public static Directory createRoot(int id, FileTime creationTime, Name name)
      Creates a new root directory with the given ID, creation time, and name.
    • copyWithoutContent

      Directory copyWithoutContent(int id, 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 class File
    • 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.
      Overrides:
      linked in class 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.
      Overrides:
      unlinked in class File
    • 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:
      IllegalArgumentException - if name 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:
      IllegalArgumentException - if name 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, 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:
      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:
      IllegalArgumentException - if there is no entry with the given name in the directory
    • iterator

      public Iterator<DirectoryEntry> iterator()
      Specified by:
      iterator in interface Iterable<DirectoryEntry>