Record Class VersionImpl

java.lang.Object
java.lang.Record
org.sonar.java.classpath.VersionImpl
All Implemented Interfaces:
Comparable<Version>, Version

public record VersionImpl(Integer major, Integer minor, @Nullable Integer patch, @Nullable String qualifier) extends Record implements Comparable<Version>, Version
Class to parse and compare versions of library jars.
  • Field Details

    • VERSION_REGEX

      public static String VERSION_REGEX
  • Constructor Details

    • VersionImpl

      public VersionImpl(Integer major, Integer minor, @Nullable Integer patch, @Nullable String qualifier)
      Creates an instance of a VersionImpl record class.
      Parameters:
      major - the value for the major record component
      minor - the value for the minor record component
      patch - the value for the patch record component
      qualifier - the value for the qualifier record component
  • Method Details

    • matcherToVersion

      public static VersionImpl matcherToVersion(Matcher matcher)
      matcher must come from a match against a pattern that contains VERSION_REGEX and no other groups.
    • parse

      public static VersionImpl parse(String versionString)
    • compareTo

      public int compareTo(Version o)
      Warning: this is a partial order: 2.5 and 2.5.1 are incomparable. Qualifiers are ignored.
      Specified by:
      compareTo in interface Comparable<Version>
    • equals

      public boolean equals(Object o)
      Indicates whether some other object is "equal to" this one. The objects are equal if the other object is of the same class and if all the record components are equal. All components in this record class are compared with Objects::equals(Object,Object).
      Specified by:
      equals in class Record
      Parameters:
      o - the object with which to compare
      Returns:
      true if this object is the same as the o argument; false otherwise.
    • hashCode

      public int hashCode()
      Returns a hash code value for this object. The value is derived from the hash code of each of the record components.
      Specified by:
      hashCode in class Record
      Returns:
      a hash code value for this object
    • toString

      public String toString()
      Returns a string representation of this record class. The representation contains the name of the class, followed by the name and value of each of the record components.
      Specified by:
      toString in class Record
      Returns:
      a string representation of this object
    • isGreaterThanOrEqualTo

      public boolean isGreaterThanOrEqualTo(Version version)
      Specified by:
      isGreaterThanOrEqualTo in interface Version
    • isGreaterThan

      public boolean isGreaterThan(Version version)
      Specified by:
      isGreaterThan in interface Version
    • isLowerThanOrEqualTo

      public boolean isLowerThanOrEqualTo(Version version)
      Specified by:
      isLowerThanOrEqualTo in interface Version
    • isLowerThan

      public boolean isLowerThan(Version version)
      Specified by:
      isLowerThan in interface Version
    • isGreaterThanOrEqualTo

      public boolean isGreaterThanOrEqualTo(String version)
      Specified by:
      isGreaterThanOrEqualTo in interface Version
    • isGreaterThan

      public boolean isGreaterThan(String version)
      Specified by:
      isGreaterThan in interface Version
    • isLowerThanOrEqualTo

      public boolean isLowerThanOrEqualTo(String version)
      Specified by:
      isLowerThanOrEqualTo in interface Version
    • isLowerThan

      public boolean isLowerThan(String version)
      Specified by:
      isLowerThan in interface Version
    • major

      public Integer major()
      Returns the value of the major record component.
      Specified by:
      major in interface Version
      Returns:
      the value of the major record component
    • minor

      public Integer minor()
      Returns the value of the minor record component.
      Specified by:
      minor in interface Version
      Returns:
      the value of the minor record component
    • patch

      @Nullable public Integer patch()
      Returns the value of the patch record component.
      Specified by:
      patch in interface Version
      Returns:
      the value of the patch record component
    • qualifier

      @Nullable public String qualifier()
      Returns the value of the qualifier record component.
      Specified by:
      qualifier in interface Version
      Returns:
      the value of the qualifier record component