Package org.owasp.dependencycheck.utils
Class DependencyVersion
- java.lang.Object
-
- org.owasp.dependencycheck.utils.DependencyVersion
-
- All Implemented Interfaces:
java.lang.Comparable<DependencyVersion>,java.lang.Iterable<java.lang.String>
@NotThreadSafe public class DependencyVersion extends java.lang.Object implements java.lang.Iterable<java.lang.String>, java.lang.Comparable<DependencyVersion>
Simple object to track the parts of a version number. The parts are contained in a List such that version 1.2.3 will be stored as:
versionParts[0] = 1; versionParts[1] = 2; versionParts[2] = 3;Note, the parser contained in this class expects the version numbers to be separated by periods. If a different separator is used the parser will likely fail.
- Author:
- Jeremy Long
-
-
Constructor Summary
Constructors Constructor Description DependencyVersion()Constructor for a empty DependencyVersion.DependencyVersion(java.lang.String version)Constructor for a DependencyVersion that will parse a version string.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description intcompareTo(@NotNull DependencyVersion version)booleanequals(java.lang.Object obj)Compares the equality of this object to the one passed in as a parameter.java.util.List<java.lang.String>getVersionParts()Get the value of versionParts.inthashCode()Calculates the hashCode for this object.@NotNull java.util.Iterator<java.lang.String>iterator()Retrieves an iterator for the version parts.booleanmatchesAtLeastThreeLevels(DependencyVersion version)Determines if the three most major major version parts are identical.voidparseVersion(java.lang.String version)Parses a version string into its sub parts: major, minor, revision, build, etc.voidsetVersionParts(java.util.List<java.lang.String> versionParts)Set the value of versionParts.java.lang.StringtoString()Reconstructs the version string from the split version parts.
-
-
-
Constructor Detail
-
DependencyVersion
public DependencyVersion()
Constructor for a empty DependencyVersion.
-
DependencyVersion
public DependencyVersion(java.lang.String version)
Constructor for a DependencyVersion that will parse a version string. Note, this should only be used when the version passed in is already known to be a well formatted version number. Otherwise, DependencyVersionUtil.parseVersion() should be used instead.- Parameters:
version- the well formatted version number to parse
-
-
Method Detail
-
parseVersion
public final void parseVersion(java.lang.String version)
Parses a version string into its sub parts: major, minor, revision, build, etc. Note, this should only be used to parse something that is already known to be a version number.- Parameters:
version- the version string to parse
-
getVersionParts
public java.util.List<java.lang.String> getVersionParts()
Get the value of versionParts.- Returns:
- the value of versionParts
-
setVersionParts
public void setVersionParts(java.util.List<java.lang.String> versionParts)
Set the value of versionParts.- Parameters:
versionParts- new value of versionParts
-
iterator
@NotNull public @NotNull java.util.Iterator<java.lang.String> iterator()
Retrieves an iterator for the version parts.- Specified by:
iteratorin interfacejava.lang.Iterable<java.lang.String>- Returns:
- an iterator for the version parts
-
toString
public java.lang.String toString()
Reconstructs the version string from the split version parts.- Overrides:
toStringin classjava.lang.Object- Returns:
- a string representing the version.
-
equals
public boolean equals(java.lang.Object obj)
Compares the equality of this object to the one passed in as a parameter.- Overrides:
equalsin classjava.lang.Object- Parameters:
obj- the object to compare equality- Returns:
- returns true only if the two objects are equal, otherwise false
-
hashCode
public int hashCode()
Calculates the hashCode for this object.- Overrides:
hashCodein classjava.lang.Object- Returns:
- the hashCode
-
matchesAtLeastThreeLevels
public boolean matchesAtLeastThreeLevels(DependencyVersion version)
Determines if the three most major major version parts are identical. For instances, if version 1.2.3.4 was compared to 1.2.3 this function would return true.- Parameters:
version- the version number to compare- Returns:
- true if the first three major parts of the version are identical
-
compareTo
public int compareTo(@NotNull @NotNull DependencyVersion version)- Specified by:
compareToin interfacejava.lang.Comparable<DependencyVersion>
-
-