1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
package Torello.Java.Additional;

/**
 * An extremely basic <CODE>'Counter'</CODE> class that is used to help alleviate Java's
 * stringent <CODE>'Effectively Final'</CODE> requirement for lambda-expressions.
 * 
 * <EMBED CLASS='external-html' DATA-FILE-ID=LAMBDA_NOTE>
 * <EMBED CLASS='external-html' DATA-FILE-ID=COUNTER>
 */
public class Counter
{
    private int counter; 

    /**
     * Creates a new counter instance, and initializes it's internal-private
     * {@code int counter} field to {@code '0'}.
     */
    public Counter()
    { this.counter = 0; }

    /**
     * Creates a new counter object, and initializes it's value to the passed-parameter
     * {@code int startingValue}
     *
     * @param startingValue The with which to initialize the internal-private
     * {@code int counter} field.
     */
    public Counter(int startingValue)
    { this.counter = startingValue; }

    /**
     * Increments the internal-private {@code int counter} field by a value of 1.
     * @return The value stored in the counter, after performing the addition.
     */
    public int addOne()
    { return ++counter; } 

    /**
     * Decrements the internal-private {@code int counter} field by a value of 1.
     * @return The value stored in the counter, after performing the subtraction.
     */
    public int subtractOne()
    { return counter--; }

    /**
     * Adds the input-parameter 'n' value to the current value of the internal-private
     * {@code int counter} field.
     * @return The value stored in the counter, after performing the addition.
     */
    public int modifyBy(int n)
    { return counter += n; }

    /**
     * Sets the value of the internal-private {@code int counter} field to the value of the input
     * passed-parameter {@code 'n'}.
     * @param n The internal counter will be set to this value.
     */
    public void set(int n)
    { counter = n; }

    /**
     * Retrieves the value of the internal-private {@code int counter} field.
     * @return The current value stored in the counter.
     */
    public int size()
    { return counter; }

    /**
     * Retrieves the value of the internal-private {@code int counter} field, as a java
     * {@code java.lang.Integer} instance-object.
     * @return The current value stored in the counter, as an instantiated Integer-instance.
     */
    public Integer get()
    { return Integer.valueOf(counter); }
}