Class StoreUtil

java.lang.Object
com.jalios.jstore.StoreUtil
All Implemented Interfaces:
StoreConstants

public class StoreUtil extends Object implements StoreConstants
This class contains static utility methods
Author:
Olivier Dedieu
  • Constructor Details

    • StoreUtil

      public StoreUtil()
  • Method Details

    • generateUrid

      public static String generateUrid()
      Generates an URID based on the local hostname
      Returns:
      the URID
      Since:
      jcms-4.0.2
    • checkUrid

      public static boolean checkUrid(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(String[] args)
    • getGetterMethodName

      public static String getGetterMethodName(Field field)
      Parameters:
      field - the field
      Returns:
      the getter method name
      See Also:
    • getSetterMethodName

      public static String getSetterMethodName(Field field)
      Parameters:
      field - the field
      Returns:
      the setter method name
      See Also:
    • getField

      public static Field getField(Class<?> clazz, 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 interface
      attName - the name of the desired field
      Returns:
      the field instance
    • getFieldValue

      public static Object getFieldValue(Object instance, Field field)
      Parameters:
      instance - the instance containing the field
      field - the requested field
      Returns:
      the value of the field
      See Also:
    • setFieldValue

      public static void setFieldValue(Storable storable, Field field, Object fieldValue)
      Parameters:
      storable - the instance containing the field
      field - the field to set
      fieldValue - the new field value
      See Also:
    • encodeObject

      public static String encodeObject(Object obj, Store store)
      Generic object encoder
      Parameters:
      obj - the object to encode
      store - 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(Class<T> clazz, String objStr, Store store, DecodeContext ctxt)
      Generic object decoder
      Parameters:
      clazz - the object's class to decode
      objStr - the encoding representation of the object
      store - 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 String encodeBooleanArray(boolean[] array)
    • decodeBooleanArray

      public static boolean[] decodeBooleanArray(String arrayStr)
    • encodeByteArray

      public static String encodeByteArray(byte[] array)
    • decodeByteArray

      public static byte[] decodeByteArray(String arrayStr)
    • encodeCharArray

      public static String encodeCharArray(char[] array)
    • decodeCharArray

      public static char[] decodeCharArray(String arrayStr)
    • encodeDoubleArray

      public static String encodeDoubleArray(double[] array)
    • decodeDoubleArray

      public static double[] decodeDoubleArray(String arrayStr)
    • encodeFloatArray

      public static String encodeFloatArray(float[] array)
    • decodeFloatArray

      public static float[] decodeFloatArray(String arrayStr)
    • encodeIntArray

      public static String encodeIntArray(int[] array)
    • decodeIntArray

      public static int[] decodeIntArray(String arrayStr)
    • encodeLongArray

      public static String encodeLongArray(long[] array)
    • decodeLongArray

      public static long[] decodeLongArray(String arrayStr)
    • encodeShortArray

      public static String encodeShortArray(short[] array)
    • decodeShortArray

      public static short[] decodeShortArray(String arrayStr)
    • encodeObjectArray

      public static String encodeObjectArray(Object[] array, Store store)
    • decodeObjectArray

      public static Object[] decodeObjectArray(String arrayStr, Class<?> componentType, Store store)
    • decodeObjectArray

      public static Object[] decodeObjectArray(String arrayStr, Class<?> componentType, Store store, DecodeContext ctxt)
    • encodeStorable

      public static String encodeStorable(Storable storable, Store store)
    • decodeStorable

      public static Storable decodeStorable(String id, Store store)
    • encodeDate

      public static String encodeDate(Date date)
    • decodeDate

      public static Date decodeDate(String dateStr)
    • encodeZoneId

      public static String encodeZoneId(ZoneId zoneId)
    • decodeZoneId

      public static ZoneId decodeZoneId(String objStr, DecodeContext ctxt)
    • encodeClass

      public static String encodeClass(Class<?> clazz)
    • decodeClass

      public static Class<?> decodeClass(String classStr, Store store)
    • encodeProperties

      public static String encodeProperties(Properties properties)
    • decodeProperties

      public static Properties decodeProperties(String propertiesStr, DecodeContext ctxt)
    • encodeCollection

      public static String encodeCollection(Collection<?> coll, Store store)
    • decodeCollection

      public static Collection<?> decodeCollection(String collStr, Store store, Collection<Object> coll, DecodeContext ctxt)
    • encodeArrayList

      public static String encodeArrayList(ArrayList<?> list, Store store)
    • decodeArrayList

      public static ArrayList<?> decodeArrayList(String listStr, Store store, DecodeContext ctxt)
    • encodeLinkedList

      public static String encodeLinkedList(LinkedList<?> list, Store store)
    • decodeLinkedList

      public static LinkedList<?> decodeLinkedList(String listStr, Store store, DecodeContext ctxt)
    • encodeVector

      public static String encodeVector(Vector<?> vector, Store store)
    • decodeVector

      public static Vector<?> decodeVector(String vectorStr, Store store, DecodeContext ctxt)
    • encodeHashSet

      public static String encodeHashSet(HashSet<?> set, Store store)
    • decodeHashSet

      public static HashSet<?> decodeHashSet(String setStr, Store store, DecodeContext ctxt)
    • encodeTreeSet

      public static String encodeTreeSet(TreeSet<?> set, Store store)
    • decodeTreeSet

      public static TreeSet<?> decodeTreeSet(String setStr, Store store, DecodeContext ctxt)
    • encodeMap

      public static String encodeMap(Map<?,?> map, Store store)
    • decodeMap

      public static Map<?,?> decodeMap(String mapStr, Store store, Map<Object,Object> map, DecodeContext ctxt)
    • encodeLinkedHashMap

      public static String encodeLinkedHashMap(LinkedHashMap<?,?> map, Store store)
    • decodeLinkedHashMap

      public static LinkedHashMap<?,?> decodeLinkedHashMap(String mapStr, Store store, DecodeContext ctxt)
    • encodeHashMap

      public static String encodeHashMap(HashMap<?,?> map, Store store)
    • decodeHashMap

      public static HashMap<?,?> decodeHashMap(String mapStr, Store store, DecodeContext ctxt)
    • encodeHashtable

      public static String encodeHashtable(Hashtable<?,?> map, Store store)
    • decodeHashtable

      public static Hashtable<?,?> decodeHashtable(String mapStr, Store store, DecodeContext ctxt)
    • encodeTreeMap

      public static String encodeTreeMap(TreeMap<?,?> map, Store store)
    • decodeTreeMap

      public static TreeMap<?,?> decodeTreeMap(String mapStr, Store store, DecodeContext ctxt)
    • isArray

      public static boolean isArray(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(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(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(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(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(Collection<StampTable> stampTables, String urid)
      Find the minimal stamp for a given urid in a collection of StampTable
      Parameters:
      stampTables - the collection of StampTable
      urid - the urid
      Returns:
      the minimal stamp for a given urid in a collection of StampTable
    • findGCS

      public static Stamp findGCS(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 operations
      minPT - the stampTable to check
      minUnknownStamp - the minimal stamp present in a replica that the leader does not know
      Returns:
      the GCS
      Since:
      jcms-10.0.8