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

feat: Added support of compareTo #158

Merged
merged 10 commits into from
Jan 12, 2024
Merged

Conversation

imalygin
Copy link
Member

@imalygin imalygin commented Dec 22, 2023

PR highlights:

  • by default all fields of a class are used in compareTo method.
  • pbj.comparable option in a comment can be used to specify limited set of fields to be used in compareTo.
// <<<pbj.comparable = "int32Number, text, subObject" >>>
  • there was a small modification in Protobuf grammar definition to support it
  • Bytes and BytesValue fields are compared using byte-by-byte comparison
  • repeatable fields are not supported

Misc:

  • refactored ModelGenerator: extracted code-generating code into several independent methods
  • upgraded Gradle version to 8.5 to support Java 21
  • added dependency to Mockito framework in pbj-compiler

Related issue(s):

Fixes #103

Misc:
- refactored ModelGenerator: extracted code-generating code into several independent methods
- upgraded Gradle version to 8.5 to support Java 21
- added dependency to Mockito framework in pbj-compiler

Signed-off-by: Ivan Malygin <[email protected]>
Copy link

github-actions bot commented Dec 22, 2023

JUnit Test Report

     47 files  ±0       47 suites  ±0   3m 29s ⏱️ +5s
1 111 tests +6  1 110 ✔️ +6    1 💤 ±0  0 ±0 
6 966 runs  +6  6 948 ✔️ +6  18 💤 ±0  0 ±0 

Results for commit 1d597cb. ± Comparison against base commit baabed4.

♻️ This comment has been updated with latest results.

Copy link
Contributor

codacy-production bot commented Dec 22, 2023

Coverage summary from Codacy

See diff coverage on Codacy

Coverage variation Diff coverage
+19.21% (target: -1.00%) 9.25%
Coverage variation details
Coverable lines Covered lines Coverage
Common ancestor commit (f4367bd) 6430 1624 25.26%
Head commit (1d597cb) 4214 (-2216) 1874 (+250) 44.47% (+19.21%)

Coverage variation is the difference between the coverage for the head and common ancestor commits of the pull request branch: <coverage of head commit> - <coverage of common ancestor commit>

Diff coverage details
Coverable lines Covered lines Diff coverage
Pull request (#158) 346 32 9.25%

Diff coverage is the percentage of lines that are covered by tests out of the coverable lines that the pull request added or modified: <covered lines added or modified>/<coverable lines added or modified> * 100%

See your quality gate settings    Change summary preferences

You may notice some variations in coverage metrics with the latest Coverage engine update. For more details, visit the documentation

Copy link

github-actions bot commented Dec 22, 2023

Integration Test Report

     232 files  +  16       232 suites  +16   6m 11s ⏱️ -42s
87 138 tests +144  87 138 ✔️ +144  0 💤 ±0  0 ±0 
87 366 runs  +144  87 366 ✔️ +144  0 💤 ±0  0 ±0 

Results for commit 1d597cb. ± Comparison against base commit baabed4.

♻️ This comment has been updated with latest results.

@imalygin imalygin force-pushed the 103-add-support-of-comparable branch from 69dd3f9 to 04af982 Compare January 11, 2024 19:39
@imalygin imalygin force-pushed the 103-add-support-of-comparable branch from 04af982 to a28cced Compare January 11, 2024 20:00
- now fields are considered comparable only if they are explicitly mentioned in `pbj.comparable` option
- preserving order of the comparable fields
- added proper support for OneOf fields
- added support for `Bytes` field
- fixed formatting
- added tests for non-compilable cases

Signed-off-by: Ivan Malygin <[email protected]>
@imalygin imalygin force-pushed the 103-add-support-of-comparable branch from a28cced to cb37aaa Compare January 11, 2024 20:25
@imalygin imalygin force-pushed the 103-add-support-of-comparable branch from b9e6d00 to a797ad3 Compare January 11, 2024 20:35
Copy link
Member

@jsync-swirlds jsync-swirlds left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Impressive effort so far, but there are a few minor issues, and some items that need to be fixed.

imalygin and others added 4 commits January 11, 2024 18:29
…pl/Common.java

Co-authored-by: Joseph Sinclair <[email protected]>
Signed-off-by: Ivan Malygin <[email protected]>
Signed-off-by: Ivan Malygin <[email protected]>
… `pbj.comparable` option.

Signed-off-by: Ivan Malygin <[email protected]>
Signed-off-by: Ivan Malygin <[email protected]>
@imalygin imalygin force-pushed the 103-add-support-of-comparable branch from f10c738 to 6fb378b Compare January 12, 2024 02:46
Fixed regex for Comparable record
Added test for primitive wrappers and unsigned values
Fixed compareTo for BytesValue

Signed-off-by: Ivan Malygin <[email protected]>
…d not mentioned in `pbj.comparable`

Signed-off-by: Ivan Malygin <[email protected]>
Copy link
Member

@jsync-swirlds jsync-swirlds left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Excellent work, Ivan.

@imalygin imalygin merged commit 1394b82 into main Jan 12, 2024
9 of 10 checks passed
@imalygin imalygin deleted the 103-add-support-of-comparable branch January 12, 2024 20:57
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.

Certain generated classes need to be Comparable
6 participants