KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > jac > aspects > tracing > Counter


1 /*
2   Copyright (C) 2001 Renaud Pawlak
3
4   This program is free software; you can redistribute it and/or modify
5   it under the terms of the GNU Lesser General Public License as
6   published by the Free Software Foundation; either version 2 of the
7   License, or (at your option) any later version.
8
9   This program is distributed in the hope that it will be useful,
10   but WITHOUT ANY WARRANTY; without even the implied warranty of
11   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12   GNU Lesser General Public License for more details.
13
14   You should have received a copy of the GNU Lesser General Public License
15   along with this program; if not, write to the Free Software
16   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */

17
18 package org.objectweb.jac.aspects.tracing;
19
20 /**
21  * The functional part of the counting aspect: a counter object.
22  *
23  * <p>This component is used by the SimpleCountingWrapper and the
24  * OptimizedCountingWrapper to count the invocations performed on the
25  * counted methods.
26  *
27  * @see SimpleCountingWrapper
28  * @see OptimizedCountingWrapper */

29
30 public class Counter {
31
32    /** Stores the counter value. */
33    int counter = 0;
34
35    /**
36     * Increments the counter with a given value.
37     */

38
39    public void incr ( int value ) {
40       counter+=value;
41    }
42
43    /**
44     * Sets the counter value.
45     *
46     * @param value the new counter value
47     * @see #get()
48     * @see #incr(int) */

49
50    public void set( int value ) {
51       counter = value;
52    }
53    
54    /**
55     * Gets the counter value.
56     *
57     * @return the counter value
58     * @see #set(int)
59     * @see #incr(int) */

60
61    public int get() {
62       return counter;
63    }
64
65    /**
66     * Print the counter in <code>System.out</code>.
67     */

68    public void printCounter() {
69       System.out.println("<<< Counting aspect says : " + counter +
70                          " line(s) printed. >>>");
71    }
72
73 }
74
75
76
77
Popular Tags