Counter (Lucene 10.5.0 core API)
Description: declaration: package: org.apache.lucene.util, class: Counter

Package org.apache.lucene.util

# Class Counter

java.lang.Object
org.apache.lucene.util.Counter

public abstract class Counter extends Object
Simple counter class

WARNING: This API is experimental and might change in incompatible ways in the next release.
NOTE: This API is for internal purposes only and might change in incompatible ways in the next release.

- ## Constructor Summary

  Constructors
  Constructor
  Description
  `Counter()`

- ## Method Summary

  Modifier and Type
  Method
  Description
  `abstract long`
  `addAndGet(long delta)`
  Adds the given delta to the counters current value
  `abstract long`
  `get()`
  Returns the counters current value
  `static Counter`
  `newCounter()`
  Returns a new counter.
  `static Counter`
  `newCounter(boolean threadSafe)`
  Returns a new counter.

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

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

- ## Constructor Details

  - ### Counter

    public Counter()

- ## Method Details

  - ### addAndGet

    public abstract long addAndGet(long delta)
    Adds the given delta to the counters current value
    Parameters:
      `delta` - the delta to add
    Returns:
      the counters updated value

  - ### get

    public abstract long get()
    Returns the counters current value
    Returns:
      the counters current value

  - ### newCounter

    public static Counter newCounter()
    Returns a new counter. The returned counter is not thread-safe.

  - ### newCounter

    public static Counter newCounter(boolean threadSafe)
    Returns a new counter.
    Parameters:
      `threadSafe` - `true` if the returned counter can be used by multiple threads concurrently.
    Returns:
      a new counter.