org.apache.commons.jrcs.rcs
Class Version

java.lang.Object
  extended by org.apache.commons.jrcs.util.ToString
      extended by org.apache.commons.jrcs.rcs.Version
All Implemented Interfaces:
java.lang.Cloneable, java.lang.Comparable

public class Version
extends ToString
implements java.lang.Cloneable, java.lang.Comparable

Contains and manages a version number of the form "x(\.y)*". This class is NOT thread safe.

Version:
$Id: Version.java 69 2003-10-13 08:00:44Z rdonkin $
Author:
Juanco Anez
See Also:
Archive

Constructor Summary
Version()
          Create an empty version number.
Version(int major)
          Creates a new Version with a single digit version number
Version(int[] num)
          Converts an array of int to a Version.
Version(java.lang.Integer[] num)
          Converts an array of Integer to a Version.
Version(int major, int minor)
          Creates a new Version with a major.minor version number.
Version(java.lang.String v)
          Converts string to a version.
Version(Version v)
          Create a new Version by copying another.
 
Method Summary
protected  void __addBranch(int branch)
           
protected  void __addBranch(java.lang.Integer branch)
           
 int at(int pos)
          Return the version number at the given position.
 java.lang.Object clone()
           
 int compareTo(java.lang.Object other)
          Compares two versions in lexigographical order.
 int compareVersions(Version ver)
          Compares two versions.
 boolean equals(java.lang.Object o)
          Determine if two versions are equal.
 boolean even()
           
 boolean even(int n)
           
 Version getBase(int positions)
          Return the last number in the version number.
 Version getBranchPoint()
           
 int[] getNumbers()
          Return the current version number as an array of int.
 int hashCode()
           
 boolean isBranch()
           
 boolean isGhost()
           
 boolean isGreaterOrEqualThan(Version ver)
          Determine if this version is greater than or equal to the given one.
 boolean isGreaterThan(Version ver)
          Determine if this version is greater than the given one.
 boolean isLessOrEqualThan(Version ver)
          Determine if this version is less than or equal to the given one.
 boolean isLessThan(Version ver)
          Determine if this version is less than the given one.
 boolean isRevision()
           
 boolean isTrunk()
           
 int last()
          Return the last number in the version number.
 Version newBranch(int branch)
           
 Version next()
           
 boolean odd()
           
 boolean odd(int n)
           
 int size()
           
 void toString(java.lang.StringBuffer s)
          Place a string image of the object in a StringBuffer.
 
Methods inherited from class org.apache.commons.jrcs.util.ToString
arrayToString, arrayToString, stringToArray, toString
 
Methods inherited from class java.lang.Object
finalize, getClass, notify, notifyAll, wait, wait, wait
 

Constructor Detail

Version

public Version(int major)
Creates a new Version with a single digit version number

Parameters:
major - the version number

Version

public Version(int major,
               int minor)
Creates a new Version with a major.minor version number.

Parameters:
major - the major version number
major - the minor version number

Version

public Version(java.lang.Integer[] num)
Converts an array of Integer to a Version.

Parameters:
num - an array of Integers

Version

public Version(int[] num)
Converts an array of int to a Version.

Parameters:
num - an array of int

Version

public Version(java.lang.String v)
        throws InvalidVersionNumberException
Converts string to a version.

Parameters:
v - a string accepted by the following regular expression. [0-9]+(.[0-9]+)*
Throws:
InvalidVersionNumberException - if the string cannot be parsed

Version

public Version(Version v)
Create a new Version by copying another.

Parameters:
v - the version to copy

Version

public Version()
Create an empty version number.

Method Detail

clone

public java.lang.Object clone()
Overrides:
clone in class java.lang.Object

getNumbers

public int[] getNumbers()
Return the current version number as an array of int.

Returns:
the current version number as an array of int.

compareVersions

public int compareVersions(Version ver)
Compares two versions. The comparison is done the usual way, i.e., 2.0 is greter than 1.99.1, and 0.1.2 is greater than 0.1

Parameters:
ver - the version to compare to.
Returns:
0 if this == ver, 1 if this greater than ver, -1 otherwise.

compareTo

public int compareTo(java.lang.Object other)
Compares two versions in lexigographical order. Unlike compareVersions, this comparison is not done in the way usual for versions numbers. The order relationship stablished here is the one CVS used to store nodes into archive files.

Specified by:
compareTo in interface java.lang.Comparable
Parameters:
other - The version to compare to
See Also:
compareVersions(org.apache.commons.jrcs.rcs.Version)

isGreaterThan

public boolean isGreaterThan(Version ver)
Determine if this version is greater than the given one.

Parameters:
ver - the version to compare to.
Returns:
true if compareVersions(ver) > 0
See Also:
compareVersions(org.apache.commons.jrcs.rcs.Version)

isGreaterOrEqualThan

public boolean isGreaterOrEqualThan(Version ver)
Determine if this version is greater than or equal to the given one.

Parameters:
ver - the version to compare to.
Returns:
true if compareVersions(ver) >= 0
See Also:
compareVersions(org.apache.commons.jrcs.rcs.Version)

isLessThan

public boolean isLessThan(Version ver)
Determine if this version is less than the given one.

Parameters:
ver - the version to compare to.
Returns:
true if compareVersions(ver) < 0
See Also:
compareVersions(org.apache.commons.jrcs.rcs.Version)

isLessOrEqualThan

public boolean isLessOrEqualThan(Version ver)
Determine if this version is less than or equal to the given one.

Parameters:
ver - the version to compare to.
Returns:
true if compareVersions(ver) <= 0
See Also:
compareVersions(org.apache.commons.jrcs.rcs.Version)

equals

public boolean equals(java.lang.Object o)
Determine if two versions are equal.

Overrides:
equals in class java.lang.Object
Parameters:
o - the version to compare to
Returns:
true if both versions represent the same version number

hashCode

public int hashCode()
Overrides:
hashCode in class java.lang.Object

at

public int at(int pos)
Return the version number at the given position.

Parameters:
pos - the position.
Returns:
the number.

last

public int last()
Return the last number in the version number.

Returns:
the number.

getBase

public Version getBase(int positions)
Return the last number in the version number.

Returns:
the number.

getBranchPoint

public Version getBranchPoint()

next

public Version next()

__addBranch

protected void __addBranch(java.lang.Integer branch)

__addBranch

protected void __addBranch(int branch)

newBranch

public Version newBranch(int branch)

size

public int size()

isTrunk

public boolean isTrunk()

isBranch

public boolean isBranch()

isRevision

public boolean isRevision()

isGhost

public boolean isGhost()

even

public boolean even(int n)

even

public boolean even()

odd

public boolean odd(int n)

odd

public boolean odd()

toString

public void toString(java.lang.StringBuffer s)
Description copied from class: ToString
Place a string image of the object in a StringBuffer.

Overrides:
toString in class ToString
Parameters:
s - the string buffer.


Copyright © 2002-2011 Apache Software Foundation. All Rights Reserved.