Class Id

java.lang.Object
com.peterphi.std.types.Id
All Implemented Interfaces:
Serializable, Comparable<Id>
Direct Known Subclasses:
SimpleId

public abstract class Id extends Object implements Comparable<Id>, Serializable
An abstract base type for a case-sensitive identifier
All implementations must directly extend this type (ie. all people who extend this type should mark their implementation as final)
It is not permitted to add any additional fields to an Id field: the sole benefit of extending an Id type is to provide clarity to what kind of Id something is
An id is never permitted to be null, nor may it be an empty String
See Also:
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    final String
    The internal value of this id; while public, this should only be required very rarely
    static final boolean
    If true the constructor for Id will verify that all Ids comply with the
  • Constructor Summary

    Constructors
    Constructor
    Description
    Id(String id)
    Constructs a new id
  • Method Summary

    Modifier and Type
    Method
    Description
    final int
    compareTo(Id that)
    Compares another Id to this id.
    final boolean
     
    final int
     
    final String
     

    Methods inherited from class java.lang.Object

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

    • SANITY_CHECK

      public static final boolean SANITY_CHECK
      If true the constructor for Id will verify that all Ids comply with the
      See Also:
    • id

      public final String id
      The internal value of this id; while public, this should only be required very rarely
  • Constructor Details

    • Id

      public Id(String id)
      Constructs a new id
      Parameters:
      id - the id value to use (may not be null)
  • Method Details

    • toString

      public final String toString()
      Overrides:
      toString in class Object
    • equals

      public final boolean equals(Object o)
      Overrides:
      equals in class Object
    • compareTo

      public final int compareTo(Id that)
      Compares another Id to this id. Two ids are only comparable if they have the exact same type: if their types are incompatible then a ClassCastException will be thrown
      If the types are comparable then the result is a case-sensitive comparison of the underlying id valued
      Specified by:
      compareTo in interface Comparable<Id>
      See Also:
    • hashCode

      public final int hashCode()
      Overrides:
      hashCode in class Object