Skip to content

Commit

Permalink
Make Filter an interface again
Browse files Browse the repository at this point in the history
  • Loading branch information
minnerbe committed Oct 19, 2023
1 parent 9dc961c commit 970b6e3
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 19 deletions.
34 changes: 17 additions & 17 deletions src/main/java/org/janelia/saalfeldlab/n5/zarr/Filter.java
Original file line number Diff line number Diff line change
Expand Up @@ -47,31 +47,31 @@
* @author Stephan Saalfeld <[email protected]>
* @author Michael Innerberger
*/
public enum Filter {
// Note: the JSON (de-)serializer below is very much tailored to this filter, which serializes to "{"id":"vlen-utf8"}"
// If additional filters are implemented, consider also changing the type adapter below
VLEN_UTF8("vlen-utf8");
public interface Filter {

private final String id;
String getId();

Filter(final String id) {
this.id = id;
}
// Note: the JSON (de-)serializer below is very much tailored to this filter, which serializes to "{"id":"vlen-utf8"}"
// If additional filters are implemented, consider also changing the type adapter below
Filter VLEN_UTF8 = new VLenStringFilter();

public String getId() {
return id;
}
class VLenStringFilter implements Filter {
private static final String id = "vlen-utf8";
@Override
public String getId() {
return id;
}
};

public static Filter fromString(final String id) {
for (final Filter filter : values())
if (filter.getId().equals(id))
return filter;
static Filter fromString(final String id) {
if (VLEN_UTF8.getId().equals(id))
return VLEN_UTF8;
return null;
}

public static final JsonAdapter jsonAdapter = new JsonAdapter();
JsonAdapter jsonAdapter = new JsonAdapter();

public static class JsonAdapter implements JsonDeserializer<Filter>, JsonSerializer<Filter> {
class JsonAdapter implements JsonDeserializer<Filter>, JsonSerializer<Filter> {

@Override
public Filter deserialize(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@
import java.net.URISyntaxException;
import java.nio.ByteBuffer;
import java.util.Arrays;
import java.util.Collection;

import org.apache.commons.compress.utils.IOUtils;
import org.janelia.saalfeldlab.n5.BlockReader;
Expand Down Expand Up @@ -841,7 +840,7 @@ protected static GsonBuilder addTypeAdapters(final GsonBuilder gsonBuilder) {
gsonBuilder.registerTypeHierarchyAdapter(Compression.class, CompressionAdapter.getJsonAdapter());
gsonBuilder.registerTypeAdapter(Compression.class, CompressionAdapter.getJsonAdapter());
gsonBuilder.registerTypeAdapter(ZArrayAttributes.class, ZArrayAttributes.jsonAdapter);
gsonBuilder.registerTypeAdapter(Filter.class, Filter.jsonAdapter);
gsonBuilder.registerTypeHierarchyAdapter(Filter.class, Filter.jsonAdapter);
gsonBuilder.disableHtmlEscaping();
gsonBuilder.serializeNulls();

Expand Down

0 comments on commit 970b6e3

Please sign in to comment.