Example usage for java.lang StringBuffer charAt

List of usage examples for java.lang StringBuffer charAt

Introduction

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

Prototype

@Override
public synchronized char charAt(int index) 

Source Link

Usage

From source file:org.openflexo.foundation.wkf.FlexoProcess.java

public static String beautifyName(String name) {
    if (name == null) {
        return null;
    }/*from w  ww.  j a  v a  2  s  .  com*/
    if (name.matches(JavaUtils.JAVA_CLASS_NAME_REGEXP)) {
        return name;
    }
    Matcher m = JavaUtils.JAVA_VARIABLE_ACCEPTABLE_PATTERN.matcher(name);
    StringBuffer sb = new StringBuffer();
    int i = 0;
    while (m.find()) {
        int n = m.start() - i;
        for (int j = 0; j < n; j++) {
            sb.append('_');
        }
        sb.append(ToolBox.capitalize(m.group(), true));
        i = m.start() + m.end();
    }
    if (sb.length() == 0 || sb.charAt(0) >= '0' && sb.charAt(0) <= '9') {
        sb.insert(0, '_');
    }
    return sb.toString();
}

From source file:ParseURL.java

/**************************************************************************
 * Create a new munge string containing the desired RBNB munge components.
 * <p>/*from   www .j a v  a 2s .  com*/
 * The user can selectively remove munge components as specified by the
 * boolean arguments.  If the user has not chosen to remove any munge
 * component, then the original, complete munge string is returned.
 *
 * @author John P. Wilson
 *
 * @param bRemoveTimeI      Remove time from returned munge?
 * @param bRemoveDurationI      Remove duration from returned munge?
 * @param bRemoveReferenceI      Remove reference from returned munge?
 * @param bRemoveFetchI      Remove fetch from returned munge?
 * @param bRemoveByteorderI      Remove byteorder from returned munge?
 * @param bRemoveDatatypeI      Remove datatype from returned munge?
 * @param bRemoveMuxI      Remove mux from returned munge?
 * @param bRemoveBlocksizeI      Remove blocksize from returned munge?
 * @param bRemoveMimeI      Remove mime from returned munge?
 * @param bRemoveNonRBNBMungeI   Remove non RBNB munges from returned munge?
 *
 * @version 09/28/2006
 */

/*
 *
 *   Date      By     Description
 * MM/DD/YYYY
 * ----------  --     -----------
 * 09/28/2006  JPW    Change "bRemoveMessageI" to "bRemoveNonRBNBMungeI"
 * 06/02/2006  JPW    Created
 *
 */

public String createNewRBNBMunge(boolean bRemoveTimeI, boolean bRemoveDurationI, boolean bRemoveReferenceI,
        boolean bRemoveFetchI, boolean bRemoveByteorderI, boolean bRemoveDatatypeI, boolean bRemoveMuxI,
        boolean bRemoveBlocksizeI, boolean bRemoveMimeI, boolean bRemoveNonRBNBMungeI) {

    // JPW 09/28/2006: If user has not chosen to remove anything, then
    //                 simply return the original, complete munge string.
    if ((!bRemoveTimeI) && (!bRemoveDurationI) && (!bRemoveReferenceI) && (!bRemoveFetchI)
            && (!bRemoveByteorderI) && (!bRemoveDatatypeI) && (!bRemoveMuxI) && (!bRemoveBlocksizeI)
            && (!bRemoveMimeI) && (!bRemoveNonRBNBMungeI)) {
        return munge;
    }

    StringBuffer newMunge = new StringBuffer();

    if ((getTime() != null) && (!bRemoveTimeI)) {
        newMunge.append("&t=" + getTime().toString());
    }
    if ((getDuration() != null) && (!bRemoveDurationI)) {
        newMunge.append("&d=" + getDuration().toString());
    }
    if ((getReference() != null) && (!bRemoveReferenceI)) {
        newMunge.append("&r=" + getReference());
    }
    if ((getFetch() != null) && (!bRemoveFetchI)) {
        newMunge.append("&f=" + getFetch());
    }
    if ((getByteorder() != null) && (!bRemoveByteorderI)) {
        newMunge.append("&bo=" + getByteorder());
    }
    if ((getDatatype() != null) && (!bRemoveDatatypeI)) {
        newMunge.append("&dt=" + getDatatype());
    }
    if ((getMux() != null) && (!bRemoveMuxI)) {
        newMunge.append("&x=" + getMux().toString());
    }
    if ((getBlocksize() != null) && (!bRemoveBlocksizeI)) {
        newMunge.append("&bs=" + getBlocksize().toString());
    }
    if ((getMime() != null) && (!bRemoveMimeI)) {
        newMunge.append("&m=" + getMime());
    }
    // JPW 09/28/2006: Return the non RBNB munges as a series of key/value
    //                 pairs; don't return them encoded in the "msg"
    //                 munge (RBNB servlet doesn't do anything special
    //                 with the "msg" munge now).
    if ((getNonRBNBMungeStr() != null) && (!bRemoveNonRBNBMungeI)) {
        newMunge.append("&" + getNonRBNBMungeStr());
    }

    if (newMunge.length() == 0) {
        return null;
    }

    // If there is a leading '&', remove it
    if (newMunge.charAt(0) == '&') {
        newMunge = newMunge.deleteCharAt(0);
    }

    return newMunge.toString();

}

From source file:com.wabacus.system.component.application.report.ListReportType.java

private String getSubDataString(Object dataObj) {
    StringBuffer resultBuf = new StringBuffer();
    Object coldataTmp;// www  . jav a  2 s . c o  m
    for (Entry<String, Method> entryTmp : this.alrbean.getSubdisplaybean().getMPropertiesAndGetMethods()
            .entrySet()) {
        resultBuf.append("\"" + entryTmp.getKey() + "\":\"");
        try {
            coldataTmp = entryTmp.getValue().invoke(dataObj, new Object[] {});
        } catch (Exception e) {
            throw new WabacusRuntimeException("??" + entryTmp.getValue().getName() + "?"
                    + rbean.getPath() + "?", e);
        }
        if (coldataTmp == null) {
            resultBuf.append("");
        } else {
            resultBuf.append(Tools.jsParamEncode(String.valueOf(coldataTmp)));
        }
        resultBuf.append("\",");
    }
    if (resultBuf.charAt(resultBuf.length() - 1) == ',')
        resultBuf.deleteCharAt(resultBuf.length() - 1);
    return resultBuf.toString();
}

From source file:cn.jsprun.struts.action.BasicSettingsAction.java

public ActionForward permissions(ActionMapping mapping, ActionForm form, HttpServletRequest request,
        HttpServletResponse response) {//w w w  .  j a  v  a2 s.  c  o m
    try {
        if (submitCheck(request, "settingsubmit")) {
            String variables[] = { "memliststatus", "reportpost", "minpostsize", "maxpostsize", "maxfavorites",
                    "maxsubscriptions", "maxavatarsize", "maxavatarpixel", "maxpolloptions", "edittimelimit",
                    "editedby", "karmaratelimit", "modratelimit", "dupkarmarate" };
            Map<String, String> oldSettings = ForumInit.settings;
            Map<String, String> settings = new HashMap<String, String>();
            for (String variable : variables) {
                String value = request.getParameter(variable);
                if (Common.matches(variable, "^(edittimelimit|karmaratelimit)$")) {
                    if (value != null) {
                        value = Double.valueOf(FormDataCheck.getDoubleString(value)).toString();
                        if (value.contains(".")) {
                            StringBuffer buffer = new StringBuffer(value);
                            while (true) {
                                if (buffer.charAt(buffer.length() - 1) == '.') {
                                    buffer.deleteCharAt(buffer.length() - 1);
                                    break;
                                } else if (buffer.charAt(buffer.length() - 1) == '0') {
                                    buffer.deleteCharAt(buffer.length() - 1);
                                } else {
                                    break;
                                }
                            }
                            value = buffer.toString();
                        }
                    }
                } else if ("|minpostsize|maxpostsize|maxavatarsize|maxavatarpixel|maxpolloptions|maxfavorites|maxsubscriptions|"
                        .contains(variable)) {
                    value = Common.toDigit(value) + "";
                }
                this.putValue(variable, value, oldSettings, settings);
            }
            this.updateSettings(settings, oldSettings);
            return this.getForward(mapping, request);
        }
    } catch (Exception e) {
        request.setAttribute("message", e.getMessage());
        return mapping.findForward("message");
    }
    return mapping.findForward("setting_permissions");
}

From source file:cn.jsprun.struts.action.BasicSettingsAction.java

private boolean validateExpressions(String expression) {
    String reg = "[\\*/\\+]";
    String reg2 = "\\-";
    String reg3 = "[\\-]?[\\(]*[\\-]?extcredits[1-8][\\)]*";
    String reg4 = "\\(";
    String reg5 = "[\\-]?[\\(]*[\\-]?[0-9]+[\\)]*";
    String reg5_ = "[\\-]?[\\(]*[\\-]?[0-9]*.[0-9]+[\\)]*";
    String reg6 = "[\\-]?[\\(]*[\\-]?posts[\\)]*";
    String reg7 = "[\\-]?[\\(]*[\\-]?digestposts[\\)]*";
    String reg8 = "[\\-]?[\\(]*[\\-]?oltime[\\)]*";
    String reg9 = "[\\-]?[\\(]*[\\-]?pageviews[\\)]*";
    String[] temp = expression.split(reg);
    for (int i = 0; i < temp.length; i++) {
        if (temp[i].trim().equals("") || temp[i].trim().endsWith("-")) {
            return false;
        }//from  ww  w . j  av  a 2  s  .  co  m
    }
    for (int i = 0; i < temp.length; i++) {
        String[] temp2 = temp[i].trim().split(reg2);
        int sign = 0;
        for (int j = 0; j < temp2.length; j++) {
            String temp2v = temp2[j].trim();
            if ((!temp2v.matches(reg3) && !temp2v.matches(reg4) && !temp2v.matches(reg5)
                    && !temp2v.matches(reg5_) && !temp2v.matches(reg6) && !temp2v.matches(reg7)
                    && !temp2v.matches(reg8) && !temp2v.matches(reg9)) && !temp2v.equals("")) {
                return false;
            }
            if (sign == 2) {
                return false;
            }
            if (temp2v.equals("")) {
                sign++;
            }
            if (sign == 1 && !temp2v.equals("")) {
                sign--;
            }
        }
    }
    boolean boolFront = true;
    StringBuffer buffer = new StringBuffer(expression);
    int chrIndex = 0;
    for (int i = 0; i < buffer.length(); i++) {
        char chr = buffer.charAt(i);
        if (boolFront && chr == ')') {
            return false;
        }
        if (chr == '(') {
            chrIndex = i;
            boolFront = false;
        }
        if (!boolFront && chr == ')') {
            buffer.replace(chrIndex, chrIndex + 1, "V");
            buffer.replace(i, i + 1, "V");
            boolFront = true;
            i = -1;
        }
    }
    if (!boolFront) {
        return false;
    }
    return true;
}

From source file:org.apache.poi.ss.format.CellNumberFormatter.java

private void writeScientific(double value, StringBuffer output, Set<StringMod> mods) {

    StringBuffer result = new StringBuffer();
    FieldPosition fractionPos = new FieldPosition(DecimalFormat.FRACTION_FIELD);
    decimalFmt.format(value, result, fractionPos);
    writeInteger(result, output, integerSpecials, mods, integerCommas);
    writeFractional(result, output);/*from w  w w.  j a v a  2s .  c om*/

    /*
    * Exponent sign handling is complex.
    *
    * In DecimalFormat, you never put the sign in the format, and the sign only
    * comes out of the format if it is negative.
    *
    * In Excel, you always say whether to always show the sign ("e+") or only
    * show negative signs ("e-").
    *
    * Also in Excel, where you put the sign in the format is NOT where it comes
    * out in the result.  In the format, the sign goes with the "e"; in the
    * output it goes with the exponent value.  That is, if you say "#e-|#" you
    * get "1e|-5", not "1e-|5". This makes sense I suppose, but it complicates
    * things.
    *
    * Finally, everything else in this formatting code assumes that the base of
    * the result is the original format, and that starting from that situation,
    * the indexes of the original special characters can be used to place the new
    * characters.  As just described, this is not true for the exponent's sign.
    * <p/>
    * So here is how we handle it:
    *
    * (1) When parsing the format, remove the sign from after the 'e' and put it
    * before the first digit of the exponent (where it will be shown).
    *
    * (2) Determine the result's sign.
    *
    * (3) If it's missing, put the sign into the output to keep the result
    * lined up with the output. (In the result, "after the 'e'" and "before the
    * first digit" are the same because the result has no extra chars to be in
    * the way.)
    *
    * (4) In the output, remove the sign if it should not be shown ("e-" was used
    * and the sign is negative) or set it to the correct value.
    */

    // (2) Determine the result's sign.
    int ePos = fractionPos.getEndIndex();
    int signPos = ePos + 1;
    char expSignRes = result.charAt(signPos);
    if (expSignRes != '-') {
        // not a sign, so it's a digit, and therefore a positive exponent
        expSignRes = '+';
        // (3) If it's missing, put the sign into the output to keep the result
        // lined up with the output.
        result.insert(signPos, '+');
    }

    // Now the result lines up like it is supposed to with the specials' indexes
    ListIterator<Special> it = exponentSpecials.listIterator(1);
    Special expSign = it.next();
    char expSignFmt = expSign.ch;

    // (4) In the output, remove the sign if it should not be shown or set it to
    // the correct value.
    if (expSignRes == '-' || expSignFmt == '+')
        mods.add(replaceMod(expSign, true, expSign, true, expSignRes));
    else
        mods.add(deleteMod(expSign, true, expSign, true));

    StringBuffer exponentNum = new StringBuffer(result.substring(signPos + 1));
    writeInteger(exponentNum, output, exponentDigitSpecials, mods, false);
}

From source file:cn.jsprun.struts.action.BasicSettingsAction.java

private boolean validate_1(String qualification, int temp1, StringBuffer leftString, StringBuffer rightString) {
    leftString.append(qualification.substring(0, temp1));
    rightString.append(qualification.substring(temp1 + 2));
    if (leftString.length() == 0 || rightString.length() == 0) {
        return false;
    }/*from   w  ww .  j  a v a2s . c  o  m*/
    char temp = 0;
    for (int i = leftString.length(); i > 0;) {
        temp = leftString.charAt(--i);
        if (temp == '=' || temp == '>' || temp == '<') {
            return false;
        }
    }
    for (int i = leftString.length(); i > 0;) {
        temp = leftString.charAt(--i);
        if (temp == '=' || temp == '>' || temp == '<') {
            return false;
        }
    }
    return true;
}

From source file:org.zkoss.poi.ss.format.CellNumberFormatter.java

private void writeScientific(double value, StringBuffer output, Set<StringMod> mods) {

    StringBuffer result = new StringBuffer();
    FieldPosition fractionPos = new FieldPosition(DecimalFormat.FRACTION_FIELD);
    decimalFmt.format(value, result, fractionPos);
    writeInteger(result, output, integerSpecials, mods, integerCommas, false);
    writeFractional(result, output);// w w  w.  j ava  2s . c  o  m

    /*
    * Exponent sign handling is complex.
    *
    * In DecimalFormat, you never put the sign in the format, and the sign only
    * comes out of the format if it is negative.
    *
    * In Excel, you always say whether to always show the sign ("e+") or only
    * show negative signs ("e-").
    *
    * Also in Excel, where you put the sign in the format is NOT where it comes
    * out in the result.  In the format, the sign goes with the "e"; in the
    * output it goes with the exponent value.  That is, if you say "#e-|#" you
    * get "1e|-5", not "1e-|5". This makes sense I suppose, but it complicates
    * things.
    *
    * Finally, everything else in this formatting code assumes that the base of
    * the result is the original format, and that starting from that situation,
    * the indexes of the original special characters can be used to place the new
    * characters.  As just described, this is not true for the exponent's sign.
    * <p/>
    * So here is how we handle it:
    *
    * (1) When parsing the format, remove the sign from after the 'e' and put it
    * before the first digit of the exponent (where it will be shown).
    *
    * (2) Determine the result's sign.
    *
    * (3) If it's missing, put the sign into the output to keep the result
    * lined up with the output. (In the result, "after the 'e'" and "before the
    * first digit" are the same because the result has no extra chars to be in
    * the way.)
    *
    * (4) In the output, remove the sign if it should not be shown ("e-" was used
    * and the sign is negative) or set it to the correct value.
    */

    // (2) Determine the result's sign.
    int ePos = fractionPos.getEndIndex();
    int signPos = ePos + 1;
    char expSignRes = result.charAt(signPos);
    if (expSignRes != '-') {
        // not a sign, so it's a digit, and therefore a positive exponent
        expSignRes = '+';
        // (3) If it's missing, put the sign into the output to keep the result
        // lined up with the output.
        result.insert(signPos, '+');
    }

    // Now the result lines up like it is supposed to with the specials' indexes
    ListIterator<Special> it = exponentSpecials.listIterator(1);
    Special expSign = it.next();
    char expSignFmt = expSign.ch;

    // (4) In the output, remove the sign if it should not be shown or set it to
    // the correct value.
    if (expSignRes == '-' || expSignFmt == '+')
        mods.add(replaceMod(expSign, true, expSign, true, expSignRes));
    else
        mods.add(deleteMod(expSign, true, expSign, true));

    StringBuffer exponentNum = new StringBuffer(result.substring(signPos + 1));
    writeInteger(exponentNum, output, exponentDigitSpecials, mods, false, false);
}

From source file:org.talend.designer.runprocess.java.JavaProcessor.java

protected String getNeededModulesJarStr() {
    final String classPathSeparator = extractClassPathSeparator();
    final String libPrefixPath = getRootWorkingDir(true);

    Set<ModuleNeeded> neededModules = getNeededModules();
    JavaProcessorUtilities.checkJavaProjectLib(neededModules);

    StringBuffer libPath = new StringBuffer();
    if (isExportConfig() || isRunAsExport()) {
        boolean hasLibPrefix = libPrefixPath.length() > 0;
        for (ModuleNeeded neededModule : neededModules) {
            if (hasLibPrefix) {
                libPath.append(libPrefixPath);
            }/*  w  w w  . java 2  s. c  o  m*/
            libPath.append(getBaseLibPath());
            libPath.append(JavaUtils.PATH_SEPARATOR);
            libPath.append(neededModule.getModuleName());
            libPath.append(classPathSeparator);
        }
    } else {
        Set<String> neededLibraries = new HashSet<String>();
        for (ModuleNeeded neededModule : neededModules) {
            neededLibraries.add(neededModule.getModuleName());
        }

        final File libDir = JavaProcessorUtilities.getJavaProjectLibFolder();
        if (libDir == null) {
            return ""; //$NON-NLS-1$
        }
        File[] jarFiles = libDir.listFiles(FilesUtils.getAcceptJARFilesFilter());

        if (jarFiles != null && jarFiles.length > 0) {
            for (File jarFile : jarFiles) {
                if (jarFile.isFile() && neededLibraries.contains(jarFile.getName())) {
                    String singleLibPath = new Path(jarFile.getAbsolutePath()).toPortableString();
                    libPath.append(singleLibPath).append(classPathSeparator);
                }
            }
        }
    }

    final int lastSep = libPath.length() - 1;
    if (libPath.length() != 0 && classPathSeparator.equals(String.valueOf(libPath.charAt(lastSep)))) {
        libPath.deleteCharAt(lastSep);
    }
    return libPath.toString();
}

From source file:cx.fbn.nevernote.gui.BrowserWindow.java

private String removeTags(String text) {
    StringBuffer buffer = new StringBuffer(text);
    boolean inTag = false;
    int bodyPosition = text.indexOf("<body");
    for (int i = buffer.length() - 1; i >= 0; i--) {
        if (buffer.charAt(i) == '>')
            inTag = true;//  ww w .  j  a  v a2  s. c o m
        if (buffer.charAt(i) == '<')
            inTag = false;
        if (inTag || buffer.charAt(i) == '<' || i < bodyPosition)
            buffer.deleteCharAt(i);
    }

    return buffer.toString();
}