From 970b6e357949e7a23ab09fedfc491ea63bed096a Mon Sep 17 00:00:00 2001 From: Michael Innerberger Date: Thu, 19 Oct 2023 17:49:46 -0400 Subject: [PATCH] Make Filter an interface again --- .../janelia/saalfeldlab/n5/zarr/Filter.java | 34 +++++++++---------- .../n5/zarr/ZarrKeyValueReader.java | 3 +- 2 files changed, 18 insertions(+), 19 deletions(-) diff --git a/src/main/java/org/janelia/saalfeldlab/n5/zarr/Filter.java b/src/main/java/org/janelia/saalfeldlab/n5/zarr/Filter.java index 988f243..3c756b2 100644 --- a/src/main/java/org/janelia/saalfeldlab/n5/zarr/Filter.java +++ b/src/main/java/org/janelia/saalfeldlab/n5/zarr/Filter.java @@ -47,31 +47,31 @@ * @author Stephan Saalfeld <saalfelds@janelia.hhmi.org> * @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, JsonSerializer { + class JsonAdapter implements JsonDeserializer, JsonSerializer { @Override public Filter deserialize( diff --git a/src/main/java/org/janelia/saalfeldlab/n5/zarr/ZarrKeyValueReader.java b/src/main/java/org/janelia/saalfeldlab/n5/zarr/ZarrKeyValueReader.java index 9ca58a2..c059b69 100644 --- a/src/main/java/org/janelia/saalfeldlab/n5/zarr/ZarrKeyValueReader.java +++ b/src/main/java/org/janelia/saalfeldlab/n5/zarr/ZarrKeyValueReader.java @@ -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; @@ -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();