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; import android.util.Log;
/** Provides methods for converting various units */ /** Provides methods for converting various units. */
public class Converter { public final class Converter {
/** Class shall not be instantiated. */
private Converter() {
}
/** Logging tag. */
private static final String TAG = "Converter"; 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 i = 0;
int result = 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)); result = (int) (input / Math.pow(1024, i));
if(result < 1000) { if (result < NUM_LENGTH) {
break; break;
} }
} }
switch(i) { switch (i) {
case 0: case B_RANGE:
return result + " B"; return result + " B";
case 1: case KB_RANGE:
return result + " KB"; return result + " KB";
case 2: case MB_RANGE:
return result + " MB"; return result + " MB";
case 3: case GB_RANGE:
return result + " GB"; return result + " GB";
default: default:
Log.e(TAG, "Error happened in byteToString"); Log.e(TAG, "Error happened in byteToString");

View File

@ -3,11 +3,21 @@ package de.podfetcher.util;
import java.util.Random; import java.util.Random;
import android.util.Log; import android.util.Log;
/** Utility class for creating large random numbers */ /**Utility class for creating large random numbers.*/
public class NumberGenerator { public final class NumberGenerator {
/** Class shall not be instantiated.*/
private NumberGenerator() {
}
/**Logging tag.*/
private static final String TAG = "NumberGenerator"; 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(); long seed = (long) strSeed.hashCode();
Log.d(TAG, "Taking " + seed + " as seed."); Log.d(TAG, "Taking " + seed + " as seed.");
return new Random(seed).nextLong(); return new Random(seed).nextLong();

View File

@ -1,29 +1,39 @@
package de.podfetcher.util; package de.podfetcher.util;
import android.webkit.URLUtil;
import android.util.Log; import android.util.Log;
/** Provides methods for checking and editing a URL */ /** Provides methods for checking and editing a URL.*/
public class URLChecker { public final class URLChecker {
private static final String TAG = "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"; 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"; private static final String FEEDBURNER_PREFIX = "?format=xml";
/** Checks if URL is valid and modifies it if necessary */ /** Checks if URL is valid and modifies it if necessary.
public static String prepareURL(String url) { * @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(); StringBuilder builder = new StringBuilder();
if(!url.startsWith("http")) { if (!url.startsWith("http")) {
builder.append("http://"); builder.append("http://");
Log.d(TAG, "Missing http; appending"); Log.d(TAG, "Missing http; appending");
} }
builder.append(url); builder.append(url);
if(url.contains(FEEDBURNER_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); builder.append(FEEDBURNER_PREFIX);
} }
return builder.toString(); return builder.toString();
} }
} }