zafarkhaja / jsemver

Java implementation of the SemVer Specification
MIT License
429 stars 82 forks source link

Support for Version.isValid(String) operation #26

Closed eric-isakson closed 6 months ago

eric-isakson commented 8 years ago

I have use cases where I need to do something if some string is not a semantic version. Currently I have to write:

// if the requested version is an exact semantic version, make no adjustments try { Version.valueOf(details.requested.version) } catch (IllegalArgumentException | ParseException ve) { // this was not an exact semantic version // do something }

I would like to write

if ( ! Version.isValid(details.requested.version) ) { // do something }

rather than using a try/catch for this logic. At my company, we have a coding standard that states "Do not use exceptions for control flow" and while I can, I shouldn't have to.

isValid should return true only if the string matches the semver spec (i.e. it should not do any of the loose parsing I've seen suggested in some other issues like accepting a 1 or 1.0 as a valid version string and padding it out to 1.0.0)

zafarkhaja commented 8 years ago

Thank you @eric-isakson for the feedback, I've scheduled this for the next 0.10.0 release.

zafarkhaja commented 1 year ago

Hello Eric! Sorry for the delay and thank you for your contribution!