public class Util
extends java.lang.Object
| Constructor and Description |
|---|
Util() |
| Modifier and Type | Method and Description |
|---|---|
protected static java.lang.Object |
deepCopy(java.lang.Object fromBean)
A utility method that creates a deep clone of the specified object.
|
static void |
delete(java.io.File f)
Utility to delete directory recursively
|
protected static java.lang.String |
determineCollectionName(java.lang.Class<?> entityClass)
A utility method to determine the collection name for a given entity class.
|
protected static <T> java.lang.String |
determineEntityCollectionName(T obj) |
protected static void |
ensureNotRestricted(java.lang.Object o) |
protected static java.lang.Object |
getIdForEntity(java.lang.Object document,
java.lang.reflect.Method getterMethodForId)
A utility method to extract the value of field marked by the @Id annotation using its
getter/accessor method.
|
static java.util.List<java.lang.Integer> |
getSliceIndexes(java.lang.String slice,
int size)
Utility method to compute the indexes to select based on slice string
|
static boolean |
isSliceable(java.lang.String slice) |
protected static java.lang.Object |
setFieldValueForEntity(java.lang.Object document,
java.lang.Object newValue,
java.lang.reflect.Method setterMethod) |
protected static java.lang.Object |
setIdForEntity(java.lang.Object document,
java.lang.reflect.Method setterMethodForId)
A utility method to set the value of field marked by the @Id annotation using its
setter/mutator method.
|
static boolean |
stampVersion(JsonDBConfig dbConfig,
java.io.File f,
java.lang.String version)
Utility to stamp the version into a newly created .json File
This method is expected to be invoked on a newly created .json file before it is usable.
|
protected static void ensureNotRestricted(java.lang.Object o)
protected static <T> java.lang.String determineEntityCollectionName(T obj)
protected static java.lang.String determineCollectionName(java.lang.Class<?> entityClass)
Document on this class.
If found then we know the collection name else it throws a exceptionentityClass - class that determines the name of the collectionprotected static java.lang.Object getIdForEntity(java.lang.Object document,
java.lang.reflect.Method getterMethodForId)
document - the actual Object representing the POJO we want the Id of.getterMethodForId - the Method that is the accessor for the attributed with @Id annotationprotected static java.lang.Object setIdForEntity(java.lang.Object document,
java.lang.reflect.Method setterMethodForId)
document - the actual Object representing the POJO we want the Id to be set for.setterMethodForId - the Method that is the mutator for the attributed with @Id annotationprotected static java.lang.Object setFieldValueForEntity(java.lang.Object document,
java.lang.Object newValue,
java.lang.reflect.Method setterMethod)
protected static java.lang.Object deepCopy(java.lang.Object fromBean)
fromBean - java bean to be cloned.public static boolean stampVersion(JsonDBConfig dbConfig, java.io.File f, java.lang.String version)
dbConfig - all the settings used by Json DBf - the target .json file on which to stamp the versionversion - the actual version string to stamppublic static void delete(java.io.File f)
f - File object representing the directory to recursively deletepublic static boolean isSliceable(java.lang.String slice)
public static java.util.List<java.lang.Integer> getSliceIndexes(java.lang.String slice,
int size)
slice - select the indices in some slice_target list or array, should be a valid slice string
The behaviour of this slicing feature is similar to
the slicing feature in python or numpy, as much as possible
https://docs.scipy.org/doc/numpy-1.13.0/reference/arrays.indexing.html
A slice is a string notation and the basic slice syntax is i:j:k, where i is the starting index,
j is the stopping index, and k is the step (k != 0). In other words it is start:stop:step
Example slice_target = [T0, T1, T2, T3, T4, T5, T6, T7, T8, T9]
slice = "1:7:2" returns [T1, T3, T5]
i is inclusive, j is exclusive
Negative i and j are interpreted as n + i and n + j where n is the number of elements found. Negative
k makes stepping go towards smaller indices.
Example slice_target = [T0, T1, T2, T3, T4, T5, T6, T7, T8, T9]
slice = "-2:10" returns [T8, T9]
slice = "-3:3:-1" returns [T7, T6, T5, T4]
Assume n is the number of elements in slice_target. Then, if i is not given it defaults to 0
for k>0 and n - 1 for k<0 . If j is not given it defaults to n for k>0 and -n-1 for k<0 .
If k is not given it defaults to 1. Note that :: is the same as : and means select all indices
from slice_target.
Example slice_target = [T0, T1, T2, T3, T4, T5, T6, T7, T8, T9]
slice = "5:" returns [T5, T6, T7, T8, T9]
Assume n is the number of elements in slice_target. Then, if j>n then it is considered as n, in case
of negative j it is considered -n.size - size of the array from which a slice is to extracted