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:de.tudarmstadt.ukp.wikipedia.parser.mediawiki.GermanTemplateParser.java

public ResolvedTemplate parseTemplate(Template t, ParsedPage pp) {

    final String templateName = t.getName();

    //Show Name and Parameters as Standart treatment.
    ResolvedTemplate result = new ResolvedTemplate(t);
    result.setPreParseReplacement(ResolvedTemplate.TEMPLATESPACER);
    StringBuilder sb = new StringBuilder();
    sb.append(templatePrefix);//from   w w  w  . ja  va  2s.  c o m
    sb.append(t.getName() + parameterDivisor);
    for (String s : t.getParameters()) {
        sb.append(s + parameterDivisor);
    }
    sb.delete(sb.length() - parameterDivisor.length(), sb.length());
    sb.append(templatePostfix);
    result.setPostParseReplacement(sb.toString());

    result.setParsedObject(t);

    //Delete Template if it is in the List
    for (String s : deleteTemplates) {
        if (s.equals(templateName)) {
            result.setPostParseReplacement("");
            result.setParsedObject(null);
            return result;
        }
    }

    //Parse Template if it is in the List
    for (String s : parseTemplates) {
        List<String> templateParameters = t.getParameters();

        if (s.equals(templateName)) {
            logger.info("ParseTemplate: " + templateName);
            if (templateName.equals("Dieser Artikel")) {

                // I removed that from the core API, as it is not likely to be present in most non-German articles. (TZ)
                //               pp.setAboutArticle( parser.parseContentElement( templateParameters.get(0) ));

                result.setPostParseReplacement("");
                result.setParsedObject(null);
                return result;
            } else if (templateName.equals("Audio") || templateName.equals("Audio genau")) {
                if (templateParameters.size() == 0) {
                    break;
                }
                if (templateParameters.size() == 1) {
                    templateParameters.add(emptyLinkText);
                }
                result.setPostParseReplacement(t.getParameters().get(1));
                result.setParsedObject(
                        new Link(null, t.getPos(), templateParameters.get(0), Link.type.AUDIO, null));

                return result;
            } else if (templateName.equals("Video")) {
                if (templateParameters.size() == 0) {
                    break;
                }
                if (templateParameters.size() == 1) {
                    templateParameters.add(emptyLinkText);
                }
                result.setPostParseReplacement(t.getParameters().get(1));
                result.setParsedObject(
                        new Link(null, t.getPos(), t.getParameters().get(0), Link.type.VIDEO, null));
                return result;
            } else {
                result.setPostParseReplacement(
                        templateNotImplementedPrefix + templateName + templateNotImplementedPostfix);
                return result;
            }
        }
    }

    return result;
}

From source file:com.autentia.wuija.trace.TraceRepository.java

private String generateOperationalTypeCondition(int numberOfTypes) {
    final StringBuilder condition = new StringBuilder();

    if (numberOfTypes != 0) {
        condition.append(" AND (");
        for (int index = 0; index < numberOfTypes; index++) {
            condition.append("operationalTrace.type = ? OR ");
        }//from   w  w w. j  av  a  2  s  .c o  m
        condition.delete(condition.lastIndexOf("OR"), condition.length());
        condition.append(")");
    }
    return condition.toString();
}

From source file:scenario.EncodingTest.java

@Test
public void utf16EncodingFromBytesTest() throws IOException {

    System.setProperty("javax.xml.transform.TransformerFactory", XslScenario.SAXON_TRANSFORMER_FACTORY_FQCN);

    File xmlFile = new File(testResources.get("utf16-doc.xml").getURI());
    File xslFile = new File(testResources.get("encoding.xsl").getURI());

    XslScenario sc = new XslScenario(xslFile);

    byte[] bytes = FileUtils.readFileToByteArray(xmlFile);
    for (byte b : bytes) {
        System.out.format("%02x ", b);
    }//from   w w w  .j  ava 2  s .  co  m

    System.out.println();

    // BOM UTF-16LE
    StringBuilder sb = new StringBuilder();
    Formatter formatter = new Formatter(sb);

    formatter.format("%02x", bytes[0]);
    assertEquals("ff", sb.toString());

    sb.delete(0, 2);

    formatter.format("%02x", bytes[1]);
    assertEquals("fe", sb.toString());

    Map<String, String> outputs = sc.apply(bytes);
    assertNotNull("outputs object cannot be null.", outputs);

}

From source file:com.github.steveash.jg2p.aligntag.AlignTagModel.java

private List<Pair<String, String>> makeGraphemes(Word x, Sequence<Object> outSeq) {
    List<String> letters = x.getValue();
    Preconditions.checkArgument(outSeq.size() == letters.size());
    ArrayList<Pair<String, String>> result = Lists.newArrayListWithCapacity(letters.size());

    StringBuilder sb = new StringBuilder();
    for (int i = 0; i < letters.size(); i++) {
        if (sb.length() > 0) {
            sb.append(' ');
        }// www  . j  a  v a 2s .co  m
        sb.append(letters.get(i));
        if (outSeq.get(i).equals("1")) {
            result.add(Pair.of(sb.toString(), ""));
            sb.delete(0, sb.length());
        }
    }
    if (sb.length() > 0) {
        result.add(Pair.of(sb.toString(), ""));
    }
    return result;
}

From source file:org.obiba.onyx.spring.context.OnyxMessageSourceFactoryBean.java

protected String resolveBasename(String pathPrefix, Resource bundleResource) {

    // Resource#getFilename() does not return the full path. As such, we must get the underlying File instance.
    // Since all Resource instances are not File instances, this will only work with resources on the filesystem.

    File bundleFile;/*from  w  w  w. j ava 2  s. c o  m*/
    try {
        bundleFile = bundleResource.getFile();
    } catch (IOException e) {
        log.info("Cannot add resource {} to MessageSource because it is not on the filesystem.",
                bundleResource.getDescription());
        return null;
    }

    String filename = bundleFile.getAbsolutePath();
    // Make file pathname compatible with Spring's pathnames (if necessary)
    if (File.separatorChar != '/') {
        filename = filename.replace(File.separatorChar, '/');
    }
    StringBuilder basename = new StringBuilder(filename);

    int rootDirIndex = basename.lastIndexOf(pathPrefix);
    // Remove everything before pathPrefix
    if (rootDirIndex > 0) {
        basename.delete(0, rootDirIndex);
    }

    // Find the last part that fits the bundle's name
    int basenameIndex = basename.lastIndexOf(MESSAGES_BUNDLENAME);
    int length = basename.length();

    // Delete anything appearing after the bundle's name
    basename.delete(basenameIndex + MESSAGES_BUNDLENAME.length(), length);
    return basename.toString();
}

From source file:com.github.ibm.domino.client.BaseClient.java

protected String getDateParameter(ZonedDateTime value) {
    StringBuilder sValue = new StringBuilder(value.format(DateTimeFormatter.ISO_DATE_TIME));
    int i = sValue.indexOf(GMT_STRING);
    if (i >= 0) {
        sValue.delete(i, i + GMT_STRING.length());
    }//www . j a  va  2 s  .co  m
    i = sValue.indexOf(PERIOD);
    if (i >= 0) {
        sValue.delete(i, i + 4);
    }
    return sValue.toString();
}

From source file:net.jofm.DefaultFixedMapper.java

/**
 * Reads the data from a <code>StringBuilder<code> from the beginning, and removes the data as well.
 *///from   w  w w .  j  a v a2s .c o  m
private String read(StringBuilder data, int length) {
    String result = data.substring(0, length);
    data.delete(0, length);
    return result;
}

From source file:com.mindquarry.model.source.ModelSourceFactory.java

private Collection<String> parseStatements(String unparsedStatements) {
    StringBuilder remainingStatements = new StringBuilder(unparsedStatements);

    Collection<String> result = new LinkedList<String>();
    int i;//  ww w  . j  av  a2  s  .c o  m
    while ((i = remainingStatements.indexOf(").")) != -1) {
        String statement = remainingStatements.substring(0, i + 1);
        remainingStatements = remainingStatements.delete(0, i + 2);
        result.add(statement);
    }
    result.add(remainingStatements.toString());
    return result;
}

From source file:org.apache.oozie.command.coord.CoordCommandUtils.java

/**
 * Resolve &lt;start-instance&gt; &lt;end-insatnce&gt; tag. Don't resolve any
 * latest()/future()//from  w w w.j  a v a2s  .c  o m
 *
 * @param event
 * @param instances
 * @param appInst
 * @param conf
 * @param eval: ELEvalautor
 * @throws Exception
 */
public static void resolveInstanceRange(Element event, StringBuilder instances, SyncCoordAction appInst,
        Configuration conf, ELEvaluator eval) throws Exception {
    Element eStartInst = event.getChild("start-instance", event.getNamespace());
    Element eEndInst = event.getChild("end-instance", event.getNamespace());
    if (eStartInst != null && eEndInst != null) {
        String strStart = evaluateInstanceFunction(event, appInst, conf, eStartInst.getTextTrim());
        String strEnd = evaluateInstanceFunction(event, appInst, conf, eEndInst.getTextTrim());
        checkIfBothSameType(strStart, strEnd);
        StringBuilder restArg = new StringBuilder(); // To store rest
                                                     // arguments for
                                                     // future
                                                     // function

        int startIndex = getInstanceNumber(strStart, restArg);
        String startRestArg = restArg.toString();
        restArg.delete(0, restArg.length());
        int endIndex = getInstanceNumber(strEnd, restArg);
        String endRestArg = restArg.toString();
        int funcType = getFuncType(strStart);

        if (funcType == ABSOLUTE) {
            resolveAbsoluteRange(event, instances, appInst, conf, eval, strStart, endIndex,
                    parseOneStringArg(strStart));
        } else if (funcType == ENDOFMONTHS) {
            resolveInstanceRangeEndOfDuration(TimeUnit.MONTH, event, instances, appInst, conf, eval, strStart,
                    startIndex, endIndex);
        } else if (funcType == ENDOFWEEKS) {
            resolveInstanceRangeEndOfDuration(TimeUnit.WEEK, event, instances, appInst, conf, eval, strStart,
                    startIndex, endIndex);
        } else if (funcType == ENDOFDAYS) {
            resolveInstanceRangeEndOfDuration(TimeUnit.DAY, event, instances, appInst, conf, eval, strStart,
                    startIndex, endIndex);
        } else {
            if (funcType == OFFSET) {
                TimeUnit startU = TimeUnit.valueOf(startRestArg);
                TimeUnit endU = TimeUnit.valueOf(endRestArg);
                if (startU.getCalendarUnit() * startIndex > endU.getCalendarUnit() * endIndex) {
                    throw new CommandException(ErrorCode.E1010,
                            " start-instance should be equal or earlier than the end-instance \n"
                                    + XmlUtils.prettyPrint(event));
                }
                Calendar startCal = CoordELFunctions.resolveOffsetRawTime(startIndex, startU, eval);
                Calendar endCal = CoordELFunctions.resolveOffsetRawTime(endIndex, endU, eval);
                if (startCal != null && endCal != null) {
                    List<Integer> expandedFreqs = CoordELFunctions.expandOffsetTimes(startCal, endCal, eval);
                    for (int i = expandedFreqs.size() - 1; i >= 0; i--) {
                        //we need to use DS timeout, bcz expandOffsetTimes will expand offset in Freqs in DS timeunit
                        String matInstance = materializeInstance(event, "${coord:offset(" + expandedFreqs.get(i)
                                + ", \"" + CoordELFunctions.getDSTimeUnit(eval) + "\")}", appInst, conf, eval);
                        if (matInstance == null || matInstance.length() == 0) {
                            // Earlier than dataset's initial instance
                            break;
                        }
                        if (instances.length() > 0) {
                            instances.append(CoordELFunctions.INSTANCE_SEPARATOR);
                        }
                        instances.append(matInstance);
                    }
                }
            } else {
                if (startIndex > endIndex) {
                    throw new CommandException(ErrorCode.E1010,
                            " start-instance should be equal or earlier than the end-instance \n"
                                    + XmlUtils.prettyPrint(event));
                }
                if (funcType == CURRENT) {
                    // Everything could be resolved NOW. no latest() ELs
                    String matInstance = materializeInstance(event,
                            "${coord:currentRange(" + startIndex + "," + endIndex + ")}", appInst, conf, eval);
                    if (matInstance != null && !matInstance.isEmpty()) {
                        if (instances.length() > 0) {
                            instances.append(CoordELFunctions.INSTANCE_SEPARATOR);
                        }
                        instances.append(matInstance);
                    }
                }

                else { // latest(n)/future() EL is present
                    if (funcType == LATEST) {
                        instances.append("${coord:latestRange(").append(startIndex).append(",").append(endIndex)
                                .append(")}");
                    } else if (funcType == FUTURE) {
                        instances.append("${coord:futureRange(").append(startIndex).append(",").append(endIndex)
                                .append(",'").append(endRestArg).append("')}");
                    }
                }
            }
        }
        // Remove start-instance and end-instances
        event.removeChild("start-instance", event.getNamespace());
        event.removeChild("end-instance", event.getNamespace());
    }
}

From source file:de.craftolution.craftoplugin.modules.protection.storage.ProtectionDatabase.java

Collection<Protection> selectProtsByChunks(final Collection<ChunkPosition> chunks, Database connection) {
    debug("selectProtsByChunks(%s chunks) called!", chunks.size());
    if (chunks.size() == 0) {
        return Collections.emptyList();
    }//from  w w  w .  java 2  s.c om

    final StringBuilder queryBuilder = new StringBuilder("SELECT * FROM `cp_protections` WHERE `chunk_id` IN(");
    for (ChunkPosition chunk : chunks) {
        queryBuilder.append(chunk.chunkHash).append(", ");
    }
    queryBuilder.delete(queryBuilder.length() - 2, queryBuilder.length()).append(");");

    try (QueryResult res = connection.execute(queryBuilder.toString())) {
        final List<Row> rows = res.getRows();
        final List<Protection> protectionList = Lists.newArrayListWithCapacity(rows.size());

        for (final Row row : rows) {
            Protection protection = this.construct(row);
            protectionList.add(protection);
        }

        debug("selectProtsByChunks(%s): Loaded %s protections!", StringUtils.join(chunks, ", "), rows.size());

        return protectionList;
    }
}