Package net.solarnetwork.central.domain
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 Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprotected UserLongCompositePKclone()intcreateKey(CompositeKey template, Object... components) Create a new key instance based on a template and component arguments.final booleanTest if the entity ID is assigned.booleanfinal StringGet the entity ID.final LongGet the user ID.final booleanTest if the group ID is assigned.inthashCode()ident()Get a short identifier string.final LongGet the first key component.final StringGet the second key component.final booleankeyComponentIsAssigned(int index) Test if a given key component is assigned a value or not.<T> TkeyComponentValue(int index, Object val) Convert a value into a key component value.protected voidPopulate a string builder with an ID value.protected voidPopulate a string builder with a friendly string value.static LongStringCompositePKunassignedEntityIdKey(Long groupId) Create a new instance using the "unassigned" entity ID value.Methods inherited from class java.lang.Object
finalize, getClass, notify, notifyAll, wait, wait, waitMethods inherited from interface net.solarnetwork.central.domain.CompositeKey2
keyComponent, keyComponentLength
-
Field Details
-
UNASSIGNED_GROUP_ID
A special "not a value" instance to be used for generated group ID values yet to be generated. -
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
Constructor.- Parameters:
groupId- the user IDentityId- the entity ID- Throws:
IllegalArgumentException- if any argument is null
-
-
Method Details
-
unassignedEntityIdKey
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
- Specified by:
compareToin interfaceComparable<LongStringCompositePK>
-
populateIdValue
Description copied from class:BasePKPopulate a string builder with an ID value.This method is called from
BasePK.getId().- Specified by:
populateIdValuein classBasePK- Parameters:
buf- the buffer to populate
-
populateStringValue
Description copied from class:BasePKPopulate 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:
populateStringValuein classBasePK- Parameters:
buf- the buffer to populate
-
clone
-
hashCode
public int hashCode() -
equals
-
ident
Get a short identifier string.The format of the returned string is
(groupId,entityId).- Returns:
- the identifier
-
getGroupId
Get the user ID.- Returns:
- the user ID
-
getEntityId
Get the entity ID.- Returns:
- the entity ID
-
keyComponent1
Description copied from interface:CompositeKey2Get the first key component.- Specified by:
keyComponent1in interfaceCompositeKey2<Long,String> - Returns:
- the first key component
-
keyComponent2
Description copied from interface:CompositeKey2Get the second key component.- Specified by:
keyComponent2in interfaceCompositeKey2<Long,String> - Returns:
- the second key component
-
keyComponentIsAssigned
public final boolean keyComponentIsAssigned(int index) Description copied from interface:CompositeKeyTest 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:
keyComponentIsAssignedin interfaceCompositeKey- Specified by:
keyComponentIsAssignedin interfaceCompositeKey2<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
Description copied from interface:CompositeKeyConvert a value into a key component value.- Specified by:
keyComponentValuein interfaceCompositeKey- Type Parameters:
T- the expected key component type- Parameters:
index- the index of the key component to convert the value forval- the value to convert, or null to use an "unassigned" value- Returns:
- the key component value
-
createKey
Description copied from interface:CompositeKeyCreate 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:
createKeyin interfaceCompositeKey- Parameters:
template- the template key, or the implementation may support null to create a new key from scratch, or elseUnsupportedOperationExceptionwill be throwncomponents- the component values to use- Returns:
- the new key instance
-