Example #1
0
 /**
  * @param value
  * @return string
  */
 public static final String toDecimal(final long value) {
   if (value < 0) {
     return '-' + Format.Compact.toDecimal(-value);
   }
   if (value >= 100L * 1000L * 1000L * 1000L * 1000L) {
     return Compact.FORMATTER.format1(value / Format.DOUBLE_TERA) + "T";
   }
   if (value >= 1000L * 1000L * 1000L * 1000L) {
     return Compact.FORMATTER.format2(value / Format.DOUBLE_TERA) + "T";
   }
   if (value >= 100L * 1000L * 1000L * 1000L) {
     return Compact.FORMATTER.format1(value / Format.DOUBLE_GIGA) + "G";
   }
   if (value >= 1000L * 1000L * 1000L) {
     return Compact.FORMATTER.format2(value / Format.DOUBLE_GIGA) + "G";
   }
   if (value >= 100L * 1000L * 1000L) {
     return Compact.FORMATTER.format1(value / Format.DOUBLE_MEGA) + "M";
   }
   if (value >= 1000L * 1000L) {
     return Compact.FORMATTER.format2(value / Format.DOUBLE_MEGA) + "M";
   }
   if (value >= 100L * 1000L) {
     return Compact.FORMATTER.format2(value / Format.DOUBLE_KILO) + "k";
   }
   if (value >= 1000L) {
     return Compact.FORMATTER.format2(value / Format.DOUBLE_KILO) + "k";
   }
   if (value >= 100L) {
     return Compact.FORMATTER.format1(value);
   }
   return Compact.FORMATTER.format2(value);
 }
Example #2
0
 /**
  * @param value
  * @return string
  */
 public static final String toPeriod(final double value) {
   if (value <= 0) {
     return String.valueOf(value);
   }
   if (value >= Format.DOUBLE_WEEK_PERIOD) {
     return Compact.FORMATTER.format2(value / Format.DOUBLE_WEEK_PERIOD) + " week(s)";
   }
   if (value >= Format.DOUBLE_DAY_PERIOD) {
     return Compact.FORMATTER.format2(value / Format.DOUBLE_DAY_PERIOD) + " day(s)";
   }
   if (value >= Format.DOUBLE_HOUR_PERIOD) {
     return Compact.FORMATTER.format2(value / Format.DOUBLE_HOUR_PERIOD) + " hour(s)";
   }
   if (value >= Format.DOUBLE_MINUTE_PERIOD) {
     return Compact.FORMATTER.format2(value / Format.DOUBLE_MINUTE_PERIOD) + " minute(s)";
   }
   if (value >= Format.DOUBLE_SECOND_PERIOD) {
     return Compact.FORMATTER.format2(value / Format.DOUBLE_SECOND_PERIOD) + " second(s)";
   }
   if (value >= Format.DOUBLE_MILLISECOND_PERIOD) {
     // return formatter.format(value / dMILLISECOND_PERIOD) + " ms";
     return Compact.FORMATTER.format2(value) + " ms";
   }
   if (value >= Format.DOUBLE_MICROSECOND_PERIOD) {
     return Compact.FORMATTER.format2(value / Format.DOUBLE_MICROSECOND_PERIOD) + " mks";
   }
   return Compact.FORMATTER.format2(value / Format.DOUBLE_NANOSECOND_PERIOD) + " nanos";
 }
Example #3
0
 /**
  * @param value
  * @return string
  */
 public static final String toBytes(final double value) {
   if (value < 1000L) {
     if (value < 0) {
       return '-' + Format.Compact.toBytes(-value);
     }
     if (value >= 1) {
       return Compact.FORMATTER.format2(value) + ' ';
     }
     if (value >= Format.DOUBLE_MILLI) {
       return Compact.FORMATTER.format2(value / Format.DOUBLE_MILLI_BYTES) + " ml";
     }
     if (value >= Format.DOUBLE_MICRO) {
       return Compact.FORMATTER.format2(value / Format.DOUBLE_MICRO_BYTES) + " mk";
     }
     return Compact.FORMATTER.format2(value / Format.DOUBLE_NANO_BYTES) + " n";
   }
   if (value >= 1000L * 1000L * 1000L * 1000L) {
     return Compact.FORMATTER.format2(value / Format.DOUBLE_TERA_BYTES) + " T";
   }
   if (value >= 1000L * 1000L * 1000L) {
     return Compact.FORMATTER.format2(value / Format.DOUBLE_GIGA_BYTES) + " G";
   }
   if (value >= 1000L * 1000L) {
     return Compact.FORMATTER.format2(value / Format.DOUBLE_MEGA_BYTES) + " M";
   }
   if (value >= 1000L) {
     return Compact.FORMATTER.format2(value / Format.DOUBLE_KILO_BYTES) + " k";
   }
   return "n/a";
 }
Example #4
0
 /**
  * @param value
  * @return string
  */
 public static final String toBytes(final long value) {
   if (value < 0) {
     return '-' + Format.Compact.toBytes(-value);
   }
   if (value < 1000L) {
     return String.valueOf(value) + ' ';
   }
   if (value >= 1000L * 1000L * 1000L * 1000L) {
     return Compact.FORMATTER.format2(value / Format.DOUBLE_TERA_BYTES) + " T";
   }
   if (value >= 1000L * 1000L * 1000L) {
     return Compact.FORMATTER.format2(value / Format.DOUBLE_GIGA_BYTES) + " G";
   }
   if (value >= 1000L * 1000L) {
     return Compact.FORMATTER.format2(value / Format.DOUBLE_MEGA_BYTES) + " M";
   }
   return Compact.FORMATTER.format2(value / Format.DOUBLE_KILO_BYTES) + " k";
 }
Example #5
0
 /**
  * @param value
  * @return string
  */
 public static final String toPeriod(final long value) {
   if (value <= 0) {
     return String.valueOf(value);
   }
   if (value >= 1000L * 60L * 60L * 24L * 7L) {
     return Compact.FORMATTER.format2(value / Format.DOUBLE_WEEK_PERIOD) + " week(s)";
   }
   if (value >= 1000L * 60L * 60L * 24L) {
     return Compact.FORMATTER.format2(value / Format.DOUBLE_DAY_PERIOD) + " day(s)";
   }
   if (value >= 1000L * 60L * 60L) {
     return Compact.FORMATTER.format2(value / Format.DOUBLE_HOUR_PERIOD) + " hour(s)";
   }
   if (value >= 1000L * 60L) {
     return Compact.FORMATTER.format2(value / Format.DOUBLE_MINUTE_PERIOD) + " minute(s)";
   }
   if (value >= 1000L) {
     return Compact.FORMATTER.format2(value / Format.DOUBLE_SECOND_PERIOD) + " second(s)";
   }
   return Compact.FORMATTER.format2(value) + " ms";
 }
Example #6
0
 /**
  * @param value
  * @return string
  */
 public static final String toDecimal(final double value) {
   if (Double.isInfinite(value)) {
     return value > 0 ? "+inf" : "-inf";
   }
   if (Double.isNaN(value)) {
     return "NaN";
   }
   if (value < 0) {
     return '-' + Format.Compact.toDecimal(-value);
   }
   if (value < Format.DOUBLE_NANO) {
     return String.valueOf(value);
   }
   if (value >= 100L * 1000L * 1000L * 1000L * 1000L) {
     return Compact.FORMATTER.format1(value / Format.DOUBLE_TERA) + "T";
   }
   if (value >= 1000L * 1000L * 1000L * 1000L) {
     return Compact.FORMATTER.format2(value / Format.DOUBLE_TERA) + "T";
   }
   if (value >= 100L * 1000L * 1000L * 1000L) {
     return Compact.FORMATTER.format1(value / Format.DOUBLE_GIGA) + "G";
   }
   if (value >= 1000L * 1000L * 1000L) {
     return Compact.FORMATTER.format2(value / Format.DOUBLE_GIGA) + "G";
   }
   if (value >= 100L * 1000L * 1000L) {
     return Compact.FORMATTER.format1(value / Format.DOUBLE_MEGA) + "M";
   }
   if (value >= 1000L * 1000L) {
     return Compact.FORMATTER.format2(value / Format.DOUBLE_MEGA) + "M";
   }
   if (value >= 100L * 1000L) {
     return Compact.FORMATTER.format1(value / Format.DOUBLE_KILO) + "k";
   }
   if (value >= 1000L) {
     return Compact.FORMATTER.format2(value / Format.DOUBLE_KILO) + "k";
   }
   if (value >= 20L) {
     return Compact.FORMATTER.format1(value);
   }
   if (value >= 1L) {
     return Compact.FORMATTER.format2(value);
   }
   if (value >= Format.DOUBLE_MILLI) {
     if (value >= Format.DOUBLE_MILLI * 10) {
       return Compact.FORMATTER.format3((int) (value * 1000) / 1000.0);
     }
     return Compact.FORMATTER.format2(value / Format.DOUBLE_MILLI) + "ml";
   }
   if (value >= Format.DOUBLE_MICRO) {
     return Compact.FORMATTER.format2(value / Format.DOUBLE_MICRO) + "mk";
   }
   return Compact.FORMATTER.format2(value / Format.DOUBLE_NANO) + "n";
 }