Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Pretty string representations for Range and Requirement #33

Merged
merged 3 commits into from Aug 16, 2019
Merged

Pretty string representations for Range and Requirement #33

merged 3 commits into from Aug 16, 2019

Conversation

joschi
Copy link
Contributor

@joschi joschi commented Jun 6, 2018

This PR adds pretty toString() representations for the Range and Requirement classes.

Instead of a relatively abstract representation for Range#toString() and Requirement#toString(), these methods now return a representation which is in turn again a valid range or version expression.

Example for Range#toString():

  • Before: "(EQ, 1.2.3)"
  • After: "=1.2.3"

Examples for Requirement#toString():

  • Before: "Requirement{(EQ, 1.2.3)}"

  • After: "=1.2.3"

  • Before: "Requirement{(EQ, 1.2.3) OR (LT, 2.0.0)}"

  • After: "=1.2.3 || <2.0.0"

´java.util.Objects`, which is being used in `Requirement`, has only been available since Java 7.
Instead of a relatively abstract representation for `Range#toString()` and `Requirement#toString()`
they now return a representation which is in turn again a valid range or version expression.

Example for `Range#toString()`:

* Before: "(EQ, 1.2.3)"
* After: "=1.2.3"

Examples for `Requirement#toString()`:

* Before: "Requirement{(EQ, 1.2.3)}"
* After: "=1.2.3"

* Before: "Requirement{(EQ, 1.2.3) OR (LT, 2.0.0)}"
* After: "=1.2.3 || <2.0.0"
@coveralls
Copy link

Coverage Status

Coverage increased (+1.0%) to 93.761% when pulling 7bc99ea on joschi:pretty-string into 3f0266e on vdurmont:master.

@joschi
Copy link
Contributor Author

joschi commented Jun 6, 2018

Refs #31 (for the correct Java version in the Maven POM)

@vdurmont
Copy link
Owner

vdurmont commented Jun 6, 2018

This is awesome, thank you very much.

One thing though, why upgrade to java 7?I get that the Objects functions are awesome but couldn't we achieve the same thing with older functions. I've been away from the Java world for some time but it looks like Objects.equals just adds the fact that if both objects are null, they're equal. I'm wondering if this only is worth dropping the retrocompatibility with java 6.

What are your thoughts?

@joschi
Copy link
Contributor Author

joschi commented Jun 7, 2018

@vdurmont I didn't add the usage of the Objects class. It was already there (probably added in 90ae863) and the project didn't successfully build because of it. 😉

This being said, are there any reservations about upgrading to Java 7 (or even Java 8) in this project?
Java 6 has been EOL for ages now (see http://www.oracle.com/technetwork/java/javase/eol-135779.html).

@joschi
Copy link
Contributor Author

joschi commented Jun 11, 2018

@vdurmont Any chance to get this merged and a new release of semver4j?

I'm currently working around the toString() implementation using reflection. 😞
https://github.com/Graylog2/graylog2-server/blob/0b3f6c1803734bfc0350cb87af41cb143562db38/graylog2-server/src/main/java/org/graylog2/jackson/SemverRequirementSerializer.java

@joschi
Copy link
Contributor Author

joschi commented Jun 19, 2018

@vdurmont Is there anything I could help you with getting this merged?

joschi pushed a commit to graylog-labs/semver4j that referenced this pull request Jul 4, 2018
@vdurmont vdurmont closed this Aug 16, 2019
@vdurmont vdurmont reopened this Aug 16, 2019
@vdurmont vdurmont merged commit eac4330 into vdurmont:master Aug 16, 2019
shuyingz pushed a commit to shuyingz/semver4j that referenced this pull request Oct 18, 2019
* Update to Java 7 in Maven POM

´java.util.Objects`, which is being used in `Requirement`, has only been available since Java 7.

* Add pretty `toString()` representation for Range and Requirement

Instead of a relatively abstract representation for `Range#toString()` and `Requirement#toString()`
they now return a representation which is in turn again a valid range or version expression.

Example for `Range#toString()`:

* Before: "(EQ, 1.2.3)"
* After: "=1.2.3"

Examples for `Requirement#toString()`:

* Before: "Requirement{(EQ, 1.2.3)}"
* After: "=1.2.3"

* Before: "Requirement{(EQ, 1.2.3) OR (LT, 2.0.0)}"
* After: "=1.2.3 || <2.0.0"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants