Browse Source

checkstyle

git-svn-id: https://svn.apache.org/repos/asf/ant/core/trunk@487796 13f79535-47bb-0310-9956-ffa450edef68
master
Peter Reilly 18 years ago
parent
commit
3c64066ee7
1 changed files with 30 additions and 28 deletions
  1. +30
    -28
      src/main/org/apache/tools/ant/util/StringUtils.java

+ 30
- 28
src/main/org/apache/tools/ant/util/StringUtils.java View File

@@ -26,6 +26,11 @@ import java.util.Vector;
* *
*/ */
public final class StringUtils { public final class StringUtils {
private static final long KILOBYTE = 1024;
private static final long MEGABYTE = KILOBYTE * 1024;
private static final long GIGABYTE = MEGABYTE * 1024;
private static final long TERABYTE = GIGABYTE * 1024;
private static final long PETABYTE = TERABYTE * 1024;


/** /**
* constructor to stop anyone instantiating the class * constructor to stop anyone instantiating the class
@@ -186,41 +191,38 @@ public final class StringUtils {
} }
return b.toString(); return b.toString();
} }
/** /**
* Takes a human readable size representation eg 10K * Takes a human readable size representation eg 10K
* a long value. Doesn't support 1.1K or other rational values. * a long value. Doesn't support 1.1K or other rational values.
* @param humanSize
* @param humanSize the amount as a human readable string.
* @return a long value representation * @return a long value representation
* @throws Exception
* @throws Exception if there is a problem.
* @since Ant 1.7 * @since Ant 1.7
*/ */
public static long parseHumanSizes(String humanSize) throws Exception { public static long parseHumanSizes(String humanSize) throws Exception {
final long KILOBYTE = 1024;
final long MEGABYTE = KILOBYTE * 1024;
final long GIGABYTE = MEGABYTE * 1024;
final long TERABYTE = GIGABYTE * 1024;
final long PETABYTE = TERABYTE * 1024;
//last character isn't a digit //last character isn't a digit
if(!Character.isDigit(humanSize.charAt(humanSize.length()-1))) {
char c = humanSize.charAt(humanSize.length()-1);
long value = Long.valueOf(humanSize.substring(0, humanSize.length()-1)).longValue();
switch (c) {
case 'K':
return value * KILOBYTE;
case 'M':
return value * MEGABYTE;
case 'G':
return value * GIGABYTE;
case 'T':
return value * TERABYTE;
case 'P':
return value * PETABYTE;
default:
return value;
}
} else {
return Long.parseLong(humanSize);
}
if (!Character.isDigit(humanSize.charAt(humanSize.length() - 1))) {
char c = humanSize.charAt(humanSize.length() - 1);
long value = Long.valueOf(
humanSize.substring(
0, humanSize.length() - 1)).longValue();
switch (c) {
case 'K':
return value * KILOBYTE;
case 'M':
return value * MEGABYTE;
case 'G':
return value * GIGABYTE;
case 'T':
return value * TERABYTE;
case 'P':
return value * PETABYTE;
default:
return value;
}
} else {
return Long.parseLong(humanSize);
}
} }
} }

Loading…
Cancel
Save