summaryrefslogtreecommitdiff
path: root/src/main/java/com/amazon
diff options
context:
space:
mode:
authorBrian S. O'Neill <bronee@gmail.com>2008-07-15 16:24:01 +0000
committerBrian S. O'Neill <bronee@gmail.com>2008-07-15 16:24:01 +0000
commit717836fab714569b78673c78ada3baed0376b979 (patch)
tree359654206ca7b66dafeab135289fcacefd7f1af8 /src/main/java/com/amazon
parent9afe8abca1ae161905f1bcb179479a279580b6c8 (diff)
Key encoder/decoder no longer extend from data encoder/decoder.
Diffstat (limited to 'src/main/java/com/amazon')
-rw-r--r--src/main/java/com/amazon/carbonado/raw/DataDecoder.java5
-rw-r--r--src/main/java/com/amazon/carbonado/raw/DataEncoder.java16
-rw-r--r--src/main/java/com/amazon/carbonado/raw/EncodingConstants.java43
-rw-r--r--src/main/java/com/amazon/carbonado/raw/KeyDecoder.java18
-rw-r--r--src/main/java/com/amazon/carbonado/raw/KeyEncoder.java29
5 files changed, 71 insertions, 40 deletions
diff --git a/src/main/java/com/amazon/carbonado/raw/DataDecoder.java b/src/main/java/com/amazon/carbonado/raw/DataDecoder.java
index 34fa6e3..635b52e 100644
--- a/src/main/java/com/amazon/carbonado/raw/DataDecoder.java
+++ b/src/main/java/com/amazon/carbonado/raw/DataDecoder.java
@@ -24,17 +24,16 @@ import java.io.IOException;
import com.amazon.carbonado.CorruptEncodingException;
-import static com.amazon.carbonado.raw.DataEncoder.*;
+import static com.amazon.carbonado.raw.EncodingConstants.*;
/**
* A very low-level class that decodes key components encoded by methods of
* {@link DataEncoder}.
*
* @author Brian S O'Neill
+ * @see KeyDecoder
*/
public class DataDecoder {
- static final byte[] EMPTY_BYTE_ARRAY = new byte[0];
-
/**
* Decodes a signed integer from exactly 4 bytes.
*
diff --git a/src/main/java/com/amazon/carbonado/raw/DataEncoder.java b/src/main/java/com/amazon/carbonado/raw/DataEncoder.java
index 6eebc93..e8383b9 100644
--- a/src/main/java/com/amazon/carbonado/raw/DataEncoder.java
+++ b/src/main/java/com/amazon/carbonado/raw/DataEncoder.java
@@ -21,6 +21,8 @@ package com.amazon.carbonado.raw;
import java.io.IOException;
import java.io.OutputStream;
+import static com.amazon.carbonado.raw.EncodingConstants.*;
+
/**
* A very low-level class that supports encoding of primitive data. For
* encoding data into keys, see {@link KeyEncoder}.
@@ -29,21 +31,9 @@ import java.io.OutputStream;
* @see DataDecoder
*/
public class DataEncoder {
- // Note: Most of these methods are inherited by KeyEncoder, which is why
+ // Note: Most of these methods are also used by KeyEncoder, which is why
// they are encoded for supporting proper ordering.
- /** Byte to use for null, low ordering */
- static final byte NULL_BYTE_LOW = 0;
-
- /** Byte to use for null, high ordering */
- static final byte NULL_BYTE_HIGH = (byte)~NULL_BYTE_LOW;
-
- /** Byte to use for not-null, low ordering */
- static final byte NOT_NULL_BYTE_HIGH = (byte)128;
-
- /** Byte to use for not-null, high ordering */
- static final byte NOT_NULL_BYTE_LOW = (byte)~NOT_NULL_BYTE_HIGH;
-
/**
* Encodes the given signed integer into exactly 4 bytes.
*
diff --git a/src/main/java/com/amazon/carbonado/raw/EncodingConstants.java b/src/main/java/com/amazon/carbonado/raw/EncodingConstants.java
new file mode 100644
index 0000000..997e491
--- /dev/null
+++ b/src/main/java/com/amazon/carbonado/raw/EncodingConstants.java
@@ -0,0 +1,43 @@
+/*
+ * Copyright 2008 Amazon Technologies, Inc. or its affiliates.
+ * Amazon, Amazon.com and Carbonado are trademarks or registered trademarks
+ * of Amazon Technologies, Inc. or its affiliates. All rights reserved.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.amazon.carbonado.raw;
+
+/**
+ *
+ *
+ * @author Brian S O'Neill
+ */
+class EncodingConstants {
+ static final byte[] EMPTY_BYTE_ARRAY = new byte[0];
+
+ /** Byte to use for null, low ordering */
+ static final byte NULL_BYTE_LOW = 0;
+
+ /** Byte to use for null, high ordering */
+ static final byte NULL_BYTE_HIGH = (byte)~NULL_BYTE_LOW;
+
+ /** Byte to use for not-null, low ordering */
+ static final byte NOT_NULL_BYTE_HIGH = (byte)128;
+
+ /** Byte to use for not-null, high ordering */
+ static final byte NOT_NULL_BYTE_LOW = (byte)~NOT_NULL_BYTE_HIGH;
+
+ /** Byte to terminate variable data encoded for ascending order */
+ static final byte TERMINATOR = (byte)1;
+}
diff --git a/src/main/java/com/amazon/carbonado/raw/KeyDecoder.java b/src/main/java/com/amazon/carbonado/raw/KeyDecoder.java
index a3254b1..4f78738 100644
--- a/src/main/java/com/amazon/carbonado/raw/KeyDecoder.java
+++ b/src/main/java/com/amazon/carbonado/raw/KeyDecoder.java
@@ -20,16 +20,16 @@ package com.amazon.carbonado.raw;
import com.amazon.carbonado.CorruptEncodingException;
-import static com.amazon.carbonado.raw.KeyEncoder.*;
+import static com.amazon.carbonado.raw.EncodingConstants.*;
/**
* A very low-level class that decodes key components encoded by methods of
* {@link KeyEncoder}.
*
* @author Brian S O'Neill
+ * @see DataDecoder
*/
-public class KeyDecoder extends DataDecoder {
-
+public class KeyDecoder {
/**
* Decodes a signed integer from exactly 4 bytes, as encoded for descending
* order.
@@ -41,7 +41,7 @@ public class KeyDecoder extends DataDecoder {
public static int decodeIntDesc(byte[] src, int srcOffset)
throws CorruptEncodingException
{
- return ~decodeInt(src, srcOffset);
+ return ~DataDecoder.decodeInt(src, srcOffset);
}
/**
@@ -77,7 +77,7 @@ public class KeyDecoder extends DataDecoder {
public static long decodeLongDesc(byte[] src, int srcOffset)
throws CorruptEncodingException
{
- return ~decodeLong(src, srcOffset);
+ return ~DataDecoder.decodeLong(src, srcOffset);
}
/**
@@ -273,7 +273,7 @@ public class KeyDecoder extends DataDecoder {
public static float decodeFloatDesc(byte[] src, int srcOffset)
throws CorruptEncodingException
{
- int bits = decodeFloatBits(src, srcOffset);
+ int bits = DataDecoder.decodeFloatBits(src, srcOffset);
if (bits >= 0) {
bits ^= 0x7fffffff;
}
@@ -290,7 +290,7 @@ public class KeyDecoder extends DataDecoder {
public static Float decodeFloatObjDesc(byte[] src, int srcOffset)
throws CorruptEncodingException
{
- int bits = decodeFloatBits(src, srcOffset);
+ int bits = DataDecoder.decodeFloatBits(src, srcOffset);
if (bits >= 0) {
bits ^= 0x7fffffff;
}
@@ -307,7 +307,7 @@ public class KeyDecoder extends DataDecoder {
public static double decodeDoubleDesc(byte[] src, int srcOffset)
throws CorruptEncodingException
{
- long bits = decodeDoubleBits(src, srcOffset);
+ long bits = DataDecoder.decodeDoubleBits(src, srcOffset);
if (bits >= 0) {
bits ^= 0x7fffffffffffffffL;
}
@@ -324,7 +324,7 @@ public class KeyDecoder extends DataDecoder {
public static Double decodeDoubleObjDesc(byte[] src, int srcOffset)
throws CorruptEncodingException
{
- long bits = decodeDoubleBits(src, srcOffset);
+ long bits = DataDecoder.decodeDoubleBits(src, srcOffset);
if (bits >= 0) {
bits ^= 0x7fffffffffffffffL;
}
diff --git a/src/main/java/com/amazon/carbonado/raw/KeyEncoder.java b/src/main/java/com/amazon/carbonado/raw/KeyEncoder.java
index 5b11586..8d374a1 100644
--- a/src/main/java/com/amazon/carbonado/raw/KeyEncoder.java
+++ b/src/main/java/com/amazon/carbonado/raw/KeyEncoder.java
@@ -18,6 +18,8 @@
package com.amazon.carbonado.raw;
+import static com.amazon.carbonado.raw.EncodingConstants.*;
+
/**
* A very low-level class that supports encoding of primitive data into unique,
* sortable byte array keys. If the data to encode is of a variable size, then
@@ -29,12 +31,9 @@ package com.amazon.carbonado.raw;
*
* @author Brian S O'Neill
* @see KeyDecoder
+ * @see DataEncoder
*/
-public class KeyEncoder extends DataEncoder {
-
- /** Byte to terminate variable data encoded for ascending order */
- static final byte TERMINATOR = (byte)1;
-
+public class KeyEncoder {
/**
* Encodes the given signed integer into exactly 4 bytes for descending
* order.
@@ -44,7 +43,7 @@ public class KeyEncoder extends DataEncoder {
* @param dstOffset offset into destination array
*/
public static void encodeDesc(int value, byte[] dst, int dstOffset) {
- encode(~value, dst, dstOffset);
+ DataEncoder.encode(~value, dst, dstOffset);
}
/**
@@ -63,7 +62,7 @@ public class KeyEncoder extends DataEncoder {
return 1;
} else {
dst[dstOffset] = NOT_NULL_BYTE_LOW;
- encode(~value.intValue(), dst, dstOffset + 1);
+ DataEncoder.encode(~value.intValue(), dst, dstOffset + 1);
return 5;
}
}
@@ -76,7 +75,7 @@ public class KeyEncoder extends DataEncoder {
* @param dstOffset offset into destination array
*/
public static void encodeDesc(long value, byte[] dst, int dstOffset) {
- encode(~value, dst, dstOffset);
+ DataEncoder.encode(~value, dst, dstOffset);
}
/**
@@ -95,7 +94,7 @@ public class KeyEncoder extends DataEncoder {
return 1;
} else {
dst[dstOffset] = NOT_NULL_BYTE_LOW;
- encode(~value.longValue(), dst, dstOffset + 1);
+ DataEncoder.encode(~value.longValue(), dst, dstOffset + 1);
return 9;
}
}
@@ -141,7 +140,7 @@ public class KeyEncoder extends DataEncoder {
* @param dstOffset offset into destination array
*/
public static void encodeDesc(short value, byte[] dst, int dstOffset) {
- encode((short) ~value, dst, dstOffset);
+ DataEncoder.encode((short) ~value, dst, dstOffset);
}
/**
@@ -160,7 +159,7 @@ public class KeyEncoder extends DataEncoder {
return 1;
} else {
dst[dstOffset] = NOT_NULL_BYTE_LOW;
- encode((short) ~value.shortValue(), dst, dstOffset + 1);
+ DataEncoder.encode((short) ~value.shortValue(), dst, dstOffset + 1);
return 3;
}
}
@@ -173,7 +172,7 @@ public class KeyEncoder extends DataEncoder {
* @param dstOffset offset into destination array
*/
public static void encodeDesc(char value, byte[] dst, int dstOffset) {
- encode((char) ~value, dst, dstOffset);
+ DataEncoder.encode((char) ~value, dst, dstOffset);
}
/**
@@ -192,7 +191,7 @@ public class KeyEncoder extends DataEncoder {
return 1;
} else {
dst[dstOffset] = NOT_NULL_BYTE_LOW;
- encode((char) ~value.charValue(), dst, dstOffset + 1);
+ DataEncoder.encode((char) ~value.charValue(), dst, dstOffset + 1);
return 3;
}
}
@@ -252,7 +251,7 @@ public class KeyEncoder extends DataEncoder {
*/
public static void encodeDesc(Float value, byte[] dst, int dstOffset) {
if (value == null) {
- encode(~0x7fffffff, dst, dstOffset);
+ DataEncoder.encode(~0x7fffffff, dst, dstOffset);
} else {
encodeDesc(value.floatValue(), dst, dstOffset);
}
@@ -292,7 +291,7 @@ public class KeyEncoder extends DataEncoder {
*/
public static void encodeDesc(Double value, byte[] dst, int dstOffset) {
if (value == null) {
- encode(~0x7fffffffffffffffL, dst, dstOffset);
+ DataEncoder.encode(~0x7fffffffffffffffL, dst, dstOffset);
} else {
encodeDesc(value.doubleValue(), dst, dstOffset);
}