Example usage for java.lang StringBuilder delete

List of usage examples for java.lang StringBuilder delete

Introduction

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

Prototype

@Override
public StringBuilder delete(int start, int end) 

Source Link

Usage

From source file:jfs.sync.encryption.AbstractEncryptedStorageAccess.java

protected String getMetaDataFileName(String relativePath) {
    StringBuilder result = new StringBuilder(getLastPathElement(JFSConfig.getInstance().getEncryptionPassPhrase(), relativePath));
    result.reverse();/*  w w  w.  j av a  2  s.c  om*/
    if (result.length()>8) {
        result.delete(0, result.length()-8);
    } // if
    result.append(".mt");
    return result.toString();
}

From source file:org.aksw.simba.cetus.annotator.CetusSurfaceFormExtractor.java

private void generateNEsForType(List<CoreLabel> tokens, int[][] tokenPositions, int startTokenId,
        int numberOfTokens, List<ExtendedTypedNamedEntity> results) {
    if (numberOfTokens == 0) {
        LOGGER.warn("got a type without tokens.");
        return;// w  w  w.ja v  a2  s  .c o m
    }
    // FIXME here, we need a way to add the type hierarchy!!!
    String labels[] = new String[numberOfTokens];
    String uppercaseLabels[] = new String[numberOfTokens];
    for (int i = 0; i < numberOfTokens; ++i) {
        labels[i] = tokens.get(i + startTokenId).getString(TextAnnotation.class);
        uppercaseLabels[i] = Character.toUpperCase(labels[i].charAt(0)) + labels[i].substring(1);
    }
    StringBuilder uriBuilder = new StringBuilder();
    StringBuilder labelBuilder = new StringBuilder();
    int startPosition;
    int endPosition = tokenPositions[startTokenId + numberOfTokens - 1][ORIG_TEXT_END];
    for (int i = numberOfTokens - 1; i >= 0; --i) {
        startPosition = tokenPositions[startTokenId + i][ORIG_TEXT_START];
        uriBuilder.delete(0, uriBuilder.length());
        labelBuilder.delete(0, labelBuilder.length());
        uriBuilder.append(BASE_URI);
        uriBuilder.append(uppercaseLabels[i]);
        labelBuilder.append(labels[i]);
        for (int j = i + 1; j < numberOfTokens; ++j) {
            uriBuilder.append(uppercaseLabels[j]);
            labelBuilder.append(' ');
            labelBuilder.append(labels[j]);
        }
        results.add(
                new ExtendedTypedNamedEntity(startPosition, endPosition - startPosition, uriBuilder.toString(),
                        new HashSet<String>(Arrays.asList(RDFS.Class.getURI())), labelBuilder.toString()));
    }
}

From source file:org.apache.gora.dynamodb.compiler.GoraDynamoDBCompiler.java

/**
 * Creates the key attributes within the generated class
 * @param pKeySchema/*  ww  w.  j av a  2 s .c  o  m*/
 *          schema
 * @param attType
 *          attribute type
 * @param pIden
 *          of spaces used for indentation
 * @throws IOException
 */
private void setKeyAttributes(KeySchemaElement pKeySchema, String attType, int pIden) throws IOException {
    StringBuilder strBuilder = new StringBuilder();
    attType = attType.equals("S") ? "String " : "double ";
    if (pKeySchema != null) {
        strBuilder.append("private " + attType);
        strBuilder.append(pKeySchema.getAttributeName() + ";");
        line(pIden, strBuilder.toString());
    }
    strBuilder.delete(0, strBuilder.length());
    line(0, "");
}

From source file:org.vietspider.crawl.link.Link.java

public String buildURL() {
    StringBuilder builder = new StringBuilder(address);
    if (params != null) {
        for (int i = 0; i < params.size(); i++) {
            builder.append('&').append(params.get(i).toString());
        }/* w  ww .  j  av  a2 s  . c o m*/
    }
    if (builder.length() >= 2000) {
        builder.delete(2000, builder.length());
    }
    return builder.toString();
}

From source file:jp.primecloud.auto.process.vmware.VmwareInitProcess.java

protected String convertMapToString(Map<String, String> map) {
    if (map.isEmpty()) {
        return "";
    }//from  www  .j av  a2s  . c  o m

    StringBuilder sb = new StringBuilder();
    for (Entry<String, String> entry : map.entrySet()) {
        String key = entry.getKey();
        String value = entry.getValue();
        if (key != null && value != null) {
            sb.append(key).append("=").append(value).append(";");
        }
    }
    sb.delete(sb.length() - 1, sb.length());

    return sb.toString();
}

From source file:com.scaleunlimited.cascading.FlowMonitor.java

private void replace(StringBuilder template, String key, String value) {
    int offset = template.indexOf(key);
    if (offset == -1) {
        throw new RuntimeException("Key doesn't exist in template: " + key);
    }/*from  w  ww.j a  v a 2 s  .c om*/

    template.delete(offset, offset + key.length());
    template.insert(offset, value);
}

From source file:benedict.zhang.addon.roleplaying.model.RolePlayingConfiguration.java

public RolePlayingConfiguration() {
    this.addonName = new SimpleStringProperty("");
    this.spellCastInQueueMax = new SimpleStringProperty("");
    this.spellLockGlobal = new SimpleStringProperty("");
    this.spellList = FXCollections.observableArrayList();
    this.spells = new ArrayList<>();
    this.dateGeneration = new SimpleStringProperty("");
    this.addonDigest = new SimpleStringProperty("");
    this.generateDate = new Date();
    spellList.addListener((ListChangeListener.Change<? extends SpellConfiguration> c) -> {
        c.next();//from  ww w.  j a  v  a  2 s  . co m
        StringBuilder sb = new StringBuilder();
        if (spellList.size() > 0) {
            sb.append(this.getAddonName()).append(" : ");
            sb.append("[").append(this.spellList.get(0).getSpellName());
            for (int i = 1; i < spellList.size(); i++) {
                sb.append(",").append(spellList.get(i).getSpellName());
            }
            ;
            sb.append("]");
        }
        this.setAddonDigest(sb.toString());
        sb.delete(0, sb.length());
        this.spells.clear();
        for (SpellConfiguration spell : this.spellList) {
            this.spells.add(spell);
        }
    });
}

From source file:com.panet.imeta.trans.steps.textfileinput.TextFileInput.java

public static final String[] guessStringsFromLine(String line, TextFileInputMeta inf) throws KettleException {
    List<String> strings = new ArrayList<String>();
    int fieldnr;//  w  w w  .  ja v a2  s .  co m

    String pol; // piece of line

    try {
        if (line == null)
            return null;

        if (inf.getFileType().equalsIgnoreCase("CSV")) {
            // Split string in pieces, only for CSV!

            fieldnr = 0;
            int pos = 0;
            int length = line.length();
            boolean dencl = false;

            int len_encl = (inf.getEnclosure() == null ? 0 : inf.getEnclosure().length());
            int len_esc = (inf.getEscapeCharacter() == null ? 0 : inf.getEscapeCharacter().length());

            while (pos < length) {
                int from = pos;
                int next;

                boolean encl_found;
                boolean contains_escaped_enclosures = false;
                boolean contains_escaped_separators = false;

                // Is the field beginning with an enclosure?
                // "aa;aa";123;"aaa-aaa";000;...
                if (len_encl > 0
                        && line.substring(from, from + len_encl).equalsIgnoreCase(inf.getEnclosure())) {
                    if (log.isRowLevel())
                        log.logRowlevel(Messages.getString("TextFileInput.Log.ConvertLineToRowTitle"),
                                Messages.getString("TextFileInput.Log.ConvertLineToRow",
                                        line.substring(from, from + len_encl)));
                    encl_found = true;
                    int p = from + len_encl;

                    boolean is_enclosure = len_encl > 0 && p + len_encl < length
                            && line.substring(p, p + len_encl).equalsIgnoreCase(inf.getEnclosure());
                    boolean is_escape = len_esc > 0 && p + len_esc < length
                            && line.substring(p, p + len_esc).equalsIgnoreCase(inf.getEscapeCharacter());

                    boolean enclosure_after = false;

                    // Is it really an enclosure? See if it's not repeated twice or escaped!
                    if ((is_enclosure || is_escape) && p < length - 1) {
                        String strnext = line.substring(p + len_encl, p + 2 * len_encl);
                        if (strnext.equalsIgnoreCase(inf.getEnclosure())) {
                            p++;
                            enclosure_after = true;
                            dencl = true;

                            // Remember to replace them later on!
                            if (is_escape)
                                contains_escaped_enclosures = true;
                        }
                    }

                    // Look for a closing enclosure!
                    while ((!is_enclosure || enclosure_after) && p < line.length()) {
                        p++;
                        enclosure_after = false;
                        is_enclosure = len_encl > 0 && p + len_encl < length
                                && line.substring(p, p + len_encl).equals(inf.getEnclosure());
                        is_escape = len_esc > 0 && p + len_esc < length
                                && line.substring(p, p + len_esc).equals(inf.getEscapeCharacter());

                        // Is it really an enclosure? See if it's not repeated twice or escaped!
                        if ((is_enclosure || is_escape) && p < length - 1) // Is
                        {
                            String strnext = line.substring(p + len_encl, p + 2 * len_encl);
                            if (strnext.equals(inf.getEnclosure())) {
                                p++;
                                enclosure_after = true;
                                dencl = true;

                                // Remember to replace them later on!
                                if (is_escape)
                                    contains_escaped_enclosures = true; // remember
                            }
                        }
                    }

                    if (p >= length)
                        next = p;
                    else
                        next = p + len_encl;

                    if (log.isRowLevel())
                        log.logRowlevel(Messages.getString("TextFileInput.Log.ConvertLineToRowTitle"),
                                Messages.getString("TextFileInput.Log.EndOfEnclosure", "" + p));
                } else {
                    encl_found = false;
                    boolean found = false;
                    int startpoint = from;
                    int tries = 1;
                    do {
                        next = line.indexOf(inf.getSeparator(), startpoint);

                        // See if this position is preceded by an escape character.
                        if (len_esc > 0 && next - len_esc > 0) {
                            String before = line.substring(next - len_esc, next);

                            if (inf.getEscapeCharacter().equals(before)) {
                                // take the next separator, this one is escaped...
                                startpoint = next + 1;
                                tries++;
                                contains_escaped_separators = true;
                            } else {
                                found = true;
                            }
                        } else {
                            found = true;
                        }
                    } while (!found && next >= 0);
                }
                if (next == -1)
                    next = length;

                if (encl_found) {
                    pol = line.substring(from + len_encl, next - len_encl);
                    if (log.isRowLevel())
                        log.logRowlevel(Messages.getString("TextFileInput.Log.ConvertLineToRowTitle"),
                                Messages.getString("TextFileInput.Log.EnclosureFieldFound", "" + pol));
                } else {
                    pol = line.substring(from, next);
                    if (log.isRowLevel())
                        log.logRowlevel(Messages.getString("TextFileInput.Log.ConvertLineToRowTitle"),
                                Messages.getString("TextFileInput.Log.NormalFieldFound", "" + pol));
                }

                if (dencl) {
                    StringBuilder sbpol = new StringBuilder(pol);
                    int idx = sbpol.indexOf(inf.getEnclosure() + inf.getEnclosure());
                    while (idx >= 0) {
                        sbpol.delete(idx, idx + inf.getEnclosure().length());
                        idx = sbpol.indexOf(inf.getEnclosure() + inf.getEnclosure());
                    }
                    pol = sbpol.toString();
                }

                //   replace the escaped enclosures with enclosures... 
                if (contains_escaped_enclosures) {
                    String replace = inf.getEscapeCharacter() + inf.getEnclosure();
                    String replaceWith = inf.getEnclosure();

                    pol = Const.replace(pol, replace, replaceWith);
                }

                //replace the escaped separators with separators... 
                if (contains_escaped_separators) {
                    String replace = inf.getEscapeCharacter() + inf.getSeparator();
                    String replaceWith = inf.getSeparator();

                    pol = Const.replace(pol, replace, replaceWith);
                }

                // Now add pol to the strings found!
                strings.add(pol);

                pos = next + inf.getSeparator().length();
                fieldnr++;
            }
            if (pos == length) {
                if (log.isRowLevel())
                    log.logRowlevel(Messages.getString("TextFileInput.Log.ConvertLineToRowTitle"),
                            Messages.getString("TextFileInput.Log.EndOfEmptyLineFound"));
                strings.add("");
                fieldnr++;
            }
        } else {
            // Fixed file format: Simply get the strings at the required positions...
            for (int i = 0; i < inf.getInputFields().length; i++) {
                TextFileInputField field = inf.getInputFields()[i];

                int length = line.length();

                if (field.getPosition() + field.getLength() <= length) {
                    strings.add(line.substring(field.getPosition(), field.getPosition() + field.getLength()));
                } else {
                    if (field.getPosition() < length) {
                        strings.add(line.substring(field.getPosition()));
                    } else {
                        strings.add("");
                    }
                }
            }
        }
    } catch (Exception e) {
        throw new KettleException(
                Messages.getString("TextFileInput.Log.Error.ErrorConvertingLine", e.toString()), e);
    }

    return strings.toArray(new String[strings.size()]);
}

From source file:it.publisys.liferay.hook.shibboleth.ShibbolethPostLogoutAction.java

/**
 * Prepara i {@link Cookie}s da inoltrare
 *
 * @param request {@link HttpServletRequest}
 * @return cookies string/*from   w  w  w.j ava  2s  .c  o  m*/
 */
private String _prepareCookies(HttpServletRequest request) {
    StringBuilder _cookieBuffer = new StringBuilder();
    try {
        Cookie[] _cookies = request.getCookies();
        for (Cookie _cookie : _cookies) {
            _cookieBuffer.append(_cookie.getName()).append("=")
                    .append(URLEncoder.encode(_cookie.getValue(), "UTF-8"));
            _cookieBuffer.append("; ");
        }
    } catch (UnsupportedEncodingException uee) {
        uee.printStackTrace(System.err);
    }

    if (_cookieBuffer.length() > 2) {
        _cookieBuffer.delete(_cookieBuffer.length() - 2, _cookieBuffer.length());
    }
    return _cookieBuffer.toString();
}

From source file:fungus.FluctuationObserver.java

@SuppressWarnings("unchecked")
public boolean execute() {

    if (CDState.getCycle() % period != 0)
        return false;

    updateStats();/*from w ww . ja va  2  s .  c  o  m*/
    if (fluctuations.isEmpty())
        return false;

    StringBuilder sb = new StringBuilder();
    java.util.Formatter f = new java.util.Formatter(sb, Locale.US);

    Integer i = 0;

    HashMap<Integer, Integer> map = (HashMap<Integer, Integer>) fluctuations.clone();
    while (!map.isEmpty()) {
        Integer val = map.remove(i);
        if (val == null) {
            f.format("%1d:%1d, ", i, 0);
        } else {
            f.format("%1d:%1d, ", i, val);
        }
        i++;
    }

    // ah: remove last commaspace and add a newline
    sb.delete(sb.length() - 2, sb.length());
    sb.append("\n");

    // ah: TODO: copy experiment writer to get this writing to
    // a file, too, so i can make a graph out of it.
    try {
        FileOutputStream out = new FileOutputStream(filename, true);
        PrintStream p = new PrintStream(out);
        p.print(sb.toString());
        out.close();
    } catch (IOException e) {
        log.severe("Error writing fluctuation data to file");
        debug(e.getMessage());
    }

    log.info("fluctuation counts " + sb.toString());
    return false;
}