<commit_before>/*
 * Copyright 2014-2019 Real Logic Ltd.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * https://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package org.agrona.concurrent;

import java.util.concurrent.locks.LockSupport;

/**
 * When idle this strategy is to sleep for a specified period in nanoseconds.
 * <p>
 * This class uses {@link LockSupport#parkNanos(long)} to idle.
 */
public final class SleepingIdleStrategy implements IdleStrategy
{
    private final long sleepPeriodNs;

    /**
     * Constructed a new strategy that will sleep for a given period when idle.
     *
     * @param sleepPeriodNs period in nanosecond for which the strategy will sleep when work count is 0.
     */
    public SleepingIdleStrategy(final long sleepPeriodNs)
    {
        this.sleepPeriodNs = sleepPeriodNs;
    }

    /**
     *  {@inheritDoc}
     */
    public void idle(final int workCount)
    {
        if (workCount > 0)
        {
            return;
        }

        LockSupport.parkNanos(sleepPeriodNs);
    }

    /**
     *  {@inheritDoc}
     */
    public void idle()
    {
        LockSupport.parkNanos(sleepPeriodNs);
    }

    /**
     *  {@inheritDoc}
     */
    public void reset()
    {
    }

    public String toString()
    {
        return "SleepingIdleStrategy{" +
            "sleepPeriodNs=" + sleepPeriodNs +
            '}';
    }
}
<commit_msg>[Java] Provide default constructors for idle strategies.<commit_after>/*
 * Copyright 2014-2019 Real Logic Ltd.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * https://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package org.agrona.concurrent;

import java.util.concurrent.locks.LockSupport;

/**
 * When idle this strategy is to sleep for a specified period in nanoseconds.
 * <p>
 * This class uses {@link LockSupport#parkNanos(long)} to idle.
 */
public final class SleepingIdleStrategy implements IdleStrategy
{
    /**
     * Default sleep period that tends to work as the likely minimum on Linux to be effective.
     */
    public static final long DEFAULT_SLEEP_PERIOD_NS = 1000L;

    private final long sleepPeriodNs;

    /**
     * Default constructor using {@link #DEFAULT_SLEEP_PERIOD_NS}.
     */
    public SleepingIdleStrategy()
    {
        sleepPeriodNs = DEFAULT_SLEEP_PERIOD_NS;
    }

    /**
     * Constructed a new strategy that will sleep for a given period when idle.
     *
     * @param sleepPeriodNs period in nanosecond for which the strategy will sleep when work count is 0.
     */
    public SleepingIdleStrategy(final long sleepPeriodNs)
    {
        this.sleepPeriodNs = sleepPeriodNs;
    }

    /**
     *  {@inheritDoc}
     */
    public void idle(final int workCount)
    {
        if (workCount > 0)
        {
            return;
        }

        LockSupport.parkNanos(sleepPeriodNs);
    }

    /**
     *  {@inheritDoc}
     */
    public void idle()
    {
        LockSupport.parkNanos(sleepPeriodNs);
    }

    /**
     *  {@inheritDoc}
     */
    public void reset()
    {
    }

    public String toString()
    {
        return "SleepingIdleStrategy{" +
            "sleepPeriodNs=" + sleepPeriodNs +
            '}';
    }
}

{'fraction_non_alphanumeric': 0.0869671729544341, 'fraction_numerical': 0.007839294463498285, 'mean_word_length': 2.52895419187554, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 7, 'https://': 2, 'lorem ipsum': 0, 'www.': 2, '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': '5044859', 'n_tokens_mistral': 1168, 'n_tokens_neox': 1124, 'n_words': 399}