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:eu.stork.peps.auth.commons.PersonalAttributeList.java

/**
 * Creates a string in the following format.
 * //w w  w .  ja v a  2  s .co  m
 * attrName:attrType:[attrValue1,attrValue2=attrComplexValue]:attrStatus;
 * 
 * @return {@inheritDoc}
 */
@Override
public String toString() {
    final Iterator<Entry<String, PersonalAttribute>> itAttrs = this.entrySet().iterator();
    final StringBuilder strBuilder = new StringBuilder();

    while (itAttrs.hasNext()) {
        final Entry<String, PersonalAttribute> attrEntry = itAttrs.next();
        final PersonalAttribute attr = attrEntry.getValue();
        //strBuilder.append(attr.toString());
        strBuilder.insert(0, attr.toString());
    }

    return strBuilder.toString();
}

From source file:org.syncope.core.persistence.dao.impl.UserSearchDAOImpl.java

@Override
public boolean matches(final SyncopeUser user, final NodeCond searchCondition) {

    List<Object> parameters = Collections.synchronizedList(new ArrayList<Object>());

    // 1. get the query string from the search condition
    StringBuilder queryString = getQuery(searchCondition, parameters);

    // 2. take into account the passed user
    queryString.insert(0, "SELECT u.user_id FROM (");
    queryString.append(") u WHERE user_id=?").append(setParameter(parameters, user.getId()));

    // 3. prepare the search query
    Query query = entityManager.createNativeQuery(queryString.toString());

    // 4. populate the search query with parameter values
    fillWithParameters(query, parameters);

    // 5. executes query
    List<SyncopeUser> result = query.getResultList();

    return !result.isEmpty();
}

From source file:com.ace.erp.service.sys.impl.ResourceServiceImpl.java

/**
 * ?  ? :?//from www  . j  a v a 2  s.  co m
 *
 * @param resource
 * @return
 */
public String findActualResourceIdentity(Resource resource) {

    if (resource == null) {
        return null;
    }

    StringBuilder s = new StringBuilder(resource.getIdentity());

    boolean hasResourceIdentity = !StringUtils.isEmpty(resource.getIdentity());

    Resource parent = resourceMapper.getOne(resource.getParentId());
    while (parent != null) {
        if (!StringUtils.isEmpty(parent.getIdentity())) {
            s.insert(0, parent.getIdentity() + ":");
            hasResourceIdentity = true;
        }
        parent = resourceMapper.getOne(parent.getParentId());
    }

    // ?  
    if (!hasResourceIdentity) {
        return "";
    }

    //?: ??
    int length = s.length();
    if (length > 0 && s.lastIndexOf(":") == length - 1) {
        s.deleteCharAt(length - 1);
    }

    //? ?*
    /**
     boolean hasChildren = false;
     for (Resource r : resourceMapper.getList()) {
     if (resource.getId().equals(r.getParentId())) {
     hasChildren = true;
     break;
     }
     }
     **/

    if (resource.isHasChildren()) {
        s.append(":*");
    }

    return s.toString();
}

From source file:com.google.visualization.datasource.render.JsonRenderer.java

/**
 * Appends a Json representing a cell to the string buffer.
 *
 * @param cell The cell to write Json for.
 * @param sb The string buffer to append to.
 * @param includeFormatting Flase if formatting information should be omitted from the json.
 * @param isLastColumn Is this the last column in the row.
 * @param renderDateAsDateConstructor True -> date constructor, False -> date string.
 *     True if date values should be rendered into the json string as a call to
 *     Date object constructor (usually used when rendering jsonp string). 
 *     False if it should should be rendered as string.
 *     For example, when rendering the date 1/1/2011 as Date object constructor its value
 *     in the json string will be new Date(2011,1,1), and when rendered as string
 *     will be "Date(2011,1,1)". For further explanation, see class comment.
 *
 * @return The input string builder.//from   w w w. jav  a2  s. c o m
 */
static StringBuilder appendCellJson(TableCell cell, StringBuilder sb, boolean includeFormatting,
        boolean isLastColumn, boolean renderDateAsDateConstructor) {
    Value value = cell.getValue();
    ValueType type = cell.getType();
    StringBuilder valueJson = new StringBuilder();
    GregorianCalendar calendar;
    String escapedFormattedString = "";
    boolean isJsonNull = false;

    // Prepare a Json string representing the current value.
    DateValue dateValue;
    TimeOfDayValue timeOfDayValue;
    if ((value == null) || (value.isNull())) {
        valueJson.append("null");
        isJsonNull = true;
    } else {
        switch (type) {
        case BOOLEAN:
            valueJson.append(((BooleanValue) value).getValue());
            break;
        case DATE:
            valueJson.append("Date(");
            dateValue = (DateValue) value;
            valueJson.append(dateValue.getYear()).append(",");
            valueJson.append(dateValue.getMonth()).append(",");
            valueJson.append(dateValue.getDayOfMonth());
            valueJson.append(")");
            if (renderDateAsDateConstructor) {
                // Rendering date as a call to Date constructor, e.g new Date(2011,1,1)
                valueJson.insert(0, "new ");
            } else {
                // Rendering date in string format, e.g "Date(2011,1,1)"
                valueJson.insert(0, "\"");
                valueJson.append("\"");
            }
            break;
        case NUMBER:
            valueJson.append(((NumberValue) value).getValue());
            break;
        case TEXT:
            valueJson.append("\"");
            valueJson.append(EscapeUtil.jsonEscape(value.toString()));
            valueJson.append("\"");
            break;
        case TIMEOFDAY:
            valueJson.append("[");
            timeOfDayValue = (TimeOfDayValue) value;
            valueJson.append(timeOfDayValue.getHours()).append(",");
            valueJson.append(timeOfDayValue.getMinutes()).append(",");
            valueJson.append(timeOfDayValue.getSeconds()).append(",");
            valueJson.append(timeOfDayValue.getMilliseconds());
            valueJson.append("]");
            break;
        case DATETIME:
            calendar = ((DateTimeValue) value).getCalendar();
            valueJson.append("Date(");
            valueJson.append(calendar.get(GregorianCalendar.YEAR)).append(",");
            valueJson.append(calendar.get(GregorianCalendar.MONTH)).append(",");
            valueJson.append(calendar.get(GregorianCalendar.DAY_OF_MONTH));
            valueJson.append(",");
            valueJson.append(calendar.get(GregorianCalendar.HOUR_OF_DAY));
            valueJson.append(",");
            valueJson.append(calendar.get(GregorianCalendar.MINUTE)).append(",");
            valueJson.append(calendar.get(GregorianCalendar.SECOND));
            valueJson.append(")");
            if (renderDateAsDateConstructor) {
                // Rendering date as a call to Date constructor, e.g new Date(2011,1,1,0,0,0)
                valueJson.insert(0, "new ");
            } else {
                // Rendering date in string format, e.g "Date(2011,1,1,0,0,0)"
                valueJson.insert(0, "\"");
                valueJson.append("\"");
            }
            break;
        default:
            throw new IllegalArgumentException("Illegal value Type " + type);
        }
    }

    // Prepare an escaped string representing the current formatted value.
    String formattedValue = cell.getFormattedValue();
    if ((value != null) && !value.isNull() && (formattedValue != null)) {
        escapedFormattedString = EscapeUtil.jsonEscape(formattedValue);
        // Check for a value of type TEXT if the formatted value equals
        // its ordinary toString.
        if ((type == ValueType.TEXT) && value.toString().equals(formattedValue)) {
            escapedFormattedString = "";
        }
    }

    // Add a Json for this cell. And,
    // 1) If the formatted value is empty drop it.
    // 2) If the value is null, and it is not the last column in the row drop the entire Json.
    if ((isLastColumn) || (!isJsonNull)) {
        sb.append("{");
        // Value
        sb.append("\"v\":").append(valueJson);
        // Formatted value
        if ((includeFormatting) && (!escapedFormattedString.equals(""))) {
            sb.append(",\"f\":\"").append(escapedFormattedString).append("\"");
        }
        String customPropertiesString = getPropertiesMapString(cell.getCustomProperties());
        if (customPropertiesString != null) {
            sb.append(",\"p\":").append(customPropertiesString);
        }
        sb.append("}");
    }
    return sb;
}

From source file:org.mcxiaoke.commons.http.util.URIUtilsEx.java

/**
 * URLQuery??/*from   w w  w . j a v  a2s. c  om*/
 * 
 * @param url
 * @param parameters
 * @return
 */
public static String appendQueryParameters2(String url, final Map<String, String> parameters) {
    final StringBuilder urlBuilder = new StringBuilder();
    if (url == null || parameters == null || parameters.size() == 0) {
        return urlBuilder.toString();
    }

    for (Map.Entry<String, String> entry : parameters.entrySet()) {
        if (urlBuilder.length() > 0) {
            urlBuilder.append(PARAMETER_SEPARATOR);
        }
        urlBuilder.append(encode(entry.getKey()));
        urlBuilder.append(NAME_VALUE_SEPARATOR);
        urlBuilder.append(encode(entry.getValue()));
    }

    if (url.indexOf("?") < 0) {
        urlBuilder.insert(0, "?");
    } else {
        urlBuilder.insert(0, PARAMETER_SEPARATOR);
    }

    urlBuilder.insert(0, url);
    return urlBuilder.toString();
}

From source file:com.evolveum.polygon.connector.hcm.DocumentProcessing.java

public List<String> processAssignment(String attributeName, String attributeValue, String elementType,
        List<String> builderList) {

    if (START.equals(elementType)) {
        builderList.add(OPENINGBRACET);/*from w w w  .ja va 2 s. c  o m*/
        builderList.add(attributeName);
        builderList.add(SLASH);
        builderList.add(CLOSINGBRACET);
    } else if (END.equals(elementType)) {
        builderList.remove(builderList.size() - 3);

        builderList.add(OPENINGBRACET);
        builderList.add(SLASH);
        builderList.add(attributeName);
        builderList.add(CLOSINGBRACET);

    } else if (VALUE.equals(elementType)) {

        // if ("Assignment_Status_Type".equals(attributeName)) {
        //
        // if ("ACTIVE".equals(attributeValue)) {
        //
        // assigmentIsActive = true;
        // }
        //
        // }
        builderList.add(attributeValue);

    } else if (CLOSE.equals(elementType)) {
        StringBuilder buildEndTag = new StringBuilder(OPENINGBRACET).append(ASSIGNMENTTAG)
                .append(CLOSINGBRACET);

        builderList.add(0, buildEndTag.toString());
        buildEndTag.insert(1, SLASH);
        builderList.add(buildEndTag.toString());
    }
    return builderList;

}

From source file:org.syncope.core.persistence.dao.impl.UserSearchDAOImpl.java

@Override
public int count(final Set<Long> adminRoles, final NodeCond searchCondition) {

    List<Object> parameters = Collections.synchronizedList(new ArrayList<Object>());

    // 1. get the query string from the search condition
    StringBuilder queryString = getQuery(searchCondition, parameters);

    // 2. take into account administrative roles
    queryString.insert(0, "SELECT u.user_id FROM (");
    queryString.append(") u WHERE user_id NOT IN (");
    queryString.append(getAdminRolesFilter(adminRoles)).append(")");

    // 3. prepare the COUNT query
    queryString.insert(0, "SELECT COUNT(user_id) FROM (");
    queryString.append(") count_user_id");

    Query countQuery = entityManager.createNativeQuery(queryString.toString());
    fillWithParameters(countQuery, parameters);

    LOG.debug("Native count query\n{}\nwith parameters\n{}", queryString.toString(), parameters);

    int result = ((Number) countQuery.getSingleResult()).intValue();
    LOG.debug("Native count query result: {}", result);

    return result;
}

From source file:com.ace.console.service.sys.impl.ResourceServiceImpl.java

/**
 * ?  ? :?/*from  ww  w  . j  a  va2 s  . c o m*/
 *
 * @param resource
 * @return
 */
public String findActualResourceIdentity(Resources resource) {

    if (resource == null) {
        return null;
    }

    StringBuilder s = new StringBuilder(resource.getIdentity());

    boolean hasResourceIdentity = !StringUtils.isEmpty(resource.getIdentity());

    Resources parent = selectById(resource.getParentId());
    while (parent != null) {
        if (!StringUtils.isEmpty(parent.getIdentity())) {
            s.insert(0, parent.getIdentity() + ":");
            hasResourceIdentity = true;
        }
        parent = selectById(parent.getParentId());
    }

    // ?  
    if (!hasResourceIdentity) {
        return "";
    }

    //?: ??
    int length = s.length();
    if (length > 0 && s.lastIndexOf(":") == length - 1) {
        s.deleteCharAt(length - 1);
    }

    //? ?*
    /**
     boolean hasChildren = false;
     for (Resources r : resourcesMapper.getList()) {
     if (resource.getId().equals(r.getParentId())) {
     hasChildren = true;
     break;
     }
     }
     **/

    if (resource.isHasChildren()) {
        s.append(":*");
    }

    return s.toString();
}

From source file:com.trendmicro.hdfs.webdav.HDFSResource.java

@Override
public String getHref() {
    StringBuilder sb = new StringBuilder();
    Path p = this.path;
    while (p != null && !("".equals(p.getName()))) {
        sb.insert(0, p.getName());
        sb.insert(0, "/");
        p = p.getParent();/*from   w ww .j  av  a 2s  .  c om*/
    }
    if (sb.length() == 0) {
        sb.insert(0, "/");
    }
    return sb.toString();
}

From source file:com.github.jknack.handlebars.server.HbsServlet.java

/**
 * Deal with a {@link HandlebarsException}.
 *
 * @param ex The handlebars exception./* w w w  . ja va  2s.c o  m*/
 * @param request The http request.
 * @param response The http response.
 * @throws IOException If something goes wrong.
 */
private void jsonError(final JsonParseException ex, final HttpServletRequest request,
        final HttpServletResponse response) throws IOException {

    Map<String, Object> root = new HashMap<String, Object>();
    Map<String, Object> error = new HashMap<String, Object>();
    String filename = jsonFilename(request);
    JsonLocation location = ex.getLocation();
    String reason = ex.getMessage();
    int atIdx = reason.lastIndexOf(" at ");
    if (atIdx > 0) {
        reason = reason.substring(0, atIdx);
    }
    error.put("filename", filename);
    error.put("line", location.getLineNr());
    error.put("column", location.getColumnNr());
    error.put("reason", reason);
    error.put("type", "JSON error");
    String json = read(filename);
    StringBuilder evidence = new StringBuilder();
    int i = (int) location.getCharOffset();
    int nl = 0;
    while (i >= 0 && nl < 2) {
        char ch = json.charAt(i);
        if (ch == '\n') {
            nl++;
        }
        evidence.insert(0, ch);
        i--;
    }
    i = (int) location.getCharOffset() + 1;
    nl = 0;
    while (i < json.length() && nl < 2) {
        char ch = json.charAt(i);
        if (ch == '\n') {
            nl++;
        }
        evidence.append(ch);
        i++;
    }
    error.put("evidence", evidence);

    root.put("error", error);
    int firstLine = Math.max(1, ex.getLocation().getLineNr() - 1);
    fancyError(root, firstLine, "JScript", response);
}