de.caff.generics.util

## Class SimpleCounter

- java.lang.Object
- - de.caff.generics.util.SimpleCounter

- All Implemented Interfaces:
    Counter

      public final class SimpleCounter
      extends java.lang.Object
      implements Counter

  Changeable integer wrapper, to be used as counter especially as map values. Note that as this is a mutable value, it is a very bad idea to use it as a map key.

  This class is not thread safe, see `ThreadSafeCounter` for a thread safe counter!

  Author:
    Rammi

- - ### Nested Class Summary

    - ### Nested classes/interfaces inherited from interface de.caff.generics.util.Counter

      `Counter.Creator`

  - ### Field Summary

    - ### Fields inherited from interface de.caff.generics.util.Counter

      `SIMPLE, THREAD_SAFE`

  - ### Constructor Summary

    Constructors
    Constructor and Description
    `SimpleCounter()` Default constructor.
    `SimpleCounter(Counter count)` Copy constructor.
    `SimpleCounter(int val)` Constructor.

  - ### Method Summary

    All Methods Instance Methods Concrete Methods
    Modifier and Type | Method and Description
    --- | ---
    `int` | `add(Counter counter)` Add something to the counter.
    `int` | `add(int add)` Add something to the counter.
    `int` | `add1()` Add 1 to counter.
    `int` | `getValue()` Get the value.
    `void` | `setValue(int value)` Set the value.
    `int` | `subtract(Counter counter)` Subtract something from the counter.
    `int` | `subtract(int sub)` Subtract something from the counter.
    `int` | `subtract1()` Subtract 1 from counter.
    `java.lang.String` | `toString()`

    - ### Methods inherited from class java.lang.Object

      `clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait`

    - ### Methods inherited from interface de.caff.generics.util.Counter

      `add, simple, simple, substract, substract, substract1, subtract, threadSafe, threadSafe`

- - ### Constructor Detail

    - #### SimpleCounter

          public SimpleCounter()

      Default constructor. Initialize value with 0.

    - #### SimpleCounter

          public SimpleCounter(int val)

      Constructor. Initialize value with `val`.
      Parameters:
        `val` - init value

    - #### SimpleCounter

          public SimpleCounter(@NotNull
                               Counter count)

      Copy constructor. Initialize value with given counter.
      Parameters:
        `count` - counter to be copied

  - ### Method Detail

    - #### add

          public int add(int add)

      Add something to the counter.
      Specified by:
        `add` in interface `Counter`
      Parameters:
        `add` - value to add
      Returns:
        counter value

    - #### add

          public int add(@NotNull
                         Counter counter)

      Add something to the counter.
      Specified by:
        `add` in interface `Counter`
      Parameters:
        `counter` - counter which value is added
      Returns:
        counter value

    - #### add1

          public int add1()

      Add 1 to counter.
      Specified by:
        `add1` in interface `Counter`
      Returns:
        counter value

    - #### subtract

          public int subtract(int sub)

      Subtract something from the counter.
      Specified by:
        `subtract` in interface `Counter`
      Parameters:
        `sub` - value to subtract
      Returns:
        counter value

    - #### subtract

          public int subtract(@NotNull
                              Counter counter)

      Subtract something from the counter.
      Specified by:
        `subtract` in interface `Counter`
      Parameters:
        `counter` - counter which value is subtracted
      Returns:
        counter value

    - #### subtract1

          public int subtract1()

      Subtract 1 from counter.
      Specified by:
        `subtract1` in interface `Counter`
      Returns:
        counter value

    - #### getValue

          public int getValue()

      Get the value.
      Specified by:
        `getValue` in interface `Counter`
      Returns:
        accumulated value

    - #### setValue

          public void setValue(int value)

      Set the value.
      Specified by:
        `setValue` in interface `Counter`
      Parameters:
        `value` - new value

    - #### toString

          public java.lang.String toString()

      Overrides:
        `toString` in class `java.lang.Object`