Changeset 9954 in josm for trunk/src/org/openstreetmap/josm/tools
- Timestamp:
- 2016-03-08T01:22:33+01:00 (7 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/tools/Utils.java
r9916 r9954 92 92 private static final char[] DEFAULT_STRIP = {'\u200B', '\uFEFF'}; 93 93 94 private static final String[] SIZE_UNITS = {"B", "kB", "MB", "GB", "TB", "PB", "EB", "ZB", "YB"}; 95 94 96 /** 95 97 * Tests whether {@code predicate} applies to at least one element from {@code collection}. … … 1042 1044 throw new IllegalArgumentException("bytes must be >= 0"); 1043 1045 } 1044 final String[] units = {"B", "kB", "MB", "GB", "TB", "PB", "EB", "ZB", "YB"};1045 1046 int unitIndex = 0; 1046 1047 double value = bytes; 1047 while (value >= 1024 && unitIndex < units.length) {1048 while (value >= 1024 && unitIndex < SIZE_UNITS.length) { 1048 1049 value /= 1024; 1049 1050 unitIndex++; 1050 1051 } 1051 1052 if (value > 100 || unitIndex == 0) { 1052 return String.format(locale, "%.0f %s", value, units[unitIndex]);1053 return String.format(locale, "%.0f %s", value, SIZE_UNITS[unitIndex]); 1053 1054 } else if (value > 10) { 1054 return String.format(locale, "%.1f %s", value, units[unitIndex]);1055 return String.format(locale, "%.1f %s", value, SIZE_UNITS[unitIndex]); 1055 1056 } else { 1056 return String.format(locale, "%.2f %s", value, units[unitIndex]);1057 return String.format(locale, "%.2f %s", value, SIZE_UNITS[unitIndex]); 1057 1058 } 1058 1059 }
Note: See TracChangeset
for help on using the changeset viewer.