From f79f2e73285f9ea11410fb1db7a75b45d5d7785a Mon Sep 17 00:00:00 2001
From: ?? ? <ulysseskao@ximple.com.tw>
Date: Fri, 14 Mar 2008 10:35:54 +0800
Subject: [PATCH] EOFM-14

---
 ximple-spatialjob/src/main/java/com/ximple/eofms/util/Bits.java         |   28 +++---
 ximple-spatialjob/src/main/java/com/ximple/eofms/util/BinConverter.java |  161 +++++++++++++++++++++-------------------
 2 files changed, 99 insertions(+), 90 deletions(-)

diff --git a/ximple-spatialjob/src/main/java/com/ximple/eofms/util/BinConverter.java b/ximple-spatialjob/src/main/java/com/ximple/eofms/util/BinConverter.java
index 707ad61..2dd4c53 100644
--- a/ximple-spatialjob/src/main/java/com/ximple/eofms/util/BinConverter.java
+++ b/ximple-spatialjob/src/main/java/com/ximple/eofms/util/BinConverter.java
@@ -6,8 +6,6 @@
 import java.nio.ByteOrder;
 import java.nio.LongBuffer;
 
-import org.testng.Assert;
-
 /**
  * BinConverter
  * User: Ulysses
@@ -18,33 +16,35 @@
 {
     // our table for binhex conversion
     final static char[] HEXTAB =
-    {
-        '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'a', 'b', 'c', 'd', 'e', 'f'
-    };
+            {
+                    '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'a', 'b', 'c', 'd', 'e', 'f'
+            };
 
     /**
-     *  gets bytes from an array into a long
-     *  @param buffer where to get the bytes
-     *  @param nStartIndex index from where to read the data
-     *  @return the 64bit integer
+     * gets bytes from an array into a long
+     *
+     * @param buffer      where to get the bytes
+     * @param nStartIndex index from where to read the data
+     * @return the 64bit integer
      */
     public static long byteArrayToLong(byte[] buffer, int nStartIndex)
     {
         return (((long) buffer[nStartIndex]) << 56) | (((long) buffer[nStartIndex + 1] & 0x0ffL) << 48)
-               | (((long) buffer[nStartIndex + 2] & 0x0ffL) << 40) | (((long) buffer[nStartIndex + 3] & 0x0ffL) << 32)
-               | (((long) buffer[nStartIndex + 4] & 0x0ffL) << 24) | (((long) buffer[nStartIndex + 5] & 0x0ffL) << 16)
-               | (((long) buffer[nStartIndex + 6] & 0x0ffL) << 8) | ((long) buffer[nStartIndex + 7] & 0x0ff);
+                | (((long) buffer[nStartIndex + 2] & 0x0ffL) << 40) | (((long) buffer[nStartIndex + 3] & 0x0ffL) << 32)
+                | (((long) buffer[nStartIndex + 4] & 0x0ffL) << 24) | (((long) buffer[nStartIndex + 5] & 0x0ffL) << 16)
+                | (((long) buffer[nStartIndex + 6] & 0x0ffL) << 8) | ((long) buffer[nStartIndex + 7] & 0x0ff);
     }
 
     /**
-     *  converts a long o bytes which are put into a given array
-     *  @param lValue the 64bit integer to convert
-     *  @param buffer the target buffer
-     *  @param nStartIndex where to place the bytes in the buffer
+     * converts a long o bytes which are put into a given array
+     *
+     * @param lValue      the 64bit integer to convert
+     * @param buffer      the target buffer
+     * @param nStartIndex where to place the bytes in the buffer
      */
     public static void longToByteArray(long lValue, byte[] buffer, int nStartIndex)
     {
-        buffer[nStartIndex]     = (byte) (lValue >>> 56);
+        buffer[nStartIndex] = (byte) (lValue >>> 56);
         buffer[nStartIndex + 1] = (byte) ((lValue >>> 48) & 0x0ff);
         buffer[nStartIndex + 2] = (byte) ((lValue >>> 40) & 0x0ff);
         buffer[nStartIndex + 3] = (byte) ((lValue >>> 32) & 0x0ff);
@@ -55,10 +55,11 @@
     }
 
     /**
-     *  converts values from an integer array to a long
-     *  @param buffer where to get the bytes
-     *  @param nStartIndex index from where to read the data
-     *  @return the 64bit integer
+     * converts values from an integer array to a long
+     *
+     * @param buffer      where to get the bytes
+     * @param nStartIndex index from where to read the data
+     * @return the 64bit integer
      */
     public static long intArrayToLong(int[] buffer, int nStartIndex)
     {
@@ -66,22 +67,24 @@
     }
 
     /**
-     *  converts a long to integers which are put into a given array
-     *  @param lValue the 64bit integer to convert
-     *  @param buffer the target buffer
-     *  @param nStartIndex where to place the bytes in the buffer
+     * converts a long to integers which are put into a given array
+     *
+     * @param lValue      the 64bit integer to convert
+     * @param buffer      the target buffer
+     * @param nStartIndex where to place the bytes in the buffer
      */
     public static void longToIntArray(long lValue, int[] buffer, int nStartIndex)
     {
-        buffer[nStartIndex]     = (int) (lValue >>> 32);
+        buffer[nStartIndex] = (int) (lValue >>> 32);
         buffer[nStartIndex + 1] = (int) lValue;
     }
 
     /**
-     *  makes a long from two integers (treated unsigned)
-     *  @param nLo lower 32bits
-     *  @param nHi higher 32bits
-     *  @return the built long
+     * makes a long from two integers (treated unsigned)
+     *
+     * @param nLo lower 32bits
+     * @param nHi higher 32bits
+     * @return the built long
      */
     public static long makeLong(int nLo, int nHi)
     {
@@ -89,9 +92,10 @@
     }
 
     /**
-     *  gets the lower 32 bits of a long
-     *  @param lVal the long integer
-     *  @return lower 32 bits
+     * gets the lower 32 bits of a long
+     *
+     * @param lVal the long integer
+     * @return lower 32 bits
      */
     public static int longLo32(long lVal)
     {
@@ -99,9 +103,10 @@
     }
 
     /**
-     *  gets the higher 32 bits of a long
-     *  @param lVal the long integer
-     *  @return higher 32 bits
+     * gets the higher 32 bits of a long
+     *
+     * @param lVal the long integer
+     * @return higher 32 bits
      */
     public static int longHi32(long lVal)
     {
@@ -109,9 +114,10 @@
     }
 
     /**
-     *  converts a byte array to a binhex string
-     *  @param data the byte array
-     *  @return the binhex string
+     * converts a byte array to a binhex string
+     *
+     * @param data the byte array
+     * @return the binhex string
      */
     public static String bytesToBinHex(byte[] data)
     {
@@ -120,11 +126,12 @@
     }
 
     /**
-     *  converts a byte array to a binhex string
-     *  @param data the byte array
-     *  @param nStartPos start index where to get the bytes
-     *  @param nNumOfBytes number of bytes to convert
-     *  @return the binhex string
+     * converts a byte array to a binhex string
+     *
+     * @param data        the byte array
+     * @param nStartPos   start index where to get the bytes
+     * @param nNumOfBytes number of bytes to convert
+     * @return the binhex string
      */
     public static String bytesToBinHex(byte[] data, int nStartPos, int nNumOfBytes)
     {
@@ -144,19 +151,20 @@
     }
 
     /**
-     *  converts a binhex string back into a byte array (invalid codes will be skipped)
-     *  @param sBinHex binhex string
-     *  @param data the target array
-     *  @param nSrcPos from which character in the string the conversion should begin,
-     *                 remember that (nSrcPos modulo 2) should equals 0 normally
-     *  @param nDstPos to store the bytes from which position in the array
-     *  @param nNumOfBytes number of bytes to extract
-     *  @return number of extracted bytes
+     * converts a binhex string back into a byte array (invalid codes will be skipped)
+     *
+     * @param sBinHex     binhex string
+     * @param data        the target array
+     * @param nSrcPos     from which character in the string the conversion should begin,
+     *                    remember that (nSrcPos modulo 2) should equals 0 normally
+     * @param nDstPos     to store the bytes from which position in the array
+     * @param nNumOfBytes number of bytes to extract
+     * @return number of extracted bytes
      */
     public static int binHexToBytes(String sBinHex, byte[] data, int nSrcPos, int nDstPos, int nNumOfBytes)
     {
         // check for correct ranges
-        int nStrLen     = sBinHex.length();
+        int nStrLen = sBinHex.length();
         int nAvailBytes = (nStrLen - nSrcPos) >> 1;
 
         if (nAvailBytes < nNumOfBytes)
@@ -176,7 +184,7 @@
 
         for (int nI = 0; nI < nNumOfBytes; nI++)
         {
-            byte    bActByte    = 0;
+            byte bActByte = 0;
             boolean blConvertOK = true;
 
             for (int nJ = 0; nJ < 2; nJ++)
@@ -208,11 +216,12 @@
     }
 
     /**
-     *  converts a byte array into an UNICODE string
-     *  @param data the byte array
-     *  @param nStartPos where to begin the conversion
-     *  @param nNumOfBytes number of bytes to handle
-     *  @return the string
+     * converts a byte array into an UNICODE string
+     *
+     * @param data        the byte array
+     * @param nStartPos   where to begin the conversion
+     * @param nNumOfBytes number of bytes to handle
+     * @return the string
      */
     public static String byteArrayToUNCString(byte[] data, int nStartPos, int nNumOfBytes)
     {
@@ -236,7 +245,7 @@
         while (nNumOfBytes > 0)
         {
             sbuf.setCharAt(nSBufPos++, (char) (((int) data[nStartPos] << 8) | ((int) data[nStartPos + 1] & 0x0ff)));
-            nStartPos   += 2;
+            nStartPos += 2;
             nNumOfBytes -= 2;
         }
 
@@ -245,20 +254,20 @@
 
     public static long[] marshalByteArray(byte[] raws, boolean hasSignature)
     {
-        int        remainder = raws.length % 8;
-        ByteBuffer rawData   = ByteBuffer.wrap(raws);
+        int remainder = raws.length % 8;
+        ByteBuffer rawData = ByteBuffer.wrap(raws);
 
         rawData.rewind();
         rawData.order(ByteOrder.LITTLE_ENDIAN);
 
         LongBuffer longBuffer = ((ByteBuffer) rawData.rewind()).asLongBuffer();
-        int        resultSize = longBuffer.limit() + ((remainder != 0)
-            ? 1
-            : 0) + (hasSignature
-                    ? 1
-                    : 0);
-        long[]     result     = new long[resultSize];
-        int        i          = 0;
+        int resultSize = longBuffer.limit() + ((remainder != 0)
+                ? 1
+                : 0) + (hasSignature
+                ? 1
+                : 0);
+        long[] result = new long[resultSize];
+        int i = 0;
 
         if (hasSignature)
         {
@@ -275,8 +284,8 @@
         if (remainder != 0)
         {
             int pos = (i - (hasSignature
-                            ? 1
-                            : 0)) * 8;
+                    ? 1
+                    : 0)) * 8;
 
             // int pos = rawData.position();
             byte[] temp = new byte[8];
@@ -295,11 +304,11 @@
 
     public static byte[] unmarshalByteArray(long[] raws, boolean hasSignature)
     {
-        LongBuffer longBuffer       = LongBuffer.wrap(raws);
-        int        resultBufferSize = (raws.length - (hasSignature
-            ? 1
-            : 0)) * 8;
-        int        resultSize       = resultBufferSize;
+        LongBuffer longBuffer = LongBuffer.wrap(raws);
+        int resultBufferSize = (raws.length - (hasSignature
+                ? 1
+                : 0)) * 8;
+        int resultSize = resultBufferSize;
 
         if (hasSignature)
         {
diff --git a/ximple-spatialjob/src/main/java/com/ximple/eofms/util/Bits.java b/ximple-spatialjob/src/main/java/com/ximple/eofms/util/Bits.java
index 092569c..5e529ac 100644
--- a/ximple-spatialjob/src/main/java/com/ximple/eofms/util/Bits.java
+++ b/ximple-spatialjob/src/main/java/com/ximple/eofms/util/Bits.java
@@ -6,7 +6,6 @@
 import java.security.AccessController;
 import java.security.PrivilegedAction;
 
-import sun.misc.Unsafe;
 import sun.misc.VM;
 
 /**
@@ -22,17 +21,17 @@
 
     // -- Processor and memory-system properties --
     private static ByteOrder byteOrder = null;
-    private static int       pageSize  = -1;
-    private static boolean   unaligned;
-    private static boolean   unalignedKnown = false;
+    private static int pageSize = -1;
+    private static boolean unaligned;
+    private static boolean unalignedKnown = false;
 
     // -- Direct memory management --
     // A user-settable upper limit on the maximum amount of allocatable
-//  direct buffer memory. This value may be changed during VM
+    // direct buffer memory. This value may be changed during VM
     // initialization if it is launched with "-XX:MaxDirectMemorySize=<size>".
-    private static volatile long maxMemory      = VM.maxDirectMemory();
+    private static volatile long maxMemory = VM.maxDirectMemory();
     private static volatile long reservedMemory = 0;
-    private static boolean       memoryLimitSet = false;
+    private static boolean memoryLimitSet = false;
 
     private Bits()
     {
@@ -147,14 +146,14 @@
 
     public static int getHiInt(long qwValue)
     {
-        return ((int)(qwValue >>> 32));
+        return ((int) (qwValue >>> 32));
     }
 
     public static int getLoInt(long qwValue)
     {
         return ((int) (qwValue & 0xFFFFFFFF));
     }
-    
+
     private static byte long7(long x)
     {
         return (byte) (x >> 56);
@@ -253,6 +252,7 @@
         return byteOrder;
     }
     */
+
     static boolean unaligned()
     {
         if (unalignedKnown)
@@ -260,10 +260,10 @@
             return unaligned;
         }
 
-        PrivilegedAction pa   = new sun.security.action.GetPropertyAction("os.arch");
-        String           arch = (String) AccessController.doPrivileged(pa);
+        PrivilegedAction pa = new sun.security.action.GetPropertyAction("os.arch");
+        String arch = (String) AccessController.doPrivileged(pa);
 
-        unaligned      = arch.equals("i386") || arch.equals("x86");
+        unaligned = arch.equals("i386") || arch.equals("x86");
         unalignedKnown = true;
 
         return unaligned;
@@ -278,7 +278,7 @@
         {
             if (!memoryLimitSet && VM.isBooted())
             {
-                maxMemory      = VM.maxDirectMemory();
+                maxMemory = VM.maxDirectMemory();
                 memoryLimitSet = true;
             }
 
@@ -317,7 +317,7 @@
         if (reservedMemory > 0)
         {
             reservedMemory -= size;
-            assert(reservedMemory > -1);
+            assert (reservedMemory > -1);
         }
     }
 }

--
Gitblit v0.0.0-SNAPSHOT