diff options
author | cgdecker <cgdecker@google.com> | 2014-08-14 11:23:16 -0700 |
---|---|---|
committer | Colin Decker <cgdecker@google.com> | 2014-11-05 17:10:16 -0500 |
commit | 3f475ca637ae6d738bd2e062cd6ca712cae0500e (patch) | |
tree | eab81618ec48f4870440f80829c42b088cfbfe9e /jimfs/src | |
parent | c68a68bbce47d3734af6df80d4e6d892025c6edc (diff) | |
download | jimfs-3f475ca637ae6d738bd2e062cd6ca712cae0500e.tar.gz |
Misc changes to FileTree.
-------------
Created by MOE: http://code.google.com/p/moe-java
MOE_MIGRATED_REVID=73318805
Diffstat (limited to 'jimfs/src')
3 files changed, 15 insertions, 13 deletions
diff --git a/jimfs/src/main/java/com/google/common/jimfs/FileTree.java b/jimfs/src/main/java/com/google/common/jimfs/FileTree.java index d6d6603..bbd6b96 100644 --- a/jimfs/src/main/java/com/google/common/jimfs/FileTree.java +++ b/jimfs/src/main/java/com/google/common/jimfs/FileTree.java @@ -51,12 +51,12 @@ final class FileTree { /** * Map of root names to root directories. */ - private final ImmutableSortedMap<Name, File> roots; + private final ImmutableSortedMap<Name, Directory> roots; /** * Creates a new file tree with the given root directories. */ - FileTree(Map<Name, File> roots) { + FileTree(Map<Name, Directory> roots) { this.roots = ImmutableSortedMap.copyOf(roots, Name.canonicalOrdering()); } @@ -73,8 +73,8 @@ final class FileTree { */ @Nullable public DirectoryEntry getRoot(Name name) { - File file = roots.get(name); - return file == null ? null : ((Directory) file).entryInParent(); + Directory dir = roots.get(name); + return dir == null ? null : dir.entryInParent(); } /** @@ -120,11 +120,6 @@ final class FileTree { return lookUp(dir, names, options, linkDepth); } - private static boolean isEmpty(ImmutableList<Name> names) { - // the empty path (created by FileSystem.getPath("")), has no root and a single name, "" - return names.isEmpty() || names.size() == 1 && names.get(0).toString().isEmpty(); - } - /** * Looks up the given names against the given base file. If the file is not a directory, the * lookup fails. @@ -216,7 +211,9 @@ final class FileTree { Name name = entry.name(); if (name.equals(Name.SELF) || name.equals(Name.PARENT)) { - return ((Directory) entry.file()).entryInParent(); + Directory dir = toDirectory(entry.file()); + assert dir != null; + return dir.entryInParent(); } else { return entry; } @@ -226,4 +223,9 @@ final class FileTree { private Directory toDirectory(@Nullable File file) { return file == null || !file.isDirectory() ? null : (Directory) file; } + + private static boolean isEmpty(ImmutableList<Name> names) { + // the empty path (created by FileSystem.getPath("")), has no root and a single name, "" + return names.isEmpty() || names.size() == 1 && names.get(0).toString().isEmpty(); + } } diff --git a/jimfs/src/main/java/com/google/common/jimfs/JimfsFileSystems.java b/jimfs/src/main/java/com/google/common/jimfs/JimfsFileSystems.java index deb6863..7622889 100644 --- a/jimfs/src/main/java/com/google/common/jimfs/JimfsFileSystems.java +++ b/jimfs/src/main/java/com/google/common/jimfs/JimfsFileSystems.java @@ -61,7 +61,7 @@ final class JimfsFileSystems { HeapDisk disk = new HeapDisk(config); FileFactory fileFactory = new FileFactory(disk); - Map<Name, File> roots = new HashMap<>(); + Map<Name, Directory> roots = new HashMap<>(); // create roots for (String root : config.roots) { @@ -72,7 +72,7 @@ final class JimfsFileSystems { Name rootName = path.root(); - File rootDir = fileFactory.createRootDirectory(rootName); + Directory rootDir = fileFactory.createRootDirectory(rootName); attributeService.setInitialAttributes(rootDir); roots.put(rootName, rootDir); } diff --git a/jimfs/src/test/java/com/google/common/jimfs/FileTreeTest.java b/jimfs/src/test/java/com/google/common/jimfs/FileTreeTest.java index efb427a..2e64042 100644 --- a/jimfs/src/test/java/com/google/common/jimfs/FileTreeTest.java +++ b/jimfs/src/test/java/com/google/common/jimfs/FileTreeTest.java @@ -120,7 +120,7 @@ public class FileTreeTest { Directory otherRoot = Directory.createRoot(2, Name.simple("$")); files.put("$", otherRoot); - Map<Name, File> roots = new HashMap<>(); + Map<Name, Directory> roots = new HashMap<>(); roots.put(Name.simple("/"), root); roots.put(Name.simple("$"), otherRoot); |