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:lcmc.gui.resources.ServiceInfo.java

/**
 * Returns a name of the service with id in the parentheses.
 * It adds prefix 'new' if id is null./*from   w  ww . j av  a2  s  .co m*/
 */
@Override
public String toString() {
    final StringBuilder s = new StringBuilder(30);
    final String provider = resourceAgent.getProvider();
    if (!ResourceAgent.HEARTBEAT_PROVIDER.equals(provider) && !"".equals(provider)) {
        s.append(provider);
        s.append(':');
    }
    s.append(getName());
    final String string = getService().getId();

    /* 'string' contains the last string if there are more dependent
     * resources, although there is usually only one. */
    if (string == null) {
        s.insert(0, "new ");
    } else {
        if (!"".equals(string)) {
            s.append(" (");
            s.append(string);
            s.append(')');
        }
    }
    return s.toString();
}

From source file:com.quinsoft.zencas.ZGLOBAL1_Operation.java

public int InsertOI_DataIntoTemplateFile(View view, View workView, String toFile, String fromFile,
        String stringRootEntityName) throws IOException {
    BufferedWriter bw;//  w ww . j  a  v  a  2  s.  c  o m
    StringBuilder sbInsertTemplate = new StringBuilder();
    StringBuilder sbRawTemplate = new StringBuilder();
    StringBuilder sbEntityBuffer;
    StringBuilder sbAttributeBuffer;
    String swapString = null;
    String stringStart = "{";
    String stringEnd = "}";
    int nRC = 0;
    int lSelectedCount = 0;
    int lTemplateLth = 0;

    nRC = SetCursorFirstEntity(workView, stringRootEntityName, "");
    while (nRC > zCURSOR_UNCHANGED) {
        lSelectedCount++;
        nRC = SetCursorNextEntity(workView, stringRootEntityName, "");
    }

    if (lSelectedCount <= 0)
        return 0;

    lTemplateLth = ReadFileDataIntoMemory(workView, fromFile, lTemplateLth, sbRawTemplate);

    if (lTemplateLth > Integer.MAX_VALUE)
        return 0;

    // File not found.
    if (lTemplateLth < 0)
        return -1;

    swapString = sbRawTemplate.substring(1, (lTemplateLth - 1));
    lTemplateLth = swapString.length();
    sbRawTemplate = new StringBuilder();

    nRC = SetCursorFirstEntity(workView, stringRootEntityName, "");
    while (nRC > zCURSOR_UNCHANGED) {
        sbRawTemplate.insert(0, swapString);

        for (int i = 0; i < sbRawTemplate.length(); i++) {
            sbEntityBuffer = new StringBuilder();
            sbAttributeBuffer = new StringBuilder();
            if (sbRawTemplate.charAt(i) == '[' && sbRawTemplate.charAt(i + 1) == 'Z') {
                int j = i;
                i += 2;
                while (sbRawTemplate.charAt(++i) != '.')
                    sbEntityBuffer.append(sbRawTemplate.charAt(i));

                while (sbRawTemplate.charAt(++i) != ']')
                    sbAttributeBuffer.append(sbRawTemplate.charAt(i));

                i++;
                sbRawTemplate.replace(j, i, GetStringFromAttribute(workView, sbEntityBuffer.toString(),
                        sbAttributeBuffer.toString()));

            }
        }

        sbInsertTemplate.append(sbRawTemplate);
        sbRawTemplate = new StringBuilder();
        nRC = SetCursorNextEntity(workView, stringRootEntityName, "");
    }

    sbInsertTemplate.insert(0, stringStart);
    sbInsertTemplate.append(stringEnd);

    bw = new BufferedWriter(new FileWriter(toFile));
    bw.write(sbInsertTemplate.toString());
    bw.flush();
    bw.close();

    return 0;
}

From source file:com.quinsoft.zeidon.vml.VmlOperation.java

protected static final void zmemset(StringBuilder sb, char c, int nLth) {
    int k;//  w  w  w. ja va2 s .c  o m

    for (k = 0; k < nLth; k++) {
        sb.insert(k, c);
    }
}

From source file:com.quinsoft.zeidon.vml.VmlOperation.java

protected static final void zmemset(StringBuilder sb, int nOffset, char c, int nLth) {
    int k;//from   w w w .java2s .co  m

    for (k = 0; k < nLth; k++) {
        sb.insert(k + nOffset, c);
    }
}

From source file:com.quinsoft.zeidon.vml.VmlOperation.java

protected static final int zstrncpy(StringBuilder sb, int nOffset, String s, int nLth) {
    int k;//from w w  w  .j a  va2 s. c om

    if (s.length() < nLth) {
        nLth = s.length();
    }

    for (k = 0; k < nLth; k++) {
        sb.insert(nOffset++, s.charAt(k));
    }

    return nOffset; // current used length of charBuffer
}

From source file:com.quinsoft.zeidon.vml.VmlOperation.java

protected static final int zstrcpy(StringBuilder sb, int nOffset, String s) {
    if (nOffset < sb.length()) {
        sb.setLength(nOffset);/*  ww w.j  av  a2  s  . co m*/
    }
    if (s != null) // insert unfortunately appends the string "null" if inserting a null string
    {
        sb.insert(nOffset, s);
    }

    return sb.length();
}

From source file:com.quinsoft.epamms.ZGlobal1_Operation.java

public int DecipherUsageKeyword(StringBuilder sbName, String openKey, String closeKey, StringBuilder sbKeyword,
        int keywordMaxLth, StringBuilder sbKeyValue, int keyValueMaxLth) {
    sbKeyword.setLength(0);//from www.  j a va 2 s.c  o m
    sbKeyValue.setLength(0);
    int nLth = openKey.length();
    int nPos1 = sbName.indexOf(openKey);
    if (nPos1 >= 0) {
        int nPos2 = sbName.indexOf(closeKey, nPos1 + nLth);
        if (nPos2 >= 0) {
            String key = sbName.substring(nPos1 + nLth, nPos2);
            sbName.delete(nPos1, nPos2 + closeKey.length());
            sbKeyValue.append("(" + key + ")");
            int nPos = key.indexOf(' ', nLth);
            if (nPos > 0 && nPos < key.length() - 1) // ignore if space is leading or trailing
            {
                key = key.substring(0, nPos) + "#";
            }
            sbKeyword.append(key);
            sbName.insert(nPos1, "{{" + key + "}}");
            return 0;
        }
    }
    return -1;
}

From source file:org.waarp.openr66.database.data.DbTaskRunner.java

/**
 * //from ww w.ja va 2  s.  co m
 * @param preparedStatement
 * @param srcrequest
 * @param limit
 * @param orderby
 * @param startid
 * @param stopid
 * @param start
 * @param stop
 * @param rule
 * @param req
 * @param pending
 * @param transfer
 * @param error
 * @param done
 * @param all
 * @return The DbPreparedStatement already prepared according to select or delete command
 * @throws WaarpDatabaseNoConnectionException
 * @throws WaarpDatabaseSqlException
 */
private static DbPreparedStatement getFilterCondition(DbPreparedStatement preparedStatement, String srcrequest,
        int limit, String orderby, String startid, String stopid, Timestamp start, Timestamp stop, String rule,
        String req, boolean pending, boolean transfer, boolean error, boolean done, boolean all)
        throws WaarpDatabaseNoConnectionException, WaarpDatabaseSqlException {
    String request = srcrequest;
    if (startid == null && stopid == null && start == null && stop == null && rule == null && req == null
            && all) {
        // finish
        if (limit > 0) {
            request = DbModelFactory.dbModel.limitRequest(selectAllFields, request + orderby, limit);
        } else {
            request = request + orderby;
        }
        preparedStatement.createPrepareStatement(request);
        return preparedStatement;
    }
    request += " WHERE ";
    StringBuilder scondition = new StringBuilder();
    boolean hasCondition = false;
    if (start != null & stop != null) {
        scondition.append(Columns.STARTTRANS.name()).append(" >= ? AND ").append(Columns.STARTTRANS.name())
                .append(" <= ? ");
        hasCondition = true;
    } else if (start != null) {
        scondition.append(Columns.STARTTRANS.name()).append(" >= ? ");
        hasCondition = true;
    } else if (stop != null) {
        scondition.append(Columns.STARTTRANS.name()).append(" <= ? ");
        hasCondition = true;
    }
    if (startid != null) {
        if (hasCondition) {
            scondition.append(" AND ");
        }
        hasCondition = true;
        scondition.append(Columns.SPECIALID.name()).append(" >= ? ");
    }
    if (stopid != null) {
        if (hasCondition) {
            scondition.append(" AND ");
        }
        hasCondition = true;
        scondition.append(Columns.SPECIALID.name()).append(" <= ? ");
    }
    if (rule != null) {
        if (hasCondition) {
            scondition.append(" AND ");
        }
        hasCondition = true;
        scondition.append(Columns.IDRULE.name()).append(" LIKE '%").append(rule).append("%' ");
    }
    if (req != null) {
        if (hasCondition) {
            scondition.append(" AND ");
        }
        hasCondition = true;
        scondition.append("( ").append(Columns.REQUESTED.name()).append(" LIKE '%").append(req).append("%' OR ")
                .append(Columns.REQUESTER.name()).append(" LIKE '%").append(req).append("%' )");
    }
    if (!all) {
        if (hasCondition) {
            scondition.append(" AND ");
        }
        hasCondition = true;
        scondition.append("( ");
        boolean hasone = false;
        if (pending) {
            scondition.append(Columns.UPDATEDINFO.name()).append(" = ").append(UpdatedInfo.TOSUBMIT.ordinal());
            hasone = true;
        }
        if (transfer) {
            if (hasone) {
                scondition.append(" OR ");
            }
            scondition.append("( ").append(Columns.UPDATEDINFO.name()).append(" = ")
                    .append(UpdatedInfo.RUNNING.ordinal()).append(" )");
            hasone = true;
        }
        if (error) {
            if (hasone) {
                scondition.append(" OR ");
            }
            scondition.append(Columns.GLOBALSTEP.name()).append(" = ").append(TASKSTEP.ERRORTASK.ordinal())
                    .append(" OR ").append(Columns.UPDATEDINFO.name()).append(" = ")
                    .append(UpdatedInfo.INERROR.ordinal()).append(" OR ").append(Columns.UPDATEDINFO.name())
                    .append(" = ").append(UpdatedInfo.INTERRUPTED.ordinal());
            hasone = true;
        }
        if (done) {
            if (hasone) {
                scondition.append(" OR ");
            }
            scondition.append(Columns.GLOBALSTEP.name()).append(" = ").append(TASKSTEP.ALLDONETASK.ordinal())
                    .append(" OR ").append(Columns.UPDATEDINFO.name()).append(" = ")
                    .append(UpdatedInfo.DONE.ordinal());
            hasone = true;
        }
        if (!hasone) {
            scondition.append(Columns.UPDATEDINFO.name()).append(" IS NOT NULL ");
        }
        scondition.append(" )");
    }
    if (limit > 0) {
        scondition.insert(0, request).append(orderby);
        request = scondition.toString();
        request = DbModelFactory.dbModel.limitRequest(selectAllFields, request, limit);
    } else {
        scondition.insert(0, request).append(orderby);
        request = scondition.toString();
    }
    preparedStatement.createPrepareStatement(request);
    int rank = 1;
    try {
        if (start != null & stop != null) {
            preparedStatement.getPreparedStatement().setTimestamp(rank, start);
            rank++;
            preparedStatement.getPreparedStatement().setTimestamp(rank, stop);
            rank++;
        } else if (start != null) {
            preparedStatement.getPreparedStatement().setTimestamp(rank, start);
            rank++;
        } else if (stop != null) {
            preparedStatement.getPreparedStatement().setTimestamp(rank, stop);
            rank++;
        }
        if (startid != null) {
            long value = DbConstant.ILLEGALVALUE;
            try {
                value = Long.parseLong(startid);
            } catch (NumberFormatException e) {
                // ignore then
            }
            preparedStatement.getPreparedStatement().setLong(rank, value);
            rank++;
        }
        if (stopid != null) {
            long value = Long.MAX_VALUE;
            try {
                value = Long.parseLong(stopid);
            } catch (NumberFormatException e) {
                // ignore then
            }
            preparedStatement.getPreparedStatement().setLong(rank, value);
            rank++;
        }
    } catch (SQLException e) {
        preparedStatement.realClose();
        throw new WaarpDatabaseSqlException(e);
    }
    return preparedStatement;
}

From source file:com.quinsoft.zeidon.vml.VmlOperation.java

public static int AppendPathSeparator(StringBuilder sbDirectoryName) {
    char pathSeparator = File.separatorChar;
    char replaceCharacter = pathSeparator == '/' ? '\\' : '/';
    String s = sbDirectoryName.toString();
    s = s.replace(replaceCharacter, pathSeparator);
    int nLth = s.length();
    sbDirectoryName.setLength(0); // Use sb.setLength( 0 ); to clear a string buffer.
    sbDirectoryName.append(s);//from w  ww. j  a v  a2 s  .  c  o m
    if (nLth > 1 && sbDirectoryName.charAt(nLth - 1) != pathSeparator) {
        sbDirectoryName.insert(nLth++, pathSeparator);
    }

    return nLth;
}

From source file:com.github.gekoh.yagen.ddl.CreateDDL.java

private String getHistTableSqlCreateString(Dialect dialect, String sqlCreateString, String histTableName,
        String histColName, Set<String> columns, List<String> pkCols, IntervalPartitioning livePartitioning) {
    checkTableName(dialect, histTableName);

    Matcher matcher = TBL_PATTERN.matcher(sqlCreateString);
    Matcher matchUnique = UNIQUE_PATTERN.matcher(sqlCreateString);

    StringBuilder sql = new StringBuilder();

    // try matching create table sql with PK definition
    if (!matcher.matches()) {
        matcher = TBL_PATTERN_WO_PK.matcher(sqlCreateString);

        // next try without PD definition (e.g. for CollectionTable)
        if (!matcher.matches()) {
            throw new IllegalStateException("cannot find create table in sql: " + sqlCreateString);
        }//w  ww . jav a 2s .  c  o m

        sql.append(sqlCreateString.substring(0, matcher.start(TBL_PATTERN_WO_PK_IDX_TBLNAME)))
                .append(histTableName);
        sql.append(sqlCreateString.substring(matcher.end(TBL_PATTERN_WO_PK_IDX_TBLNAME),
                matcher.end(TBL_PATTERN_WO_PK_IDX_BEFORE_COL_DEF)));
        sql.append(formatColumn(dialect, HIST_TABLE_PK_COLUMN_NAME + " ${varcharType} not null",
                Constants.UUID_LEN, null, null)).append(", ");
        sql.append(
                formatColumn(dialect, HIST_OPERATION_COLUMN_NAME + " ${varcharType} not null", 1, null, null))
                .append(", ");

        sql.append(sqlCreateString.substring(matcher.end(TBL_PATTERN_WO_PK_IDX_BEFORE_COL_DEF),
                matcher.start(TBL_PATTERN_WO_PK_IDX_AFTER_COL_DEF)));

        sql.append(", ");

        if (!columns.contains(histColName)) {
            sql.append(formatColumn(dialect, histColName + " ${timestampType} not null", null, null, null))
                    .append(", ");
        }

        sql.append("primary key (");
        sql.append(HIST_TABLE_PK_COLUMN_NAME).append("), ");

        sql.append("unique (");
        for (String columnName : pkCols) {
            sql.append(columnName).append(", ");
        }
        sql.append(histColName);
        sql.append(")");

        sql.append(sqlCreateString.substring(matcher.start(TBL_PATTERN_WO_PK_IDX_AFTER_COL_DEF)));
    } else {
        sql.append(sqlCreateString.substring(0, matcher.start(TBL_PATTERN_IDX_TBLNAME))).append(histTableName);
        sql.append(sqlCreateString.substring(matcher.end(TBL_PATTERN_IDX_TBLNAME),
                matcher.start(TBL_PATTERN_IDX_TBL_DEF)));
        sql.append(formatColumn(dialect, HIST_TABLE_PK_COLUMN_NAME + " ${varcharType} not null",
                Constants.UUID_LEN, null, null)).append(", ");
        sql.append(
                formatColumn(dialect, HIST_OPERATION_COLUMN_NAME + " ${varcharType} not null", 1, null, null))
                .append(", ");

        sql.append(sqlCreateString.substring(matcher.start(TBL_PATTERN_IDX_TBL_DEF),
                matcher.start(TBL_PATTERN_IDX_PK_CLAUSE)));

        if (!columns.contains(histColName)) {
            sql.append(formatColumn(dialect, histColName + " ${timestampType} not null", null, null, null))
                    .append(", ");
        }

        sql.append(sqlCreateString.substring(matcher.start(TBL_PATTERN_IDX_PK_CLAUSE),
                matcher.start(TBL_PATTERN_IDX_PK_COLLIST)));
        sql.append(HIST_TABLE_PK_COLUMN_NAME).append("), ");
        sql.append("unique (");
        sql.append(matcher.group(TBL_PATTERN_IDX_PK_COLLIST));
        sql.append(", ");
        sql.append(histColName);
        sql.append(")");

        int restIdx = matcher.end(TBL_PATTERN_IDX_PK_CLAUSE);
        while (matchUnique.find(restIdx)) {
            restIdx = matchUnique.end(1);
        }

        sql.append(sqlCreateString.substring(restIdx));
    }

    Matcher uniqueColMatcher = COL_PATTERN.matcher(sql.toString());
    int colIdx = 0;
    while (uniqueColMatcher.find(colIdx)) {
        String colName = TableConfig.getIdentifierForReference(uniqueColMatcher.group(COL_PATTERN_IDX_COLNAME));
        //                remove unique constraint from single column
        if (uniqueColMatcher.group(COL_PATTERN_IDX_UNIQUE) != null) {
            sql.delete(uniqueColMatcher.start(COL_PATTERN_IDX_UNIQUE),
                    uniqueColMatcher.end(COL_PATTERN_IDX_UNIQUE));
            colIdx = uniqueColMatcher.start();
            uniqueColMatcher = COL_PATTERN.matcher(sql.toString());
        }
        //                remove not null constraints
        else if (!colName.equals(HIST_OPERATION_COLUMN_NAME) && !colName.equals(histColName)
                && uniqueColMatcher.group(COL_PATTERN_IDX_NOT) != null) {
            sql.delete(uniqueColMatcher.start(COL_PATTERN_IDX_NOTNULL),
                    uniqueColMatcher.end(COL_PATTERN_IDX_NOTNULL));
            colIdx = uniqueColMatcher.start();
            uniqueColMatcher = COL_PATTERN.matcher(sql.toString());
        } else if (colName.equals(histColName)) {
            String addCol = ", " + HIST_INVALID_TIMESTAMP_COLUMN_NAME + " "
                    + uniqueColMatcher.group(COL_PATTERN_IDX_TYPE);
            sql.insert(uniqueColMatcher.end() - 1, addCol);
            colIdx = uniqueColMatcher.end() + addCol.length();
            uniqueColMatcher = COL_PATTERN.matcher(sql.toString());
        } else {
            colIdx = uniqueColMatcher.end();
        }
    }

    StringBuffer additionalObjects = new StringBuffer();

    if (supportsPartitioning(dialect) && livePartitioning != null) {
        sqlCreateString = addPartitioning(additionalObjects, livePartitioning, histTableName, sql.toString(),
                columns, pkCols);
    } else {
        sqlCreateString = sql.toString();
    }

    sqlCreateString = addConstraintsAndNames(dialect, additionalObjects, sqlCreateString,
            histTableName.toLowerCase(), null);
    //        not adding default values to history tables, this will make investigations very hard
    //        sqlCreateString = addDefaultValues(sqlCreateString, histTableName.toLowerCase());

    getProfile().duplex(ObjectType.TABLE, histTableName, sqlCreateString);

    return sqlCreateString + additionalObjects.toString();
}