add unit type for bytes
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
package org.lucares.pdb.map;
|
||||
|
||||
import java.util.List;
|
||||
import org.lucares.utils.HumanBytes;
|
||||
|
||||
public class PersistentMapStats {
|
||||
private long values = 0;
|
||||
@@ -87,7 +87,7 @@ public class PersistentMapStats {
|
||||
builder.append(String.format("\navg. depth= %.2f", averageDepth));
|
||||
builder.append(String.format("\navg. fill= %.2f", averageFill));
|
||||
builder.append(String.format("\nvalues/node=%.2f", averageValuesInNode));
|
||||
builder.append(String.format("\nfile size= %s\n", toHumanBytes(fileSize)));
|
||||
builder.append(String.format("\nfile size= %s\n", HumanBytes.toHumanBytes(fileSize)));
|
||||
return builder.toString();
|
||||
}
|
||||
|
||||
@@ -100,21 +100,9 @@ public class PersistentMapStats {
|
||||
builder.append(String.format("\navg. depth= %.2f -> %.2f", old.averageDepth, averageDepth));
|
||||
builder.append(String.format("\navg. fill= %.2f -> %.2f", old.averageFill, averageFill));
|
||||
builder.append(String.format("\nvalues/node=%.2f -> %.2f", old.averageValuesInNode, averageValuesInNode));
|
||||
builder.append(String.format("\nfile size= %s -> %s\n", toHumanBytes(old.fileSize), toHumanBytes(fileSize)));
|
||||
builder.append(String.format("\nfile size= %s -> %s\n", HumanBytes.toHumanBytes(old.fileSize),
|
||||
HumanBytes.toHumanBytes(fileSize)));
|
||||
return builder.toString();
|
||||
}
|
||||
|
||||
private static String toHumanBytes(final long bytes) {
|
||||
final List<String> powers = List.of("bytes", "KB", "MB", "GB", "TB", "PB", "EB");
|
||||
|
||||
int power = 1;
|
||||
String result = String.format("%d bytes", bytes);
|
||||
while (bytes >= Math.pow(1024, power) && power < powers.size()) {
|
||||
result = String.format("%.3f", bytes / Math.pow(1024, power));
|
||||
result = result.replaceAll("\\.?0*$", "");
|
||||
result = result + " " + powers.get(power);
|
||||
power = power + 1;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user