From 7131cde7100b4594321a6be15fe60f368f4ba297 Mon Sep 17 00:00:00 2001 From: Charles Allen Date: Fri, 7 Nov 2014 11:19:32 -0800 Subject: [PATCH] Code reformat in CompressedObjectStrategy --- .../data/CompressedObjectStrategy.java | 95 ++++++++++++------- 1 file changed, 62 insertions(+), 33 deletions(-) diff --git a/processing/src/main/java/io/druid/segment/data/CompressedObjectStrategy.java b/processing/src/main/java/io/druid/segment/data/CompressedObjectStrategy.java index 0ea2d86cda9..8bf1adfbe0f 100644 --- a/processing/src/main/java/io/druid/segment/data/CompressedObjectStrategy.java +++ b/processing/src/main/java/io/druid/segment/data/CompressedObjectStrategy.java @@ -38,13 +38,14 @@ import java.nio.ByteOrder; import java.util.Map; /** -*/ + */ public class CompressedObjectStrategy implements ObjectStrategy> { public static final CompressionStrategy DEFAULT_COMPRESSION_STRATEGY = CompressionStrategy.LZ4; - public static enum CompressionStrategy { - LZF ((byte)0x0) + public static enum CompressionStrategy + { + LZF((byte) 0x0) { @Override public Decompressor getDecompressor() @@ -59,34 +60,39 @@ public class CompressedObjectStrategy implements ObjectStrateg } }, - LZ4 ((byte)0x1) { - @Override - public Decompressor getDecompressor() - { - return LZ4Decompressor.defaultDecompressor; - } + LZ4((byte) 0x1) + { + @Override + public Decompressor getDecompressor() + { + return LZ4Decompressor.defaultDecompressor; + } - @Override - public Compressor getCompressor() - { - return LZ4Compressor.defaultCompressor; - } - }, - UNCOMPRESSED((byte)0x2){ - @Override - public Decompressor getDecompressor(){ - return UncompressedDecompressor.defaultDecompressor; - } - @Override - public Compressor getCompressor(){ - return UncompressedCompressor.defaultCompressor; - } - } - ; + @Override + public Compressor getCompressor() + { + return LZ4Compressor.defaultCompressor; + } + }, + UNCOMPRESSED((byte) 0x2) + { + @Override + public Decompressor getDecompressor() + { + return UncompressedDecompressor.defaultDecompressor; + } + + @Override + public Compressor getCompressor() + { + return UncompressedCompressor.defaultCompressor; + } + }; final byte id; - CompressionStrategy(byte id) { + CompressionStrategy(byte id) + { this.id = id; } @@ -94,12 +100,17 @@ public class CompressedObjectStrategy implements ObjectStrateg { return id; } + public abstract Compressor getCompressor(); + public abstract Decompressor getDecompressor(); static final Map idMap = Maps.newHashMap(); + static { - for(CompressionStrategy strategy : CompressionStrategy.values()) idMap.put(strategy.getId(), strategy); + for (CompressionStrategy strategy : CompressionStrategy.values()) { + idMap.put(strategy.getId(), strategy); + } } public static CompressionStrategy forId(byte id) @@ -118,6 +129,7 @@ public class CompressedObjectStrategy implements ObjectStrateg * @param out */ public void decompress(ByteBuffer in, int numBytes, ByteBuffer out); + public void decompress(ByteBuffer in, int numBytes, ByteBuffer out, int decompressedSize); } @@ -127,21 +139,30 @@ public class CompressedObjectStrategy implements ObjectStrateg * Currently assumes buf is an array backed ByteBuffer * * @param bytes + * * @return */ public byte[] compress(byte[] bytes); } - public static class UncompressedCompressor implements Compressor{ + + public static class UncompressedCompressor implements Compressor + { private static final UncompressedCompressor defaultCompressor = new UncompressedCompressor(); + @Override - public byte[] compress(byte[] bytes) { + public byte[] compress(byte[] bytes) + { return bytes; } } - public static class UncompressedDecompressor implements Decompressor{ + + public static class UncompressedDecompressor implements Decompressor + { private static final UncompressedDecompressor defaultDecompressor = new UncompressedDecompressor(); + @Override - public void decompress(ByteBuffer in, int numBytes, ByteBuffer out) { + public void decompress(ByteBuffer in, int numBytes, ByteBuffer out) + { final int maxCopy = Math.min(numBytes, out.remaining()); final ByteBuffer copyBuffer = in.duplicate(); copyBuffer.limit(copyBuffer.position() + maxCopy); @@ -151,8 +172,10 @@ public class CompressedObjectStrategy implements ObjectStrateg out.flip(); in.position(in.position() + maxCopy); } + @Override - public void decompress(ByteBuffer in, int numBytes, ByteBuffer out, int decompressedSize) { + public void decompress(ByteBuffer in, int numBytes, ByteBuffer out, int decompressedSize) + { decompress(in, numBytes, out); } } @@ -160,6 +183,7 @@ public class CompressedObjectStrategy implements ObjectStrateg public static class LZFDecompressor implements Decompressor { private static final LZFDecompressor defaultDecompressor = new LZFDecompressor(); + @Override public void decompress(ByteBuffer in, int numBytes, ByteBuffer out) { @@ -187,6 +211,7 @@ public class CompressedObjectStrategy implements ObjectStrateg public static class LZFCompressor implements Compressor { private static final LZFCompressor defaultCompressor = new LZFCompressor(); + @Override public byte[] compress(byte[] bytes) { @@ -203,6 +228,7 @@ public class CompressedObjectStrategy implements ObjectStrateg private static final LZ4SafeDecompressor lz4Safe = LZ4Factory.fastestJavaInstance().safeDecompressor(); private static final LZ4FastDecompressor lz4Fast = LZ4Factory.fastestJavaInstance().fastDecompressor(); private static final LZ4Decompressor defaultDecompressor = new LZ4Decompressor(); + @Override public void decompress(ByteBuffer in, int numBytes, ByteBuffer out) { @@ -334,8 +360,11 @@ public class CompressedObjectStrategy implements ObjectStrateg public static interface BufferConverter { public T convert(ByteBuffer buf); + public int compare(T lhs, T rhs); + public int sizeOf(int count); + public T combine(ByteBuffer into, T from); } }