Skip to content

Allow checking whether Duration is zero length#27

Merged
findepi merged 1 commit into
airlift:masterfrom
findepi:findepi/allow-checking-whether-duration-is-zero-length-b0d267
Jul 4, 2023
Merged

Allow checking whether Duration is zero length#27
findepi merged 1 commit into
airlift:masterfrom
findepi:findepi/allow-checking-whether-duration-is-zero-length-b0d267

Conversation

@findepi
Copy link
Copy Markdown
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.


public boolean isZero()
{
return compareTo(ZERO) == 0;
Copy link
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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
@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