<commit_before>package com.creeaaakk.tools.concurrent;

public abstract class CountDownLatch
{
  private int count;

  public CountDownLatch(int count)
  {
    if (count < 0)
    {
      throw new IllegalArgumentException("Count must be at least 0");
    }

    this.count = count;
    checkZero();
  }

  public synchronized void countDown()
  {
    if (count > 0)
    {
      count--;
      checkZero();
    }
  }

  protected abstract void onZero();

  public int getCount()
  {
    return count;
  }

  private void checkZero()
  {
    if (count == 0)
    {
      onZero();
    }
  }<commit_msg>Improved the CountDownLatch functionality.<commit_after>package com.creeaaakk.tools.concurrent;

import java.util.concurrent.atomic.AtomicInteger;

/**
 * Enables a callback to occur when countDown() has been called
 * the specified number of times. This class is thread safe.
 */
public abstract class CountDownLatch
{
  private AtomicInteger count;

  /**
   * @param count number of times countDown() must be called before
   *              onZero() is called, if count == 0, onZero is called
   *              during construction
   */
  public CountDownLatch(int count)
  {
    if (count < 0)
    {
      throw new IllegalArgumentException("Count must be at least 0");
    }
    else if (count == 0)
    {
      onZero();
    }

    this.count = new AtomicInteger(count);
  }

  public void countDown()
  {
    if (count.decrementAndGet() == 0)
    {
      onZero();
    }
  }

  protected abstract void onZero();

  public int getCount()
  {
    return count.get();
  }
{'fraction_non_alphanumeric': 0.10355781448538755, 'fraction_numerical': 0.005717916137229987, 'mean_word_length': 2.4768211920529803, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 4, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7483357', 'n_tokens_mistral': 499, 'n_tokens_neox': 472, 'n_words': 144}