Class DefaultIDed<I>

  • All Implemented Interfaces:
    IDed<I>
    Direct Known Subclasses:
    AbstractPrincipal, DefaultIDNamed

    public class DefaultIDed<I>
    extends java.lang.Object
    implements IDed<I>
    A default implementation of a uniquely identified object. This class is useful to serve as a base class to other classes that are identified by an ID. It provides equality checking based upon the ID.

    This implementation provides the capability to provide automatic conversion of the ID when the ID is set, such as converting to lowercase.

    Author:
    Garret Wilson
    See Also:
    Object.equals(java.lang.Object)
    • Constructor Summary

      Constructors 
      Constructor Description
      DefaultIDed​(I id)
      Constructor specifying the ID.
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      boolean equals​(java.lang.Object object)
      Considers another object equal if the other object is an IDed with the same ID.
      I getID()  
      int hashCode()  
      protected void setID​(I id)
      Sets the identifier of the object.
      java.lang.String toString()  
      • Methods inherited from class java.lang.Object

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

      • DefaultIDed

        public DefaultIDed​(I id)
        Constructor specifying the ID.
        Parameters:
        id - The ID of the object.
    • Method Detail

      • getID

        public I getID()
        Specified by:
        getID in interface IDed<I>
        Returns:
        The identifier, preferably unique, of the object; or null if the object has no ID.
      • setID

        protected void setID​(I id)
        Sets the identifier of the object.
        Parameters:
        id - The identifier, preferably unique, of the object; or null if the object has no ID.
      • equals

        public boolean equals​(java.lang.Object object)
        Considers another object equal if the other object is an IDed with the same ID.
        Overrides:
        equals in class java.lang.Object
        Parameters:
        object - The object with which to compare this object; should be an IDed.
        Returns:
        true if the given object is an IDed with the same ID.
        See Also:
        getID()
      • hashCode

        public int hashCode()
        Overrides:
        hashCode in class java.lang.Object
        Returns:
        A hashcode value from the ID.
      • toString

        public java.lang.String toString()
        Overrides:
        toString in class java.lang.Object
        Returns:
        A string representation of this object in the format "objectinfo: [ID]".