All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.github.dakusui.jcunit.generators.SimpleTestArrayGenerator Maven / Gradle / Ivy

There is a newer version: 0.8.17
Show newest version
package com.github.dakusui.jcunit.generators;

import java.util.LinkedHashMap;

import com.github.dakusui.jcunit.core.GeneratorParameters;

public class SimpleTestArrayGenerator extends
    BaseTestArrayGenerator {
  @Override
  public void init(GeneratorParameters.Value[] params,
      LinkedHashMap domains) {
    super.init(params, domains);
    if (this.domains == null)
      throw new NullPointerException();
    assert this.size < 0;
    assert this.cur < 0;

    this.size = 1;
    for (T f : this.domains.keySet()) {
      this.size += Math.max(0, this.domains.get(f).length - 1);
    }
    this.cur = 0;
  }

  @Override
  public int getIndex(T key, long cur) {
    // //
    // Initialize the returned map with the default values.
    int ret = 0;
    // //
    // If cur is 0, the returned value should always be 0.
    if (cur == 0)
      return 0;
    cur--;
    for (T f : this.domains.keySet()) {
      long index = cur;
      U[] d = domains.get(f);
      if ((cur -= (d.length - 1)) < 0) {
        if (key.equals(f))
          ret = (int) (index + 1);
        break;
      }
    }
    return ret;
  }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy