@Test public void testToString() { { FileSize fs = new FileSize(8); assertEquals("8 Bytes", fs.toString()); } { FileSize fs = new FileSize(8 * 1024 + 3); assertEquals("8 KB", fs.toString()); } { FileSize fs = new FileSize(8 * 1024 * 1024 + 3 * 1024); assertEquals("8 MB", fs.toString()); } { FileSize fs = new FileSize(8*1024*1024*1024L); assertEquals("8 GB", fs.toString()); } }
@Override public String toString() { long inKB = size / KB_COEFFICIENT; if (inKB == 0) return size + " Bytes"; long inMB = size / MB_COEFFICIENT; if (inMB == 0) { return inKB + " KB"; } long inGB = size / GB_COEFFICIENT; if(inGB == 0) { return inMB + " MB"; } return inGB + " GB"; }
FileSize { @Override public String toString() { long inKB = size / KB_COEFFICIENT; if (inKB == 0) return size + " Bytes"; long inMB = size / MB_COEFFICIENT; if (inMB == 0) { return inKB + " KB"; } long inGB = size / GB_COEFFICIENT; if(inGB == 0) { return inMB + " MB"; } return inGB + " GB"; } }
FileSize { @Override public String toString() { long inKB = size / KB_COEFFICIENT; if (inKB == 0) return size + " Bytes"; long inMB = size / MB_COEFFICIENT; if (inMB == 0) { return inKB + " KB"; } long inGB = size / GB_COEFFICIENT; if(inGB == 0) { return inMB + " MB"; } return inGB + " GB"; } FileSize(long size); }
FileSize { @Override public String toString() { long inKB = size / KB_COEFFICIENT; if (inKB == 0) return size + " Bytes"; long inMB = size / MB_COEFFICIENT; if (inMB == 0) { return inKB + " KB"; } long inGB = size / GB_COEFFICIENT; if(inGB == 0) { return inMB + " MB"; } return inGB + " GB"; } FileSize(long size); long getSize(); static FileSize valueOf(String fileSizeStr); @Override String toString(); }
FileSize { @Override public String toString() { long inKB = size / KB_COEFFICIENT; if (inKB == 0) return size + " Bytes"; long inMB = size / MB_COEFFICIENT; if (inMB == 0) { return inKB + " KB"; } long inGB = size / GB_COEFFICIENT; if(inGB == 0) { return inMB + " MB"; } return inGB + " GB"; } FileSize(long size); long getSize(); static FileSize valueOf(String fileSizeStr); @Override String toString(); static final long KB_COEFFICIENT; static final long MB_COEFFICIENT; static final long GB_COEFFICIENT; }