<commit_before>/*
 * Copyright 2010 <NAME>
 *
 * 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.
 */
package org.pitest.mutationtest.report.html;

import org.pitest.classinfo.ClassInfo;
import org.pitest.coverage.TestInfo;
import org.pitest.functional.FCollection;
import org.pitest.mutationtest.MutationResult;

import java.util.ArrayList;
import java.util.Collection;
import java.util.HashSet;
import java.util.Set;
import java.util.TreeSet;
import java.util.function.BiFunction;
import java.util.function.Function;

public class MutationTestSummaryData {

  private final String                     fileName;
  private final Set<String>                mutators  = new TreeSet<>();
  private final Collection<MutationResult> mutations = new ArrayList<>();
  private final Set<ClassInfo>             classes   = new HashSet<>();

  private long                             numberOfCoveredLines;

  public MutationTestSummaryData(final String fileName,
      final Collection<MutationResult> results,
      final Collection<String> mutators, final Collection<ClassInfo> classes,
      final long numberOfCoveredLines) {
    this.fileName = fileName;
    this.mutations.addAll(results);
    this.mutators.addAll(mutators);
    this.classes.addAll(classes);
    this.numberOfCoveredLines = numberOfCoveredLines;
  }

  public MutationTotals getTotals() {
    final MutationTotals mt = new MutationTotals();
    mt.addFiles(1);
    mt.addMutations(this.getNumberOfMutations());
    mt.addMutationsDetetcted(this.getNumberOfMutationsDetected());
    mt.addLines(getNumberOfLines());
    mt.addLinesCovered(this.numberOfCoveredLines);
    mt.addMutationsWithCoverage(this.getNumberOfMutationsWithCoverage());
    return mt;
  }

  private long getNumberOfMutationsWithCoverage() {
    return this.mutations.stream()
            .filter(it -> it.getStatus().hasCoverage())
            .count();
  }

  public String getPackageName() {
    final String packageName = getMutatedClasses().iterator().next().getName()
        .asJavaName();
    final int lastDot = packageName.lastIndexOf('.');
    return lastDot > 0 ? packageName.substring(0, lastDot) : "default";
  }

  public void add(final MutationTestSummaryData data) {
    this.mutations.addAll(data.mutations);
    this.mutators.addAll(data.getMutators());
    final int classesBefore = this.classes.size();
    this.classes.addAll(data.classes);
    if (classesBefore < this.classes.size()) {<commit_msg>fix(aggregate) Prevent NoSuchElementException if dependency is missing<commit_after>/*
 * Copyright 2010 <NAME>
 *
 * 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.
 */
package org.pitest.mutationtest.report.html;

import java.util.ArrayList;
import java.util.Collection;
import java.util.HashSet;
import java.util.Iterator;
import java.util.Set;
import java.util.TreeSet;
import java.util.function.BiFunction;
import java.util.function.Function;
import java.util.logging.Level;

import org.pitest.classinfo.ClassInfo;
import org.pitest.coverage.TestInfo;
import org.pitest.functional.FCollection;
import org.pitest.mutationtest.MutationResult;
import org.pitest.util.Log;

public class MutationTestSummaryData {

  private final String                     fileName;
  private final Set<String>                mutators  = new TreeSet<>();
  private final Collection<MutationResult> mutations = new ArrayList<>();
  private final Set<ClassInfo>             classes   = new HashSet<>();

  private long                             numberOfCoveredLines;

  public MutationTestSummaryData(final String fileName,
      final Collection<MutationResult> results,
      final Collection<String> mutators, final Collection<ClassInfo> classes,
      final long numberOfCoveredLines) {
    this.fileName = fileName;
    this.mutations.addAll(results);
    this.mutators.addAll(mutators);
    this.classes.addAll(classes);
    this.numberOfCoveredLines = numberOfCoveredLines;
  }

  public MutationTotals getTotals() {
    final MutationTotals mt = new MutationTotals();
    mt.addFiles(1);
    mt.addMutations(this.getNumberOfMutations());
    mt.addMutationsDetetcted(this.getNumberOfMutationsDetected());
    mt.addLines(getNumberOfLines());
    mt.addLinesCovered(this.numberOfCoveredLines);
    mt.addMutationsWithCoverage(this.getNumberOfMutationsWithCoverage());
    return mt;
  }

  private long getNumberOfMutationsWithCoverage() {
    return this.mutations.stream()
            .filter(it -> it.getStatus().hasCoverage())
            .count();
  }

  public String getPackageName() {
    Iterator<ClassInfo> iterator = getMutatedClasses().iterator();
    if (!iterator.hasNext()) {
      Log.getLogger().log(Level.WARNING, "Can't get package name for " + fileName + "."
        + "There is no mutated classes. It may happen if you are using report-aggregate "
        + "goal to merge reports using a dedicated maven project "
        + "and the dependency that contains the mutated code is missing");
      return "default";
    }
    final String packageName = iterator.next().getName()
      .asJavaName();
    final int lastDot = packageName.lastIndexOf('.');
    return lastDot > 0 ? packageName.substring(0, lastDot) : "default";
  }

  public void add(final MutationTestSummaryData data) {
    this.mutations.addAll(data.mutations);
    this.mutators.addAll(data.getMutators());
    final int classesBefore = this.classes.size();
    this.classes.addAll(data.classes);
    if (classesBefore < this.classes.size()) {
{'fraction_non_alphanumeric': 0.09950556242274412, 'fraction_numerical': 0.003399258343634116, 'mean_word_length': 3.794814814814815, 'pattern_counts': {'":': 0, '<': 26, '<?xml version=': 0, '>': 28, 'https://': 0, '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': '988367', 'n_tokens_mistral': 1851, 'n_tokens_neox': 1788, 'n_words': 486}