Skip to content

Commit

Permalink
style: code style
Browse files Browse the repository at this point in the history
  • Loading branch information
bogovicj committed Jun 5, 2024
1 parent 75a5866 commit a669885
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 36 deletions.
63 changes: 33 additions & 30 deletions src/main/java/org/janelia/saalfeldlab/n5/universe/N5Factory.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,19 @@
*/
package org.janelia.saalfeldlab.n5.universe;

import com.amazonaws.auth.AWSCredentials;
import com.amazonaws.auth.DefaultAWSCredentialsProviderChain;
import com.amazonaws.services.s3.AmazonS3;
import com.google.cloud.storage.Storage;
import com.google.gson.GsonBuilder;
import net.imglib2.util.Pair;
import net.imglib2.util.ValuePair;
import java.io.File;
import java.io.Serializable;
import java.net.URI;
import java.net.URISyntaxException;
import java.nio.file.FileSystems;
import java.nio.file.Paths;
import java.util.function.BiFunction;
import java.util.function.Predicate;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

import javax.annotation.Nullable;

import org.apache.commons.lang3.function.TriFunction;
import org.janelia.saalfeldlab.googlecloud.GoogleCloudStorageURI;
import org.janelia.saalfeldlab.googlecloud.GoogleCloudUtils;
Expand All @@ -55,17 +61,14 @@
import org.janelia.saalfeldlab.n5.zarr.ZarrKeyValueReader;
import org.janelia.saalfeldlab.n5.zarr.ZarrKeyValueWriter;

import javax.annotation.Nullable;
import java.io.File;
import java.io.Serializable;
import java.net.URI;
import java.net.URISyntaxException;
import java.nio.file.FileSystems;
import java.nio.file.Paths;
import java.util.function.BiFunction;
import java.util.function.Predicate;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import com.amazonaws.auth.AWSCredentials;
import com.amazonaws.auth.DefaultAWSCredentialsProviderChain;
import com.amazonaws.services.s3.AmazonS3;
import com.google.cloud.storage.Storage;
import com.google.gson.GsonBuilder;

import net.imglib2.util.Pair;
import net.imglib2.util.ValuePair;

/**
* Factory for various N5 readers and writers. Implementation specific
Expand Down Expand Up @@ -228,7 +231,7 @@ KeyValueAccess getKeyValueAccess(final URI uri) {
* backend take into account reasonable defaults when possible.
* Here we test from most to least restrictive.
* See the Javadoc for more details. */
for (KeyValueAccessBackend backend : KeyValueAccessBackend.values()) {
for (final KeyValueAccessBackend backend : KeyValueAccessBackend.values()) {
final KeyValueAccess kva = backend.apply(uri, this);
if (kva != null)
return kva;
Expand Down Expand Up @@ -352,10 +355,10 @@ public N5Reader openReader(final String uri) {
private N5Reader openReader(@Nullable final StorageFormat storage, @Nullable final KeyValueAccess access, String containerPath) {

if (storage == null) {
for (StorageFormat format : StorageFormat.values()) {
for (final StorageFormat format : StorageFormat.values()) {
try {
return openReader(format, access, containerPath);
} catch (Throwable e) {
} catch (final Throwable e) {
}
}
throw new N5Exception("Unable to open " + containerPath + " as N5Reader");
Expand Down Expand Up @@ -480,10 +483,10 @@ public N5Writer openWriter(final String uri) {
private N5Writer openWriter(@Nullable final StorageFormat storage, @Nullable final KeyValueAccess access, final String containerPath) {

if (storage == null) {
for (StorageFormat format : StorageFormat.values()) {
for (final StorageFormat format : StorageFormat.values()) {
try {
return openWriter(format, access, containerPath);
} catch (Throwable ignored) {
} catch (final Throwable ignored) {
}
}
throw new N5Exception("Unable to open " + containerPath + " as N5Writer");
Expand Down Expand Up @@ -511,7 +514,7 @@ private <T extends N5Reader> T openN5ContainerWithStorageFormat(
try {
final URI asUri = StorageFormat.parseUri(uri).getB();
return openWithFormat.apply(format, asUri);
} catch (URISyntaxException e) {
} catch (final URISyntaxException e) {
throw new N5Exception("Cannot create N5 Container (" + format + ") at " + uri, e);
}
}
Expand Down Expand Up @@ -547,7 +550,7 @@ private <T extends N5Reader> T openN5Container(
final Pair<StorageFormat, URI> storageAndUri;
try {
storageAndUri = StorageFormat.parseUri(containerUri);
} catch (URISyntaxException e) {
} catch (final URISyntaxException e) {
throw new N5Exception("Unable to open " + containerUri + " as N5 Container", e);
}
final StorageFormat format = storageAndUri.getA();
Expand Down Expand Up @@ -631,7 +634,7 @@ public enum StorageFormat {

public static StorageFormat guessStorageFromUri(URI uri) {

for (StorageFormat format : StorageFormat.values()) {
for (final StorageFormat format : StorageFormat.values()) {
if (format.uriTest.test(uri))
return format;
}
Expand All @@ -656,7 +659,7 @@ public static Pair<StorageFormat, String> getStorageFromNestedScheme(String uri)
final String storageFormatScheme = storageSchemeMatcher.group(STORAGE_SCHEME_GROUP);
final String uriGroup = storageSchemeMatcher.group(URI_GROUP);
if (storageFormatScheme != null) {
for (StorageFormat format : StorageFormat.values()) {
for (final StorageFormat format : StorageFormat.values()) {
if (format.schemePattern.asPredicate().test(storageFormatScheme))
return new ValuePair<>(format, uriGroup);
}
Expand Down Expand Up @@ -690,15 +693,15 @@ public static N5Reader createReader(String containerUri) {
private static URI parseUriFromString(String uri) {
try {
return URI.create(uri);
} catch (Throwable ignore) {}
} catch (final Throwable ignore) {}

try {
return Paths.get(uri).toUri();
} catch (Throwable ignore) {}
} catch (final Throwable ignore) {}

try {
return N5URI.encodeAsUri(uri);
} catch (URISyntaxException e) {
} catch (final URISyntaxException e) {
throw new N5Exception(e);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -149,8 +149,8 @@ public N5TreeNode addPath( final String path, Function<String, N5TreeNode> const

// get the appropriate child along the path if it exists, otherwise add it
N5TreeNode child = null;
Stream<N5TreeNode> cs = children.stream().filter( n -> n.getNodeName().equals(childName));
Optional<N5TreeNode> copt = cs.findFirst();
final Stream<N5TreeNode> cs = children.stream().filter( n -> n.getNodeName().equals(childName));
final Optional<N5TreeNode> copt = cs.findFirst();
if( copt.isPresent() )
child = copt.get();
else {
Expand Down Expand Up @@ -199,8 +199,8 @@ public boolean structureEquals( N5TreeNode other )
return false;

boolean childrenEqual = true;
for( N5TreeNode c : childrenList()) {
Optional<N5TreeNode> otherChildOpt = other.childrenList().stream()
for( final N5TreeNode c : childrenList()) {
final Optional<N5TreeNode> otherChildOpt = other.childrenList().stream()
.filter( x -> x.getNodeName().equals( c.getNodeName()))
.findFirst();

Expand All @@ -221,9 +221,9 @@ public String printRecursive() {

private static String printRecursiveHelper(N5TreeNode node, String prefix) {

StringBuffer out = new StringBuffer();
final StringBuffer out = new StringBuffer();
out.append(prefix + node.path + "\n");
for (N5TreeNode c : node.childrenList()) {
for (final N5TreeNode c : node.childrenList()) {
System.out.println(c.path);
out.append(printRecursiveHelper(c, prefix + " "));
}
Expand Down

0 comments on commit a669885

Please sign in to comment.