forked from elastic/elasticsearch
-
Notifications
You must be signed in to change notification settings - Fork 0
/
MinorVersion.java
47 lines (39 loc) · 1.46 KB
/
MinorVersion.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License
* 2.0 and the Server Side Public License, v 1; you may not use this file except
* in compliance with, at your election, the Elastic License 2.0 or the Server
* Side Public License, v 1.
*/
package org.elasticsearch.gradle.internal.release;
import java.util.Comparator;
import java.util.Objects;
/**
* Encapsulates comparison and printing logic for an x.y.
*/
public record MinorVersion(int major, int minor) implements Comparable<MinorVersion> {
/**
* Converts a QualifiedVersion into a MinorVersion by deleting all but the major and minor components.
*/
public static MinorVersion of(final QualifiedVersion v) {
Objects.requireNonNull(v);
return new MinorVersion(v.major(), v.minor());
}
@Override
public String toString() {
return major + "." + minor;
}
/** Generate version string with underscore instead of dot */
public String underscore() {
return major + "_" + minor;
}
private static final Comparator<MinorVersion> COMPARATOR = Comparator.comparing((MinorVersion v) -> v.major)
.thenComparing(v -> v.minor);
@Override
public int compareTo(MinorVersion other) {
return COMPARATOR.compare(this, other);
}
public boolean isBefore(MinorVersion other) {
return this.compareTo(other) < 0;
}
}