/*
* ====================================================================
*
* The Apache Software License, Version 1.1
*
* Copyright (c) 1999-2003 The Apache Software Foundation.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* distribution.
*
* 3. The end-user documentation included with the redistribution, if
* any, must include the following acknowledgement:
* "This product includes software developed by the
* Apache Software Foundation (http://www.apache.org/)."
* Alternately, this acknowledgement may appear in the software itself,
* if and wherever such third-party acknowledgements normally appear.
*
* 4. The names "The Jakarta Project", "Commons", and "Apache Software
* Foundation" must not be used to endorse or promote products derived
* from this software without prior written permission. For written
* permission, please contact apache@apache.org.
*
* 5. Products derived from this software may not be called "Apache"
* nor may "Apache" appear in their names without prior written
* permission of the Apache Software Foundation.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
* ====================================================================
*
* This software consists of voluntary contributions made by many
* individuals on behalf of the Apache Software Foundation. For more
* information on the Apache Software Foundation, please see
*
*/
/**
* Contains and manages a version number of the form "x(\.y)*".
* This class is NOT thread safe.
*
* @see Archive
*
* @author <a href="mailto:juanco@suigeneris.org">Juanco Anez</a>
* @version $Id: Version.java,v 1.4 2003/10/13 07:59:46 rdonkin Exp $
*/
@SuppressWarnings("rawtypes")
public class Version
extends ToString
implements Cloneable, Comparable
{
/**
* Creates a new Version with a single digit version number
* @param major the version number
*/
{
}
/**
* Creates a new Version with a major.minor version number.
* @param major the major version number
* @param minor the minor version number
*/
{
}
/**
* Converts an array of Integer to a Version.
* @param num an array of Integers
*/
{
{
}
}
/**
* Converts an array of int to a Version.
* @param num an array of int
*/
{
}
/**
* Converts string to a version.
* @param v a string accepted by the following regular expression.
* <code>
* [0-9]+(.[0-9]+)*
* </code>
* @throws InvalidVersionNumberException if the string cannot be parsed
*/
{
if (v.endsWith("."))
{
v = v + "0";
}
int count = t.countTokens();
/*
if (even(count) && v.endsWith(".0"))
{
count--;
} // allow a .0 ending only in branch revisions
*/
for (int i = 0; i < count; i++)
{
try
{
}
catch (NumberFormatException e)
{
throw new InvalidVersionNumberException(v);
}
}
}
/**
* Create a new Version by copying another.
* @param v the version to copy
*/
{
{
}
}
/**
* Create an empty version number.
*/
public Version()
{
}
/**
* {@inheritDoc}
*/
{
return new Version(this);
}
/**
* Return the current version number as an array of int.
* @return the current version number as an array of int.
*/
public int[] getNumbers()
{
}
/**
* 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
* @param ver the version to compare to.
* @return 0 if this == ver, 1 if this greater than ver, -1 otherwise.
*/
{
int i;
{
{
return 1;
}
{
return -1;
}
}
// all matched up to i-1
{
return -1;
}
return 0;
}
/**
* 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.
* @param other The version to compare to
* @return comparision result
* @see #compareVersions
*/
{
if (other == this)
{
return 0;
}
{
}
else {
{
}
return -compareVersions(otherVer);
}
}
/**
* Determine if this version is greater than the given one.
* @param ver the version to compare to.
* @return true if compareVersions(ver) > 0
* @see #compareVersions
*/
{
}
/**
* Determine if this version is greater than or equal to the given one.
* @param ver the version to compare to.
* @return true if compareVersions(ver) >= 0
* @see #compareVersions
*/
{
}
/**
* Determine if this version is less than the given one.
* @param ver the version to compare to.
* @return true if compareVersions(ver) < 0
* @see #compareVersions
*/
{
}
/**
* Determine if this version is less than or equal to the given one.
* @param ver the version to compare to.
* @return true if compareVersions(ver) <= 0
* @see #compareVersions
*/
{
}
/**
* Determine if two versions are equal.
* @param o the version to compare to
* @return true if both versions represent the same version number
*/
{
if (this == o)
{
return true;
}
else if (!(o instanceof Version))
{
return false;
}
{
return false;
}
else
{
return compareTo(o) == 0;
}
}
@SuppressWarnings("javadoc")
public int hashCode()
{
}
/**
* Return the version number at the given position.
* @param pos the position.
* @return the number.
*/
{
}
/**
* Return the last number in the version number.
* @return the number.
*/
public int last()
{
}
/**
* Return the last number in the version number.
* @param positions positions to copy
* @return the number.
*/
{
}
@SuppressWarnings("javadoc")
{
}
@SuppressWarnings("javadoc")
{
return result;
}
@SuppressWarnings("javadoc")
{
}
@SuppressWarnings("javadoc")
{
}
@SuppressWarnings("javadoc")
{
return result;
}
@SuppressWarnings("javadoc")
public int size()
{
}
@SuppressWarnings("javadoc")
public boolean isTrunk()
{
}
@SuppressWarnings("javadoc")
public boolean isBranch()
{
return size() > 2;
}
@SuppressWarnings("javadoc")
public boolean isRevision()
{
return even();
}
@SuppressWarnings("javadoc")
public boolean isGhost()
{
for (int i = 0; i < size(); i++)
{
if (numbers[i] <= 0)
{
return true;
}
}
return false;
}
public boolean even(int n)
{
return n % 2 == 0;
}
@SuppressWarnings("javadoc")
public boolean even()
{
}
@SuppressWarnings("javadoc")
public boolean odd(int n)
{
return !even(n);
}
@SuppressWarnings("javadoc")
public boolean odd()
{
return !even();
}
@SuppressWarnings("javadoc")
{
if (size() > 0)
{
{
s.append(".");
}
}
}
}