Example usage for java.lang StringBuffer length

List of usage examples for java.lang StringBuffer length

Introduction

In this page you can find the example usage for java.lang StringBuffer length.

Prototype

@Override
    public synchronized int length() 

Source Link

Usage

From source file:ca.uhn.hl7v2.sourcegen.SourceGenerator.java

public static String makeAlternateAccessorName(String fieldDesc, String parentName, int index) {
    StringBuffer aName = new StringBuffer();

    aName.append(StringUtils.capitalize(parentName.toLowerCase())).append(index).append("_");

    char[] chars = fieldDesc.toCharArray();
    boolean lastCharWasNotLetter = true;
    int inBrackets = 0;
    StringBuffer bracketContents = new StringBuffer();
    for (int i = 0; i < chars.length; i++) {
        if (chars[i] == '(')
            inBrackets++;/*from   www .j  a va  2 s  . co m*/
        if (chars[i] == ')')
            inBrackets--;

        if (Character.isLetterOrDigit(chars[i])) {
            if (inBrackets > 0) {
                //buffer everthing in brackets
                bracketContents.append(chars[i]);
            } else {
                //add capitalized bracketed text if appropriate 
                if (bracketContents.length() > 0) {
                    aName.append(capitalize(filterBracketedText(bracketContents.toString())));
                    bracketContents = new StringBuffer();
                }
                if (lastCharWasNotLetter) {
                    //first letter of each word is upper-case
                    aName.append(Character.toUpperCase(chars[i]));
                } else {
                    aName.append(chars[i]);
                }
                lastCharWasNotLetter = false;
            }
        } else {
            lastCharWasNotLetter = true;
        }
    }
    aName.append(capitalize(filterBracketedText(bracketContents.toString())));
    String retVal = aName.toString();

    return retVal;
}

From source file:ca.uhn.hl7v2.sourcegen.SourceGenerator.java

/**
 * Make a Java-ish accessor method name out of a field or component description
 * by removing non-letters and adding "get".  One complication is that some description
 * entries in the DB have their data types in brackets, and these should not be
 * part of the method name.  On the other hand, sometimes critical distinguishing
 * information is in brackets, so we can't omit everything in brackets.  The approach
 * taken here is to eliminate bracketed text if a it looks like a data type.
 */// ww w . ja  v a2s  . co m
public static String makeAccessorName(String fieldDesc, String parentName) {
    StringBuffer aName = new StringBuffer();
    char[] chars = fieldDesc.toCharArray();
    boolean lastCharWasNotLetter = true;
    int inBrackets = 0;
    StringBuffer bracketContents = new StringBuffer();
    for (int i = 0; i < chars.length; i++) {
        if (chars[i] == '(')
            inBrackets++;
        if (chars[i] == ')')
            inBrackets--;

        if (Character.isLetterOrDigit(chars[i])) {
            if (inBrackets > 0) {
                //buffer everthing in brackets
                bracketContents.append(chars[i]);
            } else {
                //add capitalized bracketed text if appropriate 
                if (bracketContents.length() > 0) {
                    aName.append(capitalize(filterBracketedText(bracketContents.toString())));
                    bracketContents = new StringBuffer();
                }
                if (lastCharWasNotLetter) {
                    //first letter of each word is upper-case
                    aName.append(Character.toUpperCase(chars[i]));
                } else {
                    aName.append(chars[i]);
                }
                lastCharWasNotLetter = false;
            }
        } else {
            lastCharWasNotLetter = true;
        }
    }
    aName.append(capitalize(filterBracketedText(bracketContents.toString())));
    String retVal = aName.toString();

    // Accessors with these two names conflict with existing superclass accessor names
    if (retVal.equals("Parent")) {
        retVal = parentName + "Parent";
    }
    if (retVal.equals("Name")) {
        retVal = parentName + "Name";
    }

    return retVal;
}

From source file:jdiff.API.java

/** 
 * Convert text with stuffed HTML tags ("lEsS_tHaN", etc) into HTML text.
 *///from   w  ww .j  a  va  2s . c  o m
public static String showHTMLTags(String text) {
    StringBuffer sb = new StringBuffer(text);
    StringBuffer res = new StringBuffer();
    int len = sb.length();
    res.setLength(len);
    int i = 0;
    int resIdx = 0;
    while (i < len) {
        char c = sb.charAt(i);
        if (len - i > 8 && c == 'l' && sb.charAt(i + 1) == 'E' && sb.charAt(i + 2) == 's'
                && sb.charAt(i + 3) == 'S' && sb.charAt(i + 4) == '_' && sb.charAt(i + 5) == 't'
                && sb.charAt(i + 6) == 'H' && sb.charAt(i + 7) == 'a' && sb.charAt(i + 8) == 'N') {
            res.setCharAt(resIdx, '<');
            i += 8;
        } else if (len - i > 9 && c == 'q' && sb.charAt(i + 1) == 'U' && sb.charAt(i + 2) == 'o'
                && sb.charAt(i + 3) == 'T' && sb.charAt(i + 4) == 'e' && sb.charAt(i + 5) == '_'
                && sb.charAt(i + 6) == 'c' && sb.charAt(i + 7) == 'H' && sb.charAt(i + 8) == 'a'
                && sb.charAt(i + 9) == 'R') {
            res.setCharAt(resIdx, '"');
            i += 9;
        } else if (len - i > 7 && c == 'a' && sb.charAt(i + 1) == 'N' && sb.charAt(i + 2) == 'd'
                && sb.charAt(i + 3) == '_' && sb.charAt(i + 4) == 'c' && sb.charAt(i + 5) == 'H'
                && sb.charAt(i + 6) == 'a' && sb.charAt(i + 7) == 'R') {
            res.setCharAt(resIdx, '&');
            i += 7;
        } else {
            res.setCharAt(resIdx, c);
        }
        i++;
        resIdx++;
    }
    res.setLength(resIdx);
    return res.toString();
}

From source file:com.myJava.util.Util.java

/**
 * Return the keys of the HashTable as a single String.
 * <BR>The separator passed as argument is used.
 * <BR>For instance, [1=toto 2=tutu 6=titi 9=tata] will give "1,2,6,9" if the separator
 * is ",".// w  w w .  ja v  a 2 s .  c o m
 */
public static String getContentList(Hashtable values, String separator) {
    StringBuffer sb = new StringBuffer();
    Enumeration keys = values.keys();
    while (keys.hasMoreElements()) {
        sb.append(separator);
        sb.append(keys.nextElement().toString());
    }

    if (sb.length() == 0) {
        return "";
    } else {
        return sb.toString().substring(separator.length());
    }
}

From source file:hu.netmind.beankeeper.node.impl.NodeManagerImpl.java

/**
 * Get the server addresses from interfaces.
 *///from   www.  ja v a 2 s. c o m
public static String getHostAddresses() {
    try {
        Enumeration interfaceEnumeration = NetworkInterface.getNetworkInterfaces();
        // Copy from enumeration to addresses vector, but filter loopback addresses
        ArrayList addresses = new ArrayList();
        while (interfaceEnumeration.hasMoreElements()) {
            NetworkInterface intf = (NetworkInterface) interfaceEnumeration.nextElement();
            // Remove loopback addresses
            Enumeration addressEnumeration = intf.getInetAddresses();
            while (addressEnumeration.hasMoreElements()) {
                InetAddress address = (InetAddress) addressEnumeration.nextElement();
                // Insert to addresses only if not loopback and not link local
                if ((!address.isLoopbackAddress()) && (!address.isLinkLocalAddress()))
                    addresses.add(address);
            }
        }
        // Pick one address from the remaining address space
        logger.debug("server available local addresses: " + addresses);
        // Now, multiple addresses are in the list, so copy all of them
        // into the result string.
        StringBuffer ips = new StringBuffer();
        for (int i = 0; i < addresses.size(); i++) {
            InetAddress address = (InetAddress) addresses.get(i);
            if (ips.length() > 0)
                ips.append(",");
            ips.append(address.getHostAddress());
        }
        return ips.toString();
    } catch (StoreException e) {
        throw e;
    } catch (Exception e) {
        throw new StoreException("exception while determining server address", e);
    }
}

From source file:com.sfs.whichdoctor.formatter.OutputFormatter.java

/**
 * To formatted vote number.//from   ww  w.j  a  v  a2 s. c o m
 *
 * @param voteNumber the vote number
 *
 * @return the string
 */
public static String toFormattedVoteNumber(final int voteNumber) {
    final StringBuffer vote = new StringBuffer();

    vote.append(voteNumber);

    final int maxVoteLength = 6;

    while (vote.length() < maxVoteLength) {
        // Pad the number with zeros to make it at least 6 characters
        vote.insert(0, "0");
    }
    return vote.toString();
}

From source file:com.jiangyifen.ec2.globaldata.license.LicenseManager.java

/**
 * "xx-xx-xx-xx-xx-xx"??MAC?// w w w.j a  v a 2 s .c  o  m
 * 
 * @return
 * @throws Exception
 */
private static List<String> getMacAddressList() {
    List<String> macAddressList = new ArrayList<String>();
    try {
        Enumeration<NetworkInterface> ni = NetworkInterface.getNetworkInterfaces();

        while (ni.hasMoreElements()) {
            NetworkInterface netI = ni.nextElement();

            byte[] bytes = netI.getHardwareAddress();
            if (netI.isUp() && netI != null && bytes != null && bytes.length == 6) {
                StringBuffer sb = new StringBuffer();
                for (byte b : bytes) {
                    // 11110000????4?
                    sb.append(Integer.toHexString((b & 240) >> 4));
                    // 00001111????4?
                    sb.append(Integer.toHexString(b & 15));
                    sb.append("-");
                }
                sb.deleteCharAt(sb.length() - 1);
                macAddressList.add(sb.toString().toLowerCase());
            }
        }
    } catch (Exception e) {
        e.printStackTrace();
    }

    return macAddressList;
}

From source file:com.sfs.whichdoctor.formatter.OutputFormatter.java

/**
 * To tag list./*  w w  w.j  a  va 2s. c  o m*/
 *
 * @param tags the tags
 *
 * @return the string
 */
public static String toTagList(final Collection<TagBean> tags) {
    final StringBuffer tagList = new StringBuffer();

    if (tags != null) {
        for (TagBean tag : tags) {
            if (tagList.length() > 0) {
                tagList.append(", ");
            }
            tagList.append(tag.getTagName().trim());
        }
    }
    return tagList.toString();
}

From source file:com.t3.model.MacroButtonProperties.java

public static String paddingString(String s, int n, char c, boolean paddingLeft) {
    StringBuffer str = new StringBuffer(s);
    int strLength = str.length();
    if (n > 0 && n > strLength) {
        for (int i = 0; i <= n; i++) {
            if (paddingLeft) {
                if (i < n - strLength)
                    str.insert(0, c);/*from  w ww  . java  2s. c  om*/
            } else {
                if (i > strLength)
                    str.append(c);
            }
        }
    }
    return str.toString();
}

From source file:com.sun.faces.generate.HtmlComponentGenerator.java

/**
 * <p>Load the copyright text for the top of each Java source file.</p>
 *
 * @param path Pathname of the copyright file
 *///from ww w .j a  va2  s  .  co  m
private static void copyright(String path) throws Exception {

    if (log.isDebugEnabled()) {
        log.debug("Loading copyright text from '" + path + "'");
    }
    StringBuffer sb = new StringBuffer();
    BufferedReader reader = new BufferedReader(new FileReader(path));
    int ch;
    while ((ch = reader.read()) >= 0) {
        sb.append((char) ch);
    }
    reader.close();
    if (log.isDebugEnabled()) {
        log.debug("  Copyright text contains " + sb.length() + " characters");
    }
    copyright = sb.toString();

}