Skip navigation links


org.apache.myfaces.trinidad.context
Class Version

java.lang.Object
  extended by org.apache.myfaces.trinidad.context.Version

All Implemented Interfaces:
Comparable<Version>

public final class Version
extends Object
implements Comparable<Version>

Immutable Representation of a dot-separated version. This representation allows individual sections of the version to be wild-carded and allows for comparisons between Versions with different numbers of version subsections to be compared. When comparing Versions, each version subsection is compared from left to right. If one Version doesn't have a version subsection at the current index, the value of versionPadding is used for this comparison. Version subsections with the wild-card value "*" are considered equal. The value returned by compareTo() is the value of the first non-equal version subsection or zero if all subsections match. Due to the support for wild-cards, this class has a natural ordering that is inconsistent with equals. For example, Version("5", "*").compareTo(Version("5.0", "*") == 0 Version("5", "*").equals(Version("5.0", "*") == false; The concrete versions produced by toMinimumVersion() and toMaximumVersion() do have consistent compareTo()/equals() behavior, as these versions are guaranteed to not contain wildcards.

Author:
Blake Sullivan

Field Summary
static Range<Version> ALL_VERSIONS
          A range of versions from MIN_VERSION to MAX_VERSION.
static Version MAX_VERSION
          A constant value holding a maximum upper bound for versions.
static Version MIN_VERSION
          A constant value holding the minimum value a version can have: 0.

 

Constructor Summary
Version(String version)
          Creates a Version instance from the dot-separated Version String using null as the padding
Version(String version, String versionPadding)
          Creates a Version instance from the dot-separated Version String and the versionPadding.

 

Method Summary
 int compareTo(Version otherVersion)
          When comparing Versions, each version subsection is compared from left to right.
 boolean equals(Object o)
           
 int hashCode()
           
 Version toMaximumVersion()
          Converts this Version to an equivalent "maximum" instance.
 Version toMinimumVersion()
          Converts this Version to an equivalent "minimum" instance.
 String toString()
           

 

Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait

 

Field Detail

MIN_VERSION

public static final Version MIN_VERSION
A constant value holding the minimum value a version can have: 0.

MAX_VERSION

public static final Version MAX_VERSION
A constant value holding a maximum upper bound for versions. In theory there is no upper limit to version string values, ie. version strings could be infinitely long. However, in practice it can be helpful to have some way to identify a concrete maximum upper bound to a range of versions. Version.MAX_VERSION specifies the Integer.MAX_VALUE version for this purpose.

ALL_VERSIONS

public static final Range<Version> ALL_VERSIONS
A range of versions from MIN_VERSION to MAX_VERSION.

Constructor Detail

Version

public Version(String version)
Creates a Version instance from the dot-separated Version String using null as the padding
Parameters:
version - The dot-separated version to represent
Throws:
NullPointerException - if the version is null
IllegalArgumentException - if the version is an empty String
See Also:
Version(String, String)

Version

public Version(String version,
               String versionPadding)
Creates a Version instance from the dot-separated Version String and the versionPadding.
Parameters:
version - The dot-separated version to represent
versionPadding - The value to return for sub-version sections requested beyond the sub-version sections present in the version String. If null or empty, no padding will be performed.
Throws:
NullPointerException - if version is null
IllegalArgumentException - if version is the empty String

Method Detail

compareTo

public int compareTo(Version otherVersion)
When comparing Versions, each version subsection is compared from left to right. If one Version doesn't have a version subsection at the current index, the value of versionPadding is used for this comparison. Version subsections with the wild-card value "*" care considered equal. The value returned by compareTo() is the value of the first non-equal version subsection or zero if all subsections match.
Specified by:
compareTo in interface Comparable<Version>
Parameters:
otherVersion - The Version object to compare this Version Object with
Returns:
a negative integer, zero, or a positive integer as this object is less than, equal to, or greater than the specified object.

toMinimumVersion

public Version toMinimumVersion()
Converts this Version to an equivalent "minimum" instance. Interior wildcard segements are replaced with "0". The trailing wildcard segment (if present) is dropped. Wildcard version padding is replaced with null padding. If no wilcards are present, returns this Version instance.

toMaximumVersion

public Version toMaximumVersion()
Converts this Version to an equivalent "maximum" instance. Both wildcard segements and wilcard padding are replaced with Integer.MAX_VALUE. If no wilcards are present, returns this Version instance.

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

Skip navigation links


Copyright © 2001-2013 The Apache Software Foundation. All Rights Reserved.