FileDocCategorySizeDatePackage
Tools.javaAPI DocphoneME MR2 API (J2ME)7801Wed May 02 17:59:48 BST 2007com.sun.cldchi.tools.memoryprofiler.jdwp

Tools

public class Tools extends Object
This class contains some auxillary functions that are used by classes of jdwp package.

Fields Summary
Constructors Summary
Methods Summary
public static java.lang.StringHex(long b, int length)
Returns a hex representation of long value with leading zeros.

param
b an integer value
param
length a size of the integer value (2 for short, 4 for int, 8 for long)
return
a hex representation of long value with leading zeros

	return Right(Long.toHexString(b), length).replace(' ", '0");
    
public static java.lang.StringLeft(java.lang.String source, int length)
Truncates or increases the specified string to the specified length. If the source string is less that the desired length the necessary number of spaces is added to the end of the string. If the source string is more than the desired length the necessary number of last characters is removed.

param
source a sring to be aligned
param
length a desired length of the string
return
an aligned string


        if (length <= 0)
        	return "";

        if (length <= source.length())
			return source.substring(0, length);
		else
			return PadR(source, length);
    
public static java.lang.StringPadL(java.lang.String source, int length, java.lang.String what)
Addes the specified substring to the beginning of the specified string a few times until the length of the string becomes not less than the specified length. If the length of the string is already more than the specified length the resulting value if a string of asterisks with the specified length.

param
source a source string to align
param
length a desired length of the result string
param
what a substring that must be appended to the beginning of the string
return
an aligned string


        if (length <= 0)
            return "";

        if (source.length() > length)
            return PadL("", length, "*");

	while (source.length() < length) 
		source = what + source;

	return source;
    
public static java.lang.StringPadL(java.lang.String source, int length)
Addes spaces to the beginning of the specified string a few times until the length of the string becomes not less than the specified length. If the length of the string is already more than the specified length the resulting value if a string of asterisks with the specified length.

param
source a source string to align
param
length a desired length of the result string
return
an aligned string

    	return PadL(source, length, " ");
    
public static java.lang.StringPadR(java.lang.String source, int length, java.lang.String what)
Appends the specified substring to the end of the specified string a few times until the length of the string becomes not less than the specified length. If the length of the string is already more than the specified length the resulting value if a string of asterisks with the specified length.

param
source a source string to align
param
length a desired length of the result string
param
what a substring that must be appended to the end of the string
return
an aligned string


        if (length <= 0)
        	return "";

        if (source.length() > length)
			return PadR("", length, "*");

		while (source.length() < length) 
			source = source + what;

		return source;
    
public static java.lang.StringPadR(java.lang.String source, int length)
Appends spaces to the end of the specified string a few times until the length of the string becomes not less than the specified length. If the length of the string is already more than the specified length the resulting value if a string of asterisks with the specified length.

param
source a source string to align
param
length a desired length of the result string
return
an aligned string

    	return PadR(source, length, " ");
    
public static java.lang.StringRight(java.lang.String source, int length)
Truncates or increases the specified string to the specified length. If the source string is less that the desired length the necessary number of spaces is added to the beginning of the string. If the source string is more than the desired length the necessary number of first characters is removed.

param
source a sring to be aligned
param
length a desired length of the string
return
an aligned string


        if (length <= 0)
        	return "";

		if (length <= source.length())
			return source.substring(source.length() - length, source.length());
		else
			return PadL(source, length);
    
public static intcountBytes(java.lang.String s)
Returns a number of tokens in the string. Token delimiters are spaces, colons, commas and tab characters.

param
a string that consist on tokens and delimiteres.
return
a number of tokens in the string

        return (new StringTokenizer(s, " :,\t")).countTokens();
    
public static java.lang.StringlistVector(java.util.Vector v)
Returns a content of the vector as a string where elements of the vector are separated by tabs.

param
v a vector that should be represented as a string
return
a string representation of the vector

		String s = "";
		for (int i = 0; i < v.size(); i++)
			s = s + (i + 1) + "\t" + v.elementAt(i) + "\n";
		return s;
    
public static byte[]str2bytes(java.lang.String s)
Converts a string that is a list of bytes separated by spaces, colons, commas and tab characters (for example, 01,15,44,135) to byte array.

param
s a string to be converted
return
an array of bytes that corresponds to the source string

    	
        StringTokenizer t = new StringTokenizer(s, " :,\t");

		byte[] buf = new byte[t.countTokens()];

		int k = 0;
		while (t.hasMoreTokens())
			buf[k++] = Integer.decode(t.nextToken()).byteValue();

    	return buf;
    
public static voidwait(int delay)
Suspends the current thread for the specified number of milliseconds.

param
delay suspend time in milliseconds

		try {
			Thread.sleep(delay);
		}
		catch (Exception e) {}