Class CountDown

java.lang.Object
no.digipost.concurrent.CountDown
All Implemented Interfaces:
TargetState

public final class CountDown extends Object implements TargetState
A count down implementation of TargetState, which will count the invocations of yet() and return true after a given amount of invocations.

The implementation is thread-safe in the sense that it is guaranteed that yet() will return false an exact amount of times, regardless of different threads invoking yet(), before switching to only return true.

This can often serve for testing purposes where you would like a controlled amount of queries to a TargetState, before it changes.

  • Constructor Details

    • CountDown

      public CountDown(long count)
      Create a new count down from the given start count.
      Parameters:
      count - the number of invocations where yet() will indicate the count down is not finished yet, i.e. the number of times yet() will return false, and switches to only return true.
  • Method Details

    • yet

      public boolean yet()
      Description copied from interface: TargetState
      Tell if the target state has been reached yet. Once this method returns true, it will never return false again.
      Specified by:
      yet in interface TargetState
      Returns:
      true when the target state has been reached, false otherwise.
    • toString

      public String toString()
      Overrides:
      toString in class Object