annotate graal/com.oracle.graal.replacements/src/com/oracle/graal/replacements/SnippetCounter.java @ 21744:d62a384b2415

improved formatting of snippet counters
author Doug Simon <doug.simon@oracle.com>
date Fri, 05 Jun 2015 11:58:49 +0200
parents bf8cbbfabdcf
children a71b4567d08e
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
5769
8635406a0c33 factored counter functionality out of CheckcastSnippets in SnippetCounter for use by other snippets
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
1 /*
8635406a0c33 factored counter functionality out of CheckcastSnippets in SnippetCounter for use by other snippets
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
2 * Copyright (c) 2012, Oracle and/or its affiliates. All rights reserved.
8635406a0c33 factored counter functionality out of CheckcastSnippets in SnippetCounter for use by other snippets
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
8635406a0c33 factored counter functionality out of CheckcastSnippets in SnippetCounter for use by other snippets
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
4 *
8635406a0c33 factored counter functionality out of CheckcastSnippets in SnippetCounter for use by other snippets
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
5 * This code is free software; you can redistribute it and/or modify it
8635406a0c33 factored counter functionality out of CheckcastSnippets in SnippetCounter for use by other snippets
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
6 * under the terms of the GNU General Public License version 2 only, as
8635406a0c33 factored counter functionality out of CheckcastSnippets in SnippetCounter for use by other snippets
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
7 * published by the Free Software Foundation.
8635406a0c33 factored counter functionality out of CheckcastSnippets in SnippetCounter for use by other snippets
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
8 *
8635406a0c33 factored counter functionality out of CheckcastSnippets in SnippetCounter for use by other snippets
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
9 * This code is distributed in the hope that it will be useful, but WITHOUT
8635406a0c33 factored counter functionality out of CheckcastSnippets in SnippetCounter for use by other snippets
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
8635406a0c33 factored counter functionality out of CheckcastSnippets in SnippetCounter for use by other snippets
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
8635406a0c33 factored counter functionality out of CheckcastSnippets in SnippetCounter for use by other snippets
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
12 * version 2 for more details (a copy is included in the LICENSE file that
8635406a0c33 factored counter functionality out of CheckcastSnippets in SnippetCounter for use by other snippets
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
13 * accompanied this code).
8635406a0c33 factored counter functionality out of CheckcastSnippets in SnippetCounter for use by other snippets
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
14 *
8635406a0c33 factored counter functionality out of CheckcastSnippets in SnippetCounter for use by other snippets
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
15 * You should have received a copy of the GNU General Public License version
8635406a0c33 factored counter functionality out of CheckcastSnippets in SnippetCounter for use by other snippets
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
16 * 2 along with this work; if not, write to the Free Software Foundation,
8635406a0c33 factored counter functionality out of CheckcastSnippets in SnippetCounter for use by other snippets
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
8635406a0c33 factored counter functionality out of CheckcastSnippets in SnippetCounter for use by other snippets
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
18 *
8635406a0c33 factored counter functionality out of CheckcastSnippets in SnippetCounter for use by other snippets
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
8635406a0c33 factored counter functionality out of CheckcastSnippets in SnippetCounter for use by other snippets
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
20 * or visit www.oracle.com if you need additional information or have any
8635406a0c33 factored counter functionality out of CheckcastSnippets in SnippetCounter for use by other snippets
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
21 * questions.
8635406a0c33 factored counter functionality out of CheckcastSnippets in SnippetCounter for use by other snippets
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
22 */
8415
2361bf148c06 rename packages: *snippets* -> *replacements*
Doug Simon <doug.simon@oracle.com>
parents: 7530
diff changeset
23 package com.oracle.graal.replacements;
5769
8635406a0c33 factored counter functionality out of CheckcastSnippets in SnippetCounter for use by other snippets
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
24
5777
9e56d5113c66 exclude SnippetCounter from JaCoCo processing
Doug Simon <doug.simon@oracle.com>
parents: 5772
diff changeset
25 //JaCoCo Exclude
9e56d5113c66 exclude SnippetCounter from JaCoCo processing
Doug Simon <doug.simon@oracle.com>
parents: 5772
diff changeset
26
5769
8635406a0c33 factored counter functionality out of CheckcastSnippets in SnippetCounter for use by other snippets
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
27 import java.io.*;
8635406a0c33 factored counter functionality out of CheckcastSnippets in SnippetCounter for use by other snippets
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
28 import java.util.*;
8635406a0c33 factored counter functionality out of CheckcastSnippets in SnippetCounter for use by other snippets
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
29
8635406a0c33 factored counter functionality out of CheckcastSnippets in SnippetCounter for use by other snippets
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
30 /**
7530
5e3d1a68664e applied mx eclipseformat to all Java files
Doug Simon <doug.simon@oracle.com>
parents: 6950
diff changeset
31 * A counter that can be safely {@linkplain #inc() incremented} from within a snippet for gathering
5e3d1a68664e applied mx eclipseformat to all Java files
Doug Simon <doug.simon@oracle.com>
parents: 6950
diff changeset
32 * snippet specific metrics.
5769
8635406a0c33 factored counter functionality out of CheckcastSnippets in SnippetCounter for use by other snippets
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
33 */
8635406a0c33 factored counter functionality out of CheckcastSnippets in SnippetCounter for use by other snippets
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
34 public class SnippetCounter implements Comparable<SnippetCounter> {
8635406a0c33 factored counter functionality out of CheckcastSnippets in SnippetCounter for use by other snippets
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
35 /**
8635406a0c33 factored counter functionality out of CheckcastSnippets in SnippetCounter for use by other snippets
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
36 * A group of related counters.
8635406a0c33 factored counter functionality out of CheckcastSnippets in SnippetCounter for use by other snippets
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
37 */
8635406a0c33 factored counter functionality out of CheckcastSnippets in SnippetCounter for use by other snippets
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
38 public static class Group {
7530
5e3d1a68664e applied mx eclipseformat to all Java files
Doug Simon <doug.simon@oracle.com>
parents: 6950
diff changeset
39
5769
8635406a0c33 factored counter functionality out of CheckcastSnippets in SnippetCounter for use by other snippets
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
40 final String name;
8635406a0c33 factored counter functionality out of CheckcastSnippets in SnippetCounter for use by other snippets
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
41 final List<SnippetCounter> counters;
8635406a0c33 factored counter functionality out of CheckcastSnippets in SnippetCounter for use by other snippets
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
42
8635406a0c33 factored counter functionality out of CheckcastSnippets in SnippetCounter for use by other snippets
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
43 public Group(String name) {
8635406a0c33 factored counter functionality out of CheckcastSnippets in SnippetCounter for use by other snippets
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
44 this.name = name;
8635406a0c33 factored counter functionality out of CheckcastSnippets in SnippetCounter for use by other snippets
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
45 this.counters = new ArrayList<>();
8635406a0c33 factored counter functionality out of CheckcastSnippets in SnippetCounter for use by other snippets
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
46 }
8635406a0c33 factored counter functionality out of CheckcastSnippets in SnippetCounter for use by other snippets
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
47
8635406a0c33 factored counter functionality out of CheckcastSnippets in SnippetCounter for use by other snippets
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
48 @Override
8635406a0c33 factored counter functionality out of CheckcastSnippets in SnippetCounter for use by other snippets
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
49 public synchronized String toString() {
8635406a0c33 factored counter functionality out of CheckcastSnippets in SnippetCounter for use by other snippets
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
50 Collections.sort(counters);
8635406a0c33 factored counter functionality out of CheckcastSnippets in SnippetCounter for use by other snippets
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
51
8635406a0c33 factored counter functionality out of CheckcastSnippets in SnippetCounter for use by other snippets
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
52 long total = 0;
5772
2f7a03583a32 added counters for code paths through the new object snippets
Doug Simon <doug.simon@oracle.com>
parents: 5770
diff changeset
53 int maxNameLen = 0;
5769
8635406a0c33 factored counter functionality out of CheckcastSnippets in SnippetCounter for use by other snippets
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
54 for (SnippetCounter c : counters) {
8635406a0c33 factored counter functionality out of CheckcastSnippets in SnippetCounter for use by other snippets
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
55 total += c.value;
5772
2f7a03583a32 added counters for code paths through the new object snippets
Doug Simon <doug.simon@oracle.com>
parents: 5770
diff changeset
56 maxNameLen = Math.max(c.name.length(), maxNameLen);
5769
8635406a0c33 factored counter functionality out of CheckcastSnippets in SnippetCounter for use by other snippets
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
57 }
8635406a0c33 factored counter functionality out of CheckcastSnippets in SnippetCounter for use by other snippets
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
58
8635406a0c33 factored counter functionality out of CheckcastSnippets in SnippetCounter for use by other snippets
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
59 StringBuilder buf = new StringBuilder(String.format("Counters: %s%n", name));
8635406a0c33 factored counter functionality out of CheckcastSnippets in SnippetCounter for use by other snippets
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
60
21744
d62a384b2415 improved formatting of snippet counters
Doug Simon <doug.simon@oracle.com>
parents: 21116
diff changeset
61 String formatString = " %" + maxNameLen + "s: %6.2f%%%" + (String.valueOf(total).length() + 2) + "d // %s%n";
5769
8635406a0c33 factored counter functionality out of CheckcastSnippets in SnippetCounter for use by other snippets
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
62 for (SnippetCounter c : counters) {
8635406a0c33 factored counter functionality out of CheckcastSnippets in SnippetCounter for use by other snippets
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
63 double percent = total == 0D ? 0D : ((double) (c.value * 100)) / total;
21744
d62a384b2415 improved formatting of snippet counters
Doug Simon <doug.simon@oracle.com>
parents: 21116
diff changeset
64 buf.append(String.format(formatString, c.name, percent, c.value, c.description));
5769
8635406a0c33 factored counter functionality out of CheckcastSnippets in SnippetCounter for use by other snippets
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
65 }
21744
d62a384b2415 improved formatting of snippet counters
Doug Simon <doug.simon@oracle.com>
parents: 21116
diff changeset
66 buf.append(String.format(formatString, "TOTAL", 100.0D, total, ""));
d62a384b2415 improved formatting of snippet counters
Doug Simon <doug.simon@oracle.com>
parents: 21116
diff changeset
67
5769
8635406a0c33 factored counter functionality out of CheckcastSnippets in SnippetCounter for use by other snippets
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
68 return buf.toString();
8635406a0c33 factored counter functionality out of CheckcastSnippets in SnippetCounter for use by other snippets
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
69 }
8635406a0c33 factored counter functionality out of CheckcastSnippets in SnippetCounter for use by other snippets
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
70 }
8635406a0c33 factored counter functionality out of CheckcastSnippets in SnippetCounter for use by other snippets
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
71
8635406a0c33 factored counter functionality out of CheckcastSnippets in SnippetCounter for use by other snippets
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
72 /**
8635406a0c33 factored counter functionality out of CheckcastSnippets in SnippetCounter for use by other snippets
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
73 * Sorts counters in descending order of their {@linkplain #value() values}.
8635406a0c33 factored counter functionality out of CheckcastSnippets in SnippetCounter for use by other snippets
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
74 */
8635406a0c33 factored counter functionality out of CheckcastSnippets in SnippetCounter for use by other snippets
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
75 @Override
8635406a0c33 factored counter functionality out of CheckcastSnippets in SnippetCounter for use by other snippets
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
76 public int compareTo(SnippetCounter o) {
8635406a0c33 factored counter functionality out of CheckcastSnippets in SnippetCounter for use by other snippets
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
77 if (value > o.value) {
8635406a0c33 factored counter functionality out of CheckcastSnippets in SnippetCounter for use by other snippets
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
78 return -1;
8635406a0c33 factored counter functionality out of CheckcastSnippets in SnippetCounter for use by other snippets
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
79 } else if (o.value < value) {
8635406a0c33 factored counter functionality out of CheckcastSnippets in SnippetCounter for use by other snippets
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
80 return 1;
8635406a0c33 factored counter functionality out of CheckcastSnippets in SnippetCounter for use by other snippets
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
81 }
8635406a0c33 factored counter functionality out of CheckcastSnippets in SnippetCounter for use by other snippets
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
82 return 0;
8635406a0c33 factored counter functionality out of CheckcastSnippets in SnippetCounter for use by other snippets
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
83 }
8635406a0c33 factored counter functionality out of CheckcastSnippets in SnippetCounter for use by other snippets
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
84
8635406a0c33 factored counter functionality out of CheckcastSnippets in SnippetCounter for use by other snippets
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
85 private static final List<Group> groups = new ArrayList<>();
8635406a0c33 factored counter functionality out of CheckcastSnippets in SnippetCounter for use by other snippets
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
86
8635406a0c33 factored counter functionality out of CheckcastSnippets in SnippetCounter for use by other snippets
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
87 private final Group group;
8635406a0c33 factored counter functionality out of CheckcastSnippets in SnippetCounter for use by other snippets
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
88 private final int index;
8635406a0c33 factored counter functionality out of CheckcastSnippets in SnippetCounter for use by other snippets
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
89 private final String name;
8635406a0c33 factored counter functionality out of CheckcastSnippets in SnippetCounter for use by other snippets
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
90 private final String description;
8635406a0c33 factored counter functionality out of CheckcastSnippets in SnippetCounter for use by other snippets
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
91 private long value;
8635406a0c33 factored counter functionality out of CheckcastSnippets in SnippetCounter for use by other snippets
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
92
8635406a0c33 factored counter functionality out of CheckcastSnippets in SnippetCounter for use by other snippets
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
93 /**
8635406a0c33 factored counter functionality out of CheckcastSnippets in SnippetCounter for use by other snippets
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
94 * Creates a counter.
15363
c279c6773799 snippet counter: fix location for counter access
Bernhard Urban <bernhard.urban@jku.at>
parents: 15291
diff changeset
95 *
7530
5e3d1a68664e applied mx eclipseformat to all Java files
Doug Simon <doug.simon@oracle.com>
parents: 6950
diff changeset
96 * @param group the group to which the counter belongs. If this is null, the newly created
5e3d1a68664e applied mx eclipseformat to all Java files
Doug Simon <doug.simon@oracle.com>
parents: 6950
diff changeset
97 * counter is disabled and {@linkplain #inc() incrementing} is a no-op.
5769
8635406a0c33 factored counter functionality out of CheckcastSnippets in SnippetCounter for use by other snippets
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
98 * @param name the name of the counter
8635406a0c33 factored counter functionality out of CheckcastSnippets in SnippetCounter for use by other snippets
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
99 * @param description a brief comment describing the metric represented by the counter
8635406a0c33 factored counter functionality out of CheckcastSnippets in SnippetCounter for use by other snippets
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
100 */
8635406a0c33 factored counter functionality out of CheckcastSnippets in SnippetCounter for use by other snippets
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
101 public SnippetCounter(Group group, String name, String description) {
8635406a0c33 factored counter functionality out of CheckcastSnippets in SnippetCounter for use by other snippets
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
102 this.group = group;
8635406a0c33 factored counter functionality out of CheckcastSnippets in SnippetCounter for use by other snippets
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
103 this.name = name;
8635406a0c33 factored counter functionality out of CheckcastSnippets in SnippetCounter for use by other snippets
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
104 this.description = description;
8635406a0c33 factored counter functionality out of CheckcastSnippets in SnippetCounter for use by other snippets
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
105 if (group != null) {
8635406a0c33 factored counter functionality out of CheckcastSnippets in SnippetCounter for use by other snippets
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
106 List<SnippetCounter> counters = group.counters;
8635406a0c33 factored counter functionality out of CheckcastSnippets in SnippetCounter for use by other snippets
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
107 this.index = counters.size();
8635406a0c33 factored counter functionality out of CheckcastSnippets in SnippetCounter for use by other snippets
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
108 counters.add(this);
8635406a0c33 factored counter functionality out of CheckcastSnippets in SnippetCounter for use by other snippets
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
109 if (index == 0) {
8635406a0c33 factored counter functionality out of CheckcastSnippets in SnippetCounter for use by other snippets
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
110 groups.add(group);
8635406a0c33 factored counter functionality out of CheckcastSnippets in SnippetCounter for use by other snippets
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
111 }
8635406a0c33 factored counter functionality out of CheckcastSnippets in SnippetCounter for use by other snippets
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
112 } else {
8635406a0c33 factored counter functionality out of CheckcastSnippets in SnippetCounter for use by other snippets
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
113 this.index = -1;
8635406a0c33 factored counter functionality out of CheckcastSnippets in SnippetCounter for use by other snippets
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
114 }
8635406a0c33 factored counter functionality out of CheckcastSnippets in SnippetCounter for use by other snippets
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
115 }
8635406a0c33 factored counter functionality out of CheckcastSnippets in SnippetCounter for use by other snippets
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
116
8635406a0c33 factored counter functionality out of CheckcastSnippets in SnippetCounter for use by other snippets
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
117 /**
7530
5e3d1a68664e applied mx eclipseformat to all Java files
Doug Simon <doug.simon@oracle.com>
parents: 6950
diff changeset
118 * Increments the value of this counter. This method can be safely used in a snippet if it is
5e3d1a68664e applied mx eclipseformat to all Java files
Doug Simon <doug.simon@oracle.com>
parents: 6950
diff changeset
119 * invoked on a compile-time constant {@link SnippetCounter} object.
5769
8635406a0c33 factored counter functionality out of CheckcastSnippets in SnippetCounter for use by other snippets
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
120 */
8635406a0c33 factored counter functionality out of CheckcastSnippets in SnippetCounter for use by other snippets
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
121 public void inc() {
8635406a0c33 factored counter functionality out of CheckcastSnippets in SnippetCounter for use by other snippets
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
122 if (group != null) {
21116
bf8cbbfabdcf Use snippets for incrementing snippet counters
Tom Rodriguez <tom.rodriguez@oracle.com>
parents: 18370
diff changeset
123 SnippetCounterNode.increment(this);
5769
8635406a0c33 factored counter functionality out of CheckcastSnippets in SnippetCounter for use by other snippets
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
124 }
8635406a0c33 factored counter functionality out of CheckcastSnippets in SnippetCounter for use by other snippets
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
125 }
8635406a0c33 factored counter functionality out of CheckcastSnippets in SnippetCounter for use by other snippets
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
126
8635406a0c33 factored counter functionality out of CheckcastSnippets in SnippetCounter for use by other snippets
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
127 /**
8635406a0c33 factored counter functionality out of CheckcastSnippets in SnippetCounter for use by other snippets
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
128 * Gets the value of this counter.
8635406a0c33 factored counter functionality out of CheckcastSnippets in SnippetCounter for use by other snippets
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
129 */
8635406a0c33 factored counter functionality out of CheckcastSnippets in SnippetCounter for use by other snippets
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
130 public long value() {
8635406a0c33 factored counter functionality out of CheckcastSnippets in SnippetCounter for use by other snippets
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
131 return value;
8635406a0c33 factored counter functionality out of CheckcastSnippets in SnippetCounter for use by other snippets
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
132 }
8635406a0c33 factored counter functionality out of CheckcastSnippets in SnippetCounter for use by other snippets
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
133
21116
bf8cbbfabdcf Use snippets for incrementing snippet counters
Tom Rodriguez <tom.rodriguez@oracle.com>
parents: 18370
diff changeset
134 @Override
bf8cbbfabdcf Use snippets for incrementing snippet counters
Tom Rodriguez <tom.rodriguez@oracle.com>
parents: 18370
diff changeset
135 public String toString() {
bf8cbbfabdcf Use snippets for incrementing snippet counters
Tom Rodriguez <tom.rodriguez@oracle.com>
parents: 18370
diff changeset
136 if (group != null) {
bf8cbbfabdcf Use snippets for incrementing snippet counters
Tom Rodriguez <tom.rodriguez@oracle.com>
parents: 18370
diff changeset
137 return "SnippetCounter-" + group.name + ":" + name;
bf8cbbfabdcf Use snippets for incrementing snippet counters
Tom Rodriguez <tom.rodriguez@oracle.com>
parents: 18370
diff changeset
138 }
bf8cbbfabdcf Use snippets for incrementing snippet counters
Tom Rodriguez <tom.rodriguez@oracle.com>
parents: 18370
diff changeset
139 return super.toString();
bf8cbbfabdcf Use snippets for incrementing snippet counters
Tom Rodriguez <tom.rodriguez@oracle.com>
parents: 18370
diff changeset
140 }
bf8cbbfabdcf Use snippets for incrementing snippet counters
Tom Rodriguez <tom.rodriguez@oracle.com>
parents: 18370
diff changeset
141
5769
8635406a0c33 factored counter functionality out of CheckcastSnippets in SnippetCounter for use by other snippets
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
142 /**
8635406a0c33 factored counter functionality out of CheckcastSnippets in SnippetCounter for use by other snippets
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
143 * Prints all the counter groups to a given stream.
8635406a0c33 factored counter functionality out of CheckcastSnippets in SnippetCounter for use by other snippets
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
144 */
8635406a0c33 factored counter functionality out of CheckcastSnippets in SnippetCounter for use by other snippets
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
145 public static void printGroups(PrintStream out) {
8635406a0c33 factored counter functionality out of CheckcastSnippets in SnippetCounter for use by other snippets
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
146 for (Group group : groups) {
8635406a0c33 factored counter functionality out of CheckcastSnippets in SnippetCounter for use by other snippets
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
147 out.println(group);
8635406a0c33 factored counter functionality out of CheckcastSnippets in SnippetCounter for use by other snippets
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
148 }
8635406a0c33 factored counter functionality out of CheckcastSnippets in SnippetCounter for use by other snippets
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
149 }
8635406a0c33 factored counter functionality out of CheckcastSnippets in SnippetCounter for use by other snippets
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
150 }