Class DefaultComparableIDNamed<I,​N extends java.lang.Comparable<N>>

  • All Implemented Interfaces:
    IDed<I>, Named<N>, java.lang.Comparable<Named<N>>

    public class DefaultComparableIDNamed<I,​N extends java.lang.Comparable<N>>
    extends DefaultComparableNamed<N>
    implements IDed<I>, java.lang.Comparable<Named<N>>
    A default implementation of an IDed and named object comparable by name. This implementation does not allow a null name. Note: Because this class considers equality by ID and order by name, this class has a natural ordering that is inconsistent with equals.
    Author:
    Garret Wilson
    • Constructor Summary

      Constructors 
      Constructor Description
      DefaultComparableIDNamed​(I id, N name)
      Constructor specifying the ID and name.
    • 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()  
      java.lang.String toString()  
      • Methods inherited from class java.lang.Object

        clone, finalize, getClass, notify, notifyAll, wait, wait, wait
      • Methods inherited from interface java.lang.Comparable

        compareTo
    • Constructor Detail

      • DefaultComparableIDNamed

        public DefaultComparableIDNamed​(I id,
                                        N name)
        Constructor specifying the ID and name.
        Parameters:
        id - The ID of the object, or null if the object should have no ID.
        name - The name of the object.
        Throws:
        java.lang.NullPointerException - if the given name is null.
    • 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.
      • 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 DefaultNamed<N extends java.lang.Comparable<N>>
        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 DefaultNamed<N extends java.lang.Comparable<N>>
        Returns:
        A hashcode value from the ID.
      • toString

        public java.lang.String toString()
        Overrides:
        toString in class DefaultNamed<N extends java.lang.Comparable<N>>
        Returns:
        A string representation of this object in the format "objectinfo: [ID]".