Example usage for org.apache.commons.lang3.text StrBuilder delete

List of usage examples for org.apache.commons.lang3.text StrBuilder delete

Introduction

In this page you can find the example usage for org.apache.commons.lang3.text StrBuilder delete.

Prototype

public StrBuilder delete(final int startIndex, int endIndex) 

Source Link

Document

Deletes the characters between the two specified indices.

Usage

From source file:net.radai.beanz.codecs.CollectionCodec.java

@Override
public String encode(Object object) {
    if (object == null) {
        return null;
    }/*from   www  . ja v a 2s  .  co  m*/
    if (!ReflectionUtil.isCollection(object.getClass())) {
        throw new IllegalArgumentException();
    }
    Collection<?> collection = (Collection<?>) object;
    if (collection.isEmpty()) {
        return "[]";
    }
    StrBuilder sb = new StrBuilder();
    sb.append("[");
    for (Object element : collection) {
        sb.append(elementCodec.encode(element)).append(", ");
    }
    sb.delete(sb.length() - 2, sb.length()); //last ", "
    sb.append("]");
    return sb.toString();
}

From source file:net.radai.beanz.codecs.ArrayCodec.java

@Override
public String encode(Object object) {
    if (object == null) {
        return null;
    }//from  w ww. j  a  v  a2s  .  co  m
    if (!ReflectionUtil.isArray(object.getClass())) {
        throw new IllegalArgumentException();
    }
    int size = Array.getLength(object);
    if (size == 0) {
        return "[]";
    }
    StrBuilder sb = new StrBuilder();
    sb.append("[");
    for (int i = 0; i < size; i++) {
        Object element = Array.get(object, i);
        String encoded = elementCodec.encode(element);
        sb.append(encoded).append(", ");
    }
    sb.delete(sb.length() - 2, sb.length()); //last ", "
    sb.append("]");
    return sb.toString();
}

From source file:net.radai.beanz.codecs.MapCodec.java

@Override
public String encode(Object object) {
    if (object == null) {
        return null;
    }/*w ww  .j  ava 2s . co m*/
    if (!ReflectionUtil.isMap(object.getClass())) {
        throw new IllegalArgumentException();
    }
    Map<?, ?> map = (Map) object;
    if (map.isEmpty()) {
        return "{}";
    }
    StrBuilder sb = new StrBuilder();
    sb.append("{");
    for (Map.Entry<?, ?> entry : map.entrySet()) {
        sb.append(keyCodec.encode(entry.getKey())).append("=").append(valueCodec.encode(entry.getValue()))
                .append(", ");
    }
    sb.delete(sb.length() - 2, sb.length()); //last ", "
    sb.append("}");
    return sb.toString();
}

From source file:com.hotpot.commons.pagination.PageHelper.java

/**
 * MappedStatement?????.//from www .jav a 2  s .c  o m
 *
 * @param ms the ms
 * @param newSqlSource the new sql source
 * @return the mapped statement
 */
private MappedStatement newMappedStatement(MappedStatement ms, SqlSource newSqlSource) {
    MappedStatement.Builder builder = new MappedStatement.Builder(ms.getConfiguration(),
            ms.getId() + "_PageHelper", newSqlSource, ms.getSqlCommandType());
    builder.resource(ms.getResource());
    builder.fetchSize(ms.getFetchSize());
    builder.statementType(ms.getStatementType());
    builder.keyGenerator(ms.getKeyGenerator());
    if (ms.getKeyProperties() != null && ms.getKeyProperties().length != 0) {
        StrBuilder keyProperties = new StrBuilder();
        for (String keyProperty : ms.getKeyProperties()) {
            keyProperties.append(keyProperty).append(",");
        }
        keyProperties.delete(keyProperties.length() - 1, keyProperties.length());
        builder.keyProperty(keyProperties.toString());
    }
    builder.timeout(ms.getTimeout());
    builder.parameterMap(ms.getParameterMap());
    //resultMaps?int??resultMap - ?
    List<ResultMap> resultMaps = new ArrayList<ResultMap>();
    ResultMap resultMap = new ResultMap.Builder(ms.getConfiguration(), ms.getId(), int.class,
            EMPTY_RESULTMAPPING).build();
    resultMaps.add(resultMap);
    builder.resultMaps(resultMaps);
    builder.resultSetType(ms.getResultSetType());
    builder.cache(ms.getCache());
    builder.flushCacheRequired(ms.isFlushCacheRequired());
    builder.useCache(ms.isUseCache());

    return builder.build();
}