Example usage for java.lang StringBuilder length

List of usage examples for java.lang StringBuilder length

Introduction

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

Prototype

int length();

Source Link

Document

Returns the length of this character sequence.

Usage

From source file:edu.uci.ics.hyracks.imru.jobgen.ClusterConfig.java

public static void setConf(HyracksConnection hcc) throws Exception {
    Map<String, NodeControllerInfo> map = hcc.getNodeControllerInfos();
    List<String> ncNames = new ArrayList<String>();
    ipToNcMapping = new HashMap<String, List<String>>();
    for (String key : map.keySet()) {
        NodeControllerInfo info = map.get(key);
        String id = info.getNodeId();
        byte[] ip = info.getNetworkAddress().lookupIpAddress();
        StringBuilder sb = new StringBuilder();
        for (byte b : ip) {
            if (sb.length() > 0)
                sb.append(".");
            sb.append(b & 0xFF);/*from  w  w w.ja va2s.  c  o  m*/
        }
        //            LOG.info(id + " " + sb);
        ncNames.add(id);
        List<String> ncs = ipToNcMapping.get(id);
        if (ncs == null) {
            ncs = new ArrayList<String>();
            ipToNcMapping.put(id, ncs);
        }
        ncs.add(sb.toString());
    }
    NCs = ncNames.toArray(new String[ncNames.size()]);
}

From source file:com.indoqa.lang.util.StringUtils.java

public static String escapeSolr(String value) {
    StringBuilder stringBuilder = new StringBuilder(value);

    for (int i = 0; i < stringBuilder.length(); i++) {
        boolean isCharacterToBeEscaped = Arrays.binarySearch(CHARACTERS_TO_BE_ESCAPED_FOR_SOLR,
                stringBuilder.charAt(i)) >= 0;
        if (isCharacterToBeEscaped) {
            stringBuilder.insert(i, '\\');
            i++;//  ww w.  j ava 2s  . c  o m
        }
    }

    return stringBuilder.toString();
}

From source file:com.indoqa.lang.util.StringUtils.java

public static String sanitzeHtmlId(String id) {
    if (org.apache.commons.lang3.StringUtils.isBlank(id)) {
        return "";
    }/*  w  w  w .j  a v  a 2s . c o m*/

    StringBuilder stringBuilder = new StringBuilder(id);

    for (int i = 0; i < stringBuilder.length(); i++) {
        char character = stringBuilder.charAt(i);

        if (Arrays.binarySearch(ILLEGAL_HTML_ID_CHARACTERS, character) >= 0) {
            stringBuilder.setCharAt(i, '_');
        }
    }

    return stringBuilder.toString();
}

From source file:ca.uhn.fhir.rest.method.SortParameter.java

public static String createSortStringDstu3(SortSpec ss) {
    StringBuilder val = new StringBuilder();
    while (ss != null) {

        if (isNotBlank(ss.getParamName())) {
            if (val.length() > 0) {
                val.append(',');
            }//from   ww w .  j a  va2s  .co  m
            if (ss.getOrder() == SortOrderEnum.DESC) {
                val.append('-');
            }
            val.append(ParameterUtil.escape(ss.getParamName()));
        }

        ss = ss.getChain();
    }

    String string = val.toString();
    return string;
}

From source file:com.autentia.wuija.trace.persistence.OperationalTraceBuilder.java

private static OperationalTraceParams generateParamForSimpleExpressionCheckingIfIsDate(SimpleExpression exp,
        String classOfProperty) {
    final StringBuilder builder = new StringBuilder(exp.getValues().toString());

    if (!exp.getValues().isEmpty() && exp.getValues().get(0) instanceof Date) {
        builder.delete(0, builder.length());
        for (Object date : exp.getValues()) {
            builder.append(DateFormater.format((Date) date, FORMAT.DEFAULT_DATE));
            builder.append(", ");
        }/*from w  ww .j av a  2s. co m*/
        builder.delete(builder.lastIndexOf(", "), builder.length());
    }

    return new OperationalTraceParams(
            classOfProperty == "" ? exp.getProperty() : classOfProperty + "." + exp.getProperty(),
            exp.getOperator(), builder.toString());
}

From source file:com.bedatadriven.renjin.appengine.AppEngineContextFactory.java

/**
 *
 * @param fileSystemManager/*  w  w w.j a va  2  s.c  om*/
 * @param servletContext 
 * @return
 */
private static String computeLibraryPaths(FileSystemManager fileSystemManager, ServletContext servletContext) {
    File contextRoot = contextRoot(servletContext);
    File webInfFolder = new File(contextRoot, "WEB-INF");
    File libFolder = new File(webInfFolder, "lib");

    StringBuilder paths = new StringBuilder();

    for (File lib : libFolder.listFiles()) {
        if (lib.getName().endsWith(".jar")) {
            if (paths.length() > 0) {
                paths.append(";");
            }
            paths.append("jar:file:///WEB-INF/lib/").append(lib.getName()).append("!/");
        }
    }
    return paths.toString();
}

From source file:com.exxonmobile.ace.hybris.storefront.util.MetaSanitizerUtil.java

/**
 * Takes a List of KeywordModels and returns a comma separated list of keywords as String.
 * /*w w  w  .j  a  v  a  2  s. co  m*/
 * @param keywords
 *           List of KeywordModel objects
 * @return String of comma separated keywords
 */
public static String sanitizeKeywords(final List<KeywordModel> keywords) {
    // Remove duplicates
    final List<String> keywordList = new ArrayList<String>();
    for (final KeywordModel kw : keywords) {
        keywordList.add(kw.getKeyword());
    }
    final Set<String> keywordSet = new HashSet<String>(keywordList);
    keywordList.clear();
    keywordList.addAll(keywordSet);

    // Format keywords
    final StringBuilder stringBuilder = new StringBuilder();
    String formattedKeywords = null;
    for (final String kw : keywordList) {
        stringBuilder.append(kw);
        stringBuilder.append(',');
    }
    if (stringBuilder.length() > 0) {
        formattedKeywords = stringBuilder.substring(0, stringBuilder.length() - 1);
    }
    return formattedKeywords;
}

From source file:com.porvak.bracket.social.jdbc.versioned.SqlDatabaseChange.java

private static String readScript(Resource resource) throws IOException {
    EncodedResource encoded = resource instanceof EncodedResource ? (EncodedResource) resource
            : new EncodedResource(resource);
    LineNumberReader lnr = new LineNumberReader(encoded.getReader());
    String currentStatement = lnr.readLine();
    StringBuilder scriptBuilder = new StringBuilder();
    while (currentStatement != null) {
        if (StringUtils.hasText(currentStatement)
                && (SQL_COMMENT_PREFIX != null && !currentStatement.startsWith(SQL_COMMENT_PREFIX))) {
            if (scriptBuilder.length() > 0) {
                scriptBuilder.append('\n');
            }//from w ww  .  j a va2s . co m
            scriptBuilder.append(currentStatement);
        }
        currentStatement = lnr.readLine();
    }
    return scriptBuilder.toString();
}

From source file:com.ocs.dynamo.domain.model.util.EntityModelUtil.java

/**
 * Returns a comma separated String containing the display properties of the specified entities
 * //from  www  .ja  v a2s  .c  o m
 * @param entities
 *            the entities
 * @param model
 *            the model
 * @param maxItems
 *            the maximum number of items before the description is truncated
 * @param messageService
 *            message service
 * @return
 */
public static <T> String getDisplayPropertyValue(Collection<T> entities, EntityModel<T> model, int maxItems,
        MessageService messageService) {
    String property = model.getDisplayProperty();
    StringBuilder result = new StringBuilder();

    int i = 0;
    for (T t : entities) {
        if (result.length() > 0) {
            result.append(", ");
        }

        if (i < maxItems) {
            result.append(ClassUtils.getFieldValueAsString(t, property));
        } else {
            result.append(messageService.getMessage("ocs.and.others", entities.size() - maxItems));
            break;
        }
        i++;
    }
    return result.toString();
}

From source file:com.quartercode.femtoweb.impl.ActionUriResolver.java

private static String joinNonBlankItems(String separator, String... items) {

    StringBuilder string = new StringBuilder();
    for (String item : items) {
        if (!StringUtils.isBlank(item)) {
            string.append(separator).append(item);
        }//from  w  w  w .ja va 2  s  .com
    }

    return string.length() == 0 ? "" : string.substring(separator.length());
}