au.org.consumerdatastandards.support.SemVer Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of api-model Show documentation
Show all versions of api-model Show documentation
This artefact describes the Consumer Data Standards using Java classes and annotations in a way suitable for automatic generation of Open API Specification, documentation, Server Stub, Client Libraries and Reference Test.
package au.org.consumerdatastandards.support;
import au.org.consumerdatastandards.support.data.IntegerRange;
import java.util.Objects;
/**
* Semantic Versioning
*/
public class SemVer implements Comparable {
@IntegerRange(min = 0)
private final int major;
@IntegerRange(min = 0)
private final int minor;
@IntegerRange(min = 0)
private final int patch;
public SemVer(int major, int minor, int patch) {
this.major = major;
this.minor = minor;
this.patch = patch;
}
@Override
public String toString() {
return String.format("%d.%d.%d", major, minor, patch);
}
@Override
public int compareTo(SemVer o) {
if (major != o.major) {
return major - o.major;
}
if (minor != o.minor) {
return minor - o.minor;
}
return patch - o.patch;
}
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
SemVer semVer = (SemVer) o;
return major == semVer.major &&
minor == semVer.minor &&
patch == semVer.patch;
}
@Override
public int hashCode() {
return Objects.hash(major, minor, patch);
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy