Closed nhmarujo closed 2 years ago
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 . I believe many people using Spring are using DataSize
which, for instance, is very handy to use in properties.
I get that it is not used internally by the framework, but if it is meant to be used by people using the framework and if this would be handy for them, isn't that a strong enough reason to add it?
If possible, I would even be willing to give it a try producing a PR for this 😄
As I mentioned, the team decision was not to implement additional features in DataSize
at this time.
However, if the community expresses great interest in such features over time, we may choose to revisit this topic.
I think it would be useful to add some handy operators to
DataSize
For the sake of clarity, can you please expound on any concrete use case you have where you need such functionality?
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
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 withInstant
-isBefore
andisAfter
). 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 doingDataSize.ofBytes(dataSize1.toBytes() + dataSize2.toBytes())
.