~ubuntu-branches/ubuntu/vivid/eclipse-linuxtools/vivid-proposed

« back to all changes in this revision

Viewing changes to lttng/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/viewers/statistics/model/TmfStatisticsFormatter.java

  • Committer: Package Import Robot
  • Author(s): Jakub Adam, Jakub Adam, tony mancill
  • Date: 2014-10-11 11:44:05 UTC
  • mfrom: (1.2.4)
  • Revision ID: package-import@ubuntu.com-20141011114405-yazjvxfzzhmi5sgj
Tags: 3.1.0-1
[ Jakub Adam ]
* New upstream release (Closes: #761524).
* Refreshed d/patches.
* Don't build removed feature org.eclipse.linuxtools.tools.launch
  - merged into org.eclipse.linuxtools.profiling.
* Use javac target 1.7.
* Build new feature org.eclipse.linuxtools.dataviewers.feature
  - required by Valgrind integration.
* Build-depend on eclipse-remote-services-api and eclipse-cdt-autotools.
* Bump Standards-Version to 3.9.6.
* Override incompatible-java-bytecode-format - linuxtools needs Java 7.
* Remove unused codeless-jar override.

[ tony mancill ]
* Tweak short package description to make lintian happy.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*******************************************************************************
 
2
 * Copyright (c) 2011, 2013 Ericsson
 
3
 *
 
4
 * All rights reserved. This program and the accompanying materials are
 
5
 * made available under the terms of the Eclipse Public License v1.0 which
 
6
 * accompanies this distribution, and is available at
 
7
 * http://www.eclipse.org/legal/epl-v10.html
 
8
 *
 
9
 * Contributors:
 
10
 *   Vincent Perot - Add percentages to the label provider
 
11
 *******************************************************************************/
 
12
 
 
13
package org.eclipse.linuxtools.tmf.ui.viewers.statistics.model;
 
14
 
 
15
import java.text.NumberFormat;
 
16
import java.util.Locale;
 
17
 
 
18
import org.eclipse.linuxtools.tmf.ui.viewers.statistics.model.TmfBaseColumnDataProvider.StatsColumn;
 
19
 
 
20
/**
 
21
 * Class that format data for cells in the statistics view.
 
22
 *
 
23
 * @author Vincent Perot
 
24
 * @since 3.0
 
25
 */
 
26
public final class TmfStatisticsFormatter {
 
27
 
 
28
    /**
 
29
     * Formatter for the column data
 
30
     */
 
31
    private static final NumberFormat FORMATTER = NumberFormat.getNumberInstance(Locale.getDefault());
 
32
 
 
33
    TmfStatisticsFormatter() {
 
34
        // Nothing to construct.
 
35
    }
 
36
 
 
37
    /**
 
38
     * Generate the string for display in a cell.
 
39
     *
 
40
     * @param node
 
41
     *            Current node.
 
42
     * @param config
 
43
     *            Configuration between total and partial.
 
44
     * @return The formatted string ready for display.
 
45
     */
 
46
    public static String toColumnData(TmfStatisticsTreeNode node, StatsColumn config) {
 
47
 
 
48
        long eventValue = 0;
 
49
 
 
50
        switch (config) {
 
51
 
 
52
        case TOTAL:
 
53
            eventValue = node.getValues().getTotal();
 
54
            break;
 
55
 
 
56
        case PARTIAL:
 
57
            eventValue = node.getValues().getPartial();
 
58
            break;
 
59
 
 
60
        // Other values are illegal.
 
61
        // $CASES-OMITTED$
 
62
        default:
 
63
            throw new IllegalArgumentException();
 
64
        }
 
65
 
 
66
        return FORMATTER.format(eventValue);
 
67
    }
 
68
 
 
69
    /**
 
70
     * Format the percentage according to user settings.
 
71
     *
 
72
     * @param percentage
 
73
     *            the percentage to format
 
74
     * @return The formated percentage as a string.
 
75
     */
 
76
    public static String toPercentageText(double percentage) {
 
77
 
 
78
        // The cast to long is needed because the formatter cannot truncate the number.
 
79
        double truncPercentage = ((long) (1000.0 * percentage)) / 10.0;
 
80
 
 
81
        String percentageString = String.format("%s%s%s", "  ", FORMATTER.format(truncPercentage), " %     "); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
 
82
        return percentageString;
 
83
    }
 
84
}
 
 
b'\\ No newline at end of file'