public class HGUtils extends Object
The mandatory bag of static utility method class.
Modifier and Type | Field and Description |
---|---|
static HGPersistentHandle[] |
EMPTY_HANDLE_ARRAY |
Constructor and Description |
---|
HGUtils() |
Modifier and Type | Method and Description |
---|---|
static <T> T |
cloneObject(T p,
Mapping<Pair<Object,String>,Boolean> propertyFilter) |
static void |
closeNoException(HGSearchResult<?> rs) |
static void |
directoryRecurse(File top,
Mapping<File,Boolean> mapping) |
static void |
dropHyperGraphInstance(String location)
Delete a
HyperGraph by removing the filesystem directory that holds it. |
static boolean |
eq(byte[] left,
byte[] right) |
static boolean |
eq(Object[] left,
Object[] right)
Compare two arrays for equality.
|
static boolean |
eq(Object left,
Object right)
Compare two objects for equality, checking for
null values as well. |
static boolean |
eq(Ref<?>[] left,
Ref<?>[] right) |
static boolean |
eq(Ref<?> r1,
Ref<?> r2) |
static ClassLoader |
getClassLoader(HGConfiguration config)
Returns the configured, the context or the class's classloader.
|
static ClassLoader |
getClassLoader(HyperGraph graph)
Returns the configured, the context or the class's classloader.
|
static <T> Class<T> |
getImplementationClass(String interfaceClassName,
String defaultImplementation) |
static <T> T |
getImplementationOf(String interfaceClassName,
String defaultImplementation) |
static Throwable |
getRootCause(Throwable t) |
static int |
hashIt(Object o)
Return an object's hash code or 0 if the object is
null . |
static int |
hashThem(Object one,
Object two)
Return a composite hash code of two objects.
|
static boolean |
isEmpty(String s) |
static <T> Class<T> |
loadClass(HGConfiguration config,
String classname)
Load a class using the class loader configured in the
HGConfiguration object, if
such a loader was configured. |
static <T> Class<T> |
loadClass(HyperGraph graph,
String classname)
Load a class using the class loader configured for the passed in
HyperGraph instance, if
such a loader was configured. |
static void |
logCallStack(PrintStream out) |
static void |
printStackTrace(StackTraceElement[] trace,
PrintStream out) |
static String |
printStackTrace(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,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 <T> Set<T> |
set(T... members) |
static void |
throwRuntimeException(Throwable t) |
static HGHandle[] |
toHandleArray(HGLink link) |
static void |
visit(Object object,
Mapping<Object,Boolean> visitor) |
static void |
wrapAndRethrow(Throwable t) |
public static final HGPersistentHandle[] EMPTY_HANDLE_ARRAY
public static boolean isEmpty(String s)
public static void throwRuntimeException(Throwable t)
public static boolean eq(Object left, Object right)
Compare two objects for equality, checking for null
values as well.
public static boolean eq(Object[] left, 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.
public static boolean eq(byte[] left, byte[] right)
public static int hashIt(Object o)
Return an object's hash code or 0 if the object is null
.
public static int hashThem(Object one, Object two)
Return a composite hash code of two objects.
public static String printStackTrace(Throwable t)
Print the full stack trace of a Throwable
object into a
string buffer and return the corresponding string.
public static void printStackTrace(StackTraceElement[] trace, PrintStream out)
public static void logCallStack(PrintStream out)
public static void closeNoException(HGSearchResult<?> rs)
public static void wrapAndRethrow(Throwable t)
public static <T> Class<T> loadClass(HyperGraph graph, String classname) throws ClassNotFoundException
Load a class using the class loader configured for the passed in HyperGraph
instance, if
such a loader was configured. If no class loader specific to the DB instance was configured, try
the thread context class loader. Finally, fall back to HGUtils.class.getClassLoader()
.
If you have a DB configured class loader that you need to override with a thread context class loader, you'd need to implement the delegating yourself.
T
- graph
- classname
- ClassNotFoundException
public static <T> Class<T> loadClass(HGConfiguration config, String classname) throws ClassNotFoundException
Load a class using the class loader configured in the HGConfiguration
object, if
such a loader was configured. If there is no class loader in the configuration, try
the thread context class loader. Finally, fall back to HGUtils.class.getClassLoader()
.
If you have a DB configured class loader that you need to override with a thread context class loader, you'd need to implement the delegating yourself.
T
- graph
- classname
- ClassNotFoundException
public static ClassLoader getClassLoader(HyperGraph graph)
graph
- public static ClassLoader getClassLoader(HGConfiguration config)
config
- public static <T> long queryBatchProcess(HGQuery<T> query, Mapping<T,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.
T
- 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.public static void dropHyperGraphInstance(String location)
Delete a HyperGraph
by removing the filesystem directory that holds it.
This method will first make sure to close the HyperGraph if it's currently open.
location
- The location of the graph instance.public static <T> Class<T> getImplementationClass(String interfaceClassName, String defaultImplementation)
public static <T> T getImplementationOf(String interfaceClassName, String defaultImplementation)
public static <T> Set<T> set(T... members)
public static <T> T cloneObject(T p, Mapping<Pair<Object,String>,Boolean> propertyFilter) throws Exception
Exception
Copyright © 2015. All rights reserved.