You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@beehive.apache.org by ek...@apache.org on 2005/08/12 17:23:08 UTC
svn commit: r232310 [42/92] - in /beehive/trunk/controls/test: common/
infra/gtlf/ infra/gtlf/xsl/ infra/mantis/ infra/tch/ infra/tch/messages/
infra/tch/runtime/ infra/tch/schema/ perf/ perf/bin/ perf/cases/
perf/ctlsrc/org/apache/beehive/controls/per...
Modified: beehive/trunk/controls/test/tools/tch/src/java/org/apache/beehive/test/tools/tch/common/util/StringUtils.java
URL: http://svn.apache.org/viewcvs/beehive/trunk/controls/test/tools/tch/src/java/org/apache/beehive/test/tools/tch/common/util/StringUtils.java?rev=232310&r1=232309&r2=232310&view=diff
==============================================================================
--- beehive/trunk/controls/test/tools/tch/src/java/org/apache/beehive/test/tools/tch/common/util/StringUtils.java (original)
+++ beehive/trunk/controls/test/tools/tch/src/java/org/apache/beehive/test/tools/tch/common/util/StringUtils.java Fri Aug 12 08:12:28 2005
@@ -1,466 +1,466 @@
-package org.apache.beehive.test.tools.tch.common.util;
-
-import java.io.File;
-import java.util.Enumeration;
-import java.util.StringTokenizer;
-
-/**
- * StrUtils
- * There were moved here so that they could be called internally
- * without the side-effect of pulling in alot of stuff that we
- * don't want.
- *
- */
-public class StringUtils {
-
- /**
- * Returns a String as an array of Strings
- * after dividing the original String in two
- * at the specified delimiting character.
- * For example x.y is returned as {x, y}.
- *
- * @param s Input String
- * @param delim Character delimiter
- * @return String[0] and String[1]
- */
- public static String[] split(String s, char delim) {
- String[] retVal = {s, "" };
- int dot = s.indexOf(delim);
- if (dot != -1)
- {
- retVal[0] = s.substring(0,dot);
- retVal[1] = s.substring(dot+1);
- }
- return retVal;
- }
-
- /** DOCNOTE
-
- * Splits a String in several component Strings, according to the
- * specified delimiter. (The delimiter is passed as the second arg
- * of a constructor of a java.util.StringTokenizer), and returns the
- * component Strings as an array. For example, x.y.z is returns as
- * {"x", "y", "z"}. If the returnDelim param is true it returns the
- * delimiters as well, so x.y.z would be returned as { "x", ".",
- * "y", ".", "z" }
- *
- * @param s Input string
- * @param delim Character delimiter
- * @param returnDelim Do we return the delimiter in the array.
- * @return Array of strings
- *
- * @see java.util.StringTokenizer#StringTokenizer(java.lang.String,java.lang.String)
- *
- */
- public static String[] splitCompletely(String s, String delim,
- boolean returnDelim) {
- return splitCompletely(new StringTokenizer(s, delim, returnDelim));
- }
-
- /** DOCNOTE
- * Splits a String in several component Strings, according to the
- * specified delimiter (which is passed to a
- * java.util.StringTokenizer), and returns the component Strings as
- * an array. For example, x.y.z is returns as {x, y, z}.
- *
- * @param s Input string
- * @param delim Character delimiter
- * @return Array of strings
- *
- * @see java.util.StringTokenizer#StringTokenizer(java.lang.String,java.lang.String)
- *
- */
- public static String[] splitCompletely(String s, String delim) {
- return splitCompletely(new StringTokenizer(s, delim));
- }
-
-
- /** DOCNOTE
- * Splits a String in several component Strings, according to the
- * default delimiters for a StringTokenizer ("\t\n\r"), and returns
- * the component Strings as an array. For example, x.y.z is returns
- * as {x, y, z}.
- *
- * @param s Input string
- * @param delim Character delimiter
- * @return Array of strings
- *
- * @see java.util.StringTokenizer#StringTokenizer(java.lang.String)
- */
- public static String[] splitCompletely(String s) {
- return splitCompletely(new StringTokenizer(s));
- }
-
- private static String[] splitCompletely(StringTokenizer stringTokenizer) {
- int i = stringTokenizer.countTokens();
- String st[] = new String[i];
-
- for (int j = 0; j < i; j++)
- st[j] = stringTokenizer.nextToken();
- return st;
- }
-
-
- /**
- * Splits a String into <i>n</i> component Strings, according to the
- * specified delimiter, and returns the component Strings as an
- * array, with the last element containing the remainder of the
- * string after the first <i>n - 1</i> components have been split off. For
- * example, w.x.y.z with an n of 3 is returned as {w, x, y.z}.
- *
- * @param s Input string
- * @param delim Character delimiter
- * @param limit Number of elements in returned array.
- * @return Array of strings
- */
- public static String[] splitPartially(String s, String delim, int limit) {
-
- StringTokenizer stringTokenizer = new StringTokenizer(s, delim);
-
- int tokes = stringTokenizer.countTokens();
- String st[];
-
- if ((limit == 0) || (limit >= tokes)) {
- st = new String[tokes];
- for (int j = 0; j < tokes; j++) {
- st[j] = stringTokenizer.nextToken();
- }
- } else {
- st = new String[limit];
- int j;
- for (j = 0; j < limit - 1; j++) {
- st[j] = stringTokenizer.nextToken();
- }
- st[j] = stringTokenizer.nextToken() + stringTokenizer.nextToken("");
- }
- return st;
- }
-
- /**
- * Splits a String containing a File.pathSeparator-delimited
- * path into an array of File objects.
- *
- * @param path String path to be split
- * @return Array of File objects
- */
- public static File[] splitPath(String path) {
- String[] dirs = splitCompletely(path, File.pathSeparator);
- File[] pathdirs = new File[dirs.length];
- for (int i = 0; i < dirs.length; i++) {
- pathdirs[i] = new File(dirs[i]);
- }
- return pathdirs;
- }
-
-
- /**
- * Joins an array of strings into a single string delimited by the
- * given delimiter.
- *
- * @param ss Array of Strings to join
- * @param delim Delimiter
- * @return Single string
- */
- public static String join(String[] ss, String delim) {
- return join(ss, delim, 0, ss.length);
- }
-
- public static String join(String[] ss, String delim, int start, int end) {
- StringBuffer sb = new StringBuffer();
- for (int i = start; i < end; i++) {
- sb.append(ss[i]);
- if (i < (end - 1)) sb.append(delim);
- }
- return sb.toString();
- }
-
-
- /**
- * Returns the index of the <i>n</i>th occurrence of <i>str</i> within a
- * String. Returns -1 if there is no <i>n</i>th index.
- *
- * @param s String to search in
- * @param str Substring to search for
- * @param n Number of occurrences
- * @return Index into the string
- */
- public static int nthIndexOf(String s, String str, int n) {
- int idx = 0;
- for (int i = 0; i < n; i++) {
- idx = s.indexOf(":", idx + 1);
- if (idx == -1) break;
- }
- return idx;
- }
-
- /**
- * Gets the substring from the 1st character up to
- * the specified delimiter.
- *
- * @param s Input string
- * @param delim Character delimiter
- * @return Substring
- */
- public static String upto(String s, char delim) {
- int dot = s.indexOf(delim);
- if (dot != -1)
- return s.substring(0,dot);
- else
- return s;
- }
-
-
- /**
- * Upper case the first character of a string according to the
- * default locale.
- *
- * @param s Input string.
- * @return String with first character up-cased.
- */
- public static String ucfirst(String s) {
- return Character.toUpperCase(s.charAt(0)) + s.substring(1);
- }
-
- /**
- * Return a string which may be a legal part of a Java source file.
- *
- * @param s Input String.
- * @return String with unsafe characters escaped.
- */
- public static String escapeString(String s) {
- char[] chars = s.toCharArray();
- int len = chars.length;
- StringBuffer b = new StringBuffer(len);
- char c;
- for (int i = 0; i < len; i++) {
- c = chars[i];
- switch(c) {
- case '\b':
- b.append("\\b");
- break;
- case '\t':
- b.append("\\t");
- break;
- case '\n':
- b.append("\\n");
- break;
- case '\f':
- b.append("\\f");
- break;
- case '\r':
- b.append("\\r");
- break;
- case '\"':
- b.append("\\\"");
- break;
- case '\'':
- b.append("\\\'");
- break;
- case '\\':
- b.append("\\\\");
- break;
- default:
- b.append(c);
- }
- }
- return b.toString();
- }
-
- public static String valueOf(int i) {
- char[] buf = new char[11];
- int index = buf.length;
- boolean negative = (i < 0);
- if (!negative) {
- i = -i;
- }
- while (i <= -10) {
- buf[--index] = Character.forDigit(-(i % 10), 10);
- i = i / 10;
- }
- buf[--index] = Character.forDigit(-i, 10);
- if (negative) {
- buf[--index] = '-';
- }
- return new String(buf, index, buf.length-index);
- }
-
- /**
- * Expects a string representation of a decimal number, with
- * thousands separated by a separator char given as the second
- * argument, and with a decimal separator, given as the third
- * argument.
- * <p>
- * Returns a string suitable for the constructors of Java number
- * types like BigDecimal, without a thousands separator and
- * with a decimal point.
- *
- * @param Decimal number (String)
- * @param Thousands separator
- * @param Decimal separator
- */
- public static String numStr4Java(String inputString,
- char thousandSeparator,
- char decimalSeparator) {
-
- if (inputString == null)
- return null;
-
- StringBuffer returnString = new StringBuffer();
- for (int i = 0; i < inputString.length(); ++i)
- {
- char ch = inputString.charAt(i);
- if (ch == thousandSeparator) continue; // Skip
- else if (ch == decimalSeparator) returnString.append('.'); // Substitute
- else returnString.append(ch); // Copy
- }
- return returnString.toString();
- }
-
- /**
- * Expects a string representation of a decimal number with
- * (in rare cases) thousands separated by commas. Returns a
- * String without the commas.
- */
- public static String takeCommasFromNumStr(String inputString) {
-
- if (inputString == null)
- return null;
- else if (inputString.indexOf(',') == -1) // Check to save time
- return inputString;
- else
- return numStr4Java( inputString, ',', '.' );
- }
-
- /**
- * Returns an array of the keys from the specified enumeration
- * and size (e.g., from a HashTable or Workspace).
- *
- * @param e Enumeration to return as an array
- * @param size Number of things in the Enumeration
- */
- public static String[] enumeration2StringArray(Enumeration e, int size) {
- int i=0;
- // allocate array of correct size
- String[] keys = new String[size];
-
- // save up all the elements. should be strings.
- while (e.hasMoreElements()) {
- keys[i++] = (String) e.nextElement();
- }
- return keys;
- }
-
- /**
- * Returns an array of chars as an array of bytes.
- *
- * @param chars Array of chars
- * @return Array of bytes
- */
- public static byte[] chars2bytes(char[] chars) {
-
- byte[] bytes = new byte[chars.length*2];
- int j = 0;
- for (int i = 0; i < chars.length; i++) {
- char c1 = chars[i];
- char c2 = chars[i];
- bytes[j++] = (byte) (c1 >> 8);
- bytes[j++] = (byte) c2;
- }
- return bytes;
- }
-
- /**
- * Returns an array of bytes as an array of chars.
- *
- * @param bytes Byte array
- * @return Array of chars
- * @exception java.lang.Exception if the byte array cannot be converted
- */
- public static char[] bytes2chars(byte[] bytes)
- throws Exception
- {
- if ((bytes.length % 2) != 0)
- throw new Exception("Cannot convert an odd number of bytes");
-
- char[] chars = new char[bytes.length/2];
- int j = 0;
- for (int i = 0; i < chars.length; i++) {
- byte b1 = bytes[j++];
- byte b2 = bytes[j++];
- chars[i] = (char)(((b1 << 8) & 0x0000FF00) |
- ((b2 << 0) & 0x000000FF));
- }
- return chars;
- }
-
- /**
- * Pads the specified String to the specified width.
- *
- * @param str String to pad
- * @param width Length of padded string
- * @return Padded String
- */
- public static String padStringWidth(String str, int width) {
- StringBuffer sb = null;
- if (str != null) {
- sb = new StringBuffer(str);
- sb.setLength(width);
- int start = str.length();
- for (int i = start; i < width; i++)
- sb.setCharAt(i, ' ');
- }
- else {
- sb = new StringBuffer(width);
- sb.setLength(width);
- for (int i = 0; i < width; i++)
- sb.setCharAt(i, ' ');
- }
-
- return sb.toString();
- }
-
- /**
- * Pads the specified integer value to the specified width.
- *
- * @param val Integer to pad
- * @param width Length of padded string
- * @return Padded String
- */
- public static String padStringWidth(int val, int width) {
- return padStringWidth(String.valueOf(val), width);
- }
-
- /**
- * Pads the specified float value to the specified width.
- *
- * @param val Float value to pad
- * @param width Length of padded string
- * @return Padded String
- */
- public static String padStringWidth(float val, int width) {
- return padStringWidth(String.valueOf(val), width);
- }
-
- /**
- * Pads the specified long value to the specified width.
- *
- * @param val Long to pad
- * @param width Length of padded string
- * @return Padded String
- */
- public static String padStringWidth(long val, int width) {
- return padStringWidth(String.valueOf(val), width);
- }
-
- /**
- * Pads the specified double value to the specified width.
- *
- * @param val Double to pad
- * @param width Length of padded string
- * @return Padded String
- */
- public static String padStringWidth(double val, int width) {
- return padStringWidth(String.valueOf(val), width);
- }
-
-}
+package org.apache.beehive.test.tools.tch.common.util;
+
+import java.io.File;
+import java.util.Enumeration;
+import java.util.StringTokenizer;
+
+/**
+ * StrUtils
+ * There were moved here so that they could be called internally
+ * without the side-effect of pulling in alot of stuff that we
+ * don't want.
+ *
+ */
+public class StringUtils {
+
+ /**
+ * Returns a String as an array of Strings
+ * after dividing the original String in two
+ * at the specified delimiting character.
+ * For example x.y is returned as {x, y}.
+ *
+ * @param s Input String
+ * @param delim Character delimiter
+ * @return String[0] and String[1]
+ */
+ public static String[] split(String s, char delim) {
+ String[] retVal = {s, "" };
+ int dot = s.indexOf(delim);
+ if (dot != -1)
+ {
+ retVal[0] = s.substring(0,dot);
+ retVal[1] = s.substring(dot+1);
+ }
+ return retVal;
+ }
+
+ /** DOCNOTE
+
+ * Splits a String in several component Strings, according to the
+ * specified delimiter. (The delimiter is passed as the second arg
+ * of a constructor of a java.util.StringTokenizer), and returns the
+ * component Strings as an array. For example, x.y.z is returns as
+ * {"x", "y", "z"}. If the returnDelim param is true it returns the
+ * delimiters as well, so x.y.z would be returned as { "x", ".",
+ * "y", ".", "z" }
+ *
+ * @param s Input string
+ * @param delim Character delimiter
+ * @param returnDelim Do we return the delimiter in the array.
+ * @return Array of strings
+ *
+ * @see java.util.StringTokenizer#StringTokenizer(java.lang.String,java.lang.String)
+ *
+ */
+ public static String[] splitCompletely(String s, String delim,
+ boolean returnDelim) {
+ return splitCompletely(new StringTokenizer(s, delim, returnDelim));
+ }
+
+ /** DOCNOTE
+ * Splits a String in several component Strings, according to the
+ * specified delimiter (which is passed to a
+ * java.util.StringTokenizer), and returns the component Strings as
+ * an array. For example, x.y.z is returns as {x, y, z}.
+ *
+ * @param s Input string
+ * @param delim Character delimiter
+ * @return Array of strings
+ *
+ * @see java.util.StringTokenizer#StringTokenizer(java.lang.String,java.lang.String)
+ *
+ */
+ public static String[] splitCompletely(String s, String delim) {
+ return splitCompletely(new StringTokenizer(s, delim));
+ }
+
+
+ /** DOCNOTE
+ * Splits a String in several component Strings, according to the
+ * default delimiters for a StringTokenizer ("\t\n\r"), and returns
+ * the component Strings as an array. For example, x.y.z is returns
+ * as {x, y, z}.
+ *
+ * @param s Input string
+ * @param delim Character delimiter
+ * @return Array of strings
+ *
+ * @see java.util.StringTokenizer#StringTokenizer(java.lang.String)
+ */
+ public static String[] splitCompletely(String s) {
+ return splitCompletely(new StringTokenizer(s));
+ }
+
+ private static String[] splitCompletely(StringTokenizer stringTokenizer) {
+ int i = stringTokenizer.countTokens();
+ String st[] = new String[i];
+
+ for (int j = 0; j < i; j++)
+ st[j] = stringTokenizer.nextToken();
+ return st;
+ }
+
+
+ /**
+ * Splits a String into <i>n</i> component Strings, according to the
+ * specified delimiter, and returns the component Strings as an
+ * array, with the last element containing the remainder of the
+ * string after the first <i>n - 1</i> components have been split off. For
+ * example, w.x.y.z with an n of 3 is returned as {w, x, y.z}.
+ *
+ * @param s Input string
+ * @param delim Character delimiter
+ * @param limit Number of elements in returned array.
+ * @return Array of strings
+ */
+ public static String[] splitPartially(String s, String delim, int limit) {
+
+ StringTokenizer stringTokenizer = new StringTokenizer(s, delim);
+
+ int tokes = stringTokenizer.countTokens();
+ String st[];
+
+ if ((limit == 0) || (limit >= tokes)) {
+ st = new String[tokes];
+ for (int j = 0; j < tokes; j++) {
+ st[j] = stringTokenizer.nextToken();
+ }
+ } else {
+ st = new String[limit];
+ int j;
+ for (j = 0; j < limit - 1; j++) {
+ st[j] = stringTokenizer.nextToken();
+ }
+ st[j] = stringTokenizer.nextToken() + stringTokenizer.nextToken("");
+ }
+ return st;
+ }
+
+ /**
+ * Splits a String containing a File.pathSeparator-delimited
+ * path into an array of File objects.
+ *
+ * @param path String path to be split
+ * @return Array of File objects
+ */
+ public static File[] splitPath(String path) {
+ String[] dirs = splitCompletely(path, File.pathSeparator);
+ File[] pathdirs = new File[dirs.length];
+ for (int i = 0; i < dirs.length; i++) {
+ pathdirs[i] = new File(dirs[i]);
+ }
+ return pathdirs;
+ }
+
+
+ /**
+ * Joins an array of strings into a single string delimited by the
+ * given delimiter.
+ *
+ * @param ss Array of Strings to join
+ * @param delim Delimiter
+ * @return Single string
+ */
+ public static String join(String[] ss, String delim) {
+ return join(ss, delim, 0, ss.length);
+ }
+
+ public static String join(String[] ss, String delim, int start, int end) {
+ StringBuffer sb = new StringBuffer();
+ for (int i = start; i < end; i++) {
+ sb.append(ss[i]);
+ if (i < (end - 1)) sb.append(delim);
+ }
+ return sb.toString();
+ }
+
+
+ /**
+ * Returns the index of the <i>n</i>th occurrence of <i>str</i> within a
+ * String. Returns -1 if there is no <i>n</i>th index.
+ *
+ * @param s String to search in
+ * @param str Substring to search for
+ * @param n Number of occurrences
+ * @return Index into the string
+ */
+ public static int nthIndexOf(String s, String str, int n) {
+ int idx = 0;
+ for (int i = 0; i < n; i++) {
+ idx = s.indexOf(":", idx + 1);
+ if (idx == -1) break;
+ }
+ return idx;
+ }
+
+ /**
+ * Gets the substring from the 1st character up to
+ * the specified delimiter.
+ *
+ * @param s Input string
+ * @param delim Character delimiter
+ * @return Substring
+ */
+ public static String upto(String s, char delim) {
+ int dot = s.indexOf(delim);
+ if (dot != -1)
+ return s.substring(0,dot);
+ else
+ return s;
+ }
+
+
+ /**
+ * Upper case the first character of a string according to the
+ * default locale.
+ *
+ * @param s Input string.
+ * @return String with first character up-cased.
+ */
+ public static String ucfirst(String s) {
+ return Character.toUpperCase(s.charAt(0)) + s.substring(1);
+ }
+
+ /**
+ * Return a string which may be a legal part of a Java source file.
+ *
+ * @param s Input String.
+ * @return String with unsafe characters escaped.
+ */
+ public static String escapeString(String s) {
+ char[] chars = s.toCharArray();
+ int len = chars.length;
+ StringBuffer b = new StringBuffer(len);
+ char c;
+ for (int i = 0; i < len; i++) {
+ c = chars[i];
+ switch(c) {
+ case '\b':
+ b.append("\\b");
+ break;
+ case '\t':
+ b.append("\\t");
+ break;
+ case '\n':
+ b.append("\\n");
+ break;
+ case '\f':
+ b.append("\\f");
+ break;
+ case '\r':
+ b.append("\\r");
+ break;
+ case '\"':
+ b.append("\\\"");
+ break;
+ case '\'':
+ b.append("\\\'");
+ break;
+ case '\\':
+ b.append("\\\\");
+ break;
+ default:
+ b.append(c);
+ }
+ }
+ return b.toString();
+ }
+
+ public static String valueOf(int i) {
+ char[] buf = new char[11];
+ int index = buf.length;
+ boolean negative = (i < 0);
+ if (!negative) {
+ i = -i;
+ }
+ while (i <= -10) {
+ buf[--index] = Character.forDigit(-(i % 10), 10);
+ i = i / 10;
+ }
+ buf[--index] = Character.forDigit(-i, 10);
+ if (negative) {
+ buf[--index] = '-';
+ }
+ return new String(buf, index, buf.length-index);
+ }
+
+ /**
+ * Expects a string representation of a decimal number, with
+ * thousands separated by a separator char given as the second
+ * argument, and with a decimal separator, given as the third
+ * argument.
+ * <p>
+ * Returns a string suitable for the constructors of Java number
+ * types like BigDecimal, without a thousands separator and
+ * with a decimal point.
+ *
+ * @param Decimal number (String)
+ * @param Thousands separator
+ * @param Decimal separator
+ */
+ public static String numStr4Java(String inputString,
+ char thousandSeparator,
+ char decimalSeparator) {
+
+ if (inputString == null)
+ return null;
+
+ StringBuffer returnString = new StringBuffer();
+ for (int i = 0; i < inputString.length(); ++i)
+ {
+ char ch = inputString.charAt(i);
+ if (ch == thousandSeparator) continue; // Skip
+ else if (ch == decimalSeparator) returnString.append('.'); // Substitute
+ else returnString.append(ch); // Copy
+ }
+ return returnString.toString();
+ }
+
+ /**
+ * Expects a string representation of a decimal number with
+ * (in rare cases) thousands separated by commas. Returns a
+ * String without the commas.
+ */
+ public static String takeCommasFromNumStr(String inputString) {
+
+ if (inputString == null)
+ return null;
+ else if (inputString.indexOf(',') == -1) // Check to save time
+ return inputString;
+ else
+ return numStr4Java( inputString, ',', '.' );
+ }
+
+ /**
+ * Returns an array of the keys from the specified enumeration
+ * and size (e.g., from a HashTable or Workspace).
+ *
+ * @param e Enumeration to return as an array
+ * @param size Number of things in the Enumeration
+ */
+ public static String[] enumeration2StringArray(Enumeration e, int size) {
+ int i=0;
+ // allocate array of correct size
+ String[] keys = new String[size];
+
+ // save up all the elements. should be strings.
+ while (e.hasMoreElements()) {
+ keys[i++] = (String) e.nextElement();
+ }
+ return keys;
+ }
+
+ /**
+ * Returns an array of chars as an array of bytes.
+ *
+ * @param chars Array of chars
+ * @return Array of bytes
+ */
+ public static byte[] chars2bytes(char[] chars) {
+
+ byte[] bytes = new byte[chars.length*2];
+ int j = 0;
+ for (int i = 0; i < chars.length; i++) {
+ char c1 = chars[i];
+ char c2 = chars[i];
+ bytes[j++] = (byte) (c1 >> 8);
+ bytes[j++] = (byte) c2;
+ }
+ return bytes;
+ }
+
+ /**
+ * Returns an array of bytes as an array of chars.
+ *
+ * @param bytes Byte array
+ * @return Array of chars
+ * @exception java.lang.Exception if the byte array cannot be converted
+ */
+ public static char[] bytes2chars(byte[] bytes)
+ throws Exception
+ {
+ if ((bytes.length % 2) != 0)
+ throw new Exception("Cannot convert an odd number of bytes");
+
+ char[] chars = new char[bytes.length/2];
+ int j = 0;
+ for (int i = 0; i < chars.length; i++) {
+ byte b1 = bytes[j++];
+ byte b2 = bytes[j++];
+ chars[i] = (char)(((b1 << 8) & 0x0000FF00) |
+ ((b2 << 0) & 0x000000FF));
+ }
+ return chars;
+ }
+
+ /**
+ * Pads the specified String to the specified width.
+ *
+ * @param str String to pad
+ * @param width Length of padded string
+ * @return Padded String
+ */
+ public static String padStringWidth(String str, int width) {
+ StringBuffer sb = null;
+ if (str != null) {
+ sb = new StringBuffer(str);
+ sb.setLength(width);
+ int start = str.length();
+ for (int i = start; i < width; i++)
+ sb.setCharAt(i, ' ');
+ }
+ else {
+ sb = new StringBuffer(width);
+ sb.setLength(width);
+ for (int i = 0; i < width; i++)
+ sb.setCharAt(i, ' ');
+ }
+
+ return sb.toString();
+ }
+
+ /**
+ * Pads the specified integer value to the specified width.
+ *
+ * @param val Integer to pad
+ * @param width Length of padded string
+ * @return Padded String
+ */
+ public static String padStringWidth(int val, int width) {
+ return padStringWidth(String.valueOf(val), width);
+ }
+
+ /**
+ * Pads the specified float value to the specified width.
+ *
+ * @param val Float value to pad
+ * @param width Length of padded string
+ * @return Padded String
+ */
+ public static String padStringWidth(float val, int width) {
+ return padStringWidth(String.valueOf(val), width);
+ }
+
+ /**
+ * Pads the specified long value to the specified width.
+ *
+ * @param val Long to pad
+ * @param width Length of padded string
+ * @return Padded String
+ */
+ public static String padStringWidth(long val, int width) {
+ return padStringWidth(String.valueOf(val), width);
+ }
+
+ /**
+ * Pads the specified double value to the specified width.
+ *
+ * @param val Double to pad
+ * @param width Length of padded string
+ * @return Padded String
+ */
+ public static String padStringWidth(double val, int width) {
+ return padStringWidth(String.valueOf(val), width);
+ }
+
+}
Propchange: beehive/trunk/controls/test/tools/tch/src/java/org/apache/beehive/test/tools/tch/common/util/StringUtils.java
------------------------------------------------------------------------------
svn:eol-style = native