Skip to content

Commit

Permalink
follow ide advices
Browse files Browse the repository at this point in the history
  • Loading branch information
umjammer committed Feb 27, 2024
1 parent c0deeb0 commit 78b7443
Show file tree
Hide file tree
Showing 79 changed files with 443 additions and 555 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ public boolean isDirectory() {
*/
@Override
public long size() {
return FileInfo.class.isInstance(entry) ? FileInfo.class.cast(entry).getContentProperties().getSize() : 0;
return entry instanceof FileInfo ? ((FileInfo) entry).getContentProperties().getSize() : 0;
}

/* @see java.nio.file.attribute.PosixFileAttributes#owner() */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
* A simple Amazon Cloud Drive {@link FileStore}
*
* <p>
* This makes use of information available in {@link StorageQuota}.
* This makes use of information available in {@link AccountQuota}.
* Information is computed in "real time".
* </p>
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ protected InputStream downloadEntryImpl(NodeInfo entry, Path path, Set<? extends
protected OutputStream uploadEntry(NodeInfo parentEntry, Path path, Set<? extends OpenOption> options) throws IOException {
File temp = File.createTempFile("vavi-apps-fuse-", ".upload");

return new AcdOutputStream(drive, temp, toFilenameString(path), FolderInfo.class.cast(parentEntry), file -> {
return new AcdOutputStream(drive, temp, toFilenameString(path), (FolderInfo) parentEntry, file -> {
System.out.println("file: " + file.getName() + ", " + file.getCreationDate() + ", " + file.getContentProperties().getSize());
updateEntry(path, file);
});
Expand All @@ -102,7 +102,7 @@ protected NodeInfo createDirectoryEntry(NodeInfo parentEntry, Path dir) throws I

@Override
protected boolean hasChildren(NodeInfo dirEntry, Path dir) throws IOException {
return drive.getList(dirEntry.getId()).size() > 0;
return !drive.getList(dirEntry.getId()).isEmpty();
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ public FileSystemDriver createDriver(final URI uri, final Map<String, ?> env) th
UserCredential userCredential = null;

if (env.containsKey(AcdFileSystemProvider.ENV_USER_CREDENTIAL)) {
userCredential = UserCredential.class.cast(env.get(AcdFileSystemProvider.ENV_USER_CREDENTIAL));
userCredential = (UserCredential) env.get(AcdFileSystemProvider.ENV_USER_CREDENTIAL);
}

Map<String, String> params = getParamsMap(uri);
Expand All @@ -65,7 +65,7 @@ public FileSystemDriver createDriver(final URI uri, final Map<String, ?> env) th
OAuth2AppCredential appCredential = null;

if (env.containsKey(AcdFileSystemProvider.ENV_APP_CREDENTIAL)) {
appCredential = OAuth2AppCredential.class.cast(env.get(AcdFileSystemProvider.ENV_APP_CREDENTIAL));
appCredential = (OAuth2AppCredential) env.get(AcdFileSystemProvider.ENV_APP_CREDENTIAL);
}

if (appCredential == null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
* throw an exception; which means it may throw none, or it may throw an
* <em>unchecked</em> exception. As such, the {@link #close()} method of this
* class captures all {@link RuntimeException}s which {@link
* java.io.File#close()} may throw and wrap it into a {@link
* java.io.OutputStream#close()} may throw and wrap it into a {@link
* IOException}. If the underlying output stream <em>did</em> throw an
* exception, however, then such an exception is {@link
* Throwable#addSuppressed(Throwable) suppressed}.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
public final class ArchiveBasicFileAttributesProvider extends BasicFileAttributesProvider implements PosixFileAttributes {

/** null means root */
private Entry entry;
private final Entry entry;

public ArchiveBasicFileAttributesProvider(final Entry entry) throws IOException {
this.entry = entry;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
* A simple archive {@link FileStore}
*
* <p>
* This makes use of information available in {@link StorageQuota}.
* This makes use of information available in {@link vavi.util.archive.Archive}.
* Information is computed in "real time".
* </p>
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
import java.nio.file.CopyOption;
import java.nio.file.DirectoryStream;
import java.nio.file.FileStore;
import java.nio.file.Files;
import java.nio.file.NoSuchFileException;
import java.nio.file.OpenOption;
import java.nio.file.Path;
Expand Down Expand Up @@ -66,7 +65,7 @@ static String toArchiveString(Path path) {
}

/** for the case archive#entries() does not return dirs */
private Map<Path, Set<Path>> directories = new HashMap<>();
private final Map<Path, Set<Path>> directories = new HashMap<>();

/** */
private Entry getEntry(Path path) throws FileNotFoundException{
Expand Down Expand Up @@ -170,7 +169,7 @@ private List<Path> getDirectoryEntries(final Path dir) throws IOException {
if (entry.getName().startsWith(dirString)) {
String entryName = entry.getName().substring(dirString.length());
String[] names = entryName.split("/");
if (names[0].length() > 0) { // exclude self?
if (!names[0].isEmpty()) { // exclude self?
Path childPath = dir.resolve(names[0]);
if (!list.contains(childPath))
list.add(childPath);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
* A simple Flickr {@link FileStore}
*
* <p>
* This makes use of information available in {@link StorageQuota}.
* This makes use of information available in {@link User}.
* Information is computed in "real time".
* </p>
*/
Expand All @@ -33,9 +33,9 @@ public final class FlickrFileStore extends FileStoreBase {
*
* @param flickr the (valid) Flickr flickr to use
*/
public FlickrFileStore(final Flickr drive, final FileAttributesFactory factory) {
public FlickrFileStore(final Flickr flickr, final FileAttributesFactory factory) {
super("flickr", factory, false);
this.flickr = drive;
this.flickr = flickr;
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ public FileSystemDriver createDriver(final URI uri, final Map<String, ?> env) th
UserCredential userCredential = null;

if (env.containsKey(FlickrFileSystemProvider.ENV_USER_CREDENTIAL)) {
userCredential = UserCredential.class.cast(env.get(FlickrFileSystemProvider.ENV_USER_CREDENTIAL));
userCredential = (UserCredential) env.get(FlickrFileSystemProvider.ENV_USER_CREDENTIAL);
}

Map<String, String> params = getParamsMap(uri);
Expand All @@ -63,7 +63,7 @@ public FileSystemDriver createDriver(final URI uri, final Map<String, ?> env) th
OAuth2AppCredential appCredential = null;

if (env.containsKey(FlickrFileSystemProvider.ENV_APP_CREDENTIAL)) {
appCredential = OAuth2AppCredential.class.cast(env.get(FlickrFileSystemProvider.ENV_APP_CREDENTIAL));
appCredential = (OAuth2AppCredential) env.get(FlickrFileSystemProvider.ENV_APP_CREDENTIAL);
}

if (appCredential == null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
import com.flickr4java.flickr.Flickr;
import com.flickr4java.flickr.FlickrException;
import com.flickr4java.flickr.photos.Photo;
import com.github.fge.filesystem.driver.FileSystemDriver;


/**
Expand All @@ -39,12 +38,12 @@
* <em>unchecked</em> exception. As such, the {@link #close()} method of this
* class captures all {@link RuntimeException}s which {@link
* #close()} may throw and wrap it into a {@link
* FlickrIOException}. If the underlying input stream <em>did</em> throw an
* IOException}. If the underlying input stream <em>did</em> throw an
* exception, however, then such an exception is {@link
* Throwable#addSuppressed(Throwable) suppressed}.
* </p>
*
* @see FileSystemDriver#newInputStream(Path, OpenOption...)
* @see java.nio.file.Files#newInputStream(Path, OpenOption...)
*/
@ParametersAreNonnullByDefault
public final class FlickrInputStream extends InputStream {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,8 @@
* throw an exception; which means it may throw none, or it may throw an
* <em>unchecked</em> exception. As such, the {@link #close()} method of this
* class captures all {@link RuntimeException}s which {@link
* java.io.File#close()} may throw and wrap it into a {@link
* FlickrIOException}. If the underlying output stream <em>did</em> throw an
* java.io.OutputStream#close()} may throw and wrap it into a {@link
* IOException}. If the underlying output stream <em>did</em> throw an
* exception, however, then such an exception is {@link
* Throwable#addSuppressed(Throwable) suppressed}.
* </p>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
*/
public final class GatheredBasicFileAttributesProvider extends BasicFileAttributesProvider implements PosixFileAttributes {

private Object entry;
private final Object entry;

public GatheredBasicFileAttributesProvider(@Nonnull final Object entry) throws IOException {
this.entry = entry;
Expand All @@ -52,16 +52,14 @@ public GatheredBasicFileAttributesProvider(@Nonnull final Object entry) throws I
@Override
public FileTime lastModifiedTime() {
try {
if (FileSystem.class.isInstance(entry)) {
FileSystem fs = FileSystem.class.cast(entry);
if (GatheredFileSystemProvider.class.isInstance(fs.provider())) {
if (entry instanceof FileSystem fs) {
if (fs.provider() instanceof GatheredFileSystemProvider) {
return FileTime.fromMillis(System.currentTimeMillis());
} else {
return Files.getLastModifiedTime(fs.getRootDirectories().iterator().next());
}
} else if (Path.class.isInstance(entry)) {
Path path = Path.class.cast(entry);
//System.err.println("@@@: " + entry + ", " + path.getFileSystem().provider());
} else if (entry instanceof Path path) {
//System.err.println("@@@: " + entry + ", " + path.getFileSystem().provider());
return Files.getLastModifiedTime(path);
} else {
throw new IllegalStateException("unsupported type: " + entry.getClass().getName());
Expand All @@ -82,10 +80,9 @@ public FileTime lastModifiedTime() {
*/
@Override
public boolean isRegularFile() {
if (FileSystem.class.isInstance(entry)) {
if (entry instanceof FileSystem) {
return false;
} else if (Path.class.isInstance(entry)) {
Path path = Path.class.cast(entry);
} else if (entry instanceof Path path) {
return Files.isRegularFile(path);
} else {
throw new IllegalStateException("unsupported type: " + entry.getClass().getName());
Expand All @@ -97,10 +94,9 @@ public boolean isRegularFile() {
*/
@Override
public boolean isDirectory() {
if (FileSystem.class.isInstance(entry)) {
if (entry instanceof FileSystem) {
return true;
} else if (Path.class.isInstance(entry)) {
Path path = Path.class.cast(entry);
} else if (entry instanceof Path path) {
return Files.isDirectory(path);
} else {
throw new IllegalStateException("unsupported type: " + entry.getClass().getName());
Expand All @@ -119,10 +115,10 @@ public boolean isDirectory() {
@Override
public long size() {
try {
if (FileSystem.class.isInstance(entry)) {
return FileSystem.class.cast(entry).getFileStores().iterator().next().getTotalSpace();
} else if (Path.class.isInstance(entry)) {
return Files.size(Path.class.cast(entry));
if (entry instanceof FileSystem) {
return ((FileSystem) entry).getFileStores().iterator().next().getTotalSpace();
} else if (entry instanceof Path) {
return Files.size((Path) entry);
} else {
throw new IllegalStateException("unsupported type: " + entry.getClass().getName());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,7 @@


/**
* A simple Commons VFS2 {@link FileStore}
*
* <p>
* This makes use of information available in {@link StorageQuota}.
* Information is computed in "real time".
* </p>
* A simple Commons VFS2 {@link FileStore}.
*/
public final class GatheredFileStore extends FileStoreBase {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ public GatheredFileSystemDriver(final FileStore fileStore,
super(fileStore, provider);
this.fileSystems = fileSystems;
if (env.containsKey(GatheredFileSystemProvider.ENV_NAME_MAP)) {
this.nameMap = NameMap.class.cast(env.get(GatheredFileSystemProvider.ENV_NAME_MAP));
this.nameMap = (NameMap) env.get(GatheredFileSystemProvider.ENV_NAME_MAP);
}
}

Expand All @@ -70,7 +70,7 @@ public InputStream newInputStream(final Path path, final Set<? extends OpenOptio
throw new IsDirectoryException("path: " + path);
}

return Files.newInputStream(Path.class.cast(entry));
return Files.newInputStream((Path) entry);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,11 +40,12 @@ public GatheredFileSystemRepository() {
*/
@Nonnull
@Override
@SuppressWarnings("unchecked")
public FileSystemDriver createDriver(final URI uri, final Map<String, ?> env) throws IOException {
if (!env.containsKey(GatheredFileSystemProvider.ENV_FILESYSTEMS)) {
throw new NoSuchElementException(GatheredFileSystemProvider.ENV_FILESYSTEMS);
}
Map<String, FileSystem> fileSystems = Map.class.cast(env.get(GatheredFileSystemProvider.ENV_FILESYSTEMS));
Map<String, FileSystem> fileSystems = (Map<String, FileSystem>) env.get(GatheredFileSystemProvider.ENV_FILESYSTEMS);

GatheredFileStore fileStore = new GatheredFileStore(factoryProvider.getAttributesFactory());
return new GatheredFileSystemDriver(fileStore, factoryProvider, fileSystems, env);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import java.io.IOException;
import java.net.URLDecoder;
import java.net.URLEncoder;
import java.nio.charset.StandardCharsets;
import java.util.Map;

import com.google.common.collect.BiMap;
Expand All @@ -23,14 +24,14 @@
*/
public class NameMap {

private BiMap<String, String> nameMap = HashBiMap.create();
private final BiMap<String, String> nameMap = HashBiMap.create();

/** id -> display name */
public String encodeFsName(String id) throws IOException {
if (!nameMap.isEmpty()) {
return nameMap.get(id);
} else {
return URLEncoder.encode(id, "utf-8");
return URLEncoder.encode(id, StandardCharsets.UTF_8);
}
}

Expand All @@ -39,7 +40,7 @@ public String decodeFsName(String path) throws IOException {
if (!nameMap.isEmpty()) {
return nameMap.inverse().get(path);
} else {
return URLDecoder.decode(path, "utf-8");
return URLDecoder.decode(path, StandardCharsets.UTF_8);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,13 +84,13 @@ public static void main(String[] args) throws Exception {
}

/** */
private OAuth2AppCredential microsoftAppCredential = new MicrosoftGraphLocalAppCredential();
private final OAuth2AppCredential microsoftAppCredential = new MicrosoftGraphLocalAppCredential();
/** */
private OAuth2AppCredential googleAppCredential = new GoogleLocalOAuth2AppCredential("googledrive");
private final OAuth2AppCredential googleAppCredential = new GoogleLocalOAuth2AppCredential("googledrive");
/** */
private OAuth2AppCredential boxAppCredential = new BoxLocalAppCredential();
private final OAuth2AppCredential boxAppCredential = new BoxLocalAppCredential();
/** */
private OAuth2AppCredential dropboxAppCredential = new DropBoxLocalAppCredential();
private final OAuth2AppCredential dropboxAppCredential = new DropBoxLocalAppCredential();

private FileSystem getFileSystem(String id) throws IOException {
String[] part1s = id.split(":");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,10 @@ public enum GoogleDriveCopyOption implements CopyOption {
EXPORT_AS_GDOCS("application/vnd.google-apps.document");

/** */
private String value;
private final String value;

/** */
private GoogleDriveCopyOption(String value) {
GoogleDriveCopyOption(String value) {
this.value = value;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,10 @@ public enum GoogleDriveOpenOption implements OpenOption {
IMPORT_AS_NEW_REVISION(null);

/** depends on enum stuff */
private String value;
private final String value;

/** */
private GoogleDriveOpenOption(String value) {
GoogleDriveOpenOption(String value) {
this.value = value;
}

Expand Down
Loading

0 comments on commit 78b7443

Please sign in to comment.