@Test public void getDownloadSpeedString() { assertEquals("downloadSpeedKiloBytes", "500.0 KB/s", MathUtils.GetDownloadSpeedString(500d)); assertEquals("downloadSpeedKiloBytes", "2.0 MB/s", MathUtils.GetDownloadSpeedString(2048d)); assertEquals("downloadSpeedMegaBytes", "2.0 GB/s", MathUtils.GetDownloadSpeedString(2048d * 1024)); }
public static String GetDownloadSpeedString(double averageSpeed) { if (averageSpeed <= 0) return "0 B/s"; double bps = averageSpeed * 1024D; if (bps < 1024) return String.format(LocaleUtil.getCurrent(), "%.1f B/s", bps); bps = bps / 1024; if (bps < 1024) return String.format(LocaleUtil.getCurrent(), "%.1f KB/s", bps); bps = bps / 1024; if (bps < 1024) return String.format(LocaleUtil.getCurrent(), "%.1f MB/s", bps); return String.format(LocaleUtil.getCurrent(), "%.1f GB/s", bps / 1024D); }
MathUtils { public static String GetDownloadSpeedString(double averageSpeed) { if (averageSpeed <= 0) return "0 B/s"; double bps = averageSpeed * 1024D; if (bps < 1024) return String.format(LocaleUtil.getCurrent(), "%.1f B/s", bps); bps = bps / 1024; if (bps < 1024) return String.format(LocaleUtil.getCurrent(), "%.1f KB/s", bps); bps = bps / 1024; if (bps < 1024) return String.format(LocaleUtil.getCurrent(), "%.1f MB/s", bps); return String.format(LocaleUtil.getCurrent(), "%.1f GB/s", bps / 1024D); } }
MathUtils { public static String GetDownloadSpeedString(double averageSpeed) { if (averageSpeed <= 0) return "0 B/s"; double bps = averageSpeed * 1024D; if (bps < 1024) return String.format(LocaleUtil.getCurrent(), "%.1f B/s", bps); bps = bps / 1024; if (bps < 1024) return String.format(LocaleUtil.getCurrent(), "%.1f KB/s", bps); bps = bps / 1024; if (bps < 1024) return String.format(LocaleUtil.getCurrent(), "%.1f MB/s", bps); return String.format(LocaleUtil.getCurrent(), "%.1f GB/s", bps / 1024D); }  }
MathUtils { public static String GetDownloadSpeedString(double averageSpeed) { if (averageSpeed <= 0) return "0 B/s"; double bps = averageSpeed * 1024D; if (bps < 1024) return String.format(LocaleUtil.getCurrent(), "%.1f B/s", bps); bps = bps / 1024; if (bps < 1024) return String.format(LocaleUtil.getCurrent(), "%.1f KB/s", bps); bps = bps / 1024; if (bps < 1024) return String.format(LocaleUtil.getCurrent(), "%.1f MB/s", bps); return String.format(LocaleUtil.getCurrent(), "%.1f GB/s", bps / 1024D); }  static String GetLengthString(final long lengthInBytes); static String GetTimeRemainingString(long timeRemainingMillis); static String GetTimeRemainingOrDateString(final long now,
            final long elapsed,
            final boolean bDate); static String parseTimeRelativeToNow(final String timestamp); static String GetDownloadSpeedString(double averageSpeed); static double log2(final double v); static double parseDouble(String value, double defaultVal); static int parseInt(String value, int defaultVal); }
MathUtils { public static String GetDownloadSpeedString(double averageSpeed) { if (averageSpeed <= 0) return "0 B/s"; double bps = averageSpeed * 1024D; if (bps < 1024) return String.format(LocaleUtil.getCurrent(), "%.1f B/s", bps); bps = bps / 1024; if (bps < 1024) return String.format(LocaleUtil.getCurrent(), "%.1f KB/s", bps); bps = bps / 1024; if (bps < 1024) return String.format(LocaleUtil.getCurrent(), "%.1f MB/s", bps); return String.format(LocaleUtil.getCurrent(), "%.1f GB/s", bps / 1024D); }  static String GetLengthString(final long lengthInBytes); static String GetTimeRemainingString(long timeRemainingMillis); static String GetTimeRemainingOrDateString(final long now,
            final long elapsed,
            final boolean bDate); static String parseTimeRelativeToNow(final String timestamp); static String GetDownloadSpeedString(double averageSpeed); static double log2(final double v); static double parseDouble(String value, double defaultVal); static int parseInt(String value, int defaultVal);  }