| 1 |
|
package com.atlassian.core.util; |
| 2 |
|
|
| 3 |
|
import java.text.DecimalFormat; |
| 4 |
|
import java.text.NumberFormat; |
| 5 |
|
|
| 6 |
|
|
| 7 |
|
|
| 8 |
|
|
| 9 |
|
|
|
|
|
| 96.7% |
Uncovered Elements: 1 (30) |
Complexity: 8 |
Complexity Density: 0.4 |
|
| 10 |
|
public class FileSize |
| 11 |
|
{ |
|
|
|
| - |
Uncovered Elements: 0 (0) |
Complexity: 1 |
Complexity Density: - |
|
| 12 |
0
|
public FileSize()... |
| 13 |
|
{ |
| 14 |
|
|
| 15 |
|
} |
| 16 |
|
|
| 17 |
|
private static final float KB_SIZE = 1024; |
| 18 |
|
private static final float MB_SIZE = KB_SIZE * KB_SIZE; |
| 19 |
|
|
| 20 |
|
private static final String KB = " kB"; |
| 21 |
|
private static final String MB = " MB"; |
| 22 |
|
|
| 23 |
|
|
| 24 |
|
|
| 25 |
|
@param |
| 26 |
|
@return |
| 27 |
|
@see |
| 28 |
|
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 29 |
1
|
public static String format(Long filesize)... |
| 30 |
|
{ |
| 31 |
1
|
return format(filesize.longValue()); |
| 32 |
|
} |
| 33 |
|
|
| 34 |
|
|
| 35 |
|
|
| 36 |
|
|
| 37 |
|
|
| 38 |
|
|
| 39 |
|
|
| 40 |
|
|
| 41 |
|
|
| 42 |
|
|
| 43 |
|
|
| 44 |
|
|
| 45 |
|
|
| 46 |
|
|
| 47 |
|
|
| 48 |
|
|
| 49 |
|
|
| 50 |
|
|
| 51 |
|
@param |
| 52 |
|
@return |
| 53 |
|
|
|
|
|
| 100% |
Uncovered Elements: 0 (9) |
Complexity: 3 |
Complexity Density: 0.6 |
|
| 54 |
21
|
public static String format(long filesize)... |
| 55 |
|
{ |
| 56 |
|
|
| 57 |
|
|
| 58 |
21
|
if (filesize > MB_SIZE) |
| 59 |
|
{ |
| 60 |
5
|
return formatMB(filesize); |
| 61 |
|
} |
| 62 |
16
|
else if (filesize > KB_SIZE) |
| 63 |
|
{ |
| 64 |
10
|
return formatKB(filesize); |
| 65 |
|
} |
| 66 |
|
else |
| 67 |
|
{ |
| 68 |
6
|
return formatBytes(filesize); |
| 69 |
|
} |
| 70 |
|
|
| 71 |
|
} |
| 72 |
|
|
|
|
|
| 100% |
Uncovered Elements: 0 (6) |
Complexity: 1 |
Complexity Density: 0.17 |
|
| 73 |
5
|
private static String formatMB(long filesize)... |
| 74 |
|
{ |
| 75 |
5
|
NumberFormat mbFormat = new DecimalFormat(); |
| 76 |
5
|
mbFormat.setMinimumIntegerDigits(1); |
| 77 |
5
|
mbFormat.setMaximumFractionDigits(2); |
| 78 |
5
|
mbFormat.setMinimumFractionDigits(2); |
| 79 |
5
|
float mbsize = (float) filesize / MB_SIZE; |
| 80 |
5
|
return mbFormat.format(mbsize) + MB; |
| 81 |
|
} |
| 82 |
|
|
|
|
|
| 100% |
Uncovered Elements: 0 (2) |
Complexity: 1 |
Complexity Density: 0.5 |
|
| 83 |
10
|
private static String formatKB(long filesize)... |
| 84 |
|
{ |
| 85 |
10
|
long kbsize = Math.round((float) filesize / KB_SIZE); |
| 86 |
10
|
return String.valueOf(kbsize) + KB; |
| 87 |
|
} |
| 88 |
|
|
|
|
|
| 100% |
Uncovered Elements: 0 (6) |
Complexity: 1 |
Complexity Density: 0.17 |
|
| 89 |
6
|
private static String formatBytes(long filesize)... |
| 90 |
|
{ |
| 91 |
6
|
NumberFormat bFormat = new DecimalFormat(); |
| 92 |
6
|
bFormat.setMinimumIntegerDigits(1); |
| 93 |
6
|
bFormat.setMaximumFractionDigits(1); |
| 94 |
6
|
bFormat.setMinimumFractionDigits(1); |
| 95 |
6
|
float mbsize = (float) filesize / KB_SIZE; |
| 96 |
6
|
return bFormat.format(mbsize) + KB; |
| 97 |
|
} |
| 98 |
|
} |