Enhance DataSize with comparators and simple algebra
See original GitHub issueI think it would be useful to add some handy operators to DataSize
, like comparators and some algebra:
DataSize plus(DataSize dataSize)
DataSize minus(DataSize dataSize)
DataSize divide(int scalar)
DataSize multiply(int scalar)
boolean isGreaterThan(DataSize dataSize)
boolean isLessThan(DataSize dataSize)
boolean isEqualTo(DataSize dataSize)
static DataSize sum(DataSize ...dataSizes)
static DataSize min(DataSize ...dataSizes)
static DataSize max(DataSize ...dataSizes)
static DataSize between(DataSize x, DataSize y)
These comparators are far more readable than using the .compareTo
(Similar to Java’s approach with Instant
- isBefore
and isAfter
). Also being able to do some simple algebra will be very handy for when you are doing calculations with sizes (dataSize1.plus(dataSize2)
is far more readable than doing DataSize.ofBytes(dataSize1.toBytes() + dataSize2.toBytes())
.
Issue Analytics
- State:
- Created 2 years ago
- Reactions:5
- Comments:5 (3 by maintainers)
Top Results From Across the Web
Teaching Strategies for Improving Algebra Knowledge in ...
This guide synthesizes the best available research and shares practices that are supported by evidence. It is intended to be practical and easy...
Read more >Awesome Algebra Apps and Websites
Awesome Algebra Apps and Websites. Algebra serves as a building block for more advanced math like calculus or statistics. It helps us solve...
Read more >SQL Operators - W3Schools
SQL Operators · SQL Arithmetic Operators · SQL Bitwise Operators · SQL Comparison Operators · SQL Compound Operators · SQL Logical Operators ·...
Read more >Algebra Basics: Laws Of Exponents - Math Antics - YouTube
This is a re-upload to correct a minor math typo.Learn More at mathantics.comVisit http://www.mathantics.com for more Free math videos and ...
Read more >Algebra Basics: The Distributive Property - Math Antics
This video introduces the Distributive Property in its general algebraic form: a(b + c) = ab + ac It shows how this patten...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Hi @nhmarujo,
Thanks for the proposal (and your first issue) for the Spring Framework.
At this time, the team does not wish to add to the public API of
DataSize
since such additions are not needed within the framework itself.In light of that, I am closing this issue.
Hi @sbrannen . Thank you for your reply.
I can provide a concrete use case we had recently - we were creating a way to automatically calibrate
argon2
parameters. For that we had to try to iteratively find the best memory setting, which involved starting at some given value, do some runs and then calculate next step until some criteria was met. This simple example involved:DataSize
DataSize
DataSize
I can, however, think of more use cases:
Of course you can do any of these without the operators I was suggesting, but I reckon they would make the code far easier to implement and much more readable.
Best regards