Class DefaultIDed<I>

java.lang.Object
com.globalmentor.model.DefaultIDed<I>
All Implemented Interfaces:
IDed<I>
Direct Known Subclasses:
AbstractPrincipal, DefaultIDNamed

public class DefaultIDed<I> extends 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:
  • Constructor Details

    • DefaultIDed

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

    • 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(Object object)
      Considers another object equal if the other object is an IDed with the same ID.
      Overrides:
      equals in class 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:
    • hashCode

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

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