org.hypergraphdb.util
Class HGUtils

java.lang.Object
  extended by org.hypergraphdb.util.HGUtils

public class HGUtils
extends java.lang.Object

The mandatory bag of static utility method class.

Author:
Borislav Iordanov

Constructor Summary
HGUtils()
           
 
Method Summary
static void closeNoException(HGSearchResult<?> rs)
           
static boolean eq(byte[] left, byte[] right)
           
static boolean eq(java.lang.Object[] left, java.lang.Object[] right)
          Compare two arrays for equality.
static boolean eq(java.lang.Object left, java.lang.Object right)
           Compare two objects for equality, checking for null values as well.
static java.lang.Throwable getRootCause(java.lang.Throwable t)
           
static int hashIt(java.lang.Object o)
          Return an object's hash code or 0 if the object is null.
static int hashThem(java.lang.Object one, java.lang.Object two)
          Return a composite hash code of two objects.
static boolean isEmpty(java.lang.String s)
           
static
<T> java.lang.Class<T>
loadClass(java.lang.String classname)
           
static void logCallStack(java.io.PrintStream out)
           
static void printStackTrace(java.lang.StackTraceElement[] trace, java.io.PrintStream out)
           
static java.lang.String printStackTrace(java.lang.Throwable t)
           Print the full stack trace of a Throwable object into a string buffer and return the corresponding string.
static
<T> long
queryBatchProcess(HGQuery<T> query, Mapping<T,java.lang.Boolean> F, int batchSize, T startAfter, long first)
           Process a potentially large query result in batches where each batch is a encapsulated in a single transaction.
static java.lang.RuntimeException throwRuntimeException(java.lang.Throwable t)
           
static HGHandle[] toHandleArray(HGLink link)
           
static void wrapAndRethrow(java.lang.Throwable t)
           
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

HGUtils

public HGUtils()
Method Detail

isEmpty

public static boolean isEmpty(java.lang.String s)

throwRuntimeException

public static java.lang.RuntimeException throwRuntimeException(java.lang.Throwable t)

getRootCause

public static java.lang.Throwable getRootCause(java.lang.Throwable t)

eq

public static boolean eq(java.lang.Object left,
                         java.lang.Object right)

Compare two objects for equality, checking for null values as well.


eq

public static boolean eq(java.lang.Object[] left,
                         java.lang.Object[] right)

Compare two arrays for equality. This will perform a deep comparison, return true if and only if all elements of the passed in arrays are equal.


eq

public static boolean eq(byte[] left,
                         byte[] right)

hashIt

public static int hashIt(java.lang.Object o)

Return an object's hash code or 0 if the object is null.


hashThem

public static int hashThem(java.lang.Object one,
                           java.lang.Object two)

Return a composite hash code of two objects.


printStackTrace

public static java.lang.String printStackTrace(java.lang.Throwable t)

Print the full stack trace of a Throwable object into a string buffer and return the corresponding string.


printStackTrace

public static void printStackTrace(java.lang.StackTraceElement[] trace,
                                   java.io.PrintStream out)

logCallStack

public static void logCallStack(java.io.PrintStream out)

closeNoException

public static void closeNoException(HGSearchResult<?> rs)

wrapAndRethrow

public static void wrapAndRethrow(java.lang.Throwable t)

loadClass

public static <T> java.lang.Class<T> loadClass(java.lang.String classname)
                                    throws java.lang.ClassNotFoundException
Throws:
java.lang.ClassNotFoundException

toHandleArray

public static HGHandle[] toHandleArray(HGLink link)

queryBatchProcess

public static <T> long queryBatchProcess(HGQuery<T> query,
                                         Mapping<T,java.lang.Boolean> F,
                                         int batchSize,
                                         T startAfter,
                                         long first)

Process a potentially large query result in batches where each batch is a encapsulated in a single transaction. It is assumed that the result of the query is a HGRandomAccessResult so it is possible to quickly position at the beginning of the next batch.

The startAfter and first parameters define a starting point for the process. Use either one of them, but not both.

Type Parameters:
T -
Parameters:
query - The query that produces the result set to be scanned.
F - The function to perform on that query. The function takes a query result item and return a boolean which indicates whether to continue processing (if true) or stop (if false).
batchSize - The number of result items to encapsulate in a single transaction.
startAfter - Start processing at the first element after this parameter.
first - A 1-based index of the first element to process.
Returns:
The total number of elements processed.