org.usergrid.utils
Class Version

java.lang.Object
  extended by org.usergrid.utils.Version
All Implemented Interfaces:
Serializable, Cloneable, Comparable<Version>

public class Version
extends Object
implements Serializable, Cloneable, Comparable<Version>

The Version class can be used to parse a standard version string into its four components, MAJOR.MINOR.BUILD.REVISION.

Author:
akutz
See Also:
Serialized Form

Constructor Summary
Version()
          Initialize a new Version object that is set to "0.0.0.0".
 
Method Summary
 void addBuild(int toAdd)
          Adds a whole (positive or negative) integer to the BUILD component of the version.
 void addMajor(int toAdd)
          Adds a whole (positive or negative) integer to the MAJOR component of the version.
 void addMinor(int toAdd)
          Adds a whole (positive or negative) integer to the MINOR component of the version.
 void addRevision(int toAdd)
          Adds a whole (positive or negative) integer to the REVISION component of the version.
 Object clone()
           
 int compareTo(Version toCompare)
           
 boolean equals(Object toCompare)
           
 String getBuild()
          Gets the version's BUILD component.
 String getMajor()
          Gets the version's MAJOR component.
 String getMinor()
          Gets the version's MINOR component.
 int getNumberOfComponents()
          Gets the number of components that make up the version.
 String getPrefix()
          Gets everything before the version in the string that was parsed.
 String getRevision()
          Gets the version's REVISION component.
 String getSuffix()
          Gets everything after the version in the string that was parsed.
 int hashCode()
           
static Version parse(String toParse)
          Parses a new Version object from a String.
 void setBuild(int toSet)
          Sets the version's BUILD component.
 void setBuild(String toSet)
          Sets the version's BUILD component.
 void setMajor(int toSet)
          Sets the version's MAJOR component.
 void setMajor(String toSet)
          Sets the version's MAJOR component.
 void setMinor(int toSet)
          Sets the version's MINOR component.
 void setMinor(String toSet)
          Sets the version's MINOR component.
 void setNumberOfComponents(int toSet)
          Sets the number of components that make up the version.
 void setRevision(int toSet)
          Sets the version's REVISION component.
 void setRevision(String toSet)
          Sets the version's REVISION component.
 String toString()
           
 String toString(int components)
          Gets the version as a string using the specified number of components.
 String toStringRaw()
          Gets the string that was parsed to create this Version object.
 String toStringWithPrefixAndSuffix()
          Gets the version as a string including the prefix and suffix.
 String toStringWithPrefixAndSuffix(int components)
          Gets the version as a string including the prefix and suffix using the specified number of components.
 
Methods inherited from class java.lang.Object
finalize, getClass, notify, notifyAll, wait, wait, wait
 

Constructor Detail

Version

public Version()
Initialize a new Version object that is set to "0.0.0.0".

Method Detail

toStringRaw

public String toStringRaw()
Gets the string that was parsed to create this Version object. This string may not accurately reflect the current values of the Version's components.

Returns:
The string that was parsed to create this Version object. This string may not accurately reflect the current values of the Version's components.

getPrefix

public String getPrefix()
Gets everything before the version in the string that was parsed.

Returns:
Everything before the version in the string that was parsed.

getSuffix

public String getSuffix()
Gets everything after the version in the string that was parsed.

Returns:
Everything after the version in the string that was parsed.

parse

public static Version parse(String toParse)
                     throws Exception
Parses a new Version object from a String.

Parameters:
toParse - The String object to parse.
Returns:
A new Version object.
Throws:
Exception - When there is an error parsing the String.

getMajor

public String getMajor()
Gets the version's MAJOR component.

Returns:
The version's MAJOR component.

setMajor

public void setMajor(String toSet)
              throws IllegalArgumentException
Sets the version's MAJOR component.

Parameters:
toSet - The version's MAJOR component.
Throws:
IllegalArgumentException - When a null or non-numeric value is given.

setMajor

public void setMajor(int toSet)
Sets the version's MAJOR component.

Parameters:
toSet - The version's MAJOR component.

getMinor

public String getMinor()
Gets the version's MINOR component.

Returns:
The version's MINOR component.

setMinor

public void setMinor(String toSet)
              throws IllegalArgumentException
Sets the version's MINOR component.

Parameters:
toSet - The version's MINOR component.
Throws:
IllegalArgumentException - When a null or non-numeric value is given.

setMinor

public void setMinor(int toSet)
Sets the version's MINOR component.

Parameters:
toSet - The version's MINOR component.

getBuild

public String getBuild()
Gets the version's BUILD component.

Returns:
The version's BUILD component.

setBuild

public void setBuild(String toSet)
              throws IllegalArgumentException
Sets the version's BUILD component.

Parameters:
toSet - The version's BUILD component.
Throws:
IllegalArgumentException - When a null or non-numeric value is given.

setBuild

public void setBuild(int toSet)
Sets the version's BUILD component.

Parameters:
toSet - The version's BUILD component.

getRevision

public String getRevision()
Gets the version's REVISION component.

Returns:
The version's REVISION component.

setRevision

public void setRevision(String toSet)
                 throws IllegalArgumentException
Sets the version's REVISION component.

Parameters:
toSet - The version's REVISION component.
Throws:
IllegalArgumentException - When a null or non-numeric value is given.

setRevision

public void setRevision(int toSet)
Sets the version's REVISION component.

Parameters:
toSet - The version's REVISION component.

getNumberOfComponents

public int getNumberOfComponents()
Gets the number of components that make up the version. The value will always be between 1 (inclusive) and 4 (inclusive).

Returns:
The number of components that make up the version. The value will always be between 1 (inclusive) and 4 (inclusive).

setNumberOfComponents

public void setNumberOfComponents(int toSet)
Sets the number of components that make up the version.

Parameters:
toSet - The number of components that make up the version. Values less than 1 are treated as 1. Values greater than 4 are treated as 4.

clone

public Object clone()
             throws CloneNotSupportedException
Overrides:
clone in class Object
Throws:
CloneNotSupportedException

equals

public boolean equals(Object toCompare)
Overrides:
equals in class Object

hashCode

public int hashCode()
Overrides:
hashCode in class Object

toString

public String toString()
Overrides:
toString in class Object

toStringWithPrefixAndSuffix

public String toStringWithPrefixAndSuffix()
Gets the version as a string including the prefix and suffix.

Returns:
The version as a string including the prefix and suffix.

toString

public String toString(int components)
Gets the version as a string using the specified number of components.

Parameters:
components - The number of components. Values less than 1 will be treated as 1 and values greater than 4 will be treated as 4.
Returns:
The version as a string using the specified number of components.

toStringWithPrefixAndSuffix

public String toStringWithPrefixAndSuffix(int components)
Gets the version as a string including the prefix and suffix using the specified number of components.

Parameters:
components - The number of components. Values less than 1 will be treated as 1 and values greater than 4 will be treated as 4.
Returns:
The version as a string including the prefix and suffix using the specified number of components.

compareTo

public int compareTo(Version toCompare)
Specified by:
compareTo in interface Comparable<Version>

addMajor

public void addMajor(int toAdd)
Adds a whole (positive or negative) integer to the MAJOR component of the version. If the number to add is negative and results in a sum less than 0, the sum is set to 0.

Parameters:
toAdd - A whole (positive or negative) integer.

addMinor

public void addMinor(int toAdd)
Adds a whole (positive or negative) integer to the MINOR component of the version. If the number to add is negative and results in a sum less than 0, the sum is set to 0.

Parameters:
toAdd - A whole (positive or negative) integer.

addBuild

public void addBuild(int toAdd)
Adds a whole (positive or negative) integer to the BUILD component of the version. If the number to add is negative and results in a sum less than 0, the sum is set to 0.

Parameters:
toAdd - A whole (positive or negative) integer.

addRevision

public void addRevision(int toAdd)
Adds a whole (positive or negative) integer to the REVISION component of the version. If the number to add is negative and results in a sum less than 0, the sum is set to 0.

Parameters:
toAdd - A whole (positive or negative) integer.


Copyright © 2013. All Rights Reserved.