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

Allow checking whether Duration is zero length #27

Conversation

findepi
Copy link
Contributor

@findepi findepi commented Aug 3, 2022

This introduces new API method for checking whether duration is empty.
The tempting terse alternative of duration.toMillis() == 0 does not
work correctly for sub-milli duration, so it's better to provide a
shortcut that's correct.

@@ -164,6 +169,11 @@ public int compareTo(Duration o)
return Double.compare(getValue(MILLISECONDS), o.getValue(MILLISECONDS));
}

public boolean isZero()
{
return compareTo(ZERO) == 0;
Copy link
Member

Choose a reason for hiding this comment

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

Why not

return equals(ZERO);

This gets us the fast identity comparison, which seems to be the point of having a ZERO constant instance.

@findepi findepi force-pushed the findepi/allow-checking-whether-duration-is-zero-length-b0d267 branch 2 times, most recently from 87935e7 to a8d741e Compare July 3, 2023 14:22
@findepi
Copy link
Contributor Author

findepi commented Jul 3, 2023

PTAL

This introduces new API method for checking whether duration is empty.
The tempting terse alternative of `duration.toMillis() == 0` does not
work correctly for sub-milli duration, so it's better to provide a
shortcut that's correct.
@findepi findepi force-pushed the findepi/allow-checking-whether-duration-is-zero-length-b0d267 branch from a8d741e to 8cb2838 Compare July 4, 2023 12:15
@findepi
Copy link
Contributor Author

findepi commented Jul 4, 2023

New code extracted to #33, PTAL there.
Restored original, approved, scope of this PR.

@findepi findepi merged commit 82df863 into airlift:master Jul 4, 2023
2 checks passed
@findepi findepi deleted the findepi/allow-checking-whether-duration-is-zero-length-b0d267 branch July 4, 2023 12:36
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.

2 participants