Class DefaultResource

  • All Implemented Interfaces:
    Resource, java.lang.Comparable<Resource>
    Direct Known Subclasses:
    AbstractObjectResource, FileResource

    public class DefaultResource
    extends AbstractResource
    implements java.lang.Comparable<Resource>
    Represents the default implementation of a resource. This class provides compare functionality that sorts according to the reference URI, if available.
    Author:
    Garret Wilson
    • Constructor Detail

      • DefaultResource

        protected DefaultResource()
        Default constructor that allows the URI to be set later.
      • DefaultResource

        protected DefaultResource​(java.net.URI uri)
        URI constructor.
        Parameters:
        uri - The URI for the new resource.
    • Method Detail

      • getURI

        public java.net.URI getURI()
        Specified by:
        getURI in interface Resource
        Returns:
        The resource identifier URI, or null if the identifier is not known.
      • setURI

        public void setURI​(java.net.URI uri)
        Sets the URI of the resource.
        Parameters:
        uri - The new URI, or null if the identifier is not known.
      • compareTo

        public int compareTo​(Resource resource)
        Compares this object to another object.

        This method determines order based upon the reference URI of the resource, if any; otherwise, the hash codes of the resources are compared. The resource with no URI is sorted before a resource with a URI. The same resource will always be considered equal.

        Specified by:
        compareTo in interface java.lang.Comparable<Resource>
        Parameters:
        resource - The resource with which to compare this resource.
        Returns:
        A negative integer, zero, or a positive integer as this resource reference URI is less than, equal to, or greater than the reference URI of the specified resource, respectively.
        See Also:
        getURI(), AbstractResource.hashCode()