Jump to content

Connect SuperML | Leeroopedia MCP: Equip your AI agents with best practices, code verification, and debugging knowledge. Powered by Leeroo — building Organizational Superintelligence. Contact us at founders@leeroo.com.

Implementation:Datahub project Datahub SemanticVersion

From Leeroopedia
Revision as of 14:44, 16 February 2026 by Admin (talk | contribs) (Auto-imported from implementations/Datahub_project_Datahub_SemanticVersion.md)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)


Knowledge Sources
Domains Java_SDK, Metadata_Emission, Server_Discovery
Last Updated 2026-02-10 00:00 GMT

Overview

A semantic version class supporting 3-part (1.0.0) and 4-part (1.0.0.1) version strings with comparison, parsing, and threshold checking capabilities.

Description

Version represents a parsed semantic version with four components: major, minor, patch, and build (defaulting to 0 for 3-part versions). It implements Comparable<Version> for natural ordering and provides utility methods for version threshold checks.

Parsing: The parse() static factory method handles various version string formats using the regex pattern ^v?(\d+)\.(\d+)\.(\d+)(?:\.(\d+))?(?:rc\d+|-.*)?$:

  • Optional "v" prefix: v1.0.0 and 1.0.0 are equivalent.
  • 3-part versions: v1.0.0 produces (1, 0, 0, 0).
  • 4-part versions: v1.0.0.1 produces (1, 0, 0, 1).
  • Release candidate suffixes are stripped: v1.0.0rc3 produces (1, 0, 0, 0).
  • Null or empty input returns (0, 0, 0, 0) instead of throwing.
  • Invalid format throws IllegalArgumentException.

Comparison: Versions are compared component by component in order: major, minor, patch, build. The isAtLeast() methods provide a convenient API for threshold checks without constructing comparison objects.

String representation: toString() returns a 3-part format (1.0.0) when build is 0, or a 4-part format (1.0.0.1) otherwise. The "v" prefix is not included in the output.

Usage

This class is used internally by ServerConfig to parse the server version from the /config endpoint response and perform version-based feature detection. It can also be used directly for any version comparison needs within the SDK.

Code Reference

Source Location

metadata-integration/java/datahub-client/src/main/java/datahub/client/v2/config/Version.java

Signature

public class Version implements Comparable<Version> {

    public Version(int major, int minor, int patch, int build)

    @Nonnull
    public static Version parse(@Nullable String versionString)

    public boolean isAtLeast(int major, int minor, int patch)
    public boolean isAtLeast(int major, int minor, int patch, int build)

    public int compareTo(@Nonnull Version other)
    public boolean equals(Object o)
    public int hashCode()
    public String toString()

    public int getMajor()
    public int getMinor()
    public int getPatch()
    public int getBuild()
}

Import

import datahub.client.v2.config.Version;

I/O Contract

Inputs

Constructor:

Parameter Type Description
major int Major version number
minor int Minor version number
patch int Patch version number
build int Build number (0 for 3-part versions)

parse():

Parameter Type Description
versionString String (@Nullable) Version string to parse (e.g., "v1.0.0", "1.0.0.1rc3"); null/empty returns (0,0,0,0)

Supported formats:

Input Parsed Result
"v1.0.0" (1, 0, 0, 0)
"v1.0.0.1" (1, 0, 0, 1)
"v1.0.0rc3" (1, 0, 0, 0)
"v0.3.11" (0, 3, 11, 0)
null (0, 0, 0, 0)
"invalid" throws IllegalArgumentException

Outputs

  • parse() returns a Version instance.
  • isAtLeast() returns true if this version is greater than or equal to the specified version.
  • compareTo() returns negative, zero, or positive integer following standard Comparable contract.
  • toString() returns "1.0.0" or "1.0.0.1" format.

Usage Examples

// Parse various version formats
Version v1 = Version.parse("v1.0.0");       // (1, 0, 0, 0)
Version v2 = Version.parse("v1.0.0.1");     // (1, 0, 0, 1)
Version v3 = Version.parse("v0.3.11");      // (0, 3, 11, 0)
Version v4 = Version.parse(null);           // (0, 0, 0, 0)

// Version threshold checks
boolean meetsMinimum = v1.isAtLeast(1, 0, 0);          // true
boolean needsNewer   = v1.isAtLeast(1, 0, 1);          // false
boolean cloudCheck   = v3.isAtLeast(0, 3, 11, 0);      // true

// Comparison
int result = v1.compareTo(v2);  // negative (v1 < v2)

// String representation
v1.toString();  // "1.0.0"
v2.toString();  // "1.0.0.1"

Related Pages

Page Connections

Double-click a node to navigate. Hold to expand connections.
Principle
Implementation
Heuristic
Environment