Class TechKey

  • All Implemented Interfaces:
    java.io.Serializable

    public final class TechKey
    extends java.lang.Object
    implements java.io.Serializable
    Class representing the concept of an unique identifier for an object. The key may be a database primary key, a GUID or some other identifier.
    See Also:
    Serialized Form
    • Field Summary

      Fields 
      Modifier and Type Field Description
      static TechKey EMPTY_KEY
      An empty TechKey.
    • Constructor Summary

      Constructors 
      Constructor Description
      TechKey​(java.lang.String id)
      Creates a new instance by providing a string representation of the key.
    • Method Summary

      All Methods Static Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      boolean equals​(java.lang.Object o)
      Compares this TechKey to the specified object.
      static TechKey fromUUIDString​(java.lang.String uuidString)
      Creates a new unique technical key using as GUID with length 32 using the UUID string format.
      static TechKey generateKey()
      Creates a new unique technical key using as GUID with length 32 using the class UUID.
      java.lang.String getIdAsString()
      Retrieves the id as a String.
      int hashCode()
      Returns the hash code of the key.
      static boolean isEmpty​(TechKey techKey)
      Checks if the passed TechKey instance is empty.
      boolean isInitial()
      Tells you, whether the actual key is initial or not.
      java.lang.String toString()
      Returns the string representation of the TechKey.
      java.lang.String toUUIDString()
      Returns the UUID string representation of the given object.
      • Methods inherited from class java.lang.Object

        clone, finalize, getClass, notify, notifyAll, wait, wait, wait
    • Field Detail

      • EMPTY_KEY

        public static final TechKey EMPTY_KEY
        An empty TechKey. Use this if you need an empty technical key for your purposes. Do not create them with new TechKey(""). If you ask this key if its initial it says "yes I am".
    • Constructor Detail

      • TechKey

        public TechKey​(java.lang.String id)
        Creates a new instance by providing a string representation of the key. Do not create new technical keys using new TechKey(null) but use the defined static final EMPTY_KEY.
        Parameters:
        id - key to be used for the construction
    • Method Detail

      • isInitial

        public boolean isInitial()
        Tells you, whether the actual key is initial or not.
        Returns:
        true if the key is initial or false if its not.
      • getIdAsString

        public java.lang.String getIdAsString()
        Retrieves the id as a String.
        Returns:
        String representation of the key
      • isEmpty

        public static boolean isEmpty​(TechKey techKey)
        Checks if the passed TechKey instance is empty.

        It is empty, if the id is null or if the content as String contains whitespaces only.

        Parameters:
        techKey - TechKey instance
        Returns:
        true if the provided techKey is empty
      • toString

        public java.lang.String toString()
        Returns the string representation of the TechKey.
        Overrides:
        toString in class java.lang.Object
        Returns:
        String string representation
      • toUUIDString

        public java.lang.String toUUIDString()
        Returns the UUID string representation of the given object.

        Example: 12345678-9012-3456-7890-1234567890AB

        Returns:
        UUID String representation
      • hashCode

        public int hashCode()
        Returns the hash code of the key.
        Overrides:
        hashCode in class java.lang.Object
        Returns:
        hash code
      • equals

        public boolean equals​(java.lang.Object o)
        Compares this TechKey to the specified object. The result is true if and only if the argument is not null and is a TechKey object that represents the same key value as this object.
        Overrides:
        equals in class java.lang.Object
        Parameters:
        o - object to compare with
        Returns:
        true if the keys are identical; otherwise false.
      • generateKey

        public static TechKey generateKey()
        Creates a new unique technical key using as GUID with length 32 using the class UUID.
        Returns:
        new unique technical key
      • fromUUIDString

        public static TechKey fromUUIDString​(java.lang.String uuidString)
        Creates a new unique technical key using as GUID with length 32 using the UUID string format.
        Parameters:
        uuidString - UUID formatted String
        Returns:
        new unique technical key