Example usage for java.lang StringBuffer deleteCharAt

List of usage examples for java.lang StringBuffer deleteCharAt

Introduction

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

Prototype

@Override
public synchronized StringBuffer deleteCharAt(int index) 

Source Link

Usage

From source file:logfilegenerator.loglineanalyser.modules.Cluster.java

private String generateRegexFromDescription(String cluster) {

    StringBuffer sbuf = new StringBuffer();

    //EDIT: better first remove the time stamp of the logline, as SLCT does. do not allow a reluctant 
    //number of characters in the beginning, because in this case, the regular expression will also match 
    //lines, where the significant words are found on different positions.
    //NOTE: SLCT cares about the position of a word

    //store the cluster description in a List, splitted by the SLCT wildcard symbol <*
    String[] s = descr.split("\\<\\*");

    //iterate through the string list
    for (int i = 0; i < s.length; i++) {
        s[i] = s[i].replaceAll("(\\?)", "\\\\$1");
        s[i] = s[i].replaceAll("([\\[\\]\\(\\)\\+\\|\\$\\^\\{\\}\\.\\*])", "\\\\$1");
        s[i] = s[i].replace("\\\\", "\\\\");

        sbuf.append(s[i]);//  w w w .  ja  v a 2s. co  m
        //replace SLCT wildcard symbol
        //NOTE: be careful if a line starts with the wildcard symbol
        if (i == 0 && s[i].equals("") && !(s[i + 1].substring(0, 1).equals(" "))) {
            sbuf.append("\\S*");
        } else if (i == 0 && s[i].equals(""))
            sbuf.append("\\S+");
        else if (!(i + 1 == s.length)) {
            //\S*? or \S* or \S+ ?
            //EDIT: has to be \S+, because SLCT does not consider a space as a word and \S* allows spaces,
            //because then the next "empty" string is considered as a word.
            //EDIT: if in SLCT the refine option is used, some wildcard symbols are extended with characters. In this case, the wildcard 
            //symbol can be also replaced by an empty string.
            if (!(s[i].substring(s[i].length() - 1).equals(" ")) || !(s[i + 1].substring(0, 1).equals(" "))) {
                sbuf.append("\\S*");
            } else {
                sbuf.append("\\S+");
            }
        }
    }
    //delete the last character, because it is a space. Therefore, \S+ .* is returned instead of \S+.*.
    sbuf.deleteCharAt(sbuf.length() - 1);
    if (descr.trim().substring(descr.length() - 3).equals("<*")) {
        sbuf.append(".*");
    } else {
        //if the cluster description doesn't end with a wild card, the $ symbol makes sure, that the last symbol of the log line, which matches
        //the cluster, is equal to the last symbol of the regular expression
        sbuf.append("$.*");
    }

    System.out.println("generated regex: " + sbuf.toString());

    return sbuf.toString();
}

From source file:net.sourceforge.floggy.persistence.Weaver.java

/**
 * DOCUMENT ME!// w  w  w  . j  a  v a  2s .c  o  m
*
* @throws CannotCompileException DOCUMENT ME!
* @throws IOException DOCUMENT ME!
* @throws NotFoundException DOCUMENT ME!
*/
protected void addPersistableMetadataManagerClass()
        throws CannotCompileException, IOException, NotFoundException {
    alreadyProcessedMetadatas.addAll(configuration.getPersistableMetadatas());

    Set metadatas = alreadyProcessedMetadatas;
    StringBuffer buffer = new StringBuffer();

    buffer.append("public static void init() throws Exception {\n");
    buffer.append("rmsBasedMetadatas = new java.util.Hashtable();\n");
    buffer.append("classBasedMetadatas = new java.util.Hashtable();\n");
    buffer.append("java.util.Hashtable persistableImplementations = null;\n");
    buffer.append("java.util.Vector indexMetadatas = null;\n");
    buffer.append("java.util.Vector fields = null;\n");

    for (Iterator iterator = metadatas.iterator(); iterator.hasNext();) {
        PersistableMetadata metadata = (PersistableMetadata) iterator.next();
        boolean isAbstract = metadata.isAbstract();
        String className = metadata.getClassName();
        String superClassName = metadata.getSuperClassName();
        String[] fieldNames = metadata.getFieldNames();
        int[] fieldTypes = metadata.getFieldTypes();
        Hashtable persistableImplementations = metadata.getPersistableImplementations();
        String recordStoreName = metadata.getRecordStoreName();
        int persistableStrategy = metadata.getPersistableStrategy();
        Vector indexMetadatas = metadata.getIndexMetadatas();
        String[] descendents = metadata.getDescendents();

        StringBuffer fieldNamesBuffer = new StringBuffer("new String[");
        StringBuffer fieldTypesBuffer = new StringBuffer("new int[");
        boolean addHeader = true;

        for (int i = 0; i < fieldNames.length; i++) {
            if (addHeader) {
                fieldNamesBuffer.append("]{");
                fieldTypesBuffer.append("]{");
                addHeader = false;
            }

            fieldNamesBuffer.append("\"");
            fieldNamesBuffer.append(fieldNames[i]);
            fieldNamesBuffer.append("\",");

            fieldTypesBuffer.append(fieldTypes[i]);
            fieldTypesBuffer.append(",");
        }

        if (addHeader) {
            fieldNamesBuffer.append("0]");
            fieldTypesBuffer.append("0]");
        } else {
            fieldNamesBuffer.deleteCharAt(fieldNamesBuffer.length() - 1);
            fieldNamesBuffer.append("}");
            fieldTypesBuffer.deleteCharAt(fieldTypesBuffer.length() - 1);
            fieldTypesBuffer.append("}");
        }

        if ((persistableImplementations != null) && !persistableImplementations.isEmpty()) {
            buffer.append("persistableImplementations = new java.util.Hashtable();\n");

            Enumeration enumeration = persistableImplementations.keys();

            while (enumeration.hasMoreElements()) {
                String fieldName = (String) enumeration.nextElement();
                String classNameOfField = (String) persistableImplementations.get(fieldName);
                buffer.append("persistableImplementations.put(\"");
                buffer.append(fieldName);
                buffer.append("\", \"");
                buffer.append(classNameOfField);
                buffer.append("\");\n");
            }
        } else {
            buffer.append("persistableImplementations = null;\n");
        }

        if ((indexMetadatas != null) && !indexMetadatas.isEmpty()) {
            buffer.append("indexMetadatas = new java.util.Vector();\n");

            Enumeration enumeration = indexMetadatas.elements();

            while (enumeration.hasMoreElements()) {
                IndexMetadata indexMetadata = (IndexMetadata) enumeration.nextElement();

                buffer.append("fields = new java.util.Vector();\n");

                Vector fields = indexMetadata.getFields();

                for (int j = 0; j < fields.size(); j++) {
                    buffer.append("fields.addElement(\"");
                    buffer.append(fields.elementAt(j));
                    buffer.append("\");\n");
                }

                buffer.append(
                        "indexMetadatas.addElement(new net.sourceforge.floggy.persistence.impl.IndexMetadata(\"");
                buffer.append(indexMetadata.getRecordStoreName());
                buffer.append("\", \"");
                buffer.append(indexMetadata.getName());
                buffer.append("\", fields));\n");
            }
        } else {
            buffer.append("indexMetadatas = null;\n");
        }

        StringBuffer descendentsBuffer = new StringBuffer("new String[");
        addHeader = true;

        if (descendents != null) {
            for (int i = 0; i < descendents.length; i++) {
                if (addHeader) {
                    descendentsBuffer.append("]{");
                    addHeader = false;
                }

                descendentsBuffer.append("\"");
                descendentsBuffer.append(descendents[i]);
                descendentsBuffer.append("\",");
            }
        }

        if (addHeader) {
            descendentsBuffer.append("0]");
        } else {
            descendentsBuffer.deleteCharAt(descendentsBuffer.length() - 1);
            descendentsBuffer.append("}");
        }

        buffer.append("classBasedMetadatas.put(\"" + className
                + "\", new net.sourceforge.floggy.persistence.impl.PersistableMetadata(" + isAbstract + ", \""
                + className + "\", "
                + ((superClassName != null) ? ("\"" + superClassName + "\", ") : ("null, "))
                + fieldNamesBuffer.toString() + ", " + fieldTypesBuffer.toString()
                + ", persistableImplementations, indexMetadatas, " + "\"" + recordStoreName + "\", "
                + persistableStrategy + ", " + descendentsBuffer.toString() + "));\n");
    }

    buffer.append("load();\n");
    buffer.append("}\n");

    CtClass ctClass = this.classpathPool
            .get("net.sourceforge.floggy.persistence.impl.PersistableMetadataManager");
    CtMethod[] methods = ctClass.getMethods();

    for (int i = 0; i < methods.length; i++) {
        if (methods[i].getName().equals("init")) {
            ctClass.removeMethod(methods[i]);
        }
    }

    ctClass.addMethod(CtNewMethod.make(buffer.toString(), ctClass));
    embeddedClassesOutputPool.addClass(ctClass);
}

From source file:repast.simphony.relogo.ide.wizards.NetlogoImportWizard.java

public String getJavaName(String name) {
    StringBuffer buf = new StringBuffer();

    buf.append(name.trim());/*w  w  w. j a  v a 2s  . c  om*/

    for (int i = 0; i < buf.length(); i++) {
        if (Character.isLetterOrDigit(buf.charAt(i))) {
            continue;
        } else if (buf.charAt(i) == '_') {
            continue;
        } else if (buf.charAt(i) == '?') {
            buf.setCharAt(i, 'Q');
        } else if (buf.charAt(i) == '%') {
            buf.setCharAt(i, 'p');
        } else if (buf.charAt(i) == '!') {
            buf.setCharAt(i, 'X');
        } else if (Character.isWhitespace(buf.charAt(i)) || buf.charAt(i) == '-') {
            buf.deleteCharAt(i);
            if (i < buf.length() && Character.isLetterOrDigit(buf.charAt(i))) {
                if (buf.charAt(i) != '?' && buf.charAt(i) != '%' && buf.charAt(i) != '!') {
                    buf.setCharAt(i, Character.toUpperCase(buf.charAt(i)));
                } else if (buf.charAt(i) == '_') {
                    continue;
                } else if (buf.charAt(i) == '?') {
                    buf.setCharAt(i, 'Q');
                } else if (buf.charAt(i) == '%') {
                    buf.setCharAt(i, 'P');
                } else if (buf.charAt(i) == '!') {
                    buf.setCharAt(i, 'X');
                }
            }
        } else {
            buf.setCharAt(i, 'Q');
        }
    }
    if (Character.isDigit(buf.charAt(0))) {
        buf.insert(0, '_');
    }
    return buf.toString();
}

From source file:org.kuali.kfs.module.purap.document.web.struts.PurchaseOrderAction.java

/**
 * Forwards to the RetransmitForward.jsp page so that we could open 2 windows for retransmit, one is to display the PO tabbed
 * page and the other one display the pdf document.
 *
 * @param mapping/*from   www.j a  va 2 s .c o m*/
 * @param form
 * @param request
 * @param response
 * @return
 * @throws Exception
 */
public ActionForward printingRetransmitPo(ActionMapping mapping, ActionForm form, HttpServletRequest request,
        HttpServletResponse response) throws Exception {
    String basePath = getApplicationBaseUrl();
    String docId = ((PurchaseOrderForm) form).getPurchaseOrderDocument().getDocumentNumber();
    String methodToCallPrintRetransmitPurchaseOrderPDF = "printingRetransmitPoOnly";
    String methodToCallDocHandler = "docHandler";
    String printPOPDFUrl = getUrlForPrintPO(basePath, docId, methodToCallPrintRetransmitPurchaseOrderPDF);
    String displayPOTabbedPageUrl = getUrlForPrintPO(basePath, docId, methodToCallDocHandler);

    KualiDocumentFormBase kualiDocumentFormBase = (KualiDocumentFormBase) form;
    PurchaseOrderDocument po = (PurchaseOrderDocument) kualiDocumentFormBase.getDocument();

    StringBuffer itemIndexesBuffer = createSelectedItemIndexes(po.getItems());
    if (itemIndexesBuffer.length() > 0) {
        itemIndexesBuffer.deleteCharAt(itemIndexesBuffer.lastIndexOf(","));
        request.setAttribute("selectedItemIndexes", itemIndexesBuffer.toString());
    }

    if (itemIndexesBuffer.length() == 0) {
        GlobalVariables.getMessageMap().putError(PurapConstants.PO_RETRANSMIT_SELECT_TAB_ERRORS,
                PurapKeyConstants.ERROR_PURCHASE_ORDER_RETRANSMIT_SELECT);
        return returnToPreviousPage(mapping, kualiDocumentFormBase);
    }

    request.setAttribute("printPOPDFUrl", printPOPDFUrl);
    request.setAttribute("displayPOTabbedPageUrl", displayPOTabbedPageUrl);
    request.setAttribute("docId", docId);
    String label = SpringContext.getBean(DataDictionaryService.class)
            .getDocumentLabelByTypeName(KFSConstants.FinancialDocumentTypeCodes.PURCHASE_ORDER);
    request.setAttribute("purchaseOrderLabel", label);
    return mapping.findForward("retransmitPurchaseOrderPDF");
}

From source file:com.fujitsu.dc.test.jersey.bar.BarInstallTest.java

/**
 * bar?????????./*from  w w  w  .ja v  a  2 s .c  o m*/
 */
private void checkRegistData() {
    final String token = AbstractCase.MASTER_TOKEN_NAME;
    final String colName = "odatacol1";
    final String roleName = "../__/role1";
    final String nameSpace = "http://www.w3.com/standards/z39.50/";
    List<String> rolList = new ArrayList<String>();
    rolList.add("read");
    rolList.add("write");

    String resorce = UrlUtils.box(Setup.TEST_CELL1, INSTALL_TARGET);
    StringBuffer sb = new StringBuffer(resorce);
    // UrlUtil???URL???
    String boxUrl = sb.deleteCharAt(resorce.length() - 1).toString();

    // ?
    BoxUtils.get(Setup.TEST_CELL1, token, INSTALL_TARGET, HttpStatus.SC_OK);
    RelationUtils.get(Setup.TEST_CELL1, token, "relation1", INSTALL_TARGET, HttpStatus.SC_OK);
    RelationUtils.get(Setup.TEST_CELL1, token, "relation2", INSTALL_TARGET, HttpStatus.SC_OK);
    RelationUtils.get(Setup.TEST_CELL1, token, "relation3", INSTALL_TARGET, HttpStatus.SC_OK);
    RoleUtils.get(Setup.TEST_CELL1, token, "role1", INSTALL_TARGET, HttpStatus.SC_OK);
    RoleUtils.get(Setup.TEST_CELL1, token, "role2", INSTALL_TARGET, HttpStatus.SC_OK);
    RoleUtils.get(Setup.TEST_CELL1, token, "role3", INSTALL_TARGET, HttpStatus.SC_OK);
    // ComplexType?
    checkComplexType(Setup.TEST_CELL1, INSTALL_TARGET, colName, "complex1");
    checkComplexType(Setup.TEST_CELL1, INSTALL_TARGET, colName, "complex2");
    // EntityType?
    checkEntityType(Setup.TEST_CELL1, INSTALL_TARGET, colName, "entity1");
    checkEntityType(Setup.TEST_CELL1, INSTALL_TARGET, colName, "entity2");
    // AssociationEnd?
    checkAssocEnd(Setup.TEST_CELL1, INSTALL_TARGET, colName, "entity1", "entity1-entity2");
    checkAssocEnd(Setup.TEST_CELL1, INSTALL_TARGET, colName, "entity2", "entity2-entity1");
    // AssociationEnd?$links?
    checkAssocEndLinks(colName);
    // Property??
    checkProperty(Setup.TEST_CELL1, INSTALL_TARGET, colName, "entity1", null, "property1", true);
    checkProperty(Setup.TEST_CELL1, INSTALL_TARGET, colName, "entity1", null, "property2", true);
    checkProperty(Setup.TEST_CELL1, INSTALL_TARGET, colName, "entity2", null, "property3", false);
    // ComplexTypeProperty??
    checkProperty(Setup.TEST_CELL1, INSTALL_TARGET, colName, null, "complex1", "compProp1", true);
    checkProperty(Setup.TEST_CELL1, INSTALL_TARGET, colName, null, "complex1", "compProp2", true);
    checkProperty(Setup.TEST_CELL1, INSTALL_TARGET, colName, null, "complex2", "compProp3", false);

    // ??
    checkUserData(Setup.TEST_CELL1, INSTALL_TARGET, colName, "entity3", "barInstallTest");
    // OdataCollection?ACL?
    TResponse res = BarInstallTestUtils.propfind(Setup.TEST_CELL1, INSTALL_TARGET, colName,
            AbstractCase.MASTER_TOKEN_NAME,
            HttpStatus.SC_MULTI_STATUS);
    Element root = res.bodyAsXml().getDocumentElement();
    // DavCollection?ACL?
    checkAcl(root, rolList, roleName, boxUrl + "/" + colName);

    // DavCollection
    DavResourceUtils.getWebDavFile(Setup.TEST_CELL1, AbstractCase.MASTER_TOKEN_NAME, "box/dav-get.txt",
            INSTALL_TARGET, "webdavcol1", HttpStatus.SC_OK);
    // DavCollection?PROPFIND
    res = BarInstallTestUtils.propfind(Setup.TEST_CELL1, INSTALL_TARGET, "webdavcol1", "0",
            AbstractCase.MASTER_TOKEN_NAME,
            HttpStatus.SC_MULTI_STATUS);
    root = res.bodyAsXml().getDocumentElement();
    // DavCollection?ACL?
    checkAcl(root, rolList, roleName, boxUrl + "/webdavcol1");
    // DavCollection?Author?
    String author = root.getElementsByTagNameNS(nameSpace, "Author").item(0).getFirstChild().getNodeValue();
    assertEquals("Test User2", author);

    // DavFile
    DavResourceUtils.getWebDavFile(Setup.TEST_CELL1, AbstractCase.MASTER_TOKEN_NAME, "box/dav-get.txt",
            INSTALL_TARGET, "webdavcol1/testdavfile.txt", HttpStatus.SC_OK);

    // ServiceCollection
    BarInstallTestUtils.propfind(Setup.TEST_CELL1, INSTALL_TARGET, "svccol1", AbstractCase.MASTER_TOKEN_NAME,
            HttpStatus.SC_MULTI_STATUS);

    // ServiceFile
    DavResourceUtils.getWebDavFile(Setup.TEST_CELL1, AbstractCase.MASTER_TOKEN_NAME, "box/dav-get.txt",
            INSTALL_TARGET, "svccol1/__src/test.js", HttpStatus.SC_OK);

    // Box??
    res = DavResourceUtils.propfind("box/propfind-box-allprop.txt",
            token, HttpStatus.SC_MULTI_STATUS, INSTALL_TARGET);
    root = res.bodyAsXml().getDocumentElement();
    // BOX?ACL?
    checkAcl(root, rolList, roleName, boxUrl);
    // Box Author??
    author = root.getElementsByTagNameNS(nameSpace, "Author").item(0).getFirstChild().getNodeValue();
    assertEquals("Test User1", author);
}

From source file:org.exist.http.SOAPServer.java

/**
 * Writes a parameter for an XQuery function call
 * // w w w .j a  v a2s .c om
 * @param paramType   The type of the Parameter (from the internal description of the XQWS)
 * @param paramCardinality The cardinality of the Parameter (from the internal description of the XQWS)
 * @param SOAPParam   The Node from the SOAP request for the Paremeter of the Function call from the Http Request 
 * 
 * @return A String representation of the parameter, suitable for use in the function call 
 */
private StringBuffer writeXQueryFunctionParameter(String paramType, int paramCardinality, Node nSOAPParam)
        throws XPathException {
    String prefix = new String();
    String postfix = prefix;

    //determine the type of the parameter
    final int type = Type.getType(paramType);
    final int isAtomic = (Type.subTypeOf(type, Type.ATOMIC)) ? 1 : ((Type.subTypeOf(type, Type.NODE)) ? -1 : 0);

    if (isAtomic >= 0) {
        if (isAtomic > 0 && type != Type.STRING) {
            final String typeName = Type.getTypeName(type);
            if (typeName != null) {
                prefix = typeName + "(\"";
                postfix = "\")";
            }
        } else {
            prefix = "\"";
            postfix = prefix;
        }
    }

    final StringBuffer param = new StringBuffer();

    //determine the cardinality of the parameter
    if (paramCardinality >= Cardinality.MANY) {
        //sequence
        param.append("(");

        final NodeList nlParamSequenceItems = nSOAPParam.getChildNodes();
        for (int i = 0; i < nlParamSequenceItems.getLength(); i++) {
            final Node nParamSeqItem = nlParamSequenceItems.item(i);
            if (nParamSeqItem.getNodeType() == Node.ELEMENT_NODE) {
                processParameterValue(param, nParamSeqItem, prefix, postfix, isAtomic);

                param.append(","); //seperator for next item in sequence
            }
        }

        //remove last superflurous seperator
        if (param.charAt(param.length() - 1) == ',') {
            param.deleteCharAt(param.length() - 1);
        }

        param.append(")");
    } else {
        processParameterValue(param, nSOAPParam, prefix, postfix, isAtomic);
    }

    return param;
}

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

private void interpretCommas(StringBuffer sb) {
    // In the integer part, commas at the end are scaling commas; other commas mean to show thousand-grouping commas
    ListIterator<Special> it = specials.listIterator(integerEnd());

    boolean stillScaling = true;
    integerCommas = false;/*from   w ww .  j  a va  2s. c o  m*/
    while (it.hasPrevious()) {
        Special s = it.previous();
        if (s.ch != ',') {
            stillScaling = false;
        } else {
            if (stillScaling) {
                scale /= 1000;
            } else {
                integerCommas = true;
            }
        }
    }

    if (decimalPoint != null) {
        it = specials.listIterator(fractionalEnd());
        while (it.hasPrevious()) {
            Special s = it.previous();
            if (s.ch != ',') {
                break;
            } else {
                scale /= 1000;
            }
        }
    }

    // Now strip them out -- we only need their interpretation, not their presence
    it = specials.listIterator();
    int removed = 0;
    while (it.hasNext()) {
        Special s = it.next();
        s.pos -= removed;
        if (s.ch == ',') {
            removed++;
            it.remove();
            sb.deleteCharAt(s.pos);
        }
    }
}

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

/** {@inheritDoc} */
public void formatValue(StringBuffer toAppendTo, Object valueObject) {
    double value = ((Number) valueObject).doubleValue();
    value *= scale;//ww w.j a  v a2s.c  om

    // the '-' sign goes at the front, always, so we pick it out
    boolean negative = value < 0;
    if (negative)
        value = -value;

    // Split out the fractional part if we need to print a fraction
    double fractional = 0;
    if (slash != null) {
        if (improperFraction) {
            fractional = value;
            value = 0;
        } else {
            fractional = value % 1.0;
            //noinspection SillyAssignment
            value = (long) value;
        }
    }

    Set<StringMod> mods = new TreeSet<>();
    StringBuffer output = new StringBuffer(desc);

    if (exponent != null) {
        writeScientific(value, output, mods);
    } else if (improperFraction) {
        writeFraction(value, null, fractional, output, mods);
    } else {
        StringBuffer result = new StringBuffer();
        Formatter f = new Formatter(result);
        f.format(LOCALE, printfFmt, value);

        if (numerator == null) {
            writeFractional(result, output);
            writeInteger(result, output, integerSpecials, mods, integerCommas);
        } else {
            writeFraction(value, result, fractional, output, mods);
        }
    }

    // Now strip out any remaining '#'s and add any pending text ...
    ListIterator<Special> it = specials.listIterator();
    Iterator<StringMod> changes = mods.iterator();
    StringMod nextChange = (changes.hasNext() ? changes.next() : null);
    int adjust = 0;
    BitSet deletedChars = new BitSet(); // records chars already deleted
    while (it.hasNext()) {
        Special s = it.next();
        int adjustedPos = s.pos + adjust;
        if (!deletedChars.get(s.pos) && output.charAt(adjustedPos) == '#') {
            output.deleteCharAt(adjustedPos);
            adjust--;
            deletedChars.set(s.pos);
        }
        while (nextChange != null && s == nextChange.special) {
            int lenBefore = output.length();
            int modPos = s.pos + adjust;
            int posTweak = 0;
            switch (nextChange.op) {
            case StringMod.AFTER:
                // ignore adding a comma after a deleted char (which was a '#')
                if (nextChange.toAdd.equals(",") && deletedChars.get(s.pos))
                    break;
                posTweak = 1;
                //noinspection fallthrough
            case StringMod.BEFORE:
                output.insert(modPos + posTweak, nextChange.toAdd);
                break;

            case StringMod.REPLACE:
                int delPos = s.pos; // delete starting pos in original coordinates
                if (!nextChange.startInclusive) {
                    delPos++;
                    modPos++;
                }

                // Skip over anything already deleted
                while (deletedChars.get(delPos)) {
                    delPos++;
                    modPos++;
                }

                int delEndPos = nextChange.end.pos; // delete end point in original
                if (nextChange.endInclusive)
                    delEndPos++;

                int modEndPos = delEndPos + adjust; // delete end point in current

                if (modPos < modEndPos) {
                    if (nextChange.toAdd == "")
                        output.delete(modPos, modEndPos);
                    else {
                        char fillCh = nextChange.toAdd.charAt(0);
                        for (int i = modPos; i < modEndPos; i++)
                            output.setCharAt(i, fillCh);
                    }
                    deletedChars.set(delPos, delEndPos);
                }
                break;

            default:
                throw new IllegalStateException("Unknown op: " + nextChange.op);
            }
            adjust += output.length() - lenBefore;

            if (changes.hasNext())
                nextChange = changes.next();
            else
                nextChange = null;
        }
    }

    // Finally, add it to the string
    if (negative)
        toAppendTo.append('-');
    toAppendTo.append(output);
}

From source file:forseti.JUtil.java

public static synchronized String Converts(String strval, String separador, boolean si_o_ret_nada) {
    if (strval == null || strval.equals("") || strval.equals("null"))
        return "&nbsp;";

    StringBuffer str = new StringBuffer(strval);
    int cantidad = Integer.parseInt(strval);
    int comas, len;
    boolean negativo = (cantidad < 0) ? true : false;
    if (cantidad == 0 && si_o_ret_nada)
        return "&nbsp;";

    if (negativo)
        str.deleteCharAt(0);

    if (!separador.equals(" ")) {
        comas = (str.length() / 3);//from ww w  .  java 2s .c  o  m
        len = str.length();
        for (int i = 0; i < comas; i++) {
            len -= 3;
            if (len > 0)
                str.insert(len, separador);
        }
    }

    if (negativo)
        str.insert(0, '-');

    return str.toString();

}

From source file:com.openerp.orm.ORM.java

/**
 * Creates the statement.//from w ww. ja v  a  2 s.  c  o  m
 * 
 * @param moduleDBHelper
 *            the module db helper
 * @return the sQL statement
 */
public SQLStatement createStatement(BaseDBHelper moduleDBHelper) {
    this.tableName = modelToTable(moduleDBHelper.getModelName());
    this.fields = moduleDBHelper.getColumns();
    SQLStatement statement = new SQLStatement();
    StringBuffer create = new StringBuffer();

    create.append("CREATE TABLE IF NOT EXISTS ");
    create.append(this.tableName);
    create.append(" (");
    for (Fields field : this.fields) {

        Object type = field.getType();
        if (field.getType() instanceof Many2Many) {
            handleMany2ManyCol(moduleDBHelper, field);
            continue;
        }
        if (field.getType() instanceof Many2One) {
            if (((Many2One) field.getType()).isM2OObject()) {
                BaseDBHelper m2oDb = ((Many2One) field.getType()).getM2OObject();
                createMany2OneTable(m2oDb);

            }
            type = Types.integer();

        }

        try {
            create.append(field.getName());
            create.append(" ");
            create.append(type.toString());
            create.append(", ");
        } catch (Exception e) {

        }
    }
    create.deleteCharAt(create.lastIndexOf(","));
    create.append(")");
    this.statements.put("create", create.toString());
    statement.setTable_name(this.tableName);
    statement.setType("create");
    statement.setStatement(create.toString());
    return statement;

}