Java Utililty Methods ID Value Create

List of utility methods to do ID Value Create

Description

The list of methods to do ID Value Create are organized into topic(s).

Method

StringtoId(String text)
to Id
return text.replaceAll("[^a-zA-Z0-9\\-_]*", "");
StringtoIdableName(String xpath)
to Idable Name
xpath = "X" + xpath;
xpath = xpath.replace("/", "-");
xpath = xpath.replace("[", "_");
return xpath.replace("]", ":");
StringtoIdentifier(String input)
Modifies all characters which are not valid in an identifier; leading and trailing blanks are removed.
final String ti = input.trim();
if (ti.isEmpty() == true) {
    return ti;
final StringBuilder sb = new StringBuilder(ti);
char c = sb.charAt(0);
if (Character.isJavaIdentifierStart(c) == false || c == '$') {
    sb.setCharAt(0, '_');
...
StringtoIdentifier(String name)
convert a name to Java-compatible identifier name.
return xmlNameToJavaName("field", name);
voidtoIdentifier(String name, StringBuffer fieldName)
to Identifier
for (int i = 0; i < name.length(); i++) {
    if (name.charAt(i) == ' ')
        fieldName.append(Character.toUpperCase(name.charAt(++i)));
    else
        fieldName.append(name.charAt(i));
StringtoIdentifier(String str)
Given a string, returns a proper C identifier.
StringBuffer buf = new StringBuffer();
if (!str.isEmpty()) {
    char first = str.charAt(0);
    if (Character.isJavaIdentifierPart(first) && !Character.isJavaIdentifierStart(first)) {
        buf.append("_");
    for (int i = 0; i < str.length(); i++) {
        char ch = str.charAt(i);
...
StringtoIdentifier(String text)
to Identifier
String out = "";
if (Character.isDigit(text.charAt(0)))
    out += "_";
for (int i = 0; i < text.length(); i++) {
    if (Character.isJavaIdentifierPart(text.charAt(i)))
        out += text.charAt(i);
    else if (text.charAt(i) == ' ')
        out += "_";
...
StringtoIdentifierString(long val)
creates a shortest possible string representation of the given long number that qualifies as an identifier in common programming languages (and HTML-id's :-) That is, it must start with a letter.
char buf[] = new char[14];
int i = 0;
if (val < 0) {
    buf[i++] = '_';
    val = -(val + 1);
buf[i++] = ALPHAS[(int) (val % ALPHAS.length)];
val /= ALPHAS.length;
...
StringtoIdentityEncodedString(byte[] data)
to Identity Encoded String
if (data == null) {
    return null;
char[] characters = new char[data.length];
for (int i = 0; i < characters.length; i++) {
    characters[i] = (char) (data[i] & 0xff);
return new String(characters);
...
IntegertoIdentityHashCodeInteger(Object value)
to Identity Hash Code Integer
return new Integer(System.identityHashCode(value));