Skip to content

Commit

Permalink
Add range constants representing a version of Java or greater.
Browse files Browse the repository at this point in the history
  • Loading branch information
baron1405 committed Jun 29, 2024
1 parent 56e7061 commit b3fa0be
Show file tree
Hide file tree
Showing 6 changed files with 257 additions and 120 deletions.
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

- New `JavaVersion` and `JavaVersionScheme` classes to represent and interact with Java language
versions (e.g. 11, 1.4, 17.0.11+34-cthing, 8u17)
- A `JavaVersionExample` class has been added to the examples sub-project
- A `JavaVersionExample` class has been added to the examples subproject
- New `VersionConstraint.complement()` method to obtain a constraint representing all versions
not in a constraint. For example, the complement of the constraint `[1.5,2.0)` is `(,1.5),[2.0,)`.
- New `VersionConstraint.isNotEmpty()` method to indicate that a version constraint contains version
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,12 @@ public static void main(final String[] args) throws VersionParsingException {
assertThat(JavaVersionScheme.isVersion(JavaVersionScheme.JAVA_17, "17.0.11")).isTrue();
assertThat(JavaVersionScheme.isVersion(JavaVersionScheme.JAVA_17, "21")).isFalse();

assertThat(JavaVersionScheme.isVersion(JavaVersionScheme.JAVA_17_PLUS, "11")).isFalse();
assertThat(JavaVersionScheme.isVersion(JavaVersionScheme.JAVA_17_PLUS, "16")).isFalse();
assertThat(JavaVersionScheme.isVersion(JavaVersionScheme.JAVA_17_PLUS, "17")).isTrue();
assertThat(JavaVersionScheme.isVersion(JavaVersionScheme.JAVA_17_PLUS, "17.0.11")).isTrue();
assertThat(JavaVersionScheme.isVersion(JavaVersionScheme.JAVA_17_PLUS, "21")).isTrue();

// Runtime Java version
assertThat(JavaVersion.RUNTIME_VERSION.getFeature()).isGreaterThanOrEqualTo(17);
}
Expand Down
21 changes: 14 additions & 7 deletions src/main/java/org/cthing/versionparser/java/JavaVersion.java
Original file line number Diff line number Diff line change
Expand Up @@ -88,63 +88,70 @@ public boolean isPreRelease() {
}

/**
* Obtains the build number, if present. See {@link Runtime.Version#build()}.
* Obtains the build number, if present.
*
* @return Build number
* @see Runtime.Version#build()
*/
public Optional<Integer> getBuild() {
return this.javaVersion.build();
}

/**
* Obtains the feature component of the version. See {@link Runtime.Version#feature()}.
* Obtains the feature component of the version.
*
* @return Feature component of the version.
* @see Runtime.Version#feature()
*/
public int getFeature() {
return this.javaVersion.feature();
}

/**
* Obtains the interim component of the version. See {@link Runtime.Version#interim()}.
* Obtains the interim component of the version.
*
* @return Interim component of the version.
* @see Runtime.Version#interim()
*/
public int getInterim() {
return this.javaVersion.interim();
}

/**
* Obtains the optional portion of the version, if present. See {@link Runtime.Version#optional()}.
* Obtains the optional portion of the version, if present.
*
* @return Optional portion of the version.
* @see Runtime.Version#optional()
*/
public Optional<String> getOptional() {
return this.javaVersion.optional();
}

/**
* Obtains the patch portion of the version. See {@link Runtime.Version#patch()}.
* Obtains the patch portion of the version.
*
* @return Patch portion of the version.
* @see Runtime.Version#patch()
*/
public int getPatch() {
return this.javaVersion.patch();
}

/**
* Obtains the pre-release portion of the version, if present. See {@link Runtime.Version#pre()}.
* Obtains the pre-release portion of the version, if present.
*
* @return Pre-release portion of the version.
* @see Runtime.Version#pre()
*/
public Optional<String> getPre() {
return this.javaVersion.pre();
}

/**
* Obtains the update portion of the version. See {@link Runtime.Version#update()}.
* Obtains the update portion of the version.
*
* @return Update portion of the version.
* @see Runtime.Version#update()
*/
public int getUpdate() {
return this.javaVersion.update();
Expand Down
Loading

0 comments on commit b3fa0be

Please sign in to comment.