001 /* 002 Copyright (C) 2001 Renaud Pawlak 003 004 This program is free software; you can redistribute it and/or modify 005 it under the terms of the GNU Lesser General Public License as 006 published by the Free Software Foundation; either version 2 of the 007 License, or (at your option) any later version. 008 009 This program is distributed in the hope that it will be useful, 010 but WITHOUT ANY WARRANTY; without even the implied warranty of 011 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 012 GNU Lesser General Public License for more details. 013 014 You should have received a copy of the GNU Lesser General Public License 015 along with this program; if not, write to the Free Software 016 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ 017 018 package org.objectweb.jac.aspects.tracing; 019 020 /** 021 * The functional part of the counting aspect: a counter object. 022 * 023 * <p>This component is used by the SimpleCountingWrapper and the 024 * OptimizedCountingWrapper to count the invocations performed on the 025 * counted methods. 026 * 027 * @see SimpleCountingWrapper 028 * @see OptimizedCountingWrapper */ 029 030 public class Counter { 031 032 /** Stores the counter value. */ 033 int counter = 0; 034 035 /** 036 * Increments the counter with a given value. 037 */ 038 039 public void incr ( int value ) { 040 counter+=value; 041 } 042 043 /** 044 * Sets the counter value. 045 * 046 * @param value the new counter value 047 * @see #get() 048 * @see #incr(int) */ 049 050 public void set( int value ) { 051 counter = value; 052 } 053 054 /** 055 * Gets the counter value. 056 * 057 * @return the counter value 058 * @see #set(int) 059 * @see #incr(int) */ 060 061 public int get() { 062 return counter; 063 } 064 065 /** 066 * Print the counter in <code>System.out</code>. 067 */ 068 public void printCounter() { 069 System.out.println("<<< Counting aspect says : " + counter + 070 " line(s) printed. >>>"); 071 } 072 073 } 074 075 076