question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Enhance DataSize with comparators and simple algebra

See original GitHub issue

I 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:closed
  • Created 2 years ago
  • Reactions:5
  • Comments:5 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
sbrannencommented, Oct 22, 2021

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.

0reactions
nhmarujocommented, Oct 25, 2021

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:

  • adding/substracting DataSize
  • finding middle point between 2 DataSize
  • comparing DataSize

I can, however, think of more use cases:

  • have several properties to specify how much memory is to be used in each category and then having to sum them all in code
  • Define in properties a lower and upper bound and then have in code to find out the range size or a middle point

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

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found