diff options
author | clshepherd <clshepherd@google.com> | 2019-10-11 09:32:11 -0700 |
---|---|---|
committer | Kurt Alfred Kluever <kak@google.com> | 2019-10-14 11:20:17 -0400 |
commit | 4fce17b2ff7e96cbd450c8ffc0d3560415779ce3 (patch) | |
tree | d2a0d73be732cfe96fc3e218b03ac9c3f111e2de | |
parent | c2582a6be4d35b1b9a50801e4d803574018294ab (diff) | |
download | jimfs-4fce17b2ff7e96cbd450c8ffc0d3560415779ce3.tar.gz |
Fix 6 ErrorProneStyle findings:
* Constructors and methods with the same name should appear sequentially with no other code in between. Please re-order or re-name methods.
* Use grouping parenthesis to make the operator precedence explicit
-------------
Created by MOE: https://github.com/google/moe
MOE_MIGRATED_REVID=274188261
6 files changed, 143 insertions, 143 deletions
diff --git a/jimfs/src/main/java/com/google/common/jimfs/AttributeService.java b/jimfs/src/main/java/com/google/common/jimfs/AttributeService.java index f3670fb..333a497 100644 --- a/jimfs/src/main/java/com/google/common/jimfs/AttributeService.java +++ b/jimfs/src/main/java/com/google/common/jimfs/AttributeService.java @@ -270,6 +270,15 @@ final class AttributeService { return null; } + private FileAttributeView getFileAttributeView( + FileLookup lookup, + Class<? extends FileAttributeView> viewType, + Map<String, FileAttributeView> inheritedViews) { + AttributeProvider provider = providersByViewType.get(viewType); + createInheritedViews(lookup, provider, inheritedViews); + return provider.view(lookup, ImmutableMap.copyOf(inheritedViews)); + } + private ImmutableMap<String, FileAttributeView> createInheritedViews( FileLookup lookup, AttributeProvider provider) { if (provider.inherits().isEmpty()) { @@ -297,15 +306,6 @@ final class AttributeService { } } - private FileAttributeView getFileAttributeView( - FileLookup lookup, - Class<? extends FileAttributeView> viewType, - Map<String, FileAttributeView> inheritedViews) { - AttributeProvider provider = providersByViewType.get(viewType); - createInheritedViews(lookup, provider, inheritedViews); - return provider.view(lookup, ImmutableMap.copyOf(inheritedViews)); - } - /** Implements {@link Files#readAttributes(Path, String, LinkOption...)}. */ public ImmutableMap<String, Object> readAttributes(File file, String attributes) { String view = getViewName(attributes); @@ -336,18 +336,6 @@ final class AttributeService { return ImmutableMap.copyOf(result); } - private static void readAll(File file, AttributeProvider provider, Map<String, Object> map) { - for (String attribute : provider.attributes(file)) { - Object value = provider.get(file, attribute); - - // check for null to protect against race condition when an attribute present when - // attributes(file) was called is deleted before get() is called for that attribute - if (value != null) { - map.put(attribute, value); - } - } - } - /** * Returns attributes of the given file as an object of the given type. * @@ -363,6 +351,18 @@ final class AttributeService { throw new UnsupportedOperationException("unsupported attributes type: " + type); } + private static void readAll(File file, AttributeProvider provider, Map<String, Object> map) { + for (String attribute : provider.attributes(file)) { + Object value = provider.get(file, attribute); + + // check for null to protect against race condition when an attribute present when + // attributes(file) was called is deleted before get() is called for that attribute + if (value != null) { + map.put(attribute, value); + } + } + } + private static String getViewName(String attribute) { int separatorIndex = attribute.indexOf(':'); diff --git a/jimfs/src/main/java/com/google/common/jimfs/Directory.java b/jimfs/src/main/java/com/google/common/jimfs/Directory.java index d1a1ebe..aaab83b 100644 --- a/jimfs/src/main/java/com/google/common/jimfs/Directory.java +++ b/jimfs/src/main/java/com/google/common/jimfs/Directory.java @@ -200,14 +200,6 @@ final class Directory extends File implements Iterable<DirectoryEntry> { } /** - * Adds the given entry to the directory, overwriting an existing entry with the same name if such - * an entry exists. - */ - private void forcePut(DirectoryEntry entry) { - put(entry, true); - } - - /** * Adds the given entry to the directory. {@code overwriteExisting} determines whether an existing * entry with the same name should be overwritten or an exception should be thrown. */ @@ -258,6 +250,14 @@ final class Directory extends File implements Iterable<DirectoryEntry> { entry.file().incrementLinkCount(); } + /** + * Adds the given entry to the directory, overwriting an existing entry with the same name if such + * an entry exists. + */ + private void forcePut(DirectoryEntry entry) { + put(entry, true); + } + private boolean expandIfNeeded() { if (entryCount <= resizeThreshold) { return false; 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 93df55f..c480942 100644 --- a/jimfs/src/main/java/com/google/common/jimfs/FileTree.java +++ b/jimfs/src/main/java/com/google/common/jimfs/FileTree.java @@ -216,6 +216,6 @@ final class FileTree { 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(); + return names.isEmpty() || (names.size() == 1 && names.get(0).toString().isEmpty()); } } diff --git a/jimfs/src/main/java/com/google/common/jimfs/HeapDisk.java b/jimfs/src/main/java/com/google/common/jimfs/HeapDisk.java index c0bb011..ab06933 100644 --- a/jimfs/src/main/java/com/google/common/jimfs/HeapDisk.java +++ b/jimfs/src/main/java/com/google/common/jimfs/HeapDisk.java @@ -61,11 +61,6 @@ final class HeapDisk { this.blockCache = createBlockCache(maxCachedBlockCount); } - /** Returns the nearest multiple of {@code blockSize} that is <= {@code size}. */ - private static int toBlockCount(long size, int blockSize) { - return (int) LongMath.divide(size, blockSize, RoundingMode.FLOOR); - } - /** * Creates a new disk with the given {@code blockSize}, {@code maxBlockCount} and {@code * maxCachedBlockCount}. @@ -81,6 +76,11 @@ final class HeapDisk { this.blockCache = createBlockCache(maxCachedBlockCount); } + /** Returns the nearest multiple of {@code blockSize} that is <= {@code size}. */ + private static int toBlockCount(long size, int blockSize) { + return (int) LongMath.divide(size, blockSize, RoundingMode.FLOOR); + } + private RegularFile createBlockCache(int maxCachedBlockCount) { return new RegularFile(-1, this, new byte[Math.min(maxCachedBlockCount, 8192)][], 0, 0); } diff --git a/jimfs/src/main/java/com/google/common/jimfs/JimfsFileChannel.java b/jimfs/src/main/java/com/google/common/jimfs/JimfsFileChannel.java index 2ba46fc..95863cc 100644 --- a/jimfs/src/main/java/com/google/common/jimfs/JimfsFileChannel.java +++ b/jimfs/src/main/java/com/google/common/jimfs/JimfsFileChannel.java @@ -211,6 +211,38 @@ final class JimfsFileChannel extends FileChannel { } @Override + public int read(ByteBuffer dst, long position) throws IOException { + checkNotNull(dst); + Util.checkNotNegative(position, "position"); + checkOpen(); + checkReadable(); + + int read = 0; // will definitely either be assigned or an exception will be thrown + + // no need to synchronize here; this method does not make use of the channel's position + boolean completed = false; + try { + if (!beginBlocking()) { + return 0; // AsynchronousCloseException will be thrown + } + file.readLock().lockInterruptibly(); + try { + read = file.read(position, dst); + file.updateAccessTime(); + completed = true; + } finally { + file.readLock().unlock(); + } + } catch (InterruptedException e) { + Thread.currentThread().interrupt(); + } finally { + endBlocking(completed); + } + + return read; + } + + @Override public int write(ByteBuffer src) throws IOException { checkNotNull(src); checkOpen(); @@ -285,6 +317,65 @@ final class JimfsFileChannel extends FileChannel { } @Override + public int write(ByteBuffer src, long position) throws IOException { + checkNotNull(src); + Util.checkNotNegative(position, "position"); + checkOpen(); + checkWritable(); + + int written = 0; // will definitely either be assigned or an exception will be thrown + + if (append) { + // synchronize because appending does update the channel's position + synchronized (this) { + boolean completed = false; + try { + if (!beginBlocking()) { + return 0; // AsynchronousCloseException will be thrown + } + + file.writeLock().lockInterruptibly(); + try { + position = file.sizeWithoutLocking(); + written = file.write(position, src); + this.position = position + written; + file.updateModifiedTime(); + completed = true; + } finally { + file.writeLock().unlock(); + } + } catch (InterruptedException e) { + Thread.currentThread().interrupt(); + } finally { + endBlocking(completed); + } + } + } else { + // don't synchronize because the channel's position is not involved + boolean completed = false; + try { + if (!beginBlocking()) { + return 0; // AsynchronousCloseException will be thrown + } + file.writeLock().lockInterruptibly(); + try { + written = file.write(position, src); + file.updateModifiedTime(); + completed = true; + } finally { + file.writeLock().unlock(); + } + } catch (InterruptedException e) { + Thread.currentThread().interrupt(); + } finally { + endBlocking(completed); + } + } + + return written; + } + + @Override public long position() throws IOException { checkOpen(); @@ -498,97 +589,6 @@ final class JimfsFileChannel extends FileChannel { } @Override - public int read(ByteBuffer dst, long position) throws IOException { - checkNotNull(dst); - Util.checkNotNegative(position, "position"); - checkOpen(); - checkReadable(); - - int read = 0; // will definitely either be assigned or an exception will be thrown - - // no need to synchronize here; this method does not make use of the channel's position - boolean completed = false; - try { - if (!beginBlocking()) { - return 0; // AsynchronousCloseException will be thrown - } - file.readLock().lockInterruptibly(); - try { - read = file.read(position, dst); - file.updateAccessTime(); - completed = true; - } finally { - file.readLock().unlock(); - } - } catch (InterruptedException e) { - Thread.currentThread().interrupt(); - } finally { - endBlocking(completed); - } - - return read; - } - - @Override - public int write(ByteBuffer src, long position) throws IOException { - checkNotNull(src); - Util.checkNotNegative(position, "position"); - checkOpen(); - checkWritable(); - - int written = 0; // will definitely either be assigned or an exception will be thrown - - if (append) { - // synchronize because appending does update the channel's position - synchronized (this) { - boolean completed = false; - try { - if (!beginBlocking()) { - return 0; // AsynchronousCloseException will be thrown - } - - file.writeLock().lockInterruptibly(); - try { - position = file.sizeWithoutLocking(); - written = file.write(position, src); - this.position = position + written; - file.updateModifiedTime(); - completed = true; - } finally { - file.writeLock().unlock(); - } - } catch (InterruptedException e) { - Thread.currentThread().interrupt(); - } finally { - endBlocking(completed); - } - } - } else { - // don't synchronize because the channel's position is not involved - boolean completed = false; - try { - if (!beginBlocking()) { - return 0; // AsynchronousCloseException will be thrown - } - file.writeLock().lockInterruptibly(); - try { - written = file.write(position, src); - file.updateModifiedTime(); - completed = true; - } finally { - file.writeLock().unlock(); - } - } catch (InterruptedException e) { - Thread.currentThread().interrupt(); - } finally { - endBlocking(completed); - } - } - - return written; - } - - @Override public MappedByteBuffer map(MapMode mode, long position, long size) throws IOException { // would like this to pretend to work, but can't create an implementation of MappedByteBuffer // well, a direct buffer could be cast to MappedByteBuffer, but it couldn't work in general diff --git a/jimfs/src/main/java/com/google/common/jimfs/JimfsFileSystemProvider.java b/jimfs/src/main/java/com/google/common/jimfs/JimfsFileSystemProvider.java index 9b32bd7..8d487dd 100644 --- a/jimfs/src/main/java/com/google/common/jimfs/JimfsFileSystemProvider.java +++ b/jimfs/src/main/java/com/google/common/jimfs/JimfsFileSystemProvider.java @@ -89,13 +89,6 @@ final class JimfsFileSystemProvider extends FileSystemProvider { } @Override - public FileSystem getFileSystem(URI uri) { - throw new UnsupportedOperationException( - "This method should not be called directly; " - + "use FileSystems.getFileSystem(URI) instead."); - } - - @Override public FileSystem newFileSystem(Path path, Map<String, ?> env) throws IOException { JimfsPath checkedPath = checkPath(path); checkNotNull(env); @@ -114,6 +107,18 @@ final class JimfsFileSystemProvider extends FileSystemProvider { } @Override + public FileSystem getFileSystem(URI uri) { + throw new UnsupportedOperationException( + "This method should not be called directly; " + + "use FileSystems.getFileSystem(URI) instead."); + } + + /** Gets the file system for the given path. */ + private static JimfsFileSystem getFileSystem(Path path) { + return (JimfsFileSystem) checkPath(path).getFileSystem(); + } + + @Override public Path getPath(URI uri) { throw new UnsupportedOperationException( "This method should not be called directly; " + "use Paths.get(URI) instead."); @@ -127,11 +132,6 @@ final class JimfsFileSystemProvider extends FileSystemProvider { "path " + path + " is not associated with a Jimfs file system"); } - /** Gets the file system for the given path. */ - private static JimfsFileSystem getFileSystem(Path path) { - return (JimfsFileSystem) checkPath(path).getFileSystem(); - } - /** Returns the default file system view for the given path. */ private static FileSystemView getDefaultView(JimfsPath path) { return getFileSystem(path).getDefaultView(); @@ -258,11 +258,6 @@ final class JimfsFileSystemProvider extends FileSystemProvider { copy(source, target, Options.getCopyOptions(options), false); } - @Override - public void move(Path source, Path target, CopyOption... options) throws IOException { - copy(source, target, Options.getMoveOptions(options), true); - } - private void copy(Path source, Path target, ImmutableSet<CopyOption> options, boolean move) throws IOException { JimfsPath sourcePath = checkPath(source); @@ -274,6 +269,11 @@ final class JimfsFileSystemProvider extends FileSystemProvider { } @Override + public void move(Path source, Path target, CopyOption... options) throws IOException { + copy(source, target, Options.getMoveOptions(options), true); + } + + @Override public boolean isSameFile(Path path, Path path2) throws IOException { if (path.equals(path2)) { return true; |