de.caff.generics.util

## Class ThreadSafeLongCounter

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

- All Implemented Interfaces:
    LongCounter

      public final class ThreadSafeLongCounter
      extends java.lang.Object
      implements LongCounter

  Changeable long 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 thread safe!

  Author:
    Rammi

- - ### Nested Class Summary

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

      `LongCounter.Creator`

  - ### Field Summary

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

      `SIMPLE, THREAD_SAFE`

  - ### Constructor Summary

    Constructors
    Constructor and Description
    `ThreadSafeLongCounter()` Default constructor.
    `ThreadSafeLongCounter(int val)` Constructor.
    `ThreadSafeLongCounter(LongCounter count)` Copy constructor.

  - ### Method Summary

    All Methods Instance Methods Concrete Methods
    Modifier and Type | Method and Description
    --- | ---
    `long` | `add(long add)` Add something to the counter.
    `long` | `add(LongCounter counter)` Add something to the counter.
    `long` | `add1()` Add 1 to counter.
    `long` | `getValue()` Get the value.
    `void` | `setValue(long val)` Set the value.
    `long` | `subtract(long sub)` Subtract something from the counter.
    `long` | `subtract(LongCounter counter)` Subtract something from the counter.
    `long` | `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.LongCounter

      `add, add, subtract, subtract`

- - ### Constructor Detail

    - #### ThreadSafeLongCounter

          public ThreadSafeLongCounter()

      Default constructor. Initialize value with 0.

    - #### ThreadSafeLongCounter

          public ThreadSafeLongCounter(int val)

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

    - #### ThreadSafeLongCounter

          public ThreadSafeLongCounter(@NotNull
                                       LongCounter count)

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

  - ### Method Detail

    - #### add

          public long add(long add)

      Description copied from interface: `LongCounter`
      Add something to the counter.
      Specified by:
        `add` in interface `LongCounter`
      Parameters:
        `add` - value to add
      Returns:
        counter value

    - #### add

          public long add(@NotNull
                          LongCounter counter)

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

    - #### add1

          public long add1()

      Description copied from interface: `LongCounter`
      Add 1 to counter.
      Specified by:
        `add1` in interface `LongCounter`
      Returns:
        counter value

    - #### subtract

          public long subtract(long sub)

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

    - #### subtract

          public long subtract(@NotNull
                               LongCounter counter)

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

    - #### subtract1

          public long subtract1()

      Description copied from interface: `LongCounter`
      Subtract 1 from counter.
      Specified by:
        `subtract1` in interface `LongCounter`
      Returns:
        counter value

    - #### getValue

          public long getValue()

      Description copied from interface: `LongCounter`
      Get the value.
      Specified by:
        `getValue` in interface `LongCounter`
      Returns:
        accumulated value

    - #### setValue

          public void setValue(long val)

      Description copied from interface: `LongCounter`
      Set the value.
      Specified by:
        `setValue` in interface `LongCounter`
      Parameters:
        `val` - new value

    - #### toString

          @NotNull
          public java.lang.String toString()

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