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:edu.umd.cs.psl.model.kernel.setdefinition.GroundSetDefinition.java

@Override
public String toString() {
    StringBuilder b = new StringBuilder();
    b.append(setAtom).append("=").append("{");
    for (Atom atom : referencedAtoms) {
        b.append(atom).append(" , ");
    }//  ww w.j a  va  2s. co  m
    b.delete(b.length() - 3, b.length());
    b.append("}");
    b.append(" defined by ").append(definitionType.getAggregator());
    return b.toString();
}

From source file:edu.ksu.cis.santos.mdcf.dms.test.SymbolTableTest.java

void deleteLastChars(final StringBuilder sb, final int n) {
    final int length = sb.length();
    sb.delete(length - 2, length);
}

From source file:org.apache.flume.event.EventHelper.java

public static String dumpEvent(Event event, int maxBytes) {
    StringBuilder buffer = new StringBuilder();
    if (event == null || event.getBody() == null) {
        buffer.append("null");
    } else if (event.getBody().length == 0) {
        // do nothing... in this case, HexDump.dump() will throw an exception
    } else {//from ww  w .j  a va2 s . co m
        byte[] body = event.getBody();
        byte[] data = Arrays.copyOf(body, Math.min(body.length, maxBytes));
        ByteArrayOutputStream out = new ByteArrayOutputStream();
        try {
            HexDump.dump(data, 0, out, 0);
            String hexDump = new String(out.toByteArray());
            // remove offset since it's not relevant for such a small dataset
            if (hexDump.startsWith(HEXDUMP_OFFSET)) {
                hexDump = hexDump.substring(HEXDUMP_OFFSET.length());
            }
            buffer.append(hexDump);
        } catch (Exception e) {
            if (LOGGER.isInfoEnabled()) {
                LOGGER.info("Exception while dumping event", e);
            }
            buffer.append("...Exception while dumping: ").append(e.getMessage());
        }
        String result = buffer.toString();
        if (result.endsWith(EOL) && buffer.length() > EOL.length()) {
            buffer.delete(buffer.length() - EOL.length(), buffer.length()).toString();
        }
    }
    return "{ headers:" + event.getHeaders() + " body:" + buffer + " }";
}

From source file:gov.nih.nci.cabig.caaers.domain.AdverseEventCtcTerm.java

@Override
@Transient//from   ww  w.j a  va  2s .co m
public String getUniversalTerm() {
    if (getTerm() == null) {
        return null;
    } else if (getAdverseEvent() != null && (getAdverseEvent().getDetailsForOther() != null
            || getAdverseEvent().getLowLevelTerm() != null)) {
        StringBuilder sb = new StringBuilder(getTerm().getFullName());
        // strip everything after "Other", if it is in the name
        int otherAt = sb.indexOf("Other");
        if (otherAt >= 0) {
            sb.delete(otherAt + 5, sb.length());
        }
        if (getAdverseEvent().getDetailsForOther() != null)
            sb.append(": ").append(getAdverseEvent().getDetailsForOther());
        if (getAdverseEvent().getLowLevelTerm() != null
                && getAdverseEvent().getLowLevelTerm().getMeddraTerm() != null) {
            sb.append(": ").append(getAdverseEvent().getLowLevelTerm().getMeddraTerm());
        }
        return sb.toString();
    } else {
        return getTerm().getFullName();
    }
}

From source file:edu.umd.cs.psl.model.kernel.predicateconstraint.GroundDomainRangeConstraint.java

@Override
public String toString() {
    StringBuilder b = new StringBuilder();
    b.append(template.getConstraintType().toString()).append(" on ").append("{");
    for (Atom atom : atoms) {
        b.append(atom).append(" , ");
    }//from ww  w  . ja v  a 2 s.co m
    b.delete(b.length() - 3, b.length());
    return b.append("}").toString();
}

From source file:org.apache.tajo.engine.planner.physical.ColumnPartitionedTableStoreExec.java

@Override
public Tuple next() throws IOException {
    StringBuilder sb = new StringBuilder();
    while ((tuple = child.next()) != null) {
        // set subpartition directory name
        sb.delete(0, sb.length());
        if (partitionColumnIndices != null) {
            for (int i = 0; i < partitionColumnIndices.length; i++) {
                Datum datum = tuple.get(partitionColumnIndices[i]);
                if (i > 0)
                    sb.append("/");
                sb.append(partitionColumnNames[i]).append("=");
                sb.append(datum.asChars());
            }//from  ww  w . j  av  a 2s  . c  o  m
        }

        // add tuple
        Appender appender = getAppender(sb.toString());
        appender.addTuple(tuple);
    }

    List<TableStats> statSet = new ArrayList<TableStats>();
    for (Map.Entry<String, Appender> entry : appenderMap.entrySet()) {
        Appender app = entry.getValue();
        app.flush();
        app.close();
        statSet.add(app.getStats());
    }

    // Collect and aggregated statistics data
    TableStats aggregated = StatisticsUtil.aggregateTableStat(statSet);
    context.setResultStats(aggregated);

    return null;
}

From source file:com.berico.fallwizard.SpringService.java

/**
 * Little utility to concatenate strings with a separator.
 * @param strings Strings to join//from  ww  w  .jav  a2 s .  com
 * @param separator Separator between strings
 * @return Joined String
 */
String join(String[] strings, String separator) {

    StringBuilder sb = new StringBuilder();

    for (String string : strings) {

        sb.append(string).append(separator);
    }

    return sb.delete(sb.length() - separator.length(), sb.length()).toString();
}

From source file:org.envirocar.tools.TrackToCSV.java

private CharSequence createCSVHeader(List<String> properties, List<String> spaceTimeproperties) {
    StringBuilder sb = new StringBuilder();

    for (String key : properties) {
        sb.append(key);/* www. j a  va 2  s  .co  m*/
        sb.append(delimiter);
    }

    for (String key : spaceTimeproperties) {
        sb.append(key);
        sb.append(delimiter);
    }

    return sb.delete(sb.length() - delimiter.length(), sb.length());
}

From source file:com.forerunnergames.tools.common.Strings.java

/**
 * Converts a collection of list elements to a string list, separated by separator, in case letterCase.
 *
 * @param <T>//from w w  w.j a v a 2 s . com
 *          The type of the list elements.
 * @param listElements
 *          The collection of list elements to convert, must not be null, must not contain any null elements.
 * @param separator
 *          The separator that should be added between list elements, must not be null.
 * @param letterCase
 *          The desired letter case of the list elements, must not be null, choose LetterCase.NONE to leave the list
 *          elements as-is.
 * @param hasAnd
 *          Whether or not to insert the word 'and ' between the last two elements in the list, one space after the
 *          last separator.
 *
 * @return A string list of listElements, separated by separator, in case letterCase, with an optional 'and '
 *         occurring between the last two elements of the list.
 */
public static <T> String toStringList(final Collection<T> listElements, final String separator,
        final LetterCase letterCase, final boolean hasAnd) {
    Arguments.checkIsNotNull(listElements, "listElements");
    Arguments.checkHasNoNullElements(listElements, "listElements");
    Arguments.checkIsNotNull(separator, "separator");
    Arguments.checkIsNotNull(letterCase, "letterCase");

    final ImmutableList.Builder<T> printableListElementsBuilder = ImmutableList.builder();

    for (final T element : listElements) {
        if (isPrintable(element.toString()))
            printableListElementsBuilder.add(element);
    }

    final ImmutableList<T> printableListElements = printableListElementsBuilder.build();

    // Handle the first three special cases
    if (printableListElements.isEmpty()) {
        return "";
    } else if (printableListElements.size() == 1) {
        return toCase(Iterables.getOnlyElement(printableListElements).toString(), letterCase);
    } else if (printableListElements.size() == 2) {
        final Iterator<T> iterator = printableListElements.iterator();

        // Here, if the separator is a comma, for example, it's either:
        // "item1 and item2" or "item1,item2" (if no "and" is desired)
        // because "item1, and item2" doesn't make sense grammatically, which is
        // what would happen if we didn't treat this as a special case
        return toCase(iterator.next().toString() + (hasAnd ? " and " : separator) + iterator.next().toString(),
                letterCase);
    }

    final StringBuilder s = new StringBuilder();

    for (final T element : printableListElements) {
        final String elementString = toCase(element.toString(), letterCase);

        s.append(elementString).append(separator);
    }

    try {
        // Delete the extra comma at the end of the last element in the list.
        s.delete(s.length() - separator.length(), s.length());

        if (hasAnd && s.lastIndexOf(separator) >= 0) {
            // Insert the word 'and' between the last two elements in the list,
            // after the last comma.
            s.insert(s.lastIndexOf(separator) + 1, "and ");
        }
    } catch (final StringIndexOutOfBoundsException ignored) {
    }

    return s.toString();
}

From source file:com.azaptree.services.command.http.WebXmlRequestCommand.java

public Optional<JAXBContext> getJaxbContext() {
    if (jaxbContext != null) {
        return Optional.of(jaxbContext);
    }// ww  w  . j a  v  a2  s  .  c o m

    if (hasXmlSchema()) {
        final Set<String> packageNames = new TreeSet<>();

        if (requestClass != null) {
            packageNames.add(requestClass.getPackage().getName());
        }

        if (responseClass != null) {
            packageNames.add(responseClass.getPackage().getName());
        }

        final StringBuilder sb = new StringBuilder(128);
        for (final String packageName : packageNames) {
            sb.append(packageName).append(':');
        }
        sb.delete(sb.length() - 1, sb.length());
        final String jaxbContextPath = sb.toString();
        log.info("jaxbContextPath : {}", jaxbContextPath);

        this.jaxbContext = JAXBContextCache.get(jaxbContextPath);
        return Optional.of(jaxbContext);
    }
    return Optional.absent();
}