Top Description Fields Constructors Methods
org.apache.avalon.framework

public final Class Version

extends Object
implements Comparable, Serializable
Class Inheritance
All Implemented Interfaces
java.io.Serializable, java.lang.Comparable
Imports
java.io.Serializable, java.util.StringTokenizer

This class is used to hold version information pertaining to a Component or interface.

The version number of a Component is made up of three dot-separated fields:

"major.minor.micro"

The major, minor and micro fields are integer numbers represented in decimal notation and have the following meaning:

Author
Avalon Development Team
Version
$Id: Version.java 506231 2007-02-12 02:36:54Z crossley $

Field Summary

Modifier and TypeField and Description
private int
private int
private int

Constructor Summary

AccessConstructor and Description
public
Version(final int
This Version major number.
major
,
final int
This Version minor number.
minor
,
final int
This Version micro number.
micro
)

Create a new instance of a Version object with the specified version numbers.

Method Summary

Modifier and TypeMethod and Description
public int

Returns:

number indicating relative value (-1, 0, 1)
compareTo
(Object
the object to be compared.
o
)

Implements java.lang.Comparable.compareTo.

Compare two versions together according to the Comparable interface.
public boolean

Returns:

true if this Version is compatible with the specified one
complies
(final Version
The other Version object to be compared with this for compliancy (compatibility).
other
)

Check this Version against another for compliancy (compatibility).

public boolean

Returns:

true if this Version is compatible with the specified one
equals
(final Version
The other Version object to be compared with this for equality.
other
)

Check this Version against another for equality.

public boolean

Returns:

true if the other object is equal to this Version
equals
(final Object
an Object value
other
)

Overrides java.lang.Object.equals.

Indicates whether some other object is "equal to" this Version.
public int

Returns:

the major component of version
getMajor
()

Retrieve major component of version.

public int

Returns:

the micro component of version.
getMicro
()

Retrieve micro component of version.

public int

Returns:

the minor component of version
getMinor
()

Retrieve minor component of version.

public static Version

Returns:

the new Version object
getVersion
(final String
The input version string
version
)

Parse a version out of a string.

public int

Returns:

the hashCode
hashCode
()

Overrides java.lang.Object.hashCode.

Add a hashing function to ensure the Version object is treated as expected in hashmaps and sets.
public String

Returns:

the dot seperated version string
toString
()

Overrides java.lang.Object.toString.

Overload toString to report version correctly.
Inherited from java.lang.Object:
clonefinalizegetClassnotifynotifyAllwaitwaitwait

Field Detail

m_majorback to summary
private int m_major
m_microback to summary
private int m_micro
m_minorback to summary
private int m_minor

Constructor Detail

Versionback to summary
public Version(final int major, final int minor, final int micro)

Create a new instance of a Version object with the specified version numbers.

Parameters
major:int

This Version major number.

minor:int

This Version minor number.

micro:int

This Version micro number.

Method Detail

compareToback to summary
public int compareTo(Object o)

Implements java.lang.Comparable.compareTo.

Compare two versions together according to the Comparable interface.

Parameters
o:Object

Doc from java.lang.Comparable.compareTo.

the object to be compared.

Returns:int

number indicating relative value (-1, 0, 1)

compliesback to summary
public boolean complies(final Version other)

Check this Version against another for compliancy (compatibility).

If this Version is compatible with the specified one, then true is returned, otherwise false. Be careful when using this method since, in example, version 1.3.7 is compliant to version 1.3.6, while the opposite is not.

The following example displays the expected behaviour and results of version.

final Version v1 = new Version( 1, 3 , 6 );
final Version v2 = new Version( 1, 3 , 7 );
final Version v3 = new Version( 1, 4 , 0 );
final Version v4 = new Version( 2, 0 , 1 );

assert(   v1.complies( v1 ) );
assert( ! v1.complies( v2 ) );
assert(   v2.complies( v1 ) );
assert( ! v1.complies( v3 ) );
assert(   v3.complies( v1 ) );
assert( ! v1.complies( v4 ) );
assert( ! v4.complies( v1 ) );
Parameters
other:Version

The other Version object to be compared with this for compliancy (compatibility).

Returns:boolean

true if this Version is compatible with the specified one

equalsback to summary
public boolean equals(final Version other)

Check this Version against another for equality.

If this Version is compatible with the specified one, then true is returned, otherwise false.

Parameters
other:Version

The other Version object to be compared with this for equality.

Returns:boolean

true if this Version is compatible with the specified one

Since
4.1
equalsback to summary
public boolean equals(final Object other)

Overrides java.lang.Object.equals.

Indicates whether some other object is "equal to" this Version. Returns true if the other object is an instance of Version and has the same major, minor, and micro components.

Parameters
other:Object

an Object value

Returns:boolean

true if the other object is equal to this Version

getMajorback to summary
public int getMajor()

Retrieve major component of version.

Returns:int

the major component of version

Since
4.1
getMicroback to summary
public int getMicro()

Retrieve micro component of version.

Returns:int

the micro component of version.

Since
4.1
getMinorback to summary
public int getMinor()

Retrieve minor component of version.

Returns:int

the minor component of version

Since
4.1
getVersionback to summary
public static Version getVersion(final String version) throws NumberFormatException, IllegalArgumentException

Parse a version out of a string. The version string format is .. where both minor and micro are optional.

Parameters
version:String

The input version string

Returns:Version

the new Version object

Exceptions
NumberFormatException:
if an error occurs
IllegalArgumentException:
if an error occurs
NullPointerException:
if the provided string is null
Since
4.1
hashCodeback to summary
public int hashCode()

Overrides java.lang.Object.hashCode.

Add a hashing function to ensure the Version object is treated as expected in hashmaps and sets.

Note

any time the equals() is overridden, hashCode() should also be overridden.

Returns:int

the hashCode

toStringback to summary
public String toString()

Overrides java.lang.Object.toString.

Overload toString to report version correctly.

Returns:String

the dot seperated version string