With the introduction of pattern-matching in Java 17 these classes have become
obsolete. All of their methods may be replaced by switch- or
instanceof-statements:
final PotentialSnapshotVersion version = parser.parsePotentialSnapshot("1.2.3-SNAPSHOT");
final ReleaseVersion release = version.mapEither(
Snapshot::toRelease,
Function.identity());
final SnapshotVersion snapshot = version.getSnapshotOrElseThrow(
() -> new IllegalArgumentException("expected a snapshot!"));final BaseVersion version = parser.parseBaseVersion("1.2.3-SNAPSHOT");
final ReleaseVersion release = switch (version) {
case SnapshotVersion snapshot -> snapshot.toRelease();
case ReleaseVersion release -> release;
};
if (!(version instanceof final SnapshotVersion snapshot)) {
throw new IllegalArgumentException("expected a snapshot!"));
}The VersionParser transforms Strings into either BaseVersions or
ConcreteVersions. Previously those were wrapped by PotentialSnapshotVersion
and PotentialConcreteSnapshotVersion instances in order to allow to
differentiate the implementations of these interfaces without awkward
instanceof checks.
final BaseVersion base = parser.parsePotentialSnapshot("1.2.3-SNAPSHOT")
.get();
final ConcreteVersion concrete = parser.parsePotentialConcreteSnapshot("1.2.3")
.get();These wrapper class have been removed
and with them the parsePotentialSnapshot and parsePotentialConcreteSnapshot
methods have been changed to return the BaseVersion/ConcreteVersion
directly and in the process been renamed to parseBaseVersion and
parseConcreteVersion:
final BaseVersion base = parser.parseBaseVersion("1.2.3-SNAPSHOT");
final ConcreteVersion concrete = parser.parseConcreteVersion("1.2.3");VersionsSpecificationBuilder methods addVersionRangeElement and addExplicitVersion signature changed
Previously instances of VersionRangeElement and ExplicitVersionElement had
to be created:
final Version version = new VersionsSpecificationBuilder()
.addVersionRangeElement(
new VersionRangeElement(new Boundaries<>(lower, upper)))
.addExplicitVersion(new ExplicitVersionElement(explicit))
.build();Now the methods just take the same arguments as the constructor of the
respective SpecificationElement (the class Boundaries is also superfluous
now):
final Version version = new VersionsSpecificationBuilder()
.addVersionRangeElement(lower, upper)
.addExplicitVersion(explicit)
.build();This class is merely a container for a BaseVersion and a date. It
implementing BaseVersion was complicating the usage of that interface.
It is now deprecated and will be removed in a future release.
A ConcreteSnapshotVersion requires the additional fields timestamp and
buildnumber. Previously these were supplied to the VersionBuilder via
respective setters:
final ConcreteSnapshotVersion version = new VersionBuilder()
.setMajor(1)
.setMinor(2)
.setIncremental(3)
.setConcreteSnapshotTimestamp("12345678.123456")
.setConcreteSnapshotBuildnumber(42)
.buildConcreteSnapshot();This has been improved:
final ConcreteSnapshotVersion version = new VersionBuilder()
.setMajor(1)
.setMinor(2)
.setIncremental(3)
.buildConcreteSnapshot("12345678.123456", 42);These interfaces are now sealed and can thus no longer be implemented by
other classes.
SpecificationElement and by extension ExplicitVersionElement no longer define containsVersion(Version)
This method was used internally to check, wether a Version complies with the
element. The way to determine this now is the new
VersionsSpecificationComparator, an individual element may no longer be
checked.