| 1 |
|
package org.kuali.maven.mojo.s3; |
| 2 |
|
|
| 3 |
|
import java.text.NumberFormat; |
| 4 |
|
|
| 5 |
|
import org.apache.commons.lang.StringUtils; |
| 6 |
|
|
| 7 |
|
|
| 8 |
|
|
| 9 |
|
|
| 10 |
|
@author |
| 11 |
|
@since |
| 12 |
|
|
|
|
|
| 0% |
Uncovered Elements: 48 (48) |
Complexity: 10 |
Complexity Density: 0.31 |
|
| 13 |
|
public class SimpleFormatter { |
| 14 |
|
private static final double KB = 1024; |
| 15 |
|
private static final double MB = 1024 * KB; |
| 16 |
|
private static final double GB = 1024 * MB; |
| 17 |
|
private static final double ONE_SECOND = 1000; |
| 18 |
|
private static final double ONE_MINUTE = 60 * ONE_SECOND; |
| 19 |
|
private static final double FIFTEEN_MINUTES = 15 * ONE_MINUTE; |
| 20 |
|
|
| 21 |
|
NumberFormat sizeFormatter = NumberFormat.getInstance(); |
| 22 |
|
NumberFormat timeFormatter = NumberFormat.getInstance(); |
| 23 |
|
NumberFormat rateFormatter = NumberFormat.getInstance(); |
| 24 |
|
|
|
|
|
| 0% |
Uncovered Elements: 10 (10) |
Complexity: 1 |
Complexity Density: 0.1 |
|
| 25 |
0
|
public SimpleFormatter() {... |
| 26 |
0
|
super(); |
| 27 |
0
|
sizeFormatter.setGroupingUsed(false); |
| 28 |
0
|
sizeFormatter.setMaximumFractionDigits(1); |
| 29 |
0
|
sizeFormatter.setMinimumFractionDigits(1); |
| 30 |
0
|
timeFormatter.setGroupingUsed(false); |
| 31 |
0
|
timeFormatter.setMaximumFractionDigits(3); |
| 32 |
0
|
timeFormatter.setMinimumFractionDigits(3); |
| 33 |
0
|
rateFormatter.setGroupingUsed(false); |
| 34 |
0
|
rateFormatter.setMaximumFractionDigits(1); |
| 35 |
0
|
rateFormatter.setMinimumFractionDigits(1); |
| 36 |
|
} |
| 37 |
|
|
| 38 |
|
|
| 39 |
|
|
| 40 |
|
|
|
|
|
| 0% |
Uncovered Elements: 10 (10) |
Complexity: 2 |
Complexity Density: 0.25 |
|
| 41 |
0
|
public String getRate(final long millis, final long bytes) {... |
| 42 |
0
|
int pad = 1; |
| 43 |
0
|
double seconds = millis / 1000D; |
| 44 |
0
|
double kilobytes = bytes / 1024D; |
| 45 |
0
|
double kilobytesPerSecond = kilobytes / seconds; |
| 46 |
0
|
if (kilobytesPerSecond < 1024) { |
| 47 |
0
|
return StringUtils.leftPad(rateFormatter.format(kilobytesPerSecond) + " kB/s", pad, " "); |
| 48 |
|
} else { |
| 49 |
0
|
double transferRate = kilobytesPerSecond / 1024; |
| 50 |
0
|
return StringUtils.leftPad(rateFormatter.format(transferRate) + " MB/s", pad, " "); |
| 51 |
|
} |
| 52 |
|
} |
| 53 |
|
|
| 54 |
|
|
| 55 |
|
|
| 56 |
|
|
|
|
|
| 0% |
Uncovered Elements: 14 (14) |
Complexity: 4 |
Complexity Density: 0.5 |
|
| 57 |
0
|
public String getTime(final long millis) {... |
| 58 |
0
|
int pad = 1; |
| 59 |
0
|
if (millis < ONE_SECOND) { |
| 60 |
0
|
return StringUtils.leftPad(millis + "ms", pad, " "); |
| 61 |
0
|
} else if (millis < 10 * ONE_SECOND) { |
| 62 |
0
|
return StringUtils.leftPad(timeFormatter.format(millis / ONE_SECOND) + "s", pad, " "); |
| 63 |
0
|
} else if (millis < FIFTEEN_MINUTES) { |
| 64 |
0
|
return StringUtils.leftPad(rateFormatter.format(millis / ONE_SECOND) + "s", pad, " "); |
| 65 |
|
} else { |
| 66 |
0
|
return StringUtils.leftPad(rateFormatter.format(millis / ONE_MINUTE) + "m", pad, " "); |
| 67 |
|
} |
| 68 |
|
} |
| 69 |
|
|
| 70 |
|
|
| 71 |
|
|
| 72 |
|
|
| 73 |
|
|
|
|
|
| 0% |
Uncovered Elements: 10 (10) |
Complexity: 3 |
Complexity Density: 0.5 |
|
| 74 |
0
|
public String getSize(final long bytes) {... |
| 75 |
0
|
int pad = 1; |
| 76 |
0
|
if (bytes < MB) { |
| 77 |
0
|
return StringUtils.leftPad(sizeFormatter.format(bytes / KB) + "k", pad, " "); |
| 78 |
|
} |
| 79 |
0
|
if (bytes < GB) { |
| 80 |
0
|
return StringUtils.leftPad(sizeFormatter.format(bytes / MB) + "m", pad, " "); |
| 81 |
|
} |
| 82 |
0
|
return StringUtils.leftPad(sizeFormatter.format(bytes / GB) + "g", pad, " "); |
| 83 |
|
} |
| 84 |
|
} |