Class ObjectUtils

java.lang.Object
imagingbook.common.util.ObjectUtils

public abstract class ObjectUtils extends Object
Defines static methods for object copying and encoding to strings.
Version:
2022/09/11
  • Method Details

    • copy

      public static <T> T copy(T entity)
      Returns a shallow copy of the given object using reflection. This can be used if the Cloneable interface is not (or cannot be) implemented.
      Type Parameters:
      T - generic type
      Parameters:
      entity - the object to be copied
      Returns:
      the object copy
    • encodeToString

      public static String encodeToString(Object object)
      Serializes and encodes an arbitrary object to a string. This is potentially dangerous and only intended for local use, e.g., to define constant matrices with full precision. The string encoding is 'Base64' implemented with standard Java8 functionality. See decodeFromString(String) for decoding.
      Parameters:
      object - an arbitrary object
      Returns:
      the Base64 string encoding of the object
    • decodeFromString

      public static Object decodeFromString(String string)
      Decodes and deserializes an object encoded with encodeToString(Object). The type of the encoded object must be known.
      Parameters:
      string - the encoded object string
      Returns:
      the associated object (cast to the known type)