Class DependencyVersion

java.lang.Object
org.owasp.dependencycheck.utils.DependencyVersion
All Implemented Interfaces:
Comparable<DependencyVersion>, Iterable<String>

@NotThreadSafe public class DependencyVersion extends Object implements Iterable<String>, 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 Details

    • DependencyVersion

      public DependencyVersion()
      Constructor for a empty DependencyVersion.
    • DependencyVersion

      public DependencyVersion(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 Details

    • parseVersion

      public final void parseVersion(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 List<String> getVersionParts()
      Get the value of versionParts.
      Returns:
      the value of versionParts
    • setVersionParts

      public void setVersionParts(List<String> versionParts)
      Set the value of versionParts.
      Parameters:
      versionParts - new value of versionParts
    • iterator

      public @NonNull Iterator<String> iterator()
      Retrieves an iterator for the version parts.
      Specified by:
      iterator in interface Iterable<String>
      Returns:
      an iterator for the version parts
    • toString

      public String toString()
      Reconstructs the version string from the split version parts.
      Overrides:
      toString in class Object
      Returns:
      a string representing the version.
    • equals

      public boolean equals(Object obj)
      Compares the equality of this object to the one passed in as a parameter.
      Overrides:
      equals in class 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:
      hashCode in class 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(@NonNull DependencyVersion version)
      Specified by:
      compareTo in interface Comparable<DependencyVersion>