Class StateHelper


  • public class StateHelper
    extends Object
    Helpers for deep copy and deep diff of State objects.
    • Method Detail

      • isScalar

        public static boolean isScalar​(Object value)
        Checks if we have a base type compatible with State helper processing.
      • equalsStrict

        public static boolean equalsStrict​(Object a,
                                           Object b)
        Compares two values.
      • equalsStrict

        public static boolean equalsStrict​(State a,
                                           State b)
        Compares two States.
      • equalsStrict

        public static boolean equalsStrict​(Object[] a,
                                           Object[] b)
        Compares two arrays of scalars.
      • equalsLoose

        public static boolean equalsLoose​(Object a,
                                          Object b)
        Compares two values.

        A null value or an empty array or List is equivalent to an absent value. A null State is equivalent to an empty State (or a State containing only absent values).

      • equalsLoose

        public static boolean equalsLoose​(State a,
                                          State b)
        Compares two States.

        A null value or an empty array or List is equivalent to an absent value. A null State is equivalent to an empty State (or a State containing only absent values).

      • equalsLoose

        public static boolean equalsLoose​(Object[] a,
                                          Object[] b)
        Compares two arrays of scalars.

        null values are equivalent to empty arrays.

      • deepCopy

        public static Serializable deepCopy​(Object value)
        Makes a deep copy of a value.
      • deepCopy

        public static Serializable deepCopy​(Object value,
                                            boolean threadSafe)
        Makes a deep copy of a value, optionally thread-safe.
        Parameters:
        threadSafe - if true, then thread-safe datastructures are used
      • deepCopy

        public static State deepCopy​(State state)
        Makes a deep copy of a State map.
      • deepCopy

        public static State deepCopy​(State state,
                                     boolean threadSafe)
        Makes a deep copy of a State map, optionally thread-safe.
        Parameters:
        threadSafe - if true, then thread-safe datastructures are used
      • deepCopy

        public static List<Serializable> deepCopy​(List<Serializable> list,
                                                  boolean threadSafe)
        Makes a deep copy of a List, optionally thread-safe.
        Parameters:
        threadSafe - if true, then thread-safe datastructures are used
      • diff

        public static State.StateDiff diff​(State a,
                                           State b)
        Makes a diff copy of two State maps.

        The returned diff state contains only the key/values that changed. null values are equivalent to absent values.

        For values set to null or removed, the value is null.

        When setting a delta, the old value is checked to know if the delta should be kept or if a full value should be set instead.

        For sub-documents, a recursive diff is returned.

        Returns:
        a State.StateDiff which, when applied to a, gives b.
      • rpushOrValue

        public static Serializable rpushOrValue​(Serializable value)
        Returns a pure rpush ListDiff for the value if it's an array/list.
        Parameters:
        value - the value
        Returns:
        a pure rpush ListDiff for the value, if possible
        Since:
        11.4
      • resetDeltas

        public static void resetDeltas​(State state)
        Changes the deltas stored into actual full values.
        Since:
        6.0