Class LongStringCompositePK

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

public final class LongStringCompositePK extends BasePK implements Serializable, Cloneable, Comparable<LongStringCompositePK>, CompositeKey2<Long,String>
Basic implementation of a Long and String composite key.
See Also:
  • Field Details

    • UNASSIGNED_GROUP_ID

      public static final Long UNASSIGNED_GROUP_ID
      A special "not a value" instance to be used for generated group 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

    • LongStringCompositePK

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

    • unassignedEntityIdKey

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

      public int compareTo(LongStringCompositePK o)
      Specified by:
      compareTo in interface Comparable<LongStringCompositePK>
    • 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 UserLongCompositePK 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 (groupId,entityId).

      Returns:
      the identifier
    • getGroupId

      public final Long getGroupId()
      Get the user ID.
      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
    • groupIdIsAssigned

      public final boolean groupIdIsAssigned()
      Test if the group ID is assigned.
      Returns:
      true if the group 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 LongStringCompositePK 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