org.kuali.common.util
Class FormatUtils

java.lang.Object
  extended by org.kuali.common.util.FormatUtils

public class FormatUtils
extends Object

Format time, bytes, counts, dates, and transfer rates into human friendly form

Since:
May 27, 2010 6:46:17 PM
Author:
Jeff Caddel

Field Summary
static double DAY
           
static double HOUR
           
static double MINUTE
           
static double SECOND
           
static double YEAR
           
 
Constructor Summary
FormatUtils()
           
 
Method Summary
static long getBytes(String size)
          Parse bytes from a size string that ends with a unit of measure.
static long getBytes(String size, List<String> tokens, int base)
           
protected static long getByteValue(String time, String suffix, long multiplier)
           
static String getCount(long count)
          Return a formatted count
static String getDate(Date date)
          Return a formatted date
static String getDate(long millis)
          Return a formatted date
static String getFormattedSize(long bytes, Size size)
           
static long getMillis(String time)
          Parse milliseconds from a time string that ends with a unit of measure.
static long getMillis(String time, List<String> tokens, List<Long> multipliers)
           
static String getRate(long millis, long bytes)
          Given a number of bytes and the number of milliseconds it took to transfer that number of bytes, return bytes/s, KB/s, MB/s, GB/s, TB/s, PB/s, or EB/s as appropriate
static String getSize(long bytes)
          Given a number of bytes return bytes, kilobytes, megabytes, gigabytes, terabytes, petabytes, or exabytes as appropriate.
static String getSize(long bytes, Size unitOfMeasure)
          Given a number of bytes return a string formatted into the unit of measure indicated
static Size getSizeEnum(double bytes)
           
static String getThroughputInSeconds(long millis, long count, String label)
           
static String getTime(long millis)
          Given milliseconds, return milliseconds, seconds, minutes, hours, days, or years as appropriate.
protected static List<Long> getTimeMultipliers()
           
protected static long getTimeValue(String time, String suffix, long multiplier)
           
static Date parseDate(String date)
          Parse a date from the string.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

SECOND

public static final double SECOND
See Also:
Constant Field Values

MINUTE

public static final double MINUTE
See Also:
Constant Field Values

HOUR

public static final double HOUR
See Also:
Constant Field Values

DAY

public static final double DAY
See Also:
Constant Field Values

YEAR

public static final double YEAR
See Also:
Constant Field Values
Constructor Detail

FormatUtils

public FormatUtils()
Method Detail

getBytes

public static long getBytes(String size)
Parse bytes from a size string that ends with a unit of measure. If no unit of measure is provided, bytes is assumed. Unit of measure is case insensitive.
   1  == 1 byte
   1b == 1 byte
   1k == 1 kilobyte == 1024   bytes ==                     1,024 bytes
   1m == 1 megabyte == 1024^2 bytes ==                 1,048,576 bytes
   1g == 1 gigabyte == 1024^3 bytes ==             1,073,741,824 bytes
   1t == 1 terabyte == 1024^4 bytes ==         1,099,511,627,776 bytes
   1p == 1 petabyte == 1024^5 bytes ==     1,125,899,906,842,624 bytes
   1e == 1 exabyte  == 1024^6 bytes == 1,152,921,504,606,846,976 bytes
 


getBytes

public static long getBytes(String size,
                            List<String> tokens,
                            int base)

getByteValue

protected static long getByteValue(String time,
                                   String suffix,
                                   long multiplier)

getMillis

public static long getMillis(String time)
Parse milliseconds from a time string that ends with a unit of measure. If no unit of measure is provided, milliseconds is assumed. Unit of measure is case insensitive.
   1   == 1 millisecond
   1ms == 1 millisecond
   1s  == 1 second ==           1000 milliseconds
   1m  == 1 minute ==         60,000 milliseconds
   1h  == 1 hour   ==      3,600,000 milliseconds 
   1d  == 1 day    ==     86,400,000 milliseconds
   1y  == 1 year   == 31,536,000,000 milliseconds
 


getMillis

public static long getMillis(String time,
                             List<String> tokens,
                             List<Long> multipliers)

getTimeValue

protected static long getTimeValue(String time,
                                   String suffix,
                                   long multiplier)

parseDate

public static Date parseDate(String date)
Parse a date from the string. The string must be in the same format returned by the getDate() methods


getDate

public static String getDate(long millis)
Return a formatted date


getDate

public static String getDate(Date date)
Return a formatted date


getThroughputInSeconds

public static String getThroughputInSeconds(long millis,
                                            long count,
                                            String label)

getRate

public static String getRate(long millis,
                             long bytes)
Given a number of bytes and the number of milliseconds it took to transfer that number of bytes, return bytes/s, KB/s, MB/s, GB/s, TB/s, PB/s, or EB/s as appropriate


getCount

public static String getCount(long count)
Return a formatted count


getTime

public static String getTime(long millis)
Given milliseconds, return milliseconds, seconds, minutes, hours, days, or years as appropriate. Note that years is approximate since the logic always assumes there are exactly 365 days per year.


getSize

public static String getSize(long bytes)
Given a number of bytes return bytes, kilobytes, megabytes, gigabytes, terabytes, petabytes, or exabytes as appropriate.


getSize

public static String getSize(long bytes,
                             Size unitOfMeasure)
Given a number of bytes return a string formatted into the unit of measure indicated


getFormattedSize

public static String getFormattedSize(long bytes,
                                      Size size)

getSizeEnum

public static Size getSizeEnum(double bytes)

getTimeMultipliers

protected static final List<Long> getTimeMultipliers()


Copyright © 2010-2013 The Kuali Foundation. All Rights Reserved.