Package com.yahoo.component
Class ComponentId
- java.lang.Object
-
- com.yahoo.component.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 Summary
Constructors Constructor Description 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 idComponentId(java.lang.String name, Version version)
Creates a component id from a name and version.ComponentId(java.lang.String name, Version version, ComponentId namespace)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description int
compareTo(ComponentId other)
static ComponentId
createAnonymousComponentId(java.lang.String baseName)
Creates a componentId that is unique for this run-time instanceboolean
equals(java.lang.Object o)
static ComponentId
fromFileName(java.lang.String fileName)
Creates an id from a file first name string encoded in the standard translation (seetoFileName()
).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.java.lang.String
getName()
Returns the name of this.ComponentId
getNamespace()
The namespace is null if this is a top level component idVersion
getVersion()
Returns the version of this id, or emptyVersion if no version is specifiedint
hashCode()
boolean
isAnonymous()
ComponentId
nestInNamespace(ComponentId namespace)
static void
resetGlobalCountersForTests()
WARNING: For testing only: Resets counters creating anonymous component ids for this thread.java.lang.String
stringValue()
Returns the string value of this id.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:ComponentSpecification
toSpecification()
java.lang.String
toString()
ComponentId
withoutNamespace()
Returns a copy of this id with namespace set to null
-
-
-
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
-
nestInNamespace
public ComponentId nestInNamespace(ComponentId namespace)
-
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 classjava.lang.Object
-
equals
public boolean equals(java.lang.Object o)
- Overrides:
equals
in classjava.lang.Object
-
hashCode
public int hashCode()
- Overrides:
hashCode
in classjava.lang.Object
-
toSpecification
public ComponentSpecification toSpecification()
-
compareTo
public int compareTo(ComponentId other)
- Specified by:
compareTo
in interfacejava.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 (seetoFileName()
). 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.
-
-