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.agnitas.beans.impl.MailingImpl.java

/**
 * Scans a textblock for trackable links and replaces them with encoded
 * rdir-links./*w  w  w .  j ava2s .com*/
 */
public String insertTrackableLinks(String aText1, int customerID, ApplicationContext con) {
    if (this.trackableLinks == null) {
        return aText1;
    }

    /*
     * trackableLinks is an unordered HashMap. When there are 2 links in the
     * Map, where one is part of the other, this could lead to an link
     * replacement, depending on the map ordering.
     * 
     * Link 1: http://www.mydomain.de Link 2:
     * http://www.mydomain.de/path/index.htm
     * 
     * If Link 1 is returned before Link 2 from the iterator this resulted
     * in: http://rdir.de/r.html?uid=<uid of Link1>/path/index.htm
     */
    Comparator<String> reverseString = new Comparator<String>() {
        @Override
        public int compare(String o1, String o2) {
            return o2.compareTo(o1);
        }
    };

    Set<String> sorted = new TreeSet<String>(reverseString);
    sorted.addAll(this.trackableLinks.keySet());

    Iterator<String> i = sorted.iterator();
    String aLink = null;
    int start_link = 0;
    int end_link = 0;
    TrackableLink aLinkObj = null;
    StringBuffer aBuf = new StringBuffer(aText1);
    boolean isHref = false;

    if (aText1 == null) {
        return null;
    }

    while (i.hasNext()) {
        aLink = i.next();
        end_link = 0;
        while ((start_link = aBuf.indexOf(aLink, end_link)) != -1) {
            end_link = start_link + 1;
            isHref = false;
            if (start_link > 5 && (aBuf.substring(start_link - 6, start_link).equalsIgnoreCase("href=\""))) {
                isHref = true;
            }
            if (start_link > 6 && (aBuf.substring(start_link - 7, start_link).equalsIgnoreCase("href=\""))) {
                isHref = true;
            }
            if (aBuf.length() > (start_link + aLink.length())) {
                if (!(aBuf.charAt(start_link + aLink.length()) == ' '
                        || aBuf.charAt(start_link + aLink.length()) == '\''
                        || aBuf.charAt(start_link + aLink.length()) == '"')) {
                    isHref = false;
                }
            }
            if (isHref) {
                aLinkObj = (TrackableLink) this.trackableLinks.get(aLink);
                aBuf.replace(start_link, start_link + aLink.length(),
                        aLinkObj.encodeTagStringLinkTracking(con, customerID));
            }
        }
    }
    return aBuf.toString();
}

From source file:com.projity.field.Field.java

private final void setAccessorMethods() {
    if (clazz != null && property != null) {
        StringBuffer javaName = new StringBuffer(property);
        javaName.setCharAt(0, Character.toUpperCase(javaName.charAt(0)));

        // First look for a getter that has a context (indexed or not)
        methodGet = MethodUtils.getAccessibleMethod(clazz, "get" + javaName,
                (isIndexed() ? getterIndexedContextParams : getterContextParams));
        if (methodGet == null) // try is instead of get
            methodGet = MethodUtils.getAccessibleMethod(clazz, "is" + javaName,
                    (isIndexed() ? getterIndexedContextParams : getterContextParams));

        // If not found, then use standard getter (indexed or not)
        if (methodGet == null) {
            getHasNoContext = true;/* w w  w.j a va2s.  c  o m*/
            methodGet = MethodUtils.getAccessibleMethod(clazz, "get" + javaName,
                    (isIndexed() ? getterIndexedParams : getterParams));
            if (methodGet == null) // try is instead of get
                methodGet = MethodUtils.getAccessibleMethod(clazz, "is" + javaName,
                        (isIndexed() ? getterIndexedParams : getterParams));
        }
        if (methodGet != null)
            internalType = methodGet.getReturnType();
        else
            log.error("Not getter found for field " + getId());

        // First look for a setter that has a context (indexed or not)
        methodSet = MethodUtils.getAccessibleMethod(clazz, "set" + javaName,
                (isIndexed() ? new Class[] { int.class, internalType, FieldContext.class }
                        : new Class[] { internalType, FieldContext.class }));

        // If not found, then use standard setter (indexed or not)
        if (methodSet == null) {
            setHasNoContext = true;
            methodSet = MethodUtils.getAccessibleMethod(clazz, "set" + javaName,
                    (isIndexed() ? new Class[] { int.class, internalType } : new Class[] { internalType }));
        }
        if (methodSet == null && !readOnly) {
            log.warn("No setter found for non-read-only field: " + getId());
        }
        methodReset = MethodUtils.getAccessibleMethod(clazz, "fieldReset" + javaName, getterContextParams);

        if (resetHasNoContext = (methodReset == null))
            methodReset = MethodUtils.getAccessibleMethod(clazz, "fieldReset" + javaName, getterParams);

        methodReadOnly = MethodUtils.getAccessibleMethod(clazz, "isReadOnly" + javaName, getterContextParams);
        if (readOnlyHasNoContext = (methodReadOnly == null))
            methodReadOnly = MethodUtils.getAccessibleMethod(clazz, "isReadOnly" + javaName, getterParams);
        //lc
        //         methodObjectReadOnly = MethodUtils.getAccessibleMethod(clazz, "isReadOnly", getterParams);

        methodHide = MethodUtils.getAccessibleMethod(clazz, "fieldHide" + javaName,
                (isIndexed() ? getterIndexedContextParams : getterContextParams));
        if (hideHasNoContext = (methodHide == null))
            methodHide = MethodUtils.getAccessibleMethod(clazz, "fieldHide" + javaName,
                    (isIndexed() ? getterIndexedParams : getterParams));
        methodOptions = MethodUtils.getAccessibleMethod(clazz, "fieldOptions" + javaName, getterContextParams);
        if (optionsHasNoContext = (methodOptions == null))
            methodOptions = MethodUtils.getAccessibleMethod(clazz, "fieldOptions" + javaName, getterParams);
    }
}

From source file:com.wabacus.system.inputbox.AbsInputBox.java

protected String initDisplaySpanStart(ReportRequest rrequest) {
    StringBuffer resultBuf = new StringBuffer();
    resultBuf.append("<span id=\"span_" + this.owner.getInputBoxId() + "_span\" style=\"display:none;\"");
    if (this.owner instanceof EditableReportColBean) {
        String formatemplate = ((EditableReportColBean) this.owner).getFormatemplate(rrequest);
        if (formatemplate != null && !formatemplate.trim().equals("")) {
            resultBuf.append(" formatemplate=\"").append(Tools.onlyHtmlEncode(formatemplate)).append("\"");
            resultBuf.append(" formatemplate_dyncols=\"")
                    .append(((EditableReportColBean) this.owner).getColPropertyAndPlaceHoldersInFormatemplate())
                    .append("\"");
        }/*from   w w  w .j av  a2 s  . c  o m*/
    }
    String style2 = this.getStyleproperty2(rrequest);
    if (style2 != null && !style2.trim().equals("")) {
        resultBuf.append(" styleproperty=\"" + Tools.jsParamEncode(style2) + "\"");
    }
    if (this.mStyleProperties2 != null) {
        for (Entry<String, String> entryTmp : this.mStyleProperties2.entrySet()) {
            if (entryTmp.getValue() == null || entryTmp.getValue().trim().equals(""))
                continue;
            resultBuf.append(" ").append(entryTmp.getKey()).append("_propertyvalue=\"")
                    .append(entryTmp.getValue()).append("\"");
        }
    }
    if (this.inputboxparams != null && !this.inputboxparams.trim().equals("")) {
        resultBuf.append(" inputboxparams=\"" + this.inputboxparams.trim() + "\"");
    }
    if (this.lstChildids != null && this.lstChildids.size() > 0) {
        resultBuf.append(" childboxids=\"");
        for (String childidTmp : this.lstChildids) {
            resultBuf.append(childidTmp).append(";");
        }
        if (resultBuf.charAt(resultBuf.length() - 1) == ';')
            resultBuf.deleteCharAt(resultBuf.length() - 1);
        resultBuf.append("\"");
    }
    return resultBuf.toString();
}

From source file:org.apache.hadoop.hdfs.server.namenode.TestFSDirectory.java

/** Dump the tree, make some changes, and then dump the tree again. */
@Test//from w  w  w.  j  av  a 2s  .  co m
public void testDumpTree() throws Exception {
    HopsTransactionalRequestHandler verifyFileBlocksHandler = new HopsTransactionalRequestHandler(
            HDFSOperationType.VERIFY_FILE_BLOCKS, dir.toString()) {
        @Override
        public void acquireLock(TransactionLocks locks) throws IOException {
            LockFactory lf = LockFactory.getInstance();
            INodeLock il = lf.getINodeLock(TransactionLockTypes.INodeLockType.WRITE_ON_TARGET_AND_PARENT,
                    TransactionLockTypes.INodeResolveType.PATH_AND_ALL_CHILDREN_RECURSIVELY, dir.toString())
                    .setNameNodeID(cluster.getNameNode().getId())
                    .setActiveNameNodes(cluster.getNameNode().getActiveNameNodes().getActiveNodes());
            locks.add(il).add(lf.getLeaseLock(TransactionLockTypes.LockType.WRITE))
                    .add(lf.getLeasePathLock(TransactionLockTypes.LockType.READ_COMMITTED))
                    .add(lf.getBlockLock()).add(lf.getBlockRelated(LockFactory.BLK.RE, LockFactory.BLK.CR,
                            LockFactory.BLK.UC, LockFactory.BLK.UR, LockFactory.BLK.PE, LockFactory.BLK.IV));
        }

        @Override
        public Object performTask() throws StorageException, IOException {
            final INode root = fsdir.getINode(dir.toString());

            LOG.info("Original tree");
            final StringBuffer b1 = root.dumpTreeRecursively();
            System.out.println("b1=" + b1);

            final BufferedReader in = new BufferedReader(new StringReader(b1.toString()));

            String line = in.readLine();
            checkClassName(line);

            for (; (line = in.readLine()) != null;) {
                line = line.trim();
                Assert.assertTrue(line.startsWith(INodeDirectory.DUMPTREE_LAST_ITEM)
                        || line.startsWith(INodeDirectory.DUMPTREE_EXCEPT_LAST_ITEM));
                checkClassName(line);
            }
            return b1;
        }
    };
    final StringBuffer b1 = (StringBuffer) verifyFileBlocksHandler.handle();
    LOG.info("Create a new file " + file4);
    DFSTestUtil.createFile(hdfs, file4, 1024, REPLICATION, seed);

    verifyFileBlocksHandler = new HopsTransactionalRequestHandler(HDFSOperationType.VERIFY_FILE_BLOCKS,
            dir.toString()) {
        @Override
        public void acquireLock(TransactionLocks locks) throws IOException {
            LockFactory lf = LockFactory.getInstance();
            INodeLock il = lf.getINodeLock(TransactionLockTypes.INodeLockType.WRITE_ON_TARGET_AND_PARENT,
                    TransactionLockTypes.INodeResolveType.PATH_AND_ALL_CHILDREN_RECURSIVELY, dir.toString())
                    .setNameNodeID(cluster.getNameNode().getId())
                    .setActiveNameNodes(cluster.getNameNode().getActiveNameNodes().getActiveNodes());
            locks.add(il).add(lf.getLeaseLock(TransactionLockTypes.LockType.WRITE))
                    .add(lf.getLeasePathLock(TransactionLockTypes.LockType.READ_COMMITTED))
                    .add(lf.getBlockLock()).add(lf.getBlockRelated(LockFactory.BLK.RE, LockFactory.BLK.CR,
                            LockFactory.BLK.UC, LockFactory.BLK.UR, LockFactory.BLK.PE, LockFactory.BLK.IV));
        }

        @Override
        public Object performTask() throws StorageException, IOException {
            final INode root = fsdir.getINode(dir.toString());
            final StringBuffer b2 = root.dumpTreeRecursively();
            System.out.println("b2=" + b2);

            int i = 0;
            int j = b1.length() - 1;
            for (; b1.charAt(i) == b2.charAt(i); i++)
                ;
            int k = b2.length() - 1;
            for (; b1.charAt(j) == b2.charAt(k); j--, k--)
                ;
            final String diff = b2.substring(i, k + 1);
            System.out.println("i=" + i + ", j=" + j + ", k=" + k);
            System.out.println("diff=" + diff);
            Assert.assertTrue(i > j);
            Assert.assertTrue(diff.contains(file4.getName()));
            return null;
        }
    };
    verifyFileBlocksHandler.handle();
}

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

protected String showMetaDataDisplayStringStart() {
    StringBuffer resultBuf = new StringBuffer();
    resultBuf.append(super.showMetaDataDisplayStringStart());
    String rowselecttype = this.alrbean.getRowSelectType();
    if (rowselecttype != null && !rowselecttype.trim().equals("")) {//
        resultBuf.append(" rowselecttype=\"").append(rowselecttype).append("\"");
        resultBuf.append(" isSelectRowCrossPages=\"").append(this.alrbean.isSelectRowCrossPages()).append("\"");
        if (!rowselecttype.trim().equalsIgnoreCase(Consts.ROWSELECT_NONE)) {
            List<String> lstRowSelectCallBackFuns = this.alrbean.getLstRowSelectCallBackFuncs();
            if (lstRowSelectCallBackFuns != null && lstRowSelectCallBackFuns.size() > 0) {
                StringBuffer rowSelectMethodBuf = new StringBuffer();
                rowSelectMethodBuf.append("{rowSelectMethods:[");
                for (String callbackFunc : lstRowSelectCallBackFuns) {
                    if (callbackFunc != null && !callbackFunc.trim().equals("")) {
                        rowSelectMethodBuf.append("{value:").append(callbackFunc).append("},");
                    }/*from   w  ww  .  ja va2s . c  om*/
                }
                if (rowSelectMethodBuf.charAt(rowSelectMethodBuf.length() - 1) == ',')
                    rowSelectMethodBuf.deleteCharAt(rowSelectMethodBuf.length() - 1);
                rowSelectMethodBuf.append("]}");
                resultBuf.append(" rowSelectMethods=\"").append(rowSelectMethodBuf.toString()).append("\"");
            }
        }
    }
    return resultBuf.toString();
}

From source file:org.oscm.identityservice.bean.IdentityServiceBean.java

private void removeTrailingSlashes(StringBuffer url) {
    while (url.length() > 0 && url.charAt(url.length() - 1) == '/') {
        url.replace(url.length() - 1, url.length(), "");
    }// www.  j av  a  2 s.c  om
}

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

/** {@inheritDoc} */
public void formatValue(StringBuffer toAppendTo, Object valueObject) {
    double value = ((Number) valueObject).doubleValue();
    value *= scale;//from ww w  .  j  a v  a  2s.  co  m

    // For negative numbers:
    // - If the cell format has a negative number format, this method
    // is called with a positive value and the number format has
    // the negative formatting required, e.g. minus sign or brackets.
    // - If the cell format does not have a negative number format,
    // this method is called with a negative value and the number is
    // formatted with a minus sign at the start.
    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<StringMod>();
    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, locale); //ZSS-68
        f.format(locale, printfFmt, value); //ZSS-68

        if (numerator == null) {
            writeFractional(result, output);
            writeInteger(result, output, integerSpecials, mods, integerCommas, false);
        } 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
    final String groupSeparator = "" + Formatters.getGroupingSeparator(locale); //ZSS-68
    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(groupSeparator) && deletedChars.get(s.pos)) //20110321, henrichen@zkoss.org: respect current locale
                    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:com.wabacus.system.ReportRequest.java

public String getDataExportFilename() {
    StringBuffer filenameBuf = new StringBuffer();
    if (this.lstComponentBeans == null || this.lstComponentBeans.size() == 0)
        return "NoData";
    String filenameTmp;//from   ww  w  .ja v a  2  s . c o m
    for (IComponentConfigBean ccbeanTmp : this.lstComponentBeans) {
        filenameTmp = null;
        if (ccbeanTmp.getDataExportsBean() != null) {
            filenameTmp = ccbeanTmp.getDataExportsBean().getFilename(this);
        }
        if (filenameTmp == null || filenameTmp.trim().equals("")) {//<dataexports/>?filename???
            filenameTmp = ccbeanTmp.getTitle(this);
        }
        if (filenameTmp == null || filenameTmp.trim().equals(""))
            continue;
        filenameBuf.append(filenameTmp).append(",");
    }
    if (filenameBuf.length() == 0)
        return "DataExport";
    if (filenameBuf.charAt(filenameBuf.length() - 1) == ',')
        filenameBuf.deleteCharAt(filenameBuf.length() - 1);
    return filenameBuf.toString();
}

From source file:org.pentaho.di.core.database.DatabaseMeta.java

public String stripCR(StringBuffer sbsql) {
    // DB2 Can't handle \n in SQL Statements...
    if (!supportsNewLinesInSQL()) {
        // Remove CR's
        for (int i = sbsql.length() - 1; i >= 0; i--) {
            if (sbsql.charAt(i) == '\n' || sbsql.charAt(i) == '\r')
                sbsql.setCharAt(i, ' ');
        }// ww  w. j  a  v a 2 s .c  om
    }

    return sbsql.toString();
}

From source file:stc.app.bean.lang.ToStringStyle.java

/**
 * <p>/*from   w w  w .  jav a 2s . c o  m*/
 * Remove the last field separator from the buffer.
 * </p>
 * 
 * @param buffer the <code>StringBuffer</code> to populate
 * @since 2.0
 */
protected void removeLastFieldSeparator(StringBuffer buffer) {
    int len = buffer.length();
    int sepLen = fieldSeparator.length();
    if (len > 0 && sepLen > 0 && len >= sepLen) {
        boolean match = true;
        for (int i = 0; i < sepLen; i++) {
            if (buffer.charAt(len - 1 - i) != fieldSeparator.charAt(sepLen - 1 - i)) {
                match = false;
                break;
            }
        }
        if (match) {
            buffer.setLength(len - sepLen);
        }
    }
}