Class StoreUtil

  • All Implemented Interfaces:
    StoreConstants

    public class StoreUtil
    extends java.lang.Object
    implements StoreConstants
    This class contains static utility methods
    Author:
    Olivier Dedieu
    • Constructor Detail

      • StoreUtil

        public StoreUtil()
    • 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 interface
        attName - 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 field
        field - 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 field
        field - the field to set
        fieldValue - 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 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​(java.lang.Class<T> clazz,
                                         java.lang.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 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)
      • encodeStorable

        public static java.lang.String encodeStorable​(Storable storable,
                                                      Store store)
      • decodeStorable

        public static Storable decodeStorable​(java.lang.String id,
                                              Store store)
      • 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 StampTable
        urid - 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 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