Example usage for java.lang StringBuffer delete

List of usage examples for java.lang StringBuffer delete

Introduction

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

Prototype

@Override
public synchronized StringBuffer delete(int start, int end) 

Source Link

Usage

From source file:com.thalesgroup.hudson.plugins.klocwork.util.KloMetricUtil.java

public static String getMessageSelectedSeverties(KloConfig kloConfig) {
    StringBuffer sb = new StringBuffer();

    if (kloConfig.getConfigSeverityEvaluation().isAllSeverities()) {
        sb.append("with all severities");
        return sb.toString();
    }//from www  .j  a  va2s . c o m

    if (kloConfig.getConfigSeverityEvaluation().isHighSeverity()) {
        sb.append(" and ");
        sb.append("severity 'high severity'");
    }

    if (kloConfig.getConfigSeverityEvaluation().isLowSeverity()) {
        sb.append(" and ");
        sb.append("severity 'low severity'");
    }

    if (sb.length() != 0)
        sb.delete(0, 5);

    return sb.toString();
}

From source file:org.dhatim.cdr.annotation.Configurator.java

private static String getPropertyName(Method method) {
    if (!method.getName().startsWith("set")) {
        return null;
    }//from   w  w w.  ja v a2  s .  c om

    StringBuffer methodName = new StringBuffer(method.getName());

    if (methodName.length() < 4) {
        return null;
    }

    methodName.delete(0, 3);
    methodName.setCharAt(0, Character.toLowerCase(methodName.charAt(0)));

    return methodName.toString();
}

From source file:net.duckling.ddl.service.task.TakerWrapper.java

private static String getSome(List<TaskTaker> takers, int index) {
    StringBuffer sb = new StringBuffer();
    String split = " | ";
    if (CommonUtil.isNullArray(takers)) {
        sb.append("");
        return sb.toString();
    }//from   w ww .  ja va 2 s .  co  m
    for (TaskTaker taker : takers) {
        if (taker == null || CommonUtil.isNullStr(taker.getUserId())) {
            continue;
        }
        try {
            sb.append(taker.getUserId().split("%")[index]).append(split);
        } catch (Exception e) {
            continue;
        }
    }
    if (sb.indexOf(split) > 0) {
        sb.delete(sb.length() - split.length(), sb.length());
    }
    return sb.toString();
}

From source file:org.bibsonomy.plugin.jabref.util.JabRefModelConverter.java

public static void copyTags(final BibtexEntry entry, final Post<? extends Resource> post) {
    /*//from  w  w w.  jav a 2 s. c  o m
     * concatenate tags using the JabRef keyword separator
     */
    final Set<Tag> tags = post.getTags();
    final StringBuffer tagsBuffer = new StringBuffer();
    for (final Tag tag : tags) {
        tagsBuffer.append(tag.getName() + jabRefKeywordSeparator);
    }
    /*
     * remove last separator
     */
    if (!tags.isEmpty()) {
        tagsBuffer.delete(tagsBuffer.lastIndexOf(jabRefKeywordSeparator), tagsBuffer.length());
    }
    final String tagsBufferString = tagsBuffer.toString();
    if (present(tagsBufferString))
        entry.setField("keywords", tagsBufferString);
}

From source file:FileUtils.java

/**
 * Rename the file to temporaty name with given prefix
 * /*from   ww  w. j a va2s. c om*/
 * @param flFileToRename - file to rename
 * @param strPrefix - prefix to use
 * @throws IOException - error message
 */
public static void renameToTemporaryName(File flFileToRename, String strPrefix) throws IOException {
    assert strPrefix != null : "Prefix cannot be null.";

    String strParent;
    StringBuffer sbBuffer = new StringBuffer();
    File flTemp;
    int iIndex = 0;

    strParent = flFileToRename.getParent();

    // Generate new name for the file in a deterministic way
    do {
        iIndex++;
        sbBuffer.delete(0, sbBuffer.length());
        if (strParent != null) {
            sbBuffer.append(strParent);
            sbBuffer.append(File.separatorChar);
        }

        sbBuffer.append(strPrefix);
        sbBuffer.append("_");
        sbBuffer.append(iIndex);
        sbBuffer.append("_");
        sbBuffer.append(flFileToRename.getName());

        flTemp = new File(sbBuffer.toString());
    } while (flTemp.exists());

    // Now we should have unique name
    if (!flFileToRename.renameTo(flTemp)) {
        throw new IOException(
                "Cannot rename " + flFileToRename.getAbsolutePath() + " to " + flTemp.getAbsolutePath());
    }
}

From source file:com.vmware.aurora.global.Configuration.java

/**
 * Get all of values in a property as a string type.
 * //from   w w w  .j a v a  2  s. co m
 * @param key
 *           The key of property.
 * @param defautValue
 *           The default value.
 * @return The property value.
 */
public static String getStrings(String key, String defautValue) {
    String[] values = config.getStringArray(key);
    if (values != null && values.length > 0) {
        StringBuffer buffer = new StringBuffer();
        for (String value : values) {
            buffer.append(value.trim()).append(",");
        }
        buffer.delete(buffer.length() - 1, buffer.length());
        return buffer.toString();
    } else {
        return defautValue;
    }
}

From source file:Main.java

public static String[] stringtoArray(String s) {
    s = s.substring(1, s.length() - 1);//from   w  w w . j ava  2 s  .c  o m
    // convert a String s to an Array, the elements
    // are delimited by sep
    // NOTE : for old JDK only (<1.4).
    //        for JDK 1.4 +, use String.split() instead
    StringBuffer buf = new StringBuffer(s);
    String sep = ",";
    int arraysize = 1;
    for (int i = 0; i < buf.length(); i++) {
        if (sep.indexOf(buf.charAt(i)) != -1)
            arraysize++;
    }
    String[] elements = new String[arraysize];
    int y, z = 0;
    if (buf.toString().indexOf(sep) != -1) {
        while (buf.length() > 0) {
            if (buf.toString().indexOf(sep) != -1) {
                y = buf.toString().indexOf(sep);
                if (y != buf.toString().lastIndexOf(sep)) {
                    elements[z] = buf.toString().substring(0, y);
                    z++;
                    buf.delete(0, y + 1);
                } else if (buf.toString().lastIndexOf(sep) == y) {
                    elements[z] = buf.toString().substring(0, buf.toString().indexOf(sep));
                    z++;
                    buf.delete(0, buf.toString().indexOf(sep) + 1);
                    elements[z] = buf.toString();
                    z++;
                    buf.delete(0, buf.length());
                }
            }
        }
    } else {
        elements[0] = buf.toString();
    }
    buf = null;
    return elements;
}

From source file:servletunit.struts.Common.java

/**
 * Strip ;jsessionid=<sessionid> from path.
 *
 * @return stripped path//from   www  .j  a  v a2  s  .c  om
 */
protected static String stripJSessionID(String path) {
    if (logger.isTraceEnabled())
        logger.trace("Entering - path = " + path);
    if (path == null)
        return null;

    String pathCopy = path.toLowerCase();
    int jsess_idx = pathCopy.indexOf(";jsessionid=");
    if (jsess_idx > 0) {
        StringBuffer buf = new StringBuffer(path);

        int queryIndex = pathCopy.indexOf("?");
        // Strip jsessionid from obtained path, but keep query string
        if (queryIndex > 0)
            path = buf.delete(jsess_idx, queryIndex).toString();
        // Strip jsessionid from obtained path
        else
            path = buf.delete(jsess_idx, buf.length()).toString();
    }
    if (logger.isTraceEnabled())
        logger.trace("Exiting - returning path = " + path);
    return path;
}

From source file:org.bibsonomy.layout.util.JabRefModelConverter.java

/**
 * Converts a BibSonomy post into a JabRef BibtexEntry
 * //from ww w  . j  a va  2 s  .c  om
 * @param post
 * @param urlGen
 *            - the URLGenerator to create the biburl-field
 * @return
 */
public static BibtexEntry convertPost(final Post<? extends Resource> post, URLGenerator urlGen) {

    try {
        /*
         * what we have
         */
        final BibTex bibtex = (BibTex) post.getResource();
        /*
         * what we want
         */
        final BibtexEntry entry = new BibtexEntry();
        /*
         * each entry needs an ID (otherwise we get a NPE) ... let JabRef
         * generate it
         */
        /*
         * we use introspection to get all fields ...
         */
        final BeanInfo info = Introspector.getBeanInfo(bibtex.getClass());
        final PropertyDescriptor[] descriptors = info.getPropertyDescriptors();

        /*
         * iterate over all properties
         */
        for (final PropertyDescriptor pd : descriptors) {

            final Method getter = pd.getReadMethod();

            // loop over all String attributes
            final Object o = getter.invoke(bibtex, (Object[]) null);

            if (String.class.equals(pd.getPropertyType()) && (o != null)
                    && !JabRefModelConverter.EXCLUDE_FIELDS.contains(pd.getName())) {
                final String value = ((String) o);
                if (present(value))
                    entry.setField(pd.getName().toLowerCase(), value);
            }
        }

        /*
         * convert entry type (Is never null but getType() returns null for
         * unknown types and JabRef knows less types than we.)
         * 
         * FIXME: a nicer solution would be to implement the corresponding
         * classes for the missing entrytypes.
         */
        final BibtexEntryType entryType = BibtexEntryType.getType(bibtex.getEntrytype());
        entry.setType(entryType == null ? BibtexEntryType.OTHER : entryType);

        if (present(bibtex.getMisc()) || present(bibtex.getMiscFields())) {

            // parse the misc fields and loop over them
            bibtex.parseMiscField();

            if (bibtex.getMiscFields() != null)
                for (final String key : bibtex.getMiscFields().keySet()) {
                    if ("id".equals(key)) {
                        // id is used by jabref
                        entry.setField("misc_id", bibtex.getMiscField(key));
                        continue;
                    }

                    if (key.startsWith("__")) // ignore fields starting with
                        // __ - jabref uses them for
                        // control
                        continue;

                    entry.setField(key, bibtex.getMiscField(key));
                }

        }

        final String month = bibtex.getMonth();
        if (present(month)) {
            /*
             * try to convert the month abbrev like JabRef does it
             */
            final String longMonth = Globals.MONTH_STRINGS.get(month);
            if (present(longMonth)) {
                entry.setField("month", longMonth);
            } else {
                entry.setField("month", month);
            }
        }

        final String bibAbstract = bibtex.getAbstract();
        if (present(bibAbstract))
            entry.setField("abstract", bibAbstract);

        /*
         * concatenate tags using the JabRef keyword separator
         */
        final Set<Tag> tags = post.getTags();
        final StringBuffer tagsBuffer = new StringBuffer();
        for (final Tag tag : tags) {
            tagsBuffer.append(tag.getName() + jabRefKeywordSeparator);
        }
        /*
         * remove last separator
         */
        if (!tags.isEmpty()) {
            tagsBuffer.delete(tagsBuffer.lastIndexOf(jabRefKeywordSeparator), tagsBuffer.length());
        }
        final String tagsBufferString = tagsBuffer.toString();
        if (present(tagsBufferString))
            entry.setField(BibTexUtils.ADDITIONAL_MISC_FIELD_KEYWORDS, tagsBufferString);

        // set groups - will be used in jabref when exporting to bibsonomy
        if (present(post.getGroups())) {
            final Set<Group> groups = post.getGroups();
            final StringBuffer groupsBuffer = new StringBuffer();
            for (final Group group : groups)
                groupsBuffer.append(group.getName() + " ");

            final String groupsBufferString = groupsBuffer.toString().trim();
            if (present(groupsBufferString))
                entry.setField("groups", groupsBufferString);
        }

        // set comment + description
        final String description = post.getDescription();
        if (present(description)) {
            entry.setField(BibTexUtils.ADDITIONAL_MISC_FIELD_DESCRIPTION, post.getDescription());
            entry.setField("comment", post.getDescription());
        }

        if (present(post.getDate())) {
            entry.setField("added-at", sdf.format(post.getDate()));
        }

        if (present(post.getChangeDate())) {
            entry.setField("timestamp", sdf.format(post.getChangeDate()));
        }

        if (present(post.getUser()))
            entry.setField("username", post.getUser().getName());

        // set URL to bibtex version of this entry (bibrecord = ...)
        entry.setField(BibTexUtils.ADDITIONAL_MISC_FIELD_BIBURL,
                urlGen.getPublicationUrl(bibtex, post.getUser()).toString());

        return entry;

    } catch (final Exception e) {
        log.error("Could not convert BibSonomy post into a JabRef BibTeX entry.", e);
    }

    return null;
}

From source file:com.glaf.core.util.QueryUtils.java

public static String getSQLCondition(List<String> rows, String alias, String columnName) {
    if (rows == null || rows.size() <= 0) {
        return "";
    }/*from ww  w.ja  v a  2 s  .c  o  m*/
    int index = 1;
    StringBuffer whereBuffer = new StringBuffer();
    whereBuffer.append(" and ( ").append(alias).append(".").append(columnName).append(" in ('0') ");
    StringBuffer idsBuffer = new StringBuffer();
    Iterator<String> iter = rows.iterator();
    while (iter.hasNext()) {
        String x = iter.next();
        idsBuffer.append('\'').append(x).append('\'');
        if (index == 500) {
            whereBuffer.append(" or ").append(alias).append(".").append(columnName).append(" in (")
                    .append(idsBuffer.toString()).append(')');
            index = 0;
            idsBuffer.delete(0, idsBuffer.length());
        }
        if (iter.hasNext() && index > 0) {
            idsBuffer.append(',');
        }
        index++;
    }
    if (idsBuffer.length() > 0) {
        whereBuffer.append(" or ").append(alias).append(".").append(columnName).append(" in (")
                .append(idsBuffer.toString()).append(')');
        idsBuffer.delete(0, idsBuffer.length());
    }
    whereBuffer.append(" ) ");
    return whereBuffer.toString();
}