diff options
author | Daniel Oeh <daniel@danielpc.(none)> | 2012-05-28 00:58:40 +0200 |
---|---|---|
committer | Daniel Oeh <daniel@danielpc.(none)> | 2012-05-28 00:58:40 +0200 |
commit | bc0b8fa1ef9714943152c896535c1facefc2d3af (patch) | |
tree | c5d8edb638770349a3b3ec54b2453fe3ce206af5 /src/de/podfetcher/util/Converter.java | |
parent | 831dc9d9da2847aee61f1158c656fa243c8a0902 (diff) | |
download | AntennaPod-bc0b8fa1ef9714943152c896535c1facefc2d3af.zip |
Applied some checkstyle-rules
Diffstat (limited to 'src/de/podfetcher/util/Converter.java')
-rw-r--r-- | src/de/podfetcher/util/Converter.java | 42 |
1 files changed, 32 insertions, 10 deletions
diff --git a/src/de/podfetcher/util/Converter.java b/src/de/podfetcher/util/Converter.java index fcf91015b..262debe51 100644 --- a/src/de/podfetcher/util/Converter.java +++ b/src/de/podfetcher/util/Converter.java @@ -2,29 +2,51 @@ package de.podfetcher.util; import android.util.Log; -/** Provides methods for converting various units */ -public class Converter { +/** Provides methods for converting various units. */ +public final class Converter { + /** Class shall not be instantiated. */ + private Converter() { + } + + /** Logging tag. */ private static final String TAG = "Converter"; - public static String byteToString(long input) { + + /** Indicates that the value is in the Byte range.*/ + private static final int B_RANGE = 0; + /** Indicates that the value is in the Kilobyte range.*/ + private static final int KB_RANGE = 1; + /** Indicates that the value is in the Megabyte range.*/ + private static final int MB_RANGE = 2; + /** Indicates that the value is in the Gigabyte range.*/ + private static final int GB_RANGE = 3; + /** Determines the length of the number for best readability.*/ + private static final int NUM_LENGTH = 1000; + + /** Takes a byte-value and converts it into a more readable + * String. + * @param input The value to convert + * @return The converted String with a unit + * */ + public static String byteToString(final long input) { int i = 0; int result = 0; - for(i = 0; i < 4; i++) { + for (i = 0; i < GB_RANGE + 1; i++) { result = (int) (input / Math.pow(1024, i)); - if(result < 1000) { + if (result < NUM_LENGTH) { break; } } - switch(i) { - case 0: + switch (i) { + case B_RANGE: return result + " B"; - case 1: + case KB_RANGE: return result + " KB"; - case 2: + case MB_RANGE: return result + " MB"; - case 3: + case GB_RANGE: return result + " GB"; default: Log.e(TAG, "Error happened in byteToString"); |