Class ComponentId

java.lang.Object
com.yahoo.component.ComponentId
All Implemented Interfaces:
Comparable<ComponentId>

public final class ComponentId extends Object implements 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 Details

    • ComponentId

      public ComponentId(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
    • ComponentId

      public ComponentId(String name, Version version, ComponentId namespace)
    • ComponentId

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

    • nestInNamespace

      public ComponentId nestInNamespace(ComponentId namespace)
    • getName

      public 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 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 String toString()
      Overrides:
      toString in class Object
    • equals

      public boolean equals(Object o)
      Overrides:
      equals in class Object
    • hashCode

      public int hashCode()
      Overrides:
      hashCode in class Object
    • toSpecification

      public ComponentSpecification toSpecification()
    • compareTo

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

      public static ComponentId createAnonymousComponentId(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(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 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(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.
    • resetGlobalCountersForTests

      public static void resetGlobalCountersForTests()
      WARNING: For testing only: Resets counters creating anonymous component ids for this thread.
    • newAnonymous

      public static ComponentId newAnonymous(String spec)
      Creates a component id with the given value, marked as anonymous