You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@hbase.apache.org by st...@apache.org on 2008/09/23 07:09:15 UTC
svn commit: r698090 - in /hadoop/hbase/trunk: CHANGES.txt
src/java/org/apache/hadoop/hbase/util/Bytes.java
Author: stack
Date: Mon Sep 22 22:09:14 2008
New Revision: 698090
URL: http://svn.apache.org/viewvc?rev=698090&view=rev
Log:
HBASE-884 Double and float converters for Bytes class
Modified:
hadoop/hbase/trunk/CHANGES.txt
hadoop/hbase/trunk/src/java/org/apache/hadoop/hbase/util/Bytes.java
Modified: hadoop/hbase/trunk/CHANGES.txt
URL: http://svn.apache.org/viewvc/hadoop/hbase/trunk/CHANGES.txt?rev=698090&r1=698089&r2=698090&view=diff
==============================================================================
--- hadoop/hbase/trunk/CHANGES.txt (original)
+++ hadoop/hbase/trunk/CHANGES.txt Mon Sep 22 22:09:14 2008
@@ -15,6 +15,8 @@
new table (Sishen Freecity via Stack)
HBASE-886, HBASE-895 Sort the tables in the web UI, [shell] 'list' command
should emit a sorted list of tables (Krzysztof Szlapinski via Stack)
+ HBASE-884 Double and float converters for Bytes class
+ (DoÄacan Güney via Stack)
NEW FEATURES
Modified: hadoop/hbase/trunk/src/java/org/apache/hadoop/hbase/util/Bytes.java
URL: http://svn.apache.org/viewvc/hadoop/hbase/trunk/src/java/org/apache/hadoop/hbase/util/Bytes.java?rev=698090&r1=698089&r2=698090&view=diff
==============================================================================
--- hadoop/hbase/trunk/src/java/org/apache/hadoop/hbase/util/Bytes.java (original)
+++ hadoop/hbase/trunk/src/java/org/apache/hadoop/hbase/util/Bytes.java Mon Sep 22 22:09:14 2008
@@ -27,6 +27,16 @@
* Size of int in bytes
*/
public static final int SIZEOF_INT = Integer.SIZE/Byte.SIZE;
+
+ /**
+ * Size of float in bytes
+ */
+ public static final int SIZEOF_FLOAT = Float.SIZE/Byte.SIZE;
+
+ /**
+ * Size of double in bytes
+ */
+ public static final int SIZEOF_DOUBLE = Double.SIZE/Byte.SIZE;
/**
* Pass this to TreeMaps where byte [] are keys.
@@ -143,6 +153,52 @@
}
return ByteBuffer.wrap(bytes).getInt();
}
+
+ /**
+ * Convert an float value to a byte array
+ * @param val
+ * @return the byte array
+ */
+ public static byte[] toBytes(final float val) {
+ ByteBuffer bb = ByteBuffer.allocate(SIZEOF_FLOAT);
+ bb.putFloat(val);
+ return bb.array();
+ }
+
+ /**
+ * Converts a byte array to a float value
+ * @param bytes
+ * @return the float value
+ */
+ public static float toFloat(byte[] bytes) {
+ if (bytes == null || bytes.length == 0) {
+ return -1;
+ }
+ return ByteBuffer.wrap(bytes).getFloat();
+ }
+
+ /**
+ * Convert an double value to a byte array
+ * @param val
+ * @return the byte array
+ */
+ public static byte[] toBytes(final double val) {
+ ByteBuffer bb = ByteBuffer.allocate(SIZEOF_DOUBLE);
+ bb.putDouble(val);
+ return bb.array();
+ }
+
+ /**
+ * Converts a byte array to a double value
+ * @param bytes
+ * @return the double value
+ */
+ public static double toDouble(byte[] bytes) {
+ if (bytes == null || bytes.length == 0) {
+ return -1;
+ }
+ return ByteBuffer.wrap(bytes).getDouble();
+ }
/**
* @param left