<commit_before>package com.github.mizool.core;

import java.time.Duration;

import lombok.RequiredArgsConstructor;

import com.google.common.base.Stopwatch;

/**
 * Helper class to allow for something to happen after a certain amount of time. A common uses cases might be
 * invalidation of in memory data.<br>
 * <br>
 * Example to invalidate a cache every minute:
 * <pre>
 * {@code
 * private final Interval cacheInvalidationInterval = new Interval(Duration.ofMinutes(1));
 *
 * ...
 *
 * if (cacheInvalidationInterval.isReached())
 * {
 *     invalidateCache();
 * }
 * }
 * </pre>
 */
@RequiredArgsConstructor
public class Interval
{
    private final Stopwatch stopwatch = Stopwatch.createStarted();
    private final Duration duration;

    public boolean isReached()
    {
        boolean isReached = stopwatch.elapsed()
            .compareTo(duration) > 0;
        if (isReached)
        {
            stopwatch.reset();
            stopwatch.start();
        }
        return isReached;
    }
}<commit_msg>Addressing review comments,<commit_after>package com.github.mizool.core;

import java.time.Duration;

import javax.annotation.concurrent.ThreadSafe;

import lombok.RequiredArgsConstructor;
import lombok.Synchronized;

import com.google.common.base.Stopwatch;

/**
 * Helper class to allow for something to happen at regular intervals. A common use case might be invalidation of
 * in-memory data.<br>
 * <br>
 * Example to invalidate a cache every minute:
 * <pre>
 * {@code
 * private final Interval cacheInvalidationInterval = new Interval(Duration.ofMinutes(1));
 *
 * ...
 *
 * cacheInvalidationInterval.runIfDue(this::invalidateCache);
 * }
 * </pre>
 */
@ThreadSafe
@RequiredArgsConstructor
public class Interval
{
    private final Stopwatch stopwatch = Stopwatch.createStarted();
    private final Duration duration;

    /**
     * Executes the {@code runnable} if the interval is due or <i>past due</i>. The next full interval is started after
     * completion of the runnable.
     *
     * @return {@code true} if the operation was due and the runnable completed.
     */
    @Synchronized
    public boolean runIfDue(Runnable runnable)
    {
        boolean isReached = stopwatch.elapsed()
            .compareTo(duration) > 0;
        if (isReached)
        {
            stopwatch.reset();
            runnable.run();
            stopwatch.start();
        }
        return isReached;
    }
}
{'fraction_non_alphanumeric': 0.10185567010309278, 'fraction_numerical': 0.0016494845360824743, 'mean_word_length': 2.9901315789473686, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 15, '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': '1787456', 'n_tokens_mistral': 707, 'n_tokens_neox': 694, 'n_words': 199}