KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > jac > samples > calcul > Calcul


1 /*
2   Copyright (C) AOPSYS (http://www.aopsys.com)
3
4   This program is free software; you can redistribute it and/or modify
5   it under the terms of the GNU General Public License as published by
6   the Free Software Foundation; either version 2 of the License, or
7   (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 General Public License for more details.
13
14   You should have received a copy of the GNU 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
19 package org.objectweb.jac.samples.calcul;
20
21 import java.util.List JavaDoc;
22 import java.util.Vector JavaDoc;
23
24 public class Calcul
25 {
26
27    protected float value = 0;
28
29    /**
30     * Adds toadd to value.
31     *
32     * @param toadd the value to add.
33     */

34    public void add(int toadd) {
35       value+=toadd;
36       addOp(new Op("add",""+toadd));
37    }
38
39    /**
40     * Subs tosub from value.
41     *
42     * @param tosub the value to sub.
43     */

44    public void sub(float tosub) {
45       value-=tosub;
46       addOp(new Op("sub",""+tosub));
47    }
48
49    /**
50     * Gets current value.
51     *
52     * @return the current value.
53     */

54    public float getValue() {
55       return value;
56    }
57
58    /**
59     * Sets current value.
60     *
61     * @param value the new value.
62     */

63    public void setValue( float value ) {
64       this.value=value;
65    }
66
67    /**
68     * Execute i additions of 1 to test program.
69     *
70     * @param i the number of additions to execute.
71     */

72    public void bench(int i) {
73       for (; i>0; i--) {
74          add(1);
75       }
76    }
77
78    List JavaDoc ops=new Vector JavaDoc();
79    
80    /**
81     * Get the value of ops.
82     * @return value of ops.
83     */

84    public List JavaDoc getOps() {
85       return ops;
86    }
87    
88    /**
89     * Set the value of ops.
90     * @param v Value to assign to ops.
91     */

92    public void setOps(List JavaDoc v) {
93       this.ops = v;
94    }
95    
96    public void addOp(Op op) {
97       ops.add(op);
98    }
99
100    public void removeOp(Op op) {
101       ops.remove(op);
102    }
103
104    public void clearOps() {
105       ops.clear();
106    }
107
108 }
109
110 // Local Variables: ***
111
// c-basic-offset:3 ***
112
// End: **
113

114
Popular Tags