Package com.jalios.jstore
Class StoreUtil
- java.lang.Object
-
- com.jalios.jstore.StoreUtil
-
- All Implemented Interfaces:
StoreConstants
public class StoreUtil extends java.lang.Object implements StoreConstants
This class contains static utility methods- Author:
- Olivier Dedieu
-
-
Field Summary
-
Fields inherited from interface com.jalios.jstore.StoreConstants
ARRAY_FLAG, CLEANING_STATE, COLLECTION_FLAG, CREATE_OP, DELETE_OP, IDLE_STATE, INNER_LOGS, INNER_MILESTONE, INNER_PREFIX, INNER_SYNC, ITEM_ESCAPE_CHAR, ITEM_SEPARATOR, LOADING_STATE, LOG_DIR_LOG_PREFIX, LOG_DIR_LOG_WORK, MAP_ASSIGN, MAP_CHARS_TO_ESCAPE, MAP_CLASS_SEPARATOR, MAP_FLAG, NAMESPACE, SH_SUFFIX, STORING_STATE, UPDATE_OP
-
-
Constructor Summary
Constructors Constructor Description StoreUtil()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static boolean
checkUrid(java.lang.String urid)
Checks if the given urid is validstatic StampTable
computeMinStampTable(java.util.Collection<StampTable> stampTables)
Computes the minimal StampTable of a collection of stampTablestatic java.util.ArrayList<?>
decodeArrayList(java.lang.String listStr, Store store, DecodeContext ctxt)
static boolean[]
decodeBooleanArray(java.lang.String arrayStr)
static byte[]
decodeByteArray(java.lang.String arrayStr)
static char[]
decodeCharArray(java.lang.String arrayStr)
static java.lang.Class<?>
decodeClass(java.lang.String classStr, Store store)
static java.util.Collection<?>
decodeCollection(java.lang.String collStr, Store store, java.util.Collection<java.lang.Object> coll, DecodeContext ctxt)
static java.util.Date
decodeDate(java.lang.String dateStr)
static double[]
decodeDoubleArray(java.lang.String arrayStr)
static float[]
decodeFloatArray(java.lang.String arrayStr)
static java.util.HashMap<?,?>
decodeHashMap(java.lang.String mapStr, Store store, DecodeContext ctxt)
static java.util.HashSet<?>
decodeHashSet(java.lang.String setStr, Store store, DecodeContext ctxt)
static java.util.Hashtable<?,?>
decodeHashtable(java.lang.String mapStr, Store store, DecodeContext ctxt)
static int[]
decodeIntArray(java.lang.String arrayStr)
static java.util.LinkedHashMap<?,?>
decodeLinkedHashMap(java.lang.String mapStr, Store store, DecodeContext ctxt)
static java.util.LinkedList<?>
decodeLinkedList(java.lang.String listStr, Store store, DecodeContext ctxt)
static long[]
decodeLongArray(java.lang.String arrayStr)
static java.util.Map<?,?>
decodeMap(java.lang.String mapStr, Store store, java.util.Map<java.lang.Object,java.lang.Object> map, DecodeContext ctxt)
static <T> T
decodeObject(java.lang.Class<T> clazz, java.lang.String objStr, Store store, DecodeContext ctxt)
Generic object decoderstatic java.lang.Object[]
decodeObjectArray(java.lang.String arrayStr, java.lang.Class<?> componentType, Store store)
static java.lang.Object[]
decodeObjectArray(java.lang.String arrayStr, java.lang.Class<?> componentType, Store store, DecodeContext ctxt)
static java.util.Properties
decodeProperties(java.lang.String propertiesStr, DecodeContext ctxt)
static short[]
decodeShortArray(java.lang.String arrayStr)
static Storable
decodeStorable(java.lang.String id, Store store)
static java.util.TreeMap<?,?>
decodeTreeMap(java.lang.String mapStr, Store store, DecodeContext ctxt)
static java.util.TreeSet<?>
decodeTreeSet(java.lang.String setStr, Store store, DecodeContext ctxt)
static java.util.Vector<?>
decodeVector(java.lang.String vectorStr, Store store, DecodeContext ctxt)
static java.time.ZoneId
decodeZoneId(java.lang.String objStr, DecodeContext ctxt)
static java.lang.String
encodeArrayList(java.util.ArrayList<?> list, Store store)
static java.lang.String
encodeBooleanArray(boolean[] array)
static java.lang.String
encodeByteArray(byte[] array)
static java.lang.String
encodeCharArray(char[] array)
static java.lang.String
encodeClass(java.lang.Class<?> clazz)
static java.lang.String
encodeCollection(java.util.Collection<?> coll, Store store)
static java.lang.String
encodeDate(java.util.Date date)
static java.lang.String
encodeDoubleArray(double[] array)
static java.lang.String
encodeFloatArray(float[] array)
static java.lang.String
encodeHashMap(java.util.HashMap<?,?> map, Store store)
static java.lang.String
encodeHashSet(java.util.HashSet<?> set, Store store)
static java.lang.String
encodeHashtable(java.util.Hashtable<?,?> map, Store store)
static java.lang.String
encodeIntArray(int[] array)
static java.lang.String
encodeLinkedHashMap(java.util.LinkedHashMap<?,?> map, Store store)
static java.lang.String
encodeLinkedList(java.util.LinkedList<?> list, Store store)
static java.lang.String
encodeLongArray(long[] array)
static java.lang.String
encodeMap(java.util.Map<?,?> map, Store store)
static java.lang.String
encodeObject(java.lang.Object obj, Store store)
Generic object encoderstatic java.lang.String
encodeObjectArray(java.lang.Object[] array, Store store)
static java.lang.String
encodeProperties(java.util.Properties properties)
static java.lang.String
encodeShortArray(short[] array)
static java.lang.String
encodeStorable(Storable storable, Store store)
static java.lang.String
encodeTreeMap(java.util.TreeMap<?,?> map, Store store)
static java.lang.String
encodeTreeSet(java.util.TreeSet<?> set, Store store)
static java.lang.String
encodeVector(java.util.Vector<?> vector, Store store)
static java.lang.String
encodeZoneId(java.time.ZoneId zoneId)
static Stamp
findGCS(java.util.List<StorableLogEntry> opList, StampTable minPT, Stamp minUnknownStamp)
Find the GCS (Greatest Common Stamp) in the given list of operations according the given stampTable.static Stamp
findMinStamp(java.util.Collection<StampTable> stampTables, java.lang.String urid)
Find the minimal stamp for a given urid in a collection of StampTablestatic java.lang.String
generateUrid()
Generates an URID based on the local hostnamestatic java.lang.reflect.Field
getField(java.lang.Class<?> clazz, java.lang.String attName)
Returns a Field object that reflects the specified declared field of the class or interface represented by this Class object.static java.lang.Object
getFieldValue(java.lang.Object instance, java.lang.reflect.Field field)
static java.lang.String
getGetterMethodName(java.lang.reflect.Field field)
static java.lang.String
getSetterMethodName(java.lang.reflect.Field field)
static boolean
isArray(java.lang.String value)
Returns true if this value is an array.static boolean
isArrayOrCollection(java.lang.String value)
Returns true if this value is an array or a collection.static boolean
isCollection(java.lang.String value)
Returns true if this value is a collection.static boolean
isMap(java.lang.String value)
Returns true if this value is a map.static void
main(java.lang.String[] args)
static void
setFieldValue(Storable storable, java.lang.reflect.Field field, java.lang.Object fieldValue)
-
-
-
Method Detail
-
generateUrid
public static java.lang.String generateUrid()
Generates an URID based on the local hostname- Returns:
- the URID
- Since:
- jcms-4.0.2
-
checkUrid
public static boolean checkUrid(java.lang.String urid)
Checks if the given urid is valid- Parameters:
urid
- the urid to be checked- Returns:
- true if the urid is valid
- Since:
- jcms-5.0.0
-
main
public static void main(java.lang.String[] args)
-
getGetterMethodName
public static java.lang.String getGetterMethodName(java.lang.reflect.Field field)
- Parameters:
field
- the field- Returns:
- the getter method name
- See Also:
ReflectUtil.getGetterMethodName(Field)
-
getSetterMethodName
public static java.lang.String getSetterMethodName(java.lang.reflect.Field field)
- Parameters:
field
- the field- Returns:
- the setter method name
- See Also:
ReflectUtil.getSetterMethodName(Field)
-
getField
public static java.lang.reflect.Field getField(java.lang.Class<?> clazz, java.lang.String attName)
Returns a Field object that reflects the specified declared field of the class or interface represented by this Class object.- Parameters:
clazz
- specifies the class or interfaceattName
- the name of the desired field- Returns:
- the field instance
-
getFieldValue
public static java.lang.Object getFieldValue(java.lang.Object instance, java.lang.reflect.Field field)
- Parameters:
instance
- the instance containing the fieldfield
- the requested field- Returns:
- the value of the field
- See Also:
ReflectUtil.getFieldValue(Object, Field)
-
setFieldValue
public static void setFieldValue(Storable storable, java.lang.reflect.Field field, java.lang.Object fieldValue)
- Parameters:
storable
- the instance containing the fieldfield
- the field to setfieldValue
- the new field value- See Also:
ReflectUtil.setFieldValue(Object, Field, Object)
-
encodeObject
public static java.lang.String encodeObject(java.lang.Object obj, Store store)
Generic object encoder- Parameters:
obj
- the object to encodestore
- the Store (use to swizzle Storable)- Returns:
- a String containing the encoded value of the object. Or null, if decoding failed.
-
decodeObject
public static <T> T decodeObject(java.lang.Class<T> clazz, java.lang.String objStr, Store store, DecodeContext ctxt)
Generic object decoder- Parameters:
clazz
- the object's class to decodeobjStr
- the encoding representation of the objectstore
- the Store (use to unswizzle Storable)ctxt
- the DecodeContext (use to have more information when reporting error)- Returns:
- the object. Or null if decoding failed.
-
encodeBooleanArray
public static java.lang.String encodeBooleanArray(boolean[] array)
-
decodeBooleanArray
public static boolean[] decodeBooleanArray(java.lang.String arrayStr)
-
encodeByteArray
public static java.lang.String encodeByteArray(byte[] array)
-
decodeByteArray
public static byte[] decodeByteArray(java.lang.String arrayStr)
-
encodeCharArray
public static java.lang.String encodeCharArray(char[] array)
-
decodeCharArray
public static char[] decodeCharArray(java.lang.String arrayStr)
-
encodeDoubleArray
public static java.lang.String encodeDoubleArray(double[] array)
-
decodeDoubleArray
public static double[] decodeDoubleArray(java.lang.String arrayStr)
-
encodeFloatArray
public static java.lang.String encodeFloatArray(float[] array)
-
decodeFloatArray
public static float[] decodeFloatArray(java.lang.String arrayStr)
-
encodeIntArray
public static java.lang.String encodeIntArray(int[] array)
-
decodeIntArray
public static int[] decodeIntArray(java.lang.String arrayStr)
-
encodeLongArray
public static java.lang.String encodeLongArray(long[] array)
-
decodeLongArray
public static long[] decodeLongArray(java.lang.String arrayStr)
-
encodeShortArray
public static java.lang.String encodeShortArray(short[] array)
-
decodeShortArray
public static short[] decodeShortArray(java.lang.String arrayStr)
-
encodeObjectArray
public static java.lang.String encodeObjectArray(java.lang.Object[] array, Store store)
-
decodeObjectArray
public static java.lang.Object[] decodeObjectArray(java.lang.String arrayStr, java.lang.Class<?> componentType, Store store)
-
decodeObjectArray
public static java.lang.Object[] decodeObjectArray(java.lang.String arrayStr, java.lang.Class<?> componentType, Store store, DecodeContext ctxt)
-
encodeDate
public static java.lang.String encodeDate(java.util.Date date)
-
decodeDate
public static java.util.Date decodeDate(java.lang.String dateStr)
-
encodeZoneId
public static java.lang.String encodeZoneId(java.time.ZoneId zoneId)
-
decodeZoneId
public static java.time.ZoneId decodeZoneId(java.lang.String objStr, DecodeContext ctxt)
-
encodeClass
public static java.lang.String encodeClass(java.lang.Class<?> clazz)
-
decodeClass
public static java.lang.Class<?> decodeClass(java.lang.String classStr, Store store)
-
encodeProperties
public static java.lang.String encodeProperties(java.util.Properties properties)
-
decodeProperties
public static java.util.Properties decodeProperties(java.lang.String propertiesStr, DecodeContext ctxt)
-
encodeCollection
public static java.lang.String encodeCollection(java.util.Collection<?> coll, Store store)
-
decodeCollection
public static java.util.Collection<?> decodeCollection(java.lang.String collStr, Store store, java.util.Collection<java.lang.Object> coll, DecodeContext ctxt)
-
encodeArrayList
public static java.lang.String encodeArrayList(java.util.ArrayList<?> list, Store store)
-
decodeArrayList
public static java.util.ArrayList<?> decodeArrayList(java.lang.String listStr, Store store, DecodeContext ctxt)
-
encodeLinkedList
public static java.lang.String encodeLinkedList(java.util.LinkedList<?> list, Store store)
-
decodeLinkedList
public static java.util.LinkedList<?> decodeLinkedList(java.lang.String listStr, Store store, DecodeContext ctxt)
-
encodeVector
public static java.lang.String encodeVector(java.util.Vector<?> vector, Store store)
-
decodeVector
public static java.util.Vector<?> decodeVector(java.lang.String vectorStr, Store store, DecodeContext ctxt)
-
encodeHashSet
public static java.lang.String encodeHashSet(java.util.HashSet<?> set, Store store)
-
decodeHashSet
public static java.util.HashSet<?> decodeHashSet(java.lang.String setStr, Store store, DecodeContext ctxt)
-
encodeTreeSet
public static java.lang.String encodeTreeSet(java.util.TreeSet<?> set, Store store)
-
decodeTreeSet
public static java.util.TreeSet<?> decodeTreeSet(java.lang.String setStr, Store store, DecodeContext ctxt)
-
encodeMap
public static java.lang.String encodeMap(java.util.Map<?,?> map, Store store)
-
decodeMap
public static java.util.Map<?,?> decodeMap(java.lang.String mapStr, Store store, java.util.Map<java.lang.Object,java.lang.Object> map, DecodeContext ctxt)
-
encodeLinkedHashMap
public static java.lang.String encodeLinkedHashMap(java.util.LinkedHashMap<?,?> map, Store store)
-
decodeLinkedHashMap
public static java.util.LinkedHashMap<?,?> decodeLinkedHashMap(java.lang.String mapStr, Store store, DecodeContext ctxt)
-
encodeHashMap
public static java.lang.String encodeHashMap(java.util.HashMap<?,?> map, Store store)
-
decodeHashMap
public static java.util.HashMap<?,?> decodeHashMap(java.lang.String mapStr, Store store, DecodeContext ctxt)
-
encodeHashtable
public static java.lang.String encodeHashtable(java.util.Hashtable<?,?> map, Store store)
-
decodeHashtable
public static java.util.Hashtable<?,?> decodeHashtable(java.lang.String mapStr, Store store, DecodeContext ctxt)
-
encodeTreeMap
public static java.lang.String encodeTreeMap(java.util.TreeMap<?,?> map, Store store)
-
decodeTreeMap
public static java.util.TreeMap<?,?> decodeTreeMap(java.lang.String mapStr, Store store, DecodeContext ctxt)
-
isArray
public static boolean isArray(java.lang.String value)
Returns true if this value is an array.- Parameters:
value
- the encoded value.- Returns:
- true if this value is an array.
- Since:
- jcms-8.0.1
-
isCollection
public static boolean isCollection(java.lang.String value)
Returns true if this value is a collection.- Parameters:
value
- the encoded value.- Returns:
- true if this value is a collection.
- Since:
- jcms-8.0.1
-
isArrayOrCollection
public static boolean isArrayOrCollection(java.lang.String value)
Returns true if this value is an array or a collection.- Parameters:
value
- the encoded value.- Returns:
- true if this value is an array or a collection.
- Since:
- jcms-8.0.1
-
isMap
public static boolean isMap(java.lang.String value)
Returns true if this value is a map.- Parameters:
value
- the encoded value.- Returns:
- true if this value is a map.
- Since:
- jcms-8.0.1
-
computeMinStampTable
public static StampTable computeMinStampTable(java.util.Collection<StampTable> stampTables)
Computes the minimal StampTable of a collection of stampTable- Parameters:
stampTables
- the collection of StampTable- Returns:
- the minimal StampTable
- Since:
- jcms-10.0.8
-
findMinStamp
public static Stamp findMinStamp(java.util.Collection<StampTable> stampTables, java.lang.String urid)
Find the minimal stamp for a given urid in a collection of StampTable- Parameters:
stampTables
- the collection of StampTableurid
- the urid- Returns:
- the minimal stamp for a given urid in a collection of StampTable
-
findGCS
public static Stamp findGCS(java.util.List<StorableLogEntry> opList, StampTable minPT, Stamp minUnknownStamp)
Find the GCS (Greatest Common Stamp) in the given list of operations according the given stampTable.- Parameters:
opList
- a list of operationsminPT
- the stampTable to checkminUnknownStamp
- the minimal stamp present in a replica that the leader does not know- Returns:
- the GCS
- Since:
- jcms-10.0.8
-
-