Package org.apache.commons.lang3.text

Examples of org.apache.commons.lang3.text.StrBuilder

The aim has been to provide an API that mimics very closely what StringBuffer provides, but with additional methods. It should be noted that some edge cases, with invalid indices or null input, have been altered - see individual methods. The biggest of these changes is that by default, null will not output the text 'null'. This can be controlled by a property, {@link #setNullText(String)}.

Prior to 3.0, this class implemented Cloneable but did not implement the clone method so could not be used. From 3.0 onwards it no longer implements the interface. @since 2.2 @version $Id: StrBuilder.java 1153484 2011-08-03 13:39:42Z ggregory $


     */
    private String createIdPivotPrefix() {
        if(!isPivot()) {
            return "";
        }
        return new StrBuilder().appendWithSeparators(values, PIVOT_COLUMNS_SEPARATOR)
                .append(PIVOT_SCALAR_FUNCTION_SEPARATOR).toString();
    }
View Full Code Here


     */
    private String createLabelPivotPart() {
        if(!isPivot()) {
            return "";
        }
        return new StrBuilder().appendWithSeparators(values, PIVOT_COLUMNS_SEPARATOR).toString();
    }
View Full Code Here

     * The string returned does not contain the ORDER BY keywords.
     *
     * @return The query string.
     */
    public String toQueryString() {
        StrBuilder builder = new StrBuilder();
        List<String> stringList = Lists.newArrayList();
        for(ColumnSort colSort : sortColumns) {
            stringList.add(colSort.toQueryString());
        }
        builder.appendWithSeparators(stringList, ", ");
        return builder.toString();
    }
View Full Code Here

    public String getId() {
        List<String> colIds = Lists.newArrayList();
        for(AbstractColumn col : columns) {
            colIds.add(col.getId());
        }
        return new StrBuilder(scalarFunction.getFunctionName()).append(COLUMN_FUNCTION_TYPE_SEPARATOR)
                .appendWithSeparators(colIds, COLUMN_COLUMN_SEPARATOR).toString();
    }
View Full Code Here

    public String toString() {
        List<String> colNames = Lists.newArrayList();
        for(AbstractColumn col : columns) {
            colNames.add(col.toString());
        }
        return new StrBuilder(scalarFunction.getFunctionName()).append("(")
                .appendWithSeparators(colNames, COLUMN_COLUMN_SEPARATOR).append(")").toString();
    }
View Full Code Here

        QuerySelection querySelection = new QuerySelection();
        querySelection.addColumn(new SimpleColumn("ID"));
        querySelection.addColumn(
                new AggregationColumn(new SimpleColumn("Salary"), AggregationType.MIN));
        query.setSelection(querySelection);
        StrBuilder queryStringBuilder = new StrBuilder();
        SqlDataSourceHelper.appendSelectClause(query, queryStringBuilder);
        assertEquals(queryStringBuilder.toString(), "SELECT `ID`, min(`Salary`) ",
                queryStringBuilder.toString());
    }
View Full Code Here

     * Tests the building of the SQL query FROM clause from the Gviz query.
     */
    public void testBuildFromClause() throws DataSourceException {
        Query query = new Query();

        StrBuilder queryStringBuilder = new StrBuilder();
        SqlDataSourceHelper.appendFromClause(query, queryStringBuilder, "Employee");
        assertEquals(queryStringBuilder.toString(), "FROM Employee ",
                queryStringBuilder.toString());
    }
View Full Code Here

        subFiltersList3.add(queryCompoundFilter1);
        subFiltersList3.add(queryCompoundFilter2);
        QueryFilter queryCompoundFilter3 =
                new CompoundFilter(CompoundFilter.LogicalOperator.OR, subFiltersList3);
        query.setFilter(queryCompoundFilter3);
        StrBuilder queryStringBuilder = new StrBuilder();
        SqlDataSourceHelper.appendWhereClause(query, queryStringBuilder);
        assertEquals(queryStringBuilder.toString(),
                "WHERE (((`ID`=`Salary`) AND (`ID`>=1.0)) OR ((`Fname` LIKE \"Mi%\") "
                        + "AND (`Lname` LIKE \"%SH%\") AND (`Lname` LIKE \"%tz\"))) ",
                queryStringBuilder.toString());

        // Check empty compound filters.
        List<QueryFilter> subFiltersList4 = Lists.newArrayList();
        QueryFilter queryCompoundFilter4 =
                new CompoundFilter(CompoundFilter.LogicalOperator.OR, subFiltersList4);
        query.setFilter(queryCompoundFilter4);
        queryStringBuilder = new StrBuilder();
        SqlDataSourceHelper.appendWhereClause(query, queryStringBuilder);
        assertEquals(queryStringBuilder.toString(), "WHERE false ");
        QueryFilter queryCompoundFilter5 =
                new CompoundFilter(CompoundFilter.LogicalOperator.AND, subFiltersList4);
        query.setFilter(queryCompoundFilter5);
        queryStringBuilder = new StrBuilder();
        SqlDataSourceHelper.appendWhereClause(query, queryStringBuilder);
        assertEquals(queryStringBuilder.toString(), "WHERE true ");

        // Check compound filter with one sub-filter.
        List<QueryFilter> subFiltersList6 = Lists.newArrayList(
                (QueryFilter) new ColumnColumnFilter(new SimpleColumn("ID"),
                        new SimpleColumn("Salary"), ComparisonFilter.Operator.EQ));
        QueryFilter queryCompoundFilter6 =
                new CompoundFilter(CompoundFilter.LogicalOperator.OR, subFiltersList6);
        query.setFilter(queryCompoundFilter6);
        queryStringBuilder = new StrBuilder();
        SqlDataSourceHelper.appendWhereClause(query, queryStringBuilder);
        assertEquals(queryStringBuilder.toString(), "WHERE ((`ID`=`Salary`)) ",
                queryStringBuilder.toString());

        // Check "is null".
        ColumnIsNullFilter isNullFilter = new ColumnIsNullFilter(new SimpleColumn("ID"));
        query.setFilter(isNullFilter);
        queryStringBuilder = new StrBuilder();
        SqlDataSourceHelper.appendWhereClause(query, queryStringBuilder);
        assertEquals("WHERE (`ID` IS NULL) ", queryStringBuilder.toString());

        // Check negation.
        NegationFilter negationFilter =
                new NegationFilter(new ColumnColumnFilter(new SimpleColumn("ID"),
                        new SimpleColumn("Salary"), ComparisonFilter.Operator.EQ));
        query.setFilter(negationFilter);
        queryStringBuilder = new StrBuilder();
        SqlDataSourceHelper.appendWhereClause(query, queryStringBuilder);
        assertEquals("WHERE (NOT (`ID`=`Salary`)) ", queryStringBuilder.toString());
    }
View Full Code Here

        Query query = new Query();
        QueryGroup queryGroup = new QueryGroup();
        queryGroup.addColumn(new SimpleColumn("ID"));
        queryGroup.addColumn(new SimpleColumn("FNAME"));
        query.setGroup(queryGroup);
        StrBuilder queryStringBuilder = new StrBuilder();
        SqlDataSourceHelper.appendGroupByClause(query, queryStringBuilder);
        assertEquals("GROUP BY `ID`, `FNAME` ", queryStringBuilder.toString());
    }
View Full Code Here

                new AggregationColumn(new SimpleColumn("ID"), AggregationType.COUNT);
        SimpleColumn column2 = new SimpleColumn("FNAME");
        querySort.addSort(column1, SortOrder.DESCENDING);
        querySort.addSort(column2, SortOrder.ASCENDING);
        query.setSort(querySort);
        StrBuilder queryStringBuilder = new StrBuilder();
        SqlDataSourceHelper.appendOrderByClause(query, queryStringBuilder);
        assertEquals(queryStringBuilder.toString(),
                "ORDER BY count(`ID`) DESC, `FNAME` ",
                queryStringBuilder.toString());
    }
View Full Code Here

TOP

Related Classes of org.apache.commons.lang3.text.StrBuilder

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.