Class FrontendVersion

java.lang.Object
com.vaadin.flow.internal.FrontendVersion
All Implemented Interfaces:
Serializable, Comparable<FrontendVersion>

public class FrontendVersion extends Object implements Serializable, Comparable<FrontendVersion>
Version object for frontend versions comparison and handling.

Equality, hash codes and ordering use version parts only, ignoring npm alias targets. Use isSameDependency(FrontendVersion) when both the version and package target must match, or hasSamePackageTarget(FrontendVersion) to compare targets alone.

For internal use only. May be renamed or removed in a future release.

Since:
25.1
See Also:
  • Constructor Details

    • FrontendVersion

      public FrontendVersion(int major, int minor)
      Create a version of format "major.minor.0".
      Parameters:
      major - major version
      minor - minor version
    • FrontendVersion

      public FrontendVersion(int major, int minor, int revision)
      Create a version of format "major.minor.revision".
      Parameters:
      major - major version
      minor - minor version
      revision - revision number
    • FrontendVersion

      public FrontendVersion(int major, int minor, int revision, String build)
      Create a version of format "major.minor.revision.build"
      Parameters:
      major - major version
      minor - minor version
      revision - revision number
      build - build identifier
    • FrontendVersion

      public FrontendVersion(String version)
      Parse version numbers from version string with the format "major.minor.revision[.build]". The build part is optional.

      Versions are normalized and any caret or tildes will not be considered when comparing versions. Versioned npm aliases are compared using their embedded version, while retaining the full alias specification.

      Parameters:
      version - version string as "major.minor.revision[.build]"
    • FrontendVersion

      public FrontendVersion(String name, String version)
      Parse version numbers from version string with the format "major.minor.revision[.build]". The build part is optional.

      Versions are normalized and any caret or tildes will not be considered when comparing versions. Versioned npm aliases are compared using their embedded version, while retaining the full alias specification.

      Parameters:
      name - the name of the artifact which version is to be parsed, used in error message to help discover the issue
      version - version string as "major.minor.revision[.build]"
  • Method Details

    • getFullVersion

      public String getFullVersion()
      Gets the full version, in format x.y.z or x.y.z.qualifier. For npm aliases, returns the complete alias specification so that writing it back preserves the target package.
      Returns:
      the full version number
    • hasSamePackageTarget

      public boolean hasSamePackageTarget(FrontendVersion other)
      Checks whether two versions refer to the same npm alias target, or both are ordinary versions. Version ordering itself ignores alias targets.
      Parameters:
      other - the version to compare
      Returns:
      whether the package targets match
    • isSameDependency

      public boolean isSameDependency(FrontendVersion other)
      Checks both package target and version when detecting dependency edits.
      Parameters:
      other - the version to compare
      Returns:
      whether the target and parsed version are equal
    • getMajorVersion

      public int getMajorVersion()
      Gets the major version, x in x.y.z.qualifier.
      Returns:
      the major version number
    • getMinorVersion

      public int getMinorVersion()
      Gets the minor version, y in x.y.z.qualifier.
      Returns:
      the minor version number
    • getRevision

      public int getRevision()
      Gets the revision, z in x.y.z.qualifier.
      Returns:
      the revision number
    • getBuildIdentifier

      public String getBuildIdentifier()
      Gets the version qualifier, qualifier in x.y.z.qualifier.
      Returns:
      the version qualifier
    • isOlderThan

      public boolean isOlderThan(FrontendVersion otherVersion)
      Check if this version is older than given version. Will return false if equals or is newer.
      Parameters:
      otherVersion - version to check against
      Returns:
      true if this is older than otherVersion
    • isNewerThan

      public boolean isNewerThan(FrontendVersion otherVersion)
      Check if this version is newer than given version. Will return false if equals or is older.
      Parameters:
      otherVersion - version to check against
      Returns:
      true if this is newer than otherVersion
    • isEqualOrNewer

      public boolean isEqualOrNewer(FrontendVersion otherVersion)
      Check if this version is equal or newer than given version. Will return false if is older.
      Parameters:
      otherVersion - version to check against
      Returns:
      true if this is newer than or equal to otherVersion
    • isEqualTo

      public boolean isEqualTo(FrontendVersion otherVersion)
      Check if this and the given version are equal to each other.
      Parameters:
      otherVersion - version to test equals with
      Returns:
      true if parsed version parts are exactly the same
    • equals

      public boolean equals(Object obj)
      Overrides:
      equals in class Object
    • toString

      public String toString()
      Overrides:
      toString in class Object
    • hashCode

      public int hashCode()
      Overrides:
      hashCode in class Object
    • compareTo

      public int compareTo(FrontendVersion other)
      Compare version numbers and return order as -1, 0 and 1. Where this version is older, equals, newer than given version.
      Specified by:
      compareTo in interface Comparable<FrontendVersion>
      Parameters:
      other - version to compare against this version
      Returns:
      -1 this is older, 0 versions equal, 1 this is newer