tillrohrmann commented on a change in pull request #10829: [FLINK-14853][docs]
Use higher granularity units in generated docs for Duration & MemorySize if
possible
URL: https://github.com/apache/flink/pull/10829#discussion_r366474018
##########
File path:
flink-core/src/main/java/org/apache/flink/configuration/MemorySize.java
##########
@@ -117,7 +121,30 @@ public boolean equals(Object obj) {
@Override
public String toString() {
- return bytes + " bytes";
+ List<MemoryUnit> orderedUnits = Arrays.asList(
+ BYTES,
+ KILO_BYTES,
+ MEGA_BYTES,
+ GIGA_BYTES,
+ TERA_BYTES);
+
+ MemoryUnit highestIntegerUnit = IntStream.range(0,
orderedUnits.size())
+ .sequential()
+ .filter(idx -> bytes %
orderedUnits.get(idx).getMultiplier() != 0)
+ .boxed()
+ .findFirst()
+ .map(idx -> {
+ if (idx == 0) {
+ return orderedUnits.get(0);
+ } else {
+ return orderedUnits.get(idx - 1);
+ }
+ }).orElse(BYTES);
+
+ return String.format(
+ "%d %s",
+ bytes / highestIntegerUnit.getMultiplier(),
+ highestIntegerUnit.getUnits()[1]);
Review comment:
Since this is a rather complex operation, I would suggest to cache the
result similar to what we are doing in `AbstractID`.
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
[email protected]
With regards,
Apache Git Services