<commit_before>/*
 * #%L
 * wcm.io
 * %%
 * Copyright (C) 2019 wcm.io
 * %%
 * 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
 *
 *      http://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.
 * #L%
 */
package io.wcm.qa.glnm.pairwise;

import java.util.ArrayList;
import java.util.Collection;
import java.util.Iterator;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
 * Helper to reduce test cases by applying pairwise approach.
 * Scientific background in this paper:
 * https://www.microsoft.com/en-us/research/wp-content/uploads/2017/01/160.pdf
 *
 * @since 4.0.0
 */
public final class PairwiseDefinition {

  private static final Logger LOG = LoggerFactory.getLogger(PairwiseDefinition.class);

  private PairwiseDefinition() {
    // do not instantiate
  }

  /**
   * Returns pairwise selected tupels for the domain sizes
   *
   * @param domainSizes sizes of the individual domains
   * @return all tupels in array form
   * @since 5.0.0
   */
  public static int[][] getTupelsFor(Integer... domainSizes) {
    TupelDefinition tupelDefinition = new TupelDefinition(domainDefinitions(domainSizes));
    Collection<Tupel> tupelCollection = getTupelsFor(tupelDefinition);
    int[][] tupelArray = new int[tupelCollection.size()][];
    Iterator<Tupel> tupels = tupelCollection.iterator();
    for (int i = 0; i < tupelArray.length; i++) {
      tupelArray[i] = tupels.next().toArray();
    }
    return tupelArray;
  }

  private static DomainDefinition[] domainDefinitions(Integer... domainSizes) {
    ArrayList<DomainDefinition> domains = new ArrayList<DomainDefinition>();
    for (int dimension : domainSizes) {
      domains.add(new DomainDefinition(Integer.toString(dimension), dimension));
    }
    DomainDefinition[] array = domains.toArray(new DomainDefinition[domains.size()]);
    return array;
  }

  /**
   * <p>getTupelsFor.</p>
   *
   * @param def a {@link io.wcm.qa.glnm.pairwise.TupelDefinition} object.
   * @return a {@link java.util.Collection} object.
   * @since 5.0.0
   */
  public static Collection<Tupel> getTupelsFor(TupelDefinition def) {

    Collection<Requirement> requirements = generateRequirements(def);

    Collection<Tupel> tupels = generateTupels(def, requirements);

    return tupels;
  }

  private static boolean ensureWithExistingTupels(Collection<Tupel> tupels, Requirement requirement) {
    for (Tupel tupel : tupels) {
      if (tupel.satisfy(requirement)) {
        return true;
      }
    }
    return false;
  }
<commit_msg>fix: optimized to array call<commit_after>/*
 * #%L
 * wcm.io
 * %%
 * Copyright (C) 2019 wcm.io
 * %%
 * 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
 *
 *      http://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.
 * #L%
 */
package io.wcm.qa.glnm.pairwise;

import java.util.ArrayList;
import java.util.Collection;
import java.util.Iterator;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
 * Helper to reduce test cases by applying pairwise approach.
 * Scientific background in this paper:
 * https://www.microsoft.com/en-us/research/wp-content/uploads/2017/01/160.pdf
 *
 * @since 4.0.0
 */
public final class PairwiseDefinition {

  private static final Logger LOG = LoggerFactory.getLogger(PairwiseDefinition.class);

  private PairwiseDefinition() {
    // do not instantiate
  }

  /**
   * Returns pairwise selected tupels for the domain sizes
   *
   * @param domainSizes sizes of the individual domains
   * @return all tupels in array form
   * @since 5.0.0
   */
  public static int[][] getTupelsFor(Integer... domainSizes) {
    TupelDefinition tupelDefinition = new TupelDefinition(domainDefinitions(domainSizes));
    Collection<Tupel> tupelCollection = getTupelsFor(tupelDefinition);
    int[][] tupelArray = new int[tupelCollection.size()][];
    Iterator<Tupel> tupels = tupelCollection.iterator();
    for (int i = 0; i < tupelArray.length; i++) {
      tupelArray[i] = tupels.next().toArray();
    }
    return tupelArray;
  }

  private static DomainDefinition[] domainDefinitions(Integer... domainSizes) {
    ArrayList<DomainDefinition> domains = new ArrayList<DomainDefinition>();
    for (int dimension : domainSizes) {
      domains.add(new DomainDefinition(Integer.toString(dimension), dimension));
    }
    return domains.toArray(new DomainDefinition[0]);
  }

  /**
   * <p>getTupelsFor.</p>
   *
   * @param def a {@link io.wcm.qa.glnm.pairwise.TupelDefinition} object.
   * @return a {@link java.util.Collection} object.
   * @since 5.0.0
   */
  public static Collection<Tupel> getTupelsFor(TupelDefinition def) {

    Collection<Requirement> requirements = generateRequirements(def);

    Collection<Tupel> tupels = generateTupels(def, requirements);

    return tupels;
  }

  private static boolean ensureWithExistingTupels(Collection<Tupel> tupels, Requirement requirement) {
    for (Tupel tupel : tupels) {
      if (tupel.satisfy(requirement)) {
        return true;
      }
    }
    return false;
  }

{'fraction_non_alphanumeric': 0.11019849418206708, 'fraction_numerical': 0.010095824777549623, 'mean_word_length': 3.6985530546623795, 'pattern_counts': {'":': 0, '<': 25, '<?xml version=': 0, '>': 23, 'https://': 2, 'lorem ipsum': 0, 'www.': 4, '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': '3635614', 'n_tokens_mistral': 1851, 'n_tokens_neox': 1773, 'n_words': 501}