Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -767,7 +767,7 @@ public static String long2String(long n, String unit, int decimalPlaces) {
}
//take care a special case
if (n == Long.MIN_VALUE) {
return "-8 " + EXA.symbol + unit;
return "-8" + EXA.symbol + unit;
}

final StringBuilder b = new StringBuilder();
Expand All @@ -779,7 +779,7 @@ public static String long2String(long n, String unit, int decimalPlaces) {
if (n < KILO.value) {
//no prefix
b.append(n);
return (unit.isEmpty()? b: b.append(" ").append(unit)).toString();
return (unit.isEmpty()? b: b.append(unit)).toString();
} else {
//find traditional binary prefix
int i = 0;
Expand All @@ -799,7 +799,7 @@ public static String long2String(long n, String unit, int decimalPlaces) {
}
b.append(s);
}
return b.append(' ').append(prefix.symbol).append(unit).toString();
return b.append(prefix.symbol).append(unit).toString();
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -232,8 +232,8 @@ public void testToStringHumanWithQuota() {
ContentSummary contentSummary = new ContentSummary.Builder().length(length).
fileCount(fileCount).directoryCount(directoryCount).quota(quota).
spaceConsumed(spaceConsumed).spaceQuota(spaceQuota).build();
String expected = " 212.0 M 1023 1 "
+ " -1 G 32.6 K 211.9 M 8.0 E ";
String expected = " 212.0M 1023 1 "
+ " -1G 32.6K 211.9M 8.0E ";
assertEquals(expected, contentSummary.toString(true, true));
}

Expand All @@ -250,7 +250,7 @@ public void testToStringHumanNoShowQuota() {
ContentSummary contentSummary = new ContentSummary.Builder().length(length).
fileCount(fileCount).directoryCount(directoryCount).quota(quota).
spaceConsumed(spaceConsumed).spaceQuota(spaceQuota).build();
String expected = " 32.6 K 211.9 M 8.0 E ";
String expected = " 32.6K 211.9M 8.0E ";
assertEquals(expected, contentSummary.toString(false, true));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -206,16 +206,16 @@ public void testTraditionalBinaryPrefix() throws Exception {
assertEquals(n + "", long2String(n, null, decimalPlace));
assertEquals(-n + "", long2String(-n, null, decimalPlace));
}
assertEquals("1 K", long2String(1L << 10, null, decimalPlace));
assertEquals("-1 K", long2String(-1L << 10, null, decimalPlace));
assertEquals("1K", long2String(1L << 10, null, decimalPlace));
assertEquals("-1K", long2String(-1L << 10, null, decimalPlace));
}

assertEquals("8.00 E", long2String(Long.MAX_VALUE, null, 2));
assertEquals("8.00 E", long2String(Long.MAX_VALUE - 1, null, 2));
assertEquals("-8 E", long2String(Long.MIN_VALUE, null, 2));
assertEquals("-8.00 E", long2String(Long.MIN_VALUE + 1, null, 2));
assertEquals("8.00E", long2String(Long.MAX_VALUE, null, 2));
assertEquals("8.00E", long2String(Long.MAX_VALUE - 1, null, 2));
assertEquals("-8E", long2String(Long.MIN_VALUE, null, 2));
assertEquals("-8.00E", long2String(Long.MIN_VALUE + 1, null, 2));

final String[] zeros = {" ", ".0 ", ".00 "};
final String[] zeros = {"", ".0", ".00"};
for(int decimalPlace = 0; decimalPlace < zeros.length; decimalPlace++) {
final String trailingZeros = zeros[decimalPlace];

Expand All @@ -225,7 +225,7 @@ public void testTraditionalBinaryPrefix() throws Exception {

{ // n = 2^e
final long n = 1L << e;
final String expected = (n/p.value) + " " + p.symbol;
final String expected = Long.toString(n/p.value) + p.symbol;
assertEquals("n=" + n, expected, long2String(n, null, 2));
}

Expand All @@ -243,19 +243,19 @@ public void testTraditionalBinaryPrefix() throws Exception {
}
}

assertEquals("1.50 K", long2String(3L << 9, null, 2));
assertEquals("1.5 K", long2String(3L << 9, null, 1));
assertEquals("1.50 M", long2String(3L << 19, null, 2));
assertEquals("2 M", long2String(3L << 19, null, 0));
assertEquals("3 G", long2String(3L << 30, null, 2));
assertEquals("1.50K", long2String(3L << 9, null, 2));
assertEquals("1.5K", long2String(3L << 9, null, 1));
assertEquals("1.50M", long2String(3L << 19, null, 2));
assertEquals("2M", long2String(3L << 19, null, 0));
assertEquals("3G", long2String(3L << 30, null, 2));

// test byteDesc(..)
assertEquals("0 B", StringUtils.byteDesc(0));
assertEquals("-100 B", StringUtils.byteDesc(-100));
assertEquals("1 KB", StringUtils.byteDesc(1024));
assertEquals("1.50 KB", StringUtils.byteDesc(3L << 9));
assertEquals("1.50 MB", StringUtils.byteDesc(3L << 19));
assertEquals("3 GB", StringUtils.byteDesc(3L << 30));
assertEquals("0B", StringUtils.byteDesc(0));
assertEquals("-100B", StringUtils.byteDesc(-100));
assertEquals("1KB", StringUtils.byteDesc(1024));
assertEquals("1.50KB", StringUtils.byteDesc(3L << 9));
assertEquals("1.50MB", StringUtils.byteDesc(3L << 19));
assertEquals("3GB", StringUtils.byteDesc(3L << 30));

// test formatPercent(..)
assertEquals("10%", StringUtils.formatPercent(0.1, 0));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,8 @@ public String getMessage() {
String msg = super.getMessage();
if (msg == null) {
return "The DiskSpace quota" + (pathName==null?"": " of " + pathName)
+ " is exceeded: quota = " + quota + " B = " + long2String(quota, "B", 2)
+ " but diskspace consumed = " + count + " B = " + long2String(count, "B", 2);
+ " is exceeded: quota = " + quota + "B = " + long2String(quota, "B", 2)
+ " but diskspace consumed = " + count + "B = " + long2String(count, "B", 2);
} else {
return msg;
}
Expand Down
Loading