Skip to content

Commit

Permalink
PR changes
Browse files Browse the repository at this point in the history
Signed-off-by: Nicholas Walter Knize <nknize@apache.org>
  • Loading branch information
nknize committed Aug 14, 2023
1 parent 63d971e commit ac0fbef
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
import org.opensearch.core.compress.spi.CompressorProvider;

import java.util.AbstractMap.SimpleEntry;
import java.util.Map.Entry;
import java.util.List;

/**
Expand All @@ -25,7 +26,7 @@ public class CompressionProvider implements CompressorProvider {
/** Returns the concrete {@link Compressor}s provided by the compress library */
@SuppressWarnings({ "unchecked", "rawtypes" })
@Override
public List<SimpleEntry<String, Compressor>> getCompressors() {
return List.of(new SimpleEntry(ZstdCompressor.NAME, new ZstdCompressor()));
public List<Entry<String, Compressor>> getCompressors() {
return List.of(new SimpleEntry<>(ZstdCompressor.NAME, new ZstdCompressor()));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,6 @@
import org.opensearch.core.xcontent.MediaTypeRegistry;

import java.io.IOException;
import java.util.AbstractMap.SimpleEntry;
import java.util.ArrayList;
import java.util.Map;
import java.util.Objects;
import java.util.ServiceLoader;
Expand All @@ -40,11 +38,10 @@ public final class CompressorRegistry {
private CompressorRegistry() {}

static {
ArrayList<SimpleEntry<String, Compressor>> compressors = new ArrayList<>();
for (CompressorProvider provider : ServiceLoader.load(CompressorProvider.class, CompressorProvider.class.getClassLoader())) {
compressors.addAll(provider.getCompressors());
}
registeredCompressors = Map.copyOf(compressors.stream().collect(Collectors.toMap(SimpleEntry::getKey, SimpleEntry::getValue)));
registeredCompressors = ServiceLoader.load(CompressorProvider.class, CompressorProvider.class.getClassLoader())
.stream()
.flatMap(p -> p.get().getCompressors().stream())
.collect(Collectors.toUnmodifiableMap(Map.Entry::getKey, Map.Entry::getValue));
NONE = registeredCompressors.get(NoneCompressor.NAME);
}

Expand All @@ -56,7 +53,7 @@ public static Compressor defaultCompressor() {
}

public static Compressor none() {
return registeredCompressors.get("NONE");
return registeredCompressors.get(NoneCompressor.NAME);
}

public static boolean isCompressed(BytesReference bytes) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@

import org.opensearch.core.compress.Compressor;

import java.util.AbstractMap;
import java.util.List;
import java.util.Map;

/**
* Service Provider Interface for plugins, modules, extensions providing custom
Expand All @@ -26,5 +26,5 @@
*/
public interface CompressorProvider {
/** Extensions that implement their own concrete {@link Compressor}s provide them through this interface method*/
List<AbstractMap.SimpleEntry<String, Compressor>> getCompressors();
List<Map.Entry<String, Compressor>> getCompressors();
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@

import java.util.AbstractMap.SimpleEntry;
import java.util.List;
import java.util.Map.Entry;

/**
* Default {@link Compressor} implementations provided by the
Expand All @@ -24,7 +25,7 @@ public class DefaultCompressorProvider implements CompressorProvider {
/** Returns the default {@link Compressor}s provided by the core library */
@SuppressWarnings({ "unchecked", "rawtypes" })
@Override
public List<SimpleEntry<String, Compressor>> getCompressors() {
public List<Entry<String, Compressor>> getCompressors() {
return List.of(new SimpleEntry(NoneCompressor.NAME, new NoneCompressor()));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@

import java.util.AbstractMap.SimpleEntry;
import java.util.List;
import java.util.Map.Entry;

/**
* Default {@link Compressor} implementations provided by the
Expand All @@ -29,7 +30,7 @@ public class ServerCompressorProvider implements CompressorProvider {
/** Returns the concrete {@link Compressor}s provided by the server module */
@SuppressWarnings({ "unchecked", "rawtypes" })
@Override
public List<SimpleEntry<String, Compressor>> getCompressors() {
public List<Entry<String, Compressor>> getCompressors() {
return List.of(new SimpleEntry(DeflateCompressor.NAME, new DeflateCompressor()));
}
}

0 comments on commit ac0fbef

Please sign in to comment.