<commit_before>package de.lessvoid.nifty.tools.time;

import java.util.Properties;
import java.util.logging.Logger;

import de.lessvoid.nifty.tools.TimeProvider;
import de.lessvoid.nifty.tools.time.interpolator.ExpTime;
import de.lessvoid.nifty.tools.time.interpolator.Interpolator;
import de.lessvoid.nifty.tools.time.interpolator.LinearTime;
import de.lessvoid.nifty.tools.time.interpolator.NullTime;

/**
 * TimeProvider class.
 * @author void
 */
public class TimeInterpolator {

  /**
   * the logger.
   */
  private static Logger log = Logger.getLogger(TimeInterpolator.class.getName());

  /**
   * the time provider.
   */
  private TimeProvider timeProvider;

  /**
   * the InterpolatorProvider we use.
   */
  private Interpolator interpolatorProvider;

  /**
   * the current value [0,1].
   */
  private float value = 0.0f;

  /**
   * the start time in ms the effect starts.
   */
  private long startTime;

  /**
   * the maximum time in ms.
   */
  private long lengthParam;

  /**
   * start delay time in ms.
   */
  private long startDelayParam = 0;

  /**
   * initialize with the given parameters.
   *
   * @param parameter parameter props
   * @param newTimeProvider TimeProvider to use
   */
  public TimeInterpolator(final Properties parameter, final TimeProvider newTimeProvider) {
    this.timeProvider = newTimeProvider;

    this.lengthParam = Long.parseLong(parameter.getProperty("length", "1000"));
    this.startDelayParam = Long.parseLong(parameter.getProperty("startDelay", "0"));

    // check for the given timeType to create the appropriate interpolator
    String timeType = parameter.getProperty("timeType", "linear");
    if (timeType.equals("infinite")) {
      interpolatorProvider = new NullTime();
    } else if (timeType.equals("linear")) {
      interpolatorProvider = new LinearTime();
    } else if (timeType.equals("exp")) {
      interpolatorProvider = new ExpTime();
    } else {
      log.warning(timeType + " is not supported, using NullTime for fallback. probably not what you want...");
      interpolatorProvider = new NullTime();
    }

    // initialize the provider
    interpolatorProvider.initialize(parameter);
  }

  /**
   * start the interpolation.
   */
  public final void start() {
    this.value = 0.0f;
    this.startTime = timeProvider.getMsTime() + startDelayParam;
  }

  /**<commit_msg>@public all effects now allow the length attribute set to "infinite" to create "endless" effects. this was possible before with using timeType="infinite" and this is still possible but length="infinite" can now be used too.<commit_after>package de.lessvoid.nifty.tools.time;

import java.util.Properties;
import java.util.logging.Logger;

import de.lessvoid.nifty.tools.TimeProvider;
import de.lessvoid.nifty.tools.time.interpolator.ExpTime;
import de.lessvoid.nifty.tools.time.interpolator.Interpolator;
import de.lessvoid.nifty.tools.time.interpolator.LinearTime;
import de.lessvoid.nifty.tools.time.interpolator.NullTime;

/**
 * TimeProvider class.
 * @author void
 */
public class TimeInterpolator {

  /**
   * the logger.
   */
  private static Logger log = Logger.getLogger(TimeInterpolator.class.getName());

  /**
   * the time provider.
   */
  private TimeProvider timeProvider;

  /**
   * the InterpolatorProvider we use.
   */
  private Interpolator interpolatorProvider;

  /**
   * the current value [0,1].
   */
  private float value = 0.0f;

  /**
   * the start time in ms the effect starts.
   */
  private long startTime;

  /**
   * the maximum time in ms.
   */
  private long lengthParam;

  /**
   * start delay time in ms.
   */
  private long startDelayParam = 0;

  /**
   * initialize with the given parameters.
   *
   * @param parameter parameter props
   * @param newTimeProvider TimeProvider to use
   */
  public TimeInterpolator(final Properties parameter, final TimeProvider newTimeProvider) {
    this.timeProvider = newTimeProvider;
    this.startDelayParam = Long.parseLong(parameter.getProperty("startDelay", "0"));

    interpolatorProvider = null;
    if ("infinite".equals(parameter.getProperty("length", null))) {
      interpolatorProvider = new NullTime();
    } else {
      this.lengthParam = Long.parseLong(parameter.getProperty("length", "1000"));
    }

    // check for the given timeType to create the appropriate interpolator
    if (interpolatorProvider == null) {
      String timeType = parameter.getProperty("timeType", "linear");
      if (timeType.equals("infinite")) {
        interpolatorProvider = new NullTime();
      } else if (timeType.equals("linear")) {
        interpolatorProvider = new LinearTime();
      } else if (timeType.equals("exp")) {
        interpolatorProvider = new ExpTime();
      } else {
        log.warning(timeType + " is not supported, using NullTime for fallback. probably not what you want...");
        interpolatorProvider = new NullTime();
      }
    }

    // initialize the provider
    interpolatorProvider.initialize(parameter);
  }

  /**
   * start the interpolation.
   */
  public final void start() {
    this.value = 0.0f;
    this.startTime = timeProvider.getMsTime() + startDelayParam;
  }

  /**
{'fraction_non_alphanumeric': 0.11496032514031353, 'fraction_numerical': 0.00464486162183085, 'mean_word_length': 3.3030807660283097, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, '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': '7487210', 'n_tokens_mistral': 1545, 'n_tokens_neox': 1506, 'n_words': 389}