Skip to content

Commit

Permalink
feat: optional version factory
Browse files Browse the repository at this point in the history
  • Loading branch information
darksaid98 committed Dec 22, 2024
1 parent 5f64144 commit 01763eb
Showing 1 changed file with 16 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import org.jetbrains.annotations.NotNull;

import java.util.Objects;
import java.util.Optional;

/**
* A class representing a Semantic Version.
Expand Down Expand Up @@ -77,6 +78,21 @@ public class Version extends VersionCompare implements Comparable<Version> {
return VersionParser.parse(version);
}

/**
* Create a Version object from a version string.
*
* @param version a string containing a semantic version
* @return a version object wrapped in a optional
* @apiNote Uses {@link VersionParser#parse(String)} internally
*/
public static @NotNull Optional<Version> ofOptional(String version) {
try {
return Optional.of(VersionParser.parse(version));
} catch (Exception ignored) {
return Optional.empty();
}
}

/**
* Create a Version object from semantic version data.
*
Expand Down

0 comments on commit 01763eb

Please sign in to comment.