Class ComponentId

  • All Implemented Interfaces:
    java.lang.Comparable<ComponentId>

    public final class ComponentId
    extends java.lang.Object
    implements java.lang.Comparable<ComponentId>
    The id of a component. Consists of a name, optionally a version, and optionally a namespace. This is an immutable value object.
    Author:
    bratseth, Tony Vaagenes
    • Constructor Detail

      • ComponentId

        public ComponentId​(java.lang.String name,
                           Version version,
                           ComponentId namespace)
      • ComponentId

        public ComponentId​(java.lang.String name,
                           Version version)
        Creates a component id from a name and version. The version may be null
      • ComponentId

        public ComponentId​(java.lang.String id)
        Creates a component id from the id string form: name(:version)?(@namespace)?, where version has the form 1(.2(.3(.identifier)?)?)? and namespace is a component id
    • Method Detail

      • getName

        public java.lang.String getName()
        Returns the name of this. This is never null
      • getVersion

        public Version getVersion()
        Returns the version of this id, or emptyVersion if no version is specified
      • getNamespace

        public ComponentId getNamespace()
        The namespace is null if this is a top level component id
      • stringValue

        public java.lang.String stringValue()
        Returns the string value of this id. If no version is given, this is simply the name. If a version is given, it is name:version. Trailing ".0"'s are stripped from the version part.
      • toString

        public java.lang.String toString()
        Overrides:
        toString in class java.lang.Object
      • equals

        public boolean equals​(java.lang.Object o)
        Overrides:
        equals in class java.lang.Object
      • hashCode

        public int hashCode()
        Overrides:
        hashCode in class java.lang.Object
      • compareTo

        public int compareTo​(ComponentId other)
        Specified by:
        compareTo in interface java.lang.Comparable<ComponentId>
      • createAnonymousComponentId

        public static ComponentId createAnonymousComponentId​(java.lang.String baseName)
        Creates a componentId that is unique for this run-time instance
      • isAnonymous

        public boolean isAnonymous()
      • withoutNamespace

        public ComponentId withoutNamespace()
        Returns a copy of this id with namespace set to null
      • fromString

        public static ComponentId fromString​(java.lang.String componentId)
        Creates a component id from the id string form: name(:version)?(@namespace)?, where version has the form 1(.2(.3(.identifier)?)?)? and namespace is a component id.
        Returns:
        new ComponentId(componentId), or null if the input string is null
      • toFileName

        public java.lang.String toFileName()
        Returns this id's stringValue (i.e the id without trailing ".0"'s) translated to a file name using the standard translation:
        
             : → -
             / → _
         
      • fromFileName

        public static ComponentId fromFileName​(java.lang.String fileName)
        Creates an id from a file first name string encoded in the standard translation (see toFileName()). Note that any file last name, like e.g ".xml" must be stripped off before handoff to this method.