Example usage for java.lang StringBuilder insert

List of usage examples for java.lang StringBuilder insert

Introduction

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

Prototype

@Override
public StringBuilder insert(int offset, double d) 

Source Link

Usage

From source file:com.netflix.genie.common.model.Application.java

/**
 * Helper method for checking the validity of required parameters.
 *
 * @param status The status of the application
 * @param error  Any pre-existing error condition
 * @throws GeniePreconditionException If any precondition isn't met.
 *//*from   www  .  j  a  v a 2 s. c  o  m*/
private void validate(final ApplicationStatus status, final String error) throws GeniePreconditionException {
    final StringBuilder builder = new StringBuilder();
    if (StringUtils.isNotBlank(error)) {
        builder.append(error);
    }
    if (status == null) {
        builder.append("No application status entered and is required.\n");
    }

    if (builder.length() > 0) {
        builder.insert(0, "Application configuration errors:\n");
        final String msg = builder.toString();
        LOG.error(msg);
        throw new GeniePreconditionException(msg);
    }
}

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

protected PreparedCacheControlUriConfig getPreparedUriConfig(HttpServletRequest request) {
    final String contextPath;
    final StringBuilder sb;
    final String uri;

    contextPath = request.getContextPath();
    sb = new StringBuilder(request.getRequestURI());
    if ((contextPath.length() > 0) && (sb.indexOf(contextPath) == 0)) {
        sb.delete(0, contextPath.length());
    }//from ww  w  .ja  va2  s  .c o m
    if ((sb.length() == 0) || (sb.charAt(0) != '/')) {
        sb.insert(0, '/');
    }
    uri = sb.toString();

    if (log.isDebugEnabled()) {
        log.debug("Checked URI is '" + uri + "'");
    }
    for (PreparedCacheControlUriConfig config : getUriConfigs()) {
        if ((config.getMethod() == null) || config.getMethod().name().equals(request.getMethod())) {
            if (config.getValue().matches(uri)) {
                if (log.isDebugEnabled()) {
                    log.debug("Matching configuration for URI '" + uri + "' and method '" + request.getMethod()
                            + "' is " + config);
                }
                return config;
            }
        }
    }

    if (log.isDebugEnabled()) {
        log.debug("No matching configuration for URI '" + uri + "' and method '" + request.getMethod() + "'");
    }
    return null;
}

From source file:forge.card.mana.ManaCost.java

private String getSimpleString() {
    if (this.hasNoCost) {
        return "no cost";
    }/* w w  w .  j a  v  a  2  s.  c  o m*/
    if (this.shards.isEmpty()) {
        return "{" + this.genericCost + "}";
    }

    final StringBuilder sb = new StringBuilder();
    if (this.genericCost > 0) {
        sb.append("{" + this.genericCost + "}");
    }
    for (final ManaCostShard s : this.shards) {
        if (s == ManaCostShard.X) {
            sb.insert(0, s.toString());
        } else {
            sb.append(s.toString());
        }
    }
    return sb.toString();
}

From source file:com.roche.sequencing.bioinformatics.common.utils.FileUtil.java

/**
 * taken from here http://codereview.stackexchange.com/questions/47923/simplifying-a-path -Kurt Heilman
 * //from  w  w  w.  j  a  va2 s .  c o m
 * @param path
 * @return
 */
public static String simplifyPath(String path) {
    String simplifiedPath = null;
    Deque<String> pathDeterminer = new ArrayDeque<String>();
    path = path.replaceAll(Pattern.quote("\\"), "/");
    path = path.replaceAll(Pattern.quote("\\\\"), "/");
    String[] pathSplitter = path.split("/");
    StringBuilder absolutePath = new StringBuilder();
    for (String term : pathSplitter) {
        if (term == null || term.length() == 0 || term.equals(".")) {
            /* ignore these guys */
        } else if (term.equals("..")) {
            if (pathDeterminer.size() > 0) {
                pathDeterminer.removeLast();
            }
        } else {
            pathDeterminer.addLast(term);
        }
    }
    if (pathDeterminer.isEmpty()) {
        simplifiedPath = "/";
    } else {
        while (!pathDeterminer.isEmpty()) {
            absolutePath.insert(0, pathDeterminer.removeLast());
            absolutePath.insert(0, "/");
        }
        simplifiedPath = absolutePath.toString();
    }
    return simplifiedPath;
}

From source file:jease.cmf.domain.Node.java

/**
 * Returns the path for the node. The path is built from the root node to
 * the current node by joining the ids with slashes (/).
 */// ww  w  .jav a 2s  .c  o  m
public String getPath() {
    if (getParent() == null) {
        return "/" + getId();
    }
    StringBuilder sb = new StringBuilder();
    for (Node node = this; node != null; node = node.getParent()) {
        if (!"".equals(node.getId())) {
            sb.insert(0, "/" + node.getId());
        }
    }
    return sb.toString();
}

From source file:monasca.api.infrastructure.persistence.influxdb.InfluxV9Utils.java

public String buildAlarmsPart(List<String> alarmIds) {

    StringBuilder sb = new StringBuilder();
    for (String alarmId : alarmIds) {
        if (sb.length() > 0) {
            sb.append(" or ");
        }/*  ww  w  .  jav a2s.c om*/
        sb.append(String.format(" alarm_id = '%1$s' ", alarmId));
    }

    if (sb.length() > 0) {
        sb.insert(0, " and (");
        sb.insert(sb.length(), ")");
    }
    return sb.toString();
}

From source file:org.kew.rmf.reconciliation.ws.MatchController.java

/**
 * Matches the records in the uploaded file.
 *
 * Results are put into a temporary file (available for download) and also shown in the web page.
 *///  w  w  w  . java 2 s  . c  o m
@RequestMapping(value = "/filematch/{configName}", method = RequestMethod.POST)
public String doFileMatch(@PathVariable String configName, @RequestParam("file") MultipartFile file,
        HttpServletResponse response, Model model) {
    logger.info("{}: File match query {}", configName, file);

    // Map of matches
    // Key is the ID of supplied records
    // Entries are a List of Map<String,String>
    Map<String, List<Map<String, String>>> matches = new HashMap<String, List<Map<String, String>>>();

    // Map of supplied data (useful for display)
    List<Map<String, String>> suppliedData = new ArrayList<Map<String, String>>();

    // Temporary file for results
    File resultsFile;

    List<String> properties = new ArrayList<String>();
    if (!file.isEmpty()) {
        try {
            logger.debug("Looking for : " + configName);
            LuceneMatcher matcher = reconciliationService.getMatcher(configName);
            if (matcher != null) {
                resultsFile = File.createTempFile("match-results-", ".csv");
                OutputStreamWriter resultsFileWriter = new OutputStreamWriter(new FileOutputStream(resultsFile),
                        "UTF-8");
                resultsFileWriter.write("queryId,matchId\n"); // TODO: attempt to use same line ending as input file

                // Save the property names:
                for (Property p : matcher.getConfig().getProperties()) {
                    properties.add(p.getQueryColumnName());
                }

                CsvPreference customCsvPref = new CsvPreference.Builder('"', ',', "\n").build();
                CsvMapReader mr = new CsvMapReader(new InputStreamReader(file.getInputStream(), "UTF-8"),
                        customCsvPref);
                final String[] header = mr.getHeader(true);
                Map<String, String> record = null;
                while ((record = mr.read(header)) != null) {
                    logger.debug("Next record is {}", record);
                    suppliedData.add(record);
                    try {
                        List<Map<String, String>> theseMatches = matcher.getMatches(record);
                        // Just write out some matches to std out:
                        if (theseMatches != null) {
                            logger.debug("Record ID {}, matched: {}", record.get("id"), theseMatches.size());
                        } else {
                            logger.debug("Record ID {}, matched: null", record.get("id"));
                        }
                        matches.put(record.get("id"), theseMatches);

                        // Append matche results to file
                        StringBuilder sb = new StringBuilder();
                        for (Map<String, String> result : theseMatches) {
                            if (sb.length() > 0)
                                sb.append('|');
                            sb.append(result.get("id"));
                        }
                        sb.insert(0, ',').insert(0, record.get("id")).append("\n");
                        resultsFileWriter.write(sb.toString());
                    } catch (TooManyMatchesException | MatchExecutionException e) {
                        logger.error("Problem handling match", e);
                    }
                }
                mr.close();
                resultsFileWriter.close();
                logger.debug("got file's bytes");
                model.addAttribute("resultsFile", resultsFile.getName());
                response.setHeader("X-File-Download", resultsFile.getName()); // Putting this in a header saves the unit tests from needing to parse the HTML.
            }
            model.addAttribute("suppliedData", suppliedData);
            model.addAttribute("matches", matches);
            model.addAttribute("properties", properties);
        } catch (Exception e) {
            logger.error("Problem reading file", e);
        }
    }
    return "file-matcher-results";
}

From source file:com.ewcms.core.site.model.Template.java

private void constructPath() {
    StringBuilder builder = new StringBuilder();
    for (Template template = this; template != null; template = template.parent) {
        if (StringUtils.isBlank(template.getName())) {
            break;
        }//from   w  w  w  .j  ava2  s.  c o m
        String dir = removeStartAndEndPathSeparator(template.getName());
        builder.insert(0, dir);
        builder.insert(0, PATH_SEPARATOR);
    }
    path = removeStartAndEndPathSeparator(builder.toString());
    uniquePath = getSite().getId().toString() + PATH_SEPARATOR + path;
}

From source file:ac.simons.tweetarchive.tweets.TweetStorageService.java

String extractContent(final Status status) {
    // TODO Handle quoted tweets
    final Status workStatus;
    if (status.isRetweet()) {
        workStatus = status.getRetweetedStatus();
    } else {/*from   w w  w. j  a va2s.com*/
        workStatus = status;
    }

    final StringBuilder rv = new StringBuilder();

    final String text = workStatus.getText();
    int pos = 0;
    for (URLEntity urlEntity : workStatus.getURLEntities()) {
        rv.append(text.substring(pos, urlEntity.getStart()));
        rv.append(urlEntity.getExpandedURL());
        pos = urlEntity.getEnd();

    }
    if (pos <= text.length()) {
        rv.append(text.substring(pos, text.length()));
    }

    if (status.isRetweet()) {
        rv.insert(0, String.format("RT @%s: ", workStatus.getUser().getScreenName()));
    }
    return rv.toString();
}

From source file:de.itsvs.cwtrpc.security.AbstractRpcProcessingFilter.java

protected boolean matchesFilterProcessesUrl(HttpServletRequest request) throws IOException, ServletException {
    final String contextPath;
    final StringBuilder sb;
    final String uri;

    contextPath = request.getContextPath();
    sb = new StringBuilder(request.getRequestURI());
    if ((contextPath.length() > 0) && (sb.indexOf(contextPath) == 0)) {
        sb.delete(0, contextPath.length());
    }//from  www  .  j  a v a  2 s.com
    if ((sb.length() == 0) || (sb.charAt(0) != '/')) {
        sb.insert(0, '/');
    }
    uri = sb.toString();

    if (log.isDebugEnabled()) {
        log.debug(
                "Checking received URI '" + uri + "' against configured URI '" + getFilterProcessesUrl() + "'");
    }
    return getFilterProcessesUrl().equals(uri);
}