Class UserStringCompositePK

java.lang.Object
net.solarnetwork.central.domain.BasePK
net.solarnetwork.central.domain.UserStringCompositePK
All Implemented Interfaces:
Serializable, Cloneable, Comparable<UserStringCompositePK>, CompositeKey, CompositeKey2<Long,String>, UserIdRelated

public final class UserStringCompositePK extends BasePK implements Serializable, Cloneable, Comparable<UserStringCompositePK>, CompositeKey2<Long,String>, UserIdRelated
Immutable primary key for user-related entities using a String entity key.
See Also:
  • Field Details

    • UNASSIGNED_USER_ID

      public static final Long UNASSIGNED_USER_ID
      A special "not a value" instance to be used for generated user ID values yet to be generated.
    • UNASSIGNED_ENTITY_ID

      public static final String UNASSIGNED_ENTITY_ID
      A special "not a value" instance to be used for generated entity ID values yet to be generated.
      See Also:
  • Constructor Details

    • UserStringCompositePK

      public UserStringCompositePK(Long userId, String entityId)
      Constructor.
      Parameters:
      userId - the user ID
      entityId - the entity ID
      Throws:
      IllegalArgumentException - if any argument is null
  • Method Details

    • unassignedEntityIdKey

      public static UserStringCompositePK unassignedEntityIdKey(Long userId)
      Create a new instance using the "unassigned" entity ID value.
      Parameters:
      userId - the ID of the user to use
      Returns:
      the new key instance
    • compareTo

      public int compareTo(UserStringCompositePK o)
      Specified by:
      compareTo in interface Comparable<UserStringCompositePK>
    • populateIdValue

      protected void populateIdValue(StringBuilder buf)
      Description copied from class: BasePK
      Populate a string builder with an ID value.

      This method is called from BasePK.getId().

      Specified by:
      populateIdValue in class BasePK
      Parameters:
      buf - the buffer to populate
    • populateStringValue

      protected void populateStringValue(StringBuilder buf)
      Description copied from class: BasePK
      Populate a string builder with a friendly string value.

      This method is called from BasePK.toString(). The buffer will be initially empty when invoked.

      Specified by:
      populateStringValue in class BasePK
      Parameters:
      buf - the buffer to populate
    • clone

      protected UserStringCompositePK clone()
      Overrides:
      clone in class BasePK
    • hashCode

      public int hashCode()
      Overrides:
      hashCode in class Object
    • equals

      public boolean equals(Object obj)
      Overrides:
      equals in class Object
    • ident

      public String ident()
      Get a short identifier string.

      The format of the returned string is (userId,entityId).

      Returns:
      the identifier
    • getUserId

      public final Long getUserId()
      Get the user ID.
      Specified by:
      getUserId in interface UserIdRelated
      Returns:
      the user ID
    • getEntityId

      public final String getEntityId()
      Get the entity ID.
      Returns:
      the entity ID
    • keyComponent1

      public final Long keyComponent1()
      Description copied from interface: CompositeKey2
      Get the first key component.
      Specified by:
      keyComponent1 in interface CompositeKey2<Long,String>
      Returns:
      the first key component
    • keyComponent2

      public final String keyComponent2()
      Description copied from interface: CompositeKey2
      Get the second key component.
      Specified by:
      keyComponent2 in interface CompositeKey2<Long,String>
      Returns:
      the second key component
    • keyComponentIsAssigned

      public final boolean keyComponentIsAssigned(int index)
      Description copied from interface: CompositeKey
      Test if a given key component is assigned a value or not.

      This method is designed to support cases when the key component is generated by an external system (such as a database) but the value is not allowed to be null. In this situation a placeholder value representing "not a value" can be used, and this method should return false if that value has been set on the instance.

      Specified by:
      keyComponentIsAssigned in interface CompositeKey
      Specified by:
      keyComponentIsAssigned in interface CompositeKey2<Long,String>
      Parameters:
      index - the component index to test, starting from 0
      Returns:
      true if the key component's value should be considered "assigned", false otherwise
    • userIdIsAssigned

      public final boolean userIdIsAssigned()
      Test if the user ID is assigned.
      Returns:
      true if the user ID value is assigned, false if it is considered "not a value"
    • entityIdIsAssigned

      public final boolean entityIdIsAssigned()
      Test if the entity ID is assigned.
      Returns:
      true if the entity ID value is assigned, false if it is considered "not a value"
    • keyComponentValue

      public <T> T keyComponentValue(int index, Object val)
      Description copied from interface: CompositeKey
      Convert a value into a key component value.
      Specified by:
      keyComponentValue in interface CompositeKey
      Type Parameters:
      T - the expected key component type
      Parameters:
      index - the index of the key component to convert the value for
      val - the value to convert, or null to use an "unassigned" value
      Returns:
      the key component value
    • createKey

      public UserStringCompositePK createKey(CompositeKey template, Object... components)
      Description copied from interface: CompositeKey
      Create a new key instance based on a template and component arguments.

      If less component values are provided than the length of the given key type, then "unassigned" values will be used for those components.

      Specified by:
      createKey in interface CompositeKey
      Parameters:
      template - the template key, or the implementation may support null to create a new key from scratch, or else UnsupportedOperationException will be thrown
      components - the component values to use
      Returns:
      the new key instance