Example usage for org.apache.commons.lang StringUtils abbreviate

List of usage examples for org.apache.commons.lang StringUtils abbreviate

Introduction

In this page you can find the example usage for org.apache.commons.lang StringUtils abbreviate.

Prototype

public static String abbreviate(String str, int maxWidth) 

Source Link

Document

Abbreviates a String using ellipses.

Usage

From source file:org.apache.tajo.client.TajoAdmin.java

private void processList(Writer writer) throws ParseException, IOException, ServiceException, SQLException {
    tajoClient = TajoHAClientUtil.getTajoClient(tajoConf, tajoClient);
    List<BriefQueryInfo> queryList = tajoClient.getRunningQueryList();
    SimpleDateFormat df = new SimpleDateFormat(DATE_FORMAT);
    StringBuilder builder = new StringBuilder();

    /* print title */
    builder.append(StringUtils.rightPad("QueryId", 21));
    builder.append(StringUtils.rightPad("State", 20));
    builder.append(StringUtils.rightPad("StartTime", 20));
    builder.append(StringUtils.rightPad("Query", 30)).append("\n");

    builder.append(StringUtils.rightPad(StringUtils.repeat("-", 20), 21));
    builder.append(StringUtils.rightPad(StringUtils.repeat("-", 19), 20));
    builder.append(StringUtils.rightPad(StringUtils.repeat("-", 19), 20));
    builder.append(StringUtils.rightPad(StringUtils.repeat("-", 29), 30)).append("\n");
    writer.write(builder.toString());/*  w  ww  . ja  v a 2s. c  om*/

    builder = new StringBuilder();
    for (BriefQueryInfo queryInfo : queryList) {
        builder.append(StringUtils.rightPad(new QueryId(queryInfo.getQueryId()).toString(), 21));
        builder.append(StringUtils.rightPad(queryInfo.getState().name(), 20));
        builder.append(StringUtils.rightPad(df.format(queryInfo.getStartTime()), 20));
        builder.append(StringUtils.abbreviate(queryInfo.getQuery(), 30)).append("\n");
    }
    writer.write(builder.toString());
}

From source file:org.apache.tinkerpop.gremlin.process.traversal.util.DefaultTraversalMetrics.java

private void appendMetrics(final Collection<? extends Metrics> metrics, final StringBuilder sb,
        final int indent) {
    // Append each StepMetric's row. indexToLabelMap values are ordered by index.
    for (Metrics m : metrics) {
        String rowName = m.getName();

        // Handle indentation
        for (int ii = 0; ii < indent; ii++) {
            rowName = "  " + rowName;
        }//w  w w.j a va  2  s.co  m
        // Abbreviate if necessary
        rowName = StringUtils.abbreviate(rowName, 50);

        // Grab the values
        final Long itemCount = m.getCount(ELEMENT_COUNT_ID);
        final Long traverserCount = m.getCount(TRAVERSER_COUNT_ID);
        Double percentDur = (Double) m.getAnnotation(PERCENT_DURATION_KEY);

        // Build the row string

        sb.append(String.format("%n%-50s", rowName));

        if (itemCount != null) {
            sb.append(String.format(" %21d", itemCount));
        } else {
            sb.append(String.format(" %21s", ""));
        }

        if (traverserCount != null) {
            sb.append(String.format(" %11d", traverserCount));
        } else {
            sb.append(String.format(" %11s", ""));
        }

        sb.append(String.format(" %15.3f", m.getDuration(TimeUnit.MICROSECONDS) / 1000.0));

        if (percentDur != null) {
            sb.append(String.format(" %8.2f", percentDur));
        }

        appendMetrics(m.getNested(), sb, indent + 1);
    }
}

From source file:org.apache.tinkerpop.gremlin.process.util.metric.StandardTraversalMetrics.java

private void appendMetrics(final Collection<? extends Metrics> metrics, final StringBuilder sb,
        final int indent) {
    // Append each StepMetric's row. indexToLabelMap values are ordered by index.
    for (Metrics m : metrics) {
        String rowName = m.getName();
        for (int ii = 0; ii < indent; ii++) {
            rowName = "  " + rowName;
        }/*from   ww  w . ja v  a 2 s. c o m*/
        rowName = StringUtils.abbreviate(rowName, 50);
        final long itemCount = m.getCount(TraversalMetrics.ELEMENT_COUNT_ID);
        final long traverserCount = m.getCount(TraversalMetrics.TRAVERSER_COUNT_ID);

        Double percentDur = (Double) m.getAnnotation(TraversalMetrics.PERCENT_DURATION_KEY);
        if (percentDur != null) {
            sb.append(String.format("%n%-50s %21d %11d %15.3f %8.2f", rowName, itemCount, traverserCount,
                    m.getDuration(TimeUnit.MICROSECONDS) / 1000.0, percentDur));
        } else {
            sb.append(String.format("%n%-50s %21d %11d %15.3f", rowName, itemCount, traverserCount,
                    m.getDuration(TimeUnit.MICROSECONDS) / 1000.0));
        }
        appendMetrics(m.getNested(), sb, indent + 1);
    }
}

From source file:org.apache.tinkerpop.gremlin.structure.util.StringFactory.java

/**
 * Construct the representation for a {@link org.apache.tinkerpop.gremlin.structure.Property} or {@link org.apache.tinkerpop.gremlin.structure.VertexProperty}.
 *//*from  w  w  w .  j  a va  2 s  .com*/
public static String propertyString(final Property property) {
    if (property instanceof VertexProperty) {
        if (!property.isPresent())
            return EMPTY_VERTEX_PROPERTY;
        final String valueString = String.valueOf(property.value());
        return VP + L_BRACKET + property.key() + ARROW + StringUtils.abbreviate(valueString, 20) + R_BRACKET;
    } else {
        if (!property.isPresent())
            return EMPTY_PROPERTY;
        final String valueString = String.valueOf(property.value());
        return P + L_BRACKET + property.key() + ARROW + StringUtils.abbreviate(valueString, 20) + R_BRACKET;
    }
}

From source file:org.apache.usergrid.chop.webapp.view.chart.format.Format.java

public static String formatCategories(Set<String> categories) {

    String s = "";

    for (String category : categories) {
        if (!s.isEmpty()) {
            s += ", ";
        }/*from   www. jav a2  s .  com*/

        s += String.format("'%s'", StringUtils.abbreviate(category, 10));
    }

    return String.format("[%s]", s);
}

From source file:org.apache.usergrid.chop.webapp.view.chart.layout.IterationsChartLayout.java

private String firstMessages(JSONArray arr) {

    String s = "";
    int len = Math.min(5, arr.length());

    for (int i = 0; i < len; i++) {
        JSONObject json = JsonUtil.get(arr, i);

        s += "* " + StringUtils.abbreviate(json.optString("message"), 200) + "\n"
                + StringUtils.abbreviate(json.optString("trace"), 500) + "\n\n";
    }//from  w w w  .  j  av  a  2s .co m

    return s;
}

From source file:org.apache.usergrid.chop.webapp.view.chart.layout.OverviewChartLayout.java

@Override
protected void pointClicked(JSONObject json) throws JSONException {
    super.pointClicked(json);

    String caption = "Commit: " + StringUtils.abbreviate(json.getString("commitId"), 10);
    nextChartButton.setCaption(caption);
}

From source file:org.apache.usergrid.chop.webapp.view.chart.layout.RunsChartLayout.java

@Override
protected void handleBreadcrumb() {
    String caption = "Commit: " + StringUtils.abbreviate(params.getCommitId(), 10);
    config.getBreadcrumb().setItem(this, caption, 1);
}

From source file:org.apache.usergrid.chop.webapp.view.runner.RunnersLayout.java

private void addGroup(RunnerGroup group, Table runnersTable) {

    Module module = moduleDao.get(group.getModuleId());

    if (module == null) {
        return;/* w w  w. jav  a 2s  .  co  m*/
    }

    String caption = String.format("%s / %s / %s: commit[%s], user[%s]", module.getGroupId(),
            module.getArtifactId(), module.getVersion(), StringUtils.abbreviate(group.getCommitId(), 10),
            group.getUser());

    accordion.addTab(runnersTable, caption);
}

From source file:org.batoo.jpa.core.impl.criteria.QueryImpl.java

private void dumpResultSet() throws SQLException {
    final int[] lengths = new int[this.labels.length];
    for (int i = 0; i < lengths.length; i++) {
        lengths[i] = this.max(lengths[i], StringUtils.length(this.labels[i]));
    }/*from  w  w w. j a  v  a  2  s  .  com*/

    for (final Object[] data : this.data) {
        for (int i = 0; i < this.labels.length; i++) {
            final Object value = data[i];
            if (value != null) {
                lengths[i] = this.max(lengths[i], StringUtils.length(value.toString()));
            }
        }
    }

    int length = 1;
    for (final int l : lengths) {
        length += l + 3;
    }

    final StringBuffer dump = new StringBuffer("Query returned {0} row(s):\n");

    // the labels
    dump.append(StringUtils.repeat("-", length));
    dump.append("\n| ");

    for (int i = 0; i < this.labels.length; i++) {
        String strValue = StringUtils.abbreviate(this.labels[i], lengths[i]);
        strValue = StringUtils.rightPad(strValue, lengths[i]);

        dump.append(strValue);
        dump.append(" | ");
    }

    // the data
    dump.append("\n");
    dump.append(StringUtils.repeat("-", length));

    for (final Object[] data : this.data) {
        dump.append("\n| ");

        for (int i = 0; i < this.labels.length; i++) {
            final Object value = data[i];

            String strValue = value != null ? value.toString() : "!NULL!";
            strValue = StringUtils.abbreviate(strValue, lengths[i]);
            if (value instanceof Number) {
                strValue = StringUtils.leftPad(strValue, lengths[i]);
            } else {
                strValue = StringUtils.rightPad(strValue, lengths[i]);
            }

            dump.append(strValue);
            dump.append(" | ");
        }

    }

    dump.append("\n");
    dump.append(StringUtils.repeat("-", length));

    QueryImpl.LOG.debug(dump.toString(), this.data.size());
}