Applied some checkstyle-rules

This commit is contained in:
Daniel Oeh 2012-05-28 00:58:40 +02:00
parent 831dc9d9da
commit bc0b8fa1ef
3 changed files with 65 additions and 23 deletions

View File

@ -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:
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");

View File

@ -3,11 +3,21 @@ package de.podfetcher.util;
import java.util.Random;
import android.util.Log;
/** Utility class for creating large random numbers */
public class NumberGenerator {
/**Utility class for creating large random numbers.*/
public final class NumberGenerator {
/** Class shall not be instantiated.*/
private NumberGenerator() {
}
/**Logging tag.*/
private static final String TAG = "NumberGenerator";
public static long generateLong(String strSeed) {
/** Takes a string and generates a random value out of
* the hash-value of that string.
* @param strSeed The string to take for the return value
* @return The generated random value
* */
public static long generateLong(final String strSeed) {
long seed = (long) strSeed.hashCode();
Log.d(TAG, "Taking " + seed + " as seed.");
return new Random(seed).nextLong();

View File

@ -1,17 +1,26 @@
package de.podfetcher.util;
import android.webkit.URLUtil;
import android.util.Log;
/** Provides methods for checking and editing a URL */
public class URLChecker {
/** Provides methods for checking and editing a URL.*/
public final class URLChecker {
/**Class shall not be instantiated.*/
private URLChecker() {
}
/**Logging tag.*/
private static final String TAG = "URLChecker";
/**Indicator for URLs made by Feedburner.*/
private static final String FEEDBURNER_URL = "feeds.feedburner.com";
/**Prefix that is appended to URLs by Feedburner.*/
private static final String FEEDBURNER_PREFIX = "?format=xml";
/** Checks if URL is valid and modifies it if necessary */
public static String prepareURL(String url) {
/** Checks if URL is valid and modifies it if necessary.
* @param url The url which is going to be prepared
* @return The prepared url
* */
public static String prepareURL(final String url) {
StringBuilder builder = new StringBuilder();
if (!url.startsWith("http")) {
@ -21,7 +30,8 @@ public class URLChecker {
builder.append(url);
if (url.contains(FEEDBURNER_URL)) {
Log.d(TAG, "URL seems to be Feedburner URL; appending prefix");
Log.d(TAG,
"URL seems to be Feedburner URL; appending prefix");
builder.append(FEEDBURNER_PREFIX);
}
return builder.toString();