jut.lang
Class Strings

java.lang.Object
  extended by jut.lang.Strings

public final class Strings
extends Object

static string utility methods.


Field Summary
static int[] CHAR_HEX
          table of integer values of the 16 characters used in hex strings, used for hex conversions.
static char[] HEX_CHARS
          table of the 16 characters used in hex strings, used for hex conversions.
 
Method Summary
static String hex(byte[] bytes)
          returns the corresponding upper-case hex string for a byte array.
static String hex(byte[] bytes, int len)
          returns the corresponding upper-case hex string for the first bytes of a byte array.
static byte[] hex(String string)
          returns the corresponding byte array for a hex string. this method accepts both upper case and lower case hex strings. for invalid input strings, an IllegalArgumentException is thrown.
static int indexOfDifference(String str1, String str2)
          Compares two Strings, and returns the index at which the Strings begin to differ.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

HEX_CHARS

public static final char[] HEX_CHARS
table of the 16 characters used in hex strings, used for hex conversions.


CHAR_HEX

public static final int[] CHAR_HEX
table of integer values of the 16 characters used in hex strings, used for hex conversions. table cells that do not represent a hex value are initialized with -0x100.

Method Detail

hex

public static String hex(byte[] bytes)
returns the corresponding upper-case hex string for a byte array.

this method is performance optimized.

Parameters:
bytes - - the byte array to create the hex string for.
Returns:
the corresponding hex string for a byte array.

hex

public static String hex(byte[] bytes,
                         int len)
returns the corresponding upper-case hex string for the first bytes of a byte array.

this method is performance optimized.

Parameters:
bytes - - the byte array to create the hex string from.
len - - the number of bytes to create the hex string for.
Returns:
the corresponding hex string for a byte array.

hex

public static byte[] hex(String string)
returns the corresponding byte array for a hex string. this method accepts both upper case and lower case hex strings. for invalid input strings, an IllegalArgumentException is thrown.

this method is performance optimized.

Parameters:
string - - the hex string to create a byte array for.
Returns:
the corresponding byte array for a hex string.

indexOfDifference

public static int indexOfDifference(String str1,
                                    String str2)
Compares two Strings, and returns the index at which the Strings begin to differ.

For example, indexOfDifference("i am a machine", "i am a robot") -> 7

 StringUtils.indexOfDifference(null, null) = -1
 StringUtils.indexOfDifference("", "") = -1
 StringUtils.indexOfDifference("", "abc") = 0
 StringUtils.indexOfDifference("abc", "") = 0
 StringUtils.indexOfDifference("abc", "abc") = -1
 StringUtils.indexOfDifference("ab", "abxyz") = 2
 StringUtils.indexOfDifference("abcde", "abxyz") = 2
 StringUtils.indexOfDifference("abcde", "xyz") = 0
 
this method is taken from the org.apache.commons.lang.StringUtils class and is copyright 2002-2005 The Apache Software Foundation, licensed under the Apache License, Version 2.0 http://www.apache.org/licenses/LICENSE-2.0

Parameters:
str1 - - the first String, may be null
str2 - - the second String, may be null
Returns:
the index where str2 and str1 begin to differ; -1 if they are equal.