KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > example > simple > Simple


1 /**
2  * Cobertura - http://cobertura.sourceforge.net/
3  *
4  * Copyright (C) 2003 jcoverage ltd.
5  * Copyright (C) 2005 Mark Doliner <thekingant@users.sourceforge.net>
6  *
7  * Cobertura is free software; you can redistribute it and/or modify
8  * it under the terms of the GNU General Public License as published
9  * by the Free Software Foundation; either version 2 of the License,
10  * or (at your option) any later version.
11  *
12  * Cobertura is distributed in the hope that it will be useful, but
13  * WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15  * General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with Cobertura; if not, write to the Free Software
19  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
20  * USA
21  */

22
23 package com.example.simple;
24
25 import java.util.Collection JavaDoc;
26 import java.util.Iterator JavaDoc;
27
28 import org.apache.log4j.Logger;
29
30 public class Simple
31 {
32
33     private static final Logger logger = Logger.getLogger(Simple.class);
34
35     public int square(int x)
36     {
37         if (logger.isDebugEnabled())
38         {
39             logger.debug("x: " + x);
40         }
41
42         int result = x * x;
43
44         if (logger.isDebugEnabled())
45         {
46             logger.debug("result: " + result);
47         }
48
49         return result;
50     }
51
52     public int f(int x)
53     {
54         if (logger.isDebugEnabled())
55         {
56             logger.debug("x: " + x);
57         }
58
59         if (x < 0)
60         {
61             if (logger.isDebugEnabled())
62             {
63                 logger.debug("negative x");
64             }
65
66             return square(x);
67         }
68         else if ((x >= 0) && (x <= 5))
69         {
70             if (logger.isDebugEnabled())
71             {
72                 logger.debug("0<=x<=5");
73             }
74
75             return x + 3;
76         }
77         else
78         {
79             return 2 * x;
80         }
81     }
82
83     public int sum(Collection JavaDoc c)
84     {
85         int result = 0;
86
87         for (Iterator JavaDoc i = c.iterator(); i.hasNext();)
88         {
89             int value = ((Number JavaDoc)i.next()).intValue();
90
91             if (logger.isDebugEnabled())
92             {
93                 logger.debug("value: " + value);
94             }
95
96             result += value;
97         }
98
99         if (logger.isDebugEnabled())
100         {
101             logger.debug("result: " + result);
102         }
103
104         return result;
105     }
106 }
Popular Tags