net.sf.uadetector
Class VersionNumber

java.lang.Object
  extended by net.sf.uadetector.VersionNumber
All Implemented Interfaces:
java.io.Serializable, java.lang.Comparable<ReadableVersionNumber>, ReadableVersionNumber

public final class VersionNumber
extends java.lang.Object
implements ReadableVersionNumber, java.io.Serializable

The VersionNumber class represents the version number of an operating system or User-Agent.

A VersionNumber object is immutable, their values cannot be changed after creation.

Author:
André Rouél
See Also:
Serialized Form

Field Summary
static java.lang.String EMPTY_EXTENSION
          Empty extension or addition of a version number
static java.lang.String EMPTY_GROUP
          Empty group or category of a version number
static VersionNumber UNKNOWN
          Defines an empty or not set version number
 
Constructor Summary
VersionNumber(java.util.List<java.lang.String> groups)
          Constructs a VersionNumber with the given numeric groups, such as major, minor and bugfix number.
VersionNumber(java.util.List<java.lang.String> groups, java.lang.String extension)
          Constructs a VersionNumber with the given numeric groups, such as major, minor and bugfix number and extension.
VersionNumber(java.lang.String major)
          Constructs a VersionNumber with the given major number and without a minor and bugfix number.
VersionNumber(java.lang.String major, java.lang.String minor)
          Constructs a VersionNumber with the given major, minor number and without a bugfix number.
VersionNumber(java.lang.String major, java.lang.String minor, java.lang.String bugfix)
          Constructs a VersionNumber with the given major, minor and bugfix number.
VersionNumber(java.lang.String major, java.lang.String minor, java.lang.String bugfix, java.lang.String extension)
          Constructs a VersionNumber with the given major, minor and bugfix number and extension.
 
Method Summary
 int compareTo(ReadableVersionNumber other)
          Compares this version number with the specified version number for order.
 boolean equals(java.lang.Object obj)
          Indicates whether some other object is "equal to" this version number.
 java.lang.String getBugfix()
          Gets the bugfix category of the version number.
 java.lang.String getExtension()
          Gets the addition or extension of the version number.
 java.util.List<java.lang.String> getGroups()
          Get all groups (or categories) of this version number.
 java.lang.String getMajor()
          Gets the major category of the version number.
 java.lang.String getMinor()
          Gets the major category of the version number.
 int hashCode()
           
static VersionNumber parseLastVersionNumber(java.lang.String text)
          Interprets a string with version information.
static VersionNumber parseOperatingSystemVersion(OperatingSystemFamily family, java.lang.String userAgent)
          Try to determine the version number of the operating system by parsing the user agent string.
static VersionNumber parseVersion(java.lang.String version)
          Interprets a string with version information.
static java.util.List<java.lang.String> replaceNullValueWithEmptyGroup(java.util.List<java.lang.String> groups)
          Replaces all null values in the given list of groups with VersionNumber#EMPTY_GROUP.
 java.lang.String toString()
          Returns a string representation of the version number.
 java.lang.String toVersionString()
          Gets this version number as string.
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Field Detail

EMPTY_EXTENSION

public static final java.lang.String EMPTY_EXTENSION
Empty extension or addition of a version number

See Also:
Constant Field Values

EMPTY_GROUP

public static final java.lang.String EMPTY_GROUP
Empty group or category of a version number

See Also:
Constant Field Values

UNKNOWN

public static final VersionNumber UNKNOWN
Defines an empty or not set version number

Constructor Detail

VersionNumber

public VersionNumber(@Nonnull
                     java.util.List<java.lang.String> groups)
Constructs a VersionNumber with the given numeric groups, such as major, minor and bugfix number.

Parameters:
groups - list of numbers of a version number
Throws:
net.sf.qualitycheck.exception.IllegalNullArgumentException - if the given argument is null
net.sf.qualitycheck.exception.IllegalStateOfArgumentException - if one of the segments of the version number is smaller than 0 and not empty

VersionNumber

public VersionNumber(@Nonnull
                     java.util.List<java.lang.String> groups,
                     @Nonnull
                     java.lang.String extension)
Constructs a VersionNumber with the given numeric groups, such as major, minor and bugfix number and extension.

Parameters:
groups - list of numbers of a version number
extension - extension of a version number
Throws:
net.sf.qualitycheck.exception.IllegalNullArgumentException - if one of the given arguments is null
net.sf.qualitycheck.exception.IllegalStateOfArgumentException - if one of the groups of the version number is not empty or a positive number

VersionNumber

public VersionNumber(@Nonnull
                     java.lang.String major)
Constructs a VersionNumber with the given major number and without a minor and bugfix number.

Parameters:
major - major group of the version number
Throws:
net.sf.qualitycheck.exception.IllegalNullArgumentException - if the given argument is null
net.sf.qualitycheck.exception.IllegalStateOfArgumentException - if the major segment is smaller than 0 and not empty

VersionNumber

public VersionNumber(@Nonnull
                     java.lang.String major,
                     @Nonnull
                     java.lang.String minor)
Constructs a VersionNumber with the given major, minor number and without a bugfix number.

Parameters:
major - major group of the version number
minor - minor group of the version number
Throws:
net.sf.qualitycheck.exception.IllegalNullArgumentException - if one of the given arguments is null
net.sf.qualitycheck.exception.IllegalStateOfArgumentException - if the major or minor segment is smaller than 0 and not empty

VersionNumber

public VersionNumber(@Nonnull
                     java.lang.String major,
                     @Nonnull
                     java.lang.String minor,
                     @Nonnull
                     java.lang.String bugfix)
Constructs a VersionNumber with the given major, minor and bugfix number.

Parameters:
major - major group of the version number
minor - minor group of the version number
bugfix - bugfix group of the version number
Throws:
net.sf.qualitycheck.exception.IllegalNullArgumentException - if one of the given arguments is null
net.sf.qualitycheck.exception.IllegalStateOfArgumentException - if the major, minor or bugfix segment is smaller than 0 and not empty

VersionNumber

public VersionNumber(@Nonnull
                     java.lang.String major,
                     @Nonnull
                     java.lang.String minor,
                     @Nonnull
                     java.lang.String bugfix,
                     @Nonnull
                     java.lang.String extension)
Constructs a VersionNumber with the given major, minor and bugfix number and extension.

Parameters:
major - major group of the version number
minor - minor group of the version number
bugfix - bugfix group of the version number
extension - extension of a version number
Throws:
net.sf.qualitycheck.exception.IllegalNullArgumentException - if one of the given arguments is null
net.sf.qualitycheck.exception.IllegalStateOfArgumentException - if the major, minor or bugfix segment is smaller than 0 and not empty
Method Detail

parseLastVersionNumber

public static VersionNumber parseLastVersionNumber(@Nonnull
                                                   java.lang.String text)
Interprets a string with version information. The last version number in the string will be searched and processed.

Parameters:
text - string with version information
Returns:
an object of VersionNumber, never null

parseOperatingSystemVersion

public static VersionNumber parseOperatingSystemVersion(@Nonnull
                                                        OperatingSystemFamily family,
                                                        @Nonnull
                                                        java.lang.String userAgent)
Try to determine the version number of the operating system by parsing the user agent string.

Parameters:
family - family of the operating system
userAgent - user agent string
Returns:
extracted version number

parseVersion

public static VersionNumber parseVersion(@Nonnull
                                         java.lang.String version)
Interprets a string with version information. The first found group will be taken and processed.

Parameters:
version - version as string
Returns:
an object of VersionNumber, never null

replaceNullValueWithEmptyGroup

public static java.util.List<java.lang.String> replaceNullValueWithEmptyGroup(@Nonnull
                                                                              java.util.List<java.lang.String> groups)
Replaces all null values in the given list of groups with VersionNumber#EMPTY_GROUP.

Parameters:
groups - list of numbers of a version number
Returns:
a new list of groups without null values

compareTo

public int compareTo(@Nullable
                     ReadableVersionNumber other)
Compares this version number with the specified version number for order. Returns a negative integer, zero, or a positive integer as this version number is less than, equal to, or greater than the specified version number.

Specified by:
compareTo in interface java.lang.Comparable<ReadableVersionNumber>
Returns:
a negative integer, zero, or a positive integer as this version number is less than, equal to, or greater than the specified version number.

equals

public boolean equals(java.lang.Object obj)
Indicates whether some other object is "equal to" this version number.

Overrides:
equals in class java.lang.Object
Returns:
true if the given version number is equal to this one

getBugfix

public java.lang.String getBugfix()
Gets the bugfix category of the version number.

Specified by:
getBugfix in interface ReadableVersionNumber
Returns:
bugfix segment

getExtension

public java.lang.String getExtension()
Gets the addition or extension of the version number.

Specified by:
getExtension in interface ReadableVersionNumber
Returns:
extension of the version number

getGroups

public java.util.List<java.lang.String> getGroups()
Get all groups (or categories) of this version number. The first element in the list is the major category, followed by the minor and bugfix segment of the version number.

The returned list of the version number segments is immutable.

Specified by:
getGroups in interface ReadableVersionNumber
Returns:
an unmodifiable view of the of the version number groups

getMajor

public java.lang.String getMajor()
Gets the major category of the version number.

Specified by:
getMajor in interface ReadableVersionNumber
Returns:
major segment

getMinor

public java.lang.String getMinor()
Gets the major category of the version number.

Specified by:
getMinor in interface ReadableVersionNumber
Returns:
minor segment

hashCode

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

toString

@Nonnull
public java.lang.String toString()
Returns a string representation of the version number.

Overrides:
toString in class java.lang.Object
Returns:
a string representation of this version number

toVersionString

@Nonnull
public java.lang.String toVersionString()
Gets this version number as string.

Specified by:
toVersionString in interface ReadableVersionNumber
Returns:
numeric groups as dot separated version number string


Copyright © 2011-2014. All Rights Reserved.