Example usage for java.lang StringBuilder deleteCharAt

List of usage examples for java.lang StringBuilder deleteCharAt

Introduction

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

Prototype

@Override
public StringBuilder deleteCharAt(int index) 

Source Link

Usage

From source file:com.github.hexosse.pluginframework.pluginapi.PluginCommand.java

/**
* {@inheritDoc}//w w w . j  a  va 2  s . c om
* <p/>
* Delegates to the tab completer if present.
* <p/>
* If it is not present or returns null, will delegate to the current
* command executor if it implements {@link TabCompleter}. If a non-null
* list has not been found, will default to standard player name
* completion in {@link
* Command#tabComplete(CommandSender, String, String[])}.
* <p/>
* This method does not consider permissions.
*
* @throws CommandException         if the completer or executor throw an
*                                  exception during the process of tab-completing.
* @throws IllegalArgumentException if sender, alias, or args is null
*/
@Override
public java.util.List<String> tabComplete(CommandSender sender, String alias, String[] args)
        throws CommandException, IllegalArgumentException {
    Validate.notNull(sender, "Sender cannot be null");
    Validate.notNull(args, "Arguments cannot be null");
    Validate.notNull(alias, "Alias cannot be null");

    //
    if (args.length > 0 && args[0].equals(""))
        args = Arrays.copyOfRange(args, 1, args.length);

    List<String> completions = null;
    try {
        if (args.length > 0) {
            // Sub or Base ???
            // First we check if the first arg correspond to a Sub command
            String firstArg = args[0].toLowerCase();
            // Check if a sub command exist for this arg
            PluginCommand<?> subCommand = getSubCommand(firstArg);
            // If yes, this a sub command
            if (subCommand != null) {
                String[] subArgs = Arrays.copyOfRange(args, 1, args.length);
                if (subArgs.length > 0)
                    return subCommand.tabComplete(sender, alias, subArgs);
            }
        }

        completions = this.onTabComplete(new CommandInfo(sender, this, alias, args, null));
    } catch (Throwable ex) {
        StringBuilder message = new StringBuilder();
        message.append("Unhandled exception during tab completion for command '/").append(alias).append(' ');
        for (String arg : args)
            message.append(arg).append(' ');
        message.deleteCharAt(message.length() - 1).append("' in plugin ")
                .append(plugin.getDescription().getFullName());
        throw new CommandException(message.toString(), ex);
    }

    return completions;
}

From source file:eu.smartfp7.EdgeNode.SocialNetworkFeed.java

int listRunningSocials(PrintWriter out) {
    if (socialSearchList == null || feedsClient == null) {
        out.println("{\"error\":\"Server not correctly initialised\"}");
        return -1;
    }/* w  w  w  .  j a  v a 2  s.co  m*/
    int len;
    StringBuilder socialNames = new StringBuilder();
    for (String name : socialSearchList.keySet()) {
        socialNames.append("\"" + name + "\",");
    }
    // Delete last comma character in name list
    if ((len = socialNames.length()) > 0)
        socialNames.deleteCharAt(len - 1);
    out.println("{\"names\":[" + socialNames.toString() + "]}");
    return 0;
}

From source file:com.impetus.client.oraclenosql.schemamanager.OracleNoSQLSchemaManager.java

/**
 * Creates the index.//w  w w . j a  v a  2  s .c  o  m
 * 
 * @param tableName
 *            the table name
 * @param indexName
 *            the index name
 * @param fieldName
 *            the field name
 */
private void createIndex(String tableName, String indexName, String... fieldNames) {
    StringBuilder builder = new StringBuilder();
    builder.append("CREATE INDEX IF NOT EXISTS ");
    builder.append(indexName);
    builder.append(" ON ");
    builder.append(tableName);
    builder.append(Constants.OPEN_ROUND_BRACKET);
    for (String fieldName : fieldNames) {
        builder.append(fieldName);
        builder.append(Constants.COMMA);
    }
    builder.deleteCharAt(builder.length() - 1);
    builder.append(Constants.CLOSE_ROUND_BRACKET);
    StatementResult result = tableAPI.executeSync(builder.toString());
    if (!result.isSuccessful()) {
        throw new SchemaGenerationException(
                "Unable to CREATE Index with Index Name [" + indexName + "] for table [" + tableName + "]");
    }
}

From source file:ch.digitalfondue.jfiveparse.TreeConstructionTest.java

private static void renderNode(Node node, int depth, StringBuilder sb) {

    int spaces = depth == 0 ? 1 : depth * 2 + 1;
    sb.append("|").append(StringUtils.repeat(' ', spaces));

    int depthsForTemplatesChilds = 0;

    if (node instanceof Element) {
        Element elem = (Element) node;
        sb.append("<");
        if (Node.NAMESPACE_MATHML.equals(elem.getNamespaceURI())) {
            sb.append("math ");
        } else if (Node.NAMESPACE_SVG.equals(elem.getNamespaceURI())) {
            sb.append("svg ");
        }// w w  w  .  j  a  v  a2  s  . c  o  m

        sb.append(elem.getNodeName()).append(">");

        Set<String> attributesName = new TreeSet<>(elem.getAttributes().keySet());
        if (!attributesName.isEmpty()) {
            sb.append("\n");
            for (String k : attributesName) {
                sb.append("|").append(StringUtils.repeat(' ', spaces + 2));

                AttributeNode attribute = elem.getAttributes().get(k);
                if (attribute.getNamespace() != null) {
                    if (Node.NAMESPACE_XLINK.equals(attribute.getNamespace())) {
                        sb.append("xlink ");
                    } else if (Node.NAMESPACE_XML.equals(attribute.getNamespace())) {
                        sb.append("xml ");
                    } else if (Node.NAMESPACE_XMLNS.equals(attribute.getNamespace())) {
                        sb.append("xmlns ");
                    }
                }

                sb.append(k).append("=\"").append(attribute.getValue()).append("\"\n");
            }
            sb.deleteCharAt(sb.length() - 1);
        }

        if (elem.is("template", Node.NAMESPACE_HTML)) {
            sb.append("\n|").append(StringUtils.repeat(' ', spaces + 2)).append("content");
            depthsForTemplatesChilds += 1;
        }

    } else if (node instanceof Text) {
        sb.append("\"").append(((Text) node).getData()).append("\"");
    } else if (node instanceof Comment) {
        sb.append("<!-- ").append(((Comment) node).getData()).append(" -->");
    } else if (node instanceof DocumentType) {

        DocumentType dt = (DocumentType) node;
        sb.append("<!DOCTYPE ");
        sb.append(dt.getName());
        if (StringUtils.isNotBlank(dt.getPublicId()) || StringUtils.isNotBlank(dt.getSystemId())) {
            sb.append(" ");
            sb.append("\"").append(dt.getPublicId()).append("\"");
            sb.append(" ");
            sb.append("\"").append(dt.getSystemId()).append("\"");
        }
        sb.append(">");
    }

    sb.append("\n");

    for (Node childNode : node.getChildNodes()) {
        renderNode(childNode, depth + 1 + depthsForTemplatesChilds, sb);
    }

}

From source file:com.legstar.pli2cob.util.CobolNameResolver.java

/**
 * Creates a new string built from each valid character from name.
 * @param name the proposed name with potentially invalid characters
 * @return a name that is guaranteed to contain only valid characters
 *//*  w  ww  .java  2s  .  com*/
private String switchCharacters(final String name) {
    StringBuilder sb = new StringBuilder();
    for (int i = 0; i < name.length(); i++) {
        boolean valid = false;
        for (int j = 0; j < mC.length; j++) {
            if (name.charAt(i) == mC[j]) {
                sb.append(name.charAt(i));
                valid = true;
                break;
            }
        }
        /* Ignore invalid characters unless it is an
         * underscore */
        if (!valid && name.charAt(i) == '_') {
            sb.append('-');
        }
    }

    /* Check first and last characters */
    while (sb.length() > 0 && !isValidFirst(sb.charAt(0))) {
        sb.deleteCharAt(0);
    }
    while (sb.length() > 0 && !isValidLast(sb.charAt(sb.length() - 1))) {
        sb.deleteCharAt(sb.length() - 1);
    }
    return sb.toString();
}

From source file:com.geemvc.taglib.GeemvcTagSupport.java

protected String toElementId(String name, String idSuffix) {
    StringBuilder id = new StringBuilder(ELEMENT_ID_PREFIX).append(CaseFormat.UPPER_CAMEL
            .to(CaseFormat.LOWER_HYPHEN, name).replace(Char.SQUARE_BRACKET_OPEN, Char.HYPHEN)
            .replace(Char.SQUARE_BRACKET_CLOSE, Char.HYPHEN).replace(Char.DOT, Char.HYPHEN)
            .replace(Char.SPACE, Char.HYPHEN).replace(Char.UNDERSCORE, Char.HYPHEN)
            .replace(Str.HYPHEN_2x, Str.HYPHEN));

    if (id.charAt(id.length() - 1) == Char.HYPHEN)
        id.deleteCharAt(id.length() - 1);

    if (!Str.isEmpty(idSuffix)) {
        id.append(Char.HYPHEN)/*from  w w  w  . ja v  a  2  s  . c  o m*/
                .append(idSuffix.toLowerCase().replace(Char.SQUARE_BRACKET_OPEN, Char.HYPHEN)
                        .replace(Char.SQUARE_BRACKET_CLOSE, Char.HYPHEN).replace(Char.DOT, Char.HYPHEN)
                        .replace(Char.SPACE, Char.HYPHEN).replace(Char.UNDERSCORE, Char.HYPHEN)
                        .replace(Str.HYPHEN_2x, Str.HYPHEN));
    }

    if (id.charAt(id.length() - 1) == Char.HYPHEN)
        id.deleteCharAt(id.length() - 1);

    return id.toString();
}

From source file:de.itsvs.cwtrpc.controller.RemoteServiceControllerServlet.java

protected PreparedRemoteServiceConfig getServiceConfig(HttpServletRequest request) {
    final String contextPath;
    final StringBuilder uri;
    final PreparedRemoteServiceConfig serviceConfig;

    contextPath = request.getContextPath();
    uri = new StringBuilder(request.getRequestURI());
    if ((contextPath.length() > 0) && (uri.indexOf(contextPath) == 0)) {
        uri.delete(0, contextPath.length());
    }/*from   ww  w  .  j  ava2 s. com*/
    if ((uri.length() > 0) || (uri.charAt(0) == '/')) {
        uri.deleteCharAt(0);
    }

    if (log.isDebugEnabled()) {
        log.debug("Service URI is '" + uri + "'");
    }
    serviceConfig = getServiceConfigsByUri().get(uri.toString());

    return serviceConfig;
}

From source file:fr.gael.dhus.olingo.v1.V1Processor.java

private URI makeLink(boolean remove_last_segment) throws ODataException {
    URI selfLnk = getServiceRoot();
    StringBuilder sb = new StringBuilder(selfLnk.getPath());

    if (remove_last_segment) {
        // Removes the last segment.
        int lio = sb.lastIndexOf("/");
        while (lio != -1 && lio == sb.length() - 1) {
            sb.deleteCharAt(lio);
            lio = sb.lastIndexOf("/");
        }//from w w  w  . ja  va 2  s . c  o  m
        if (lio != -1)
            sb.delete(lio + 1, sb.length());

        // Removes the `$links` segment.
        lio = sb.lastIndexOf("$links/");
        if (lio != -1)
            sb.delete(lio, lio + 7);
    } else {
        if (!sb.toString().endsWith("/") && !sb.toString().endsWith("\\")) {
            sb.append("/");
        }
    }
    try {
        URI res = new URI(selfLnk.getScheme(), selfLnk.getUserInfo(), selfLnk.getHost(), selfLnk.getPort(),
                sb.toString(), null, selfLnk.getFragment());
        return res;
    } catch (Exception e) {
        throw new ODataException(e);
    }
}

From source file:cn.vlabs.umt.ui.servlet.AuthorizationCodeServlet.java

private String tansferScope(Set<String> scopes) {
    StringBuilder sb = new StringBuilder();
    for (String s : scopes) {
        sb.append(s).append(",");
    }//from w ww  .j  av a  2 s  .  c om
    if (sb.length() > 0) {
        sb.deleteCharAt(sb.length() - 1);
    }
    return sb.toString();
}

From source file:cn.vlabs.umt.ui.servlet.AuthorizationCodeServlet.java

private String tansferScope(String[] scopes) {
    if (scopes == null || scopes.length == 0) {
        return "";
    }/*from  www  . j ava2 s  .c o  m*/
    StringBuilder sb = new StringBuilder();
    for (String s : scopes) {
        sb.append(s).append(",");
    }
    if (sb.length() > 0) {
        sb.deleteCharAt(sb.length() - 1);
    }
    return sb.toString();
}