Move size formatting code to StringUtil
This commit is contained in:
parent
8826de38b2
commit
55b219d271
|
@ -160,20 +160,7 @@ public class RecordingsTab extends Tab implements TabSelectionListener {
|
|||
if(empty || sizeInByte == null) {
|
||||
setText(null);
|
||||
} else {
|
||||
DecimalFormat df = new DecimalFormat("0.00");
|
||||
String unit = "Bytes";
|
||||
double size = sizeInByte.doubleValue();
|
||||
if(size > 1024.0 * 1024 * 1024) {
|
||||
size = size / 1024.0 / 1024 / 1024;
|
||||
unit = "GiB";
|
||||
} else if(size > 1024.0 * 1024) {
|
||||
size = size / 1024.0 / 1024;
|
||||
unit = "MiB";
|
||||
} else if(size > 1024.0) {
|
||||
size = size / 1024.0;
|
||||
unit = "KiB";
|
||||
}
|
||||
setText(df.format(size) + ' ' + unit);
|
||||
setText(StringUtil.formatSize(sizeInByte));
|
||||
}
|
||||
}
|
||||
};
|
||||
|
|
|
@ -1,5 +1,7 @@
|
|||
package ctbrec;
|
||||
|
||||
import java.text.DecimalFormat;
|
||||
|
||||
public class StringUtil {
|
||||
public static boolean isBlank(String s) {
|
||||
return s == null || s.trim().isEmpty();
|
||||
|
@ -8,4 +10,21 @@ public class StringUtil {
|
|||
public static boolean isNotBlank(String s) {
|
||||
return !isBlank(s);
|
||||
}
|
||||
|
||||
public static String formatSize(Number sizeInByte) {
|
||||
DecimalFormat df = new DecimalFormat("0.00");
|
||||
String unit = "Bytes";
|
||||
double size = sizeInByte.doubleValue();
|
||||
if(size > 1024.0 * 1024 * 1024) {
|
||||
size = size / 1024.0 / 1024 / 1024;
|
||||
unit = "GiB";
|
||||
} else if(size > 1024.0 * 1024) {
|
||||
size = size / 1024.0 / 1024;
|
||||
unit = "MiB";
|
||||
} else if(size > 1024.0) {
|
||||
size = size / 1024.0;
|
||||
unit = "KiB";
|
||||
}
|
||||
return df.format(size) + ' ' + unit;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue