Package com.yahoo.component
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 Summary
Constructors Constructor Description 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 idComponentId(String name, Version version)
Creates a component id from a name and version.ComponentId(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(String baseName)
Creates a componentId that is unique for this run-time instanceboolean
equals(Object o)
static ComponentId
fromFileName(String fileName)
Creates an id from a file first name string encoded in the standard translation (seetoFileName()
).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.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 ComponentId
newAnonymous(String spec)
Creates a component id with the given value, marked as anonymousstatic void
resetGlobalCountersForTests()
WARNING: For testing only: Resets counters creating anonymous component ids for this thread.String
stringValue()
Returns the string value of this id.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()
String
toString()
ComponentId
withoutNamespace()
Returns a copy of this id with namespace set to null
-
-
-
Constructor Detail
-
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)
-
-
Method Detail
-
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.
-
toSpecification
public ComponentSpecification toSpecification()
-
compareTo
public int compareTo(ComponentId other)
- Specified by:
compareTo
in interfaceComparable<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 (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.
-
newAnonymous
public static ComponentId newAnonymous(String spec)
Creates a component id with the given value, marked as anonymous
-
-