Package org.wildfly.plugin.tools

## Class VersionComparator

- java.lang.Object
- - org.wildfly.plugin.tools.VersionComparator

- All Implemented Interfaces:
    `Comparator<String>`

      public class VersionComparator
      extends Object
      implements Comparator<String>

  Compares two versions. The comparison is case-insensitive.

  Some qualifiers map to other qualifiers. Below is a table of those mappings.

  Qualifier | Mapping
  --- | ---
  GA | Final
  a | Alpha
  b | Beta
  m | Milestone
  cr | rc

  Author:
    James R. Perkins

- - ### Constructor Summary

    Constructors
    Constructor | Description
    --- | ---
    `VersionComparator()` | Creates a new version comparator.

  - ### Method Summary

    All Methods Static Methods Instance Methods Concrete Methods
    Modifier and Type | Method | Description
    --- | --- | ---
    `int` | `compare​(String o1, String o2)` |
    `static int` | `compareVersion​(boolean ignoreSnapshots, String v1, String v2)` | Compares the first version against the second version optionally ignoring if either version has a SNAPSHOT release extension.
    `static int` | `compareVersion​(String v1, String v2)` | Compares the first version against the second version.
    `static VersionComparator` | `getInstance()` | Returns an instance of a version comparator.
    `static VersionComparator` | `getInstance​(boolean ignoreSnapshots)` | Returns an instance of a version comparator which optionally ignore the SNAPSHOT release extension.

    - ### Methods inherited from class java.lang.Object

      `clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

    - ### Methods inherited from interface java.util.Comparator

      `equals, reversed, thenComparing, thenComparing, thenComparing, thenComparingDouble, thenComparingInt, thenComparingLong`

- - ### Constructor Detail

    - #### VersionComparator

          public VersionComparator()

      Creates a new version comparator.

  - ### Method Detail

    - #### getInstance

          public static VersionComparator getInstance()

      Returns an instance of a version comparator.
      Returns:
        a version comparator instance

    - #### getInstance

          public static VersionComparator getInstance​(boolean ignoreSnapshots)

      Returns an instance of a version comparator which optionally ignore the SNAPSHOT release extension. This can be useful for cases where you want to compare a version is at least a base version, not caring if it's a SNAPSHOT.
      Parameters:
        `ignoreSnapshots` - `true` to ignore the SNAPSHOT release extension, otherwise `false` which values a SNAPSHOT dependency less than a non-SNAPSHOT of the same version
      Returns:
        a version comparator instance

    - #### compareVersion

          public static int compareVersion​(String v1,
                                           String v2)

      Compares the first version against the second version.
      Parameters:
        `v1` - first version
        `v2` - second version
      Returns:
        `0` if the versions are equal, `-1` if version first version is less than the second version or `1` if the first version is greater than the second version
      See Also:
        `Comparator.compare(Object, Object)`

    - #### compareVersion

          public static int compareVersion​(boolean ignoreSnapshots,
                                           String v1,
                                           String v2)

      Compares the first version against the second version optionally ignoring if either version has a SNAPSHOT release extension. This can be useful for cases where you want to compare a version is at least a base version, not caring if it's a SNAPSHOT.

      If `ignoreSnapshots` is `true`, the version `1.0.0.Final` and `1.0.0.Final-SNAPSHOT` are said to be equal. If set to `false`, `1.0.0.Final` is greater than `1.0.0.Final-SNAPSHOT`.

      Parameters:
        `ignoreSnapshots` - `true` to ignore the SNAPSHOT release extension, otherwise `false` which values a SNAPSHOT dependency less than a non-SNAPSHOT of the same version
        `v1` - the first version
        `v2` - the second version
      Returns:
        `0` if the versions are equal, `-1` if version first version is less than the second version or `1` if the first version is greater than the second version

    - #### compare

          public int compare​(String o1,
                             String o2)

      Specified by:
        `compare` in interface `Comparator<String>`