scala propaganda
Nov. 13th, 2011 11:47 amsource
package com.twitter
package conversions
import com.twitter.util.StorageUnit
object storage {
class RichWholeNumber(wrapped: Long) {
require(wrapped >= 0, "Negative storage units are unsupported")
def byte = bytes
def bytes = new StorageUnit(wrapped)
def kilobyte = kilobytes
def kilobytes = new StorageUnit(wrapped * 1024)
def megabyte = megabytes
def megabytes = new StorageUnit(wrapped * 1024 * 1024)
def gigabyte = gigabytes
def gigabytes = new StorageUnit(wrapped * 1024 * 1024 * 1024)
def terabyte = terabytes
def terabytes = new StorageUnit(wrapped * 1024 * 1024 * 1024 * 1024)
def petabyte = petabytes
def petabytes = new StorageUnit(wrapped * 1024 * 1024 * 1024 * 1024 * 1024)
def thousand = wrapped * 1000
def million = wrapped * 1000 * 1000
def billion = wrapped * 1000 * 1000 * 1000
}
implicit def intToStorageUnitableWholeNumber(i: Int) = new RichWholeNumber(i)
implicit def longToStorageUnitableWholeNumber(l: Long) = new RichWholeNumber(l)
}