<commit_before>package no.rosbach.jcoru.rest;

import static java.util.stream.Collectors.toList;
import static org.apache.commons.lang3.StringUtils.isBlank;

import no.rosbach.jcoru.compile.JavaCompiler;
import no.rosbach.jcoru.filemanager.CompiledClassObject;
import no.rosbach.jcoru.rest.reports.CompilationReportBuilder;

import java.util.List;

import javax.tools.JavaFileObject;
import javax.ws.rs.BadRequestException;

public abstract class CompilerResourceBase {
  protected final CompilationReportBuilder reportBuilder = new CompilationReportBuilder();
  private final JavaCompiler compiler = new JavaCompiler(reportBuilder);
  private final ClassLoader classLoader = compiler.getClassLoader();

  protected void throwBadRequestIfSourcesAreInvalid(List<JavaSourceStringDto> sources) {
    if (sources == null) {
      throw new BadRequestException("Empty source payload.");
    }
    List<JavaSourceStringDto> invalidSources = sources.stream().filter(s -> isBlank(s.filename) || isBlank(s.sourcecode)).collect(toList());
    if (!invalidSources.isEmpty()) {
      throw new BadRequestException(
          String.format(
              "The following source files are missing file name or source code: ",
              invalidSources.stream().map(s -> s.filename).reduce((f1, f2) -> f1 + ", " + f2)));
    }
  }

  protected List<CompiledClassObject> compile(List<JavaSourceStringDto> sources) {
    return compiler.compile(sources.stream().map(source -> source.transfer()).collect(toList()));
  }

  // TODO: Remove
  protected Class<?> loadClass(JavaFileObject javaFile) {
    try {
      return classLoader.loadClass(javaFile.getName());
    } catch (ClassNotFoundException e) {
      throw new Error("Could not load class: " + javaFile.getName(), e);
    }
  }
}<commit_msg>Removed unused code.<commit_after>package no.rosbach.jcoru.rest;

import static java.util.stream.Collectors.toList;
import static org.apache.commons.lang3.StringUtils.isBlank;

import no.rosbach.jcoru.compile.JavaCompiler;
import no.rosbach.jcoru.filemanager.CompiledClassObject;
import no.rosbach.jcoru.rest.reports.CompilationReportBuilder;

import java.util.List;

import javax.ws.rs.BadRequestException;

public abstract class CompilerResourceBase {
  protected final CompilationReportBuilder reportBuilder = new CompilationReportBuilder();
  private final JavaCompiler compiler = new JavaCompiler(reportBuilder);

  protected void throwBadRequestIfSourcesAreInvalid(List<JavaSourceStringDto> sources) {
    if (sources == null) {
      throw new BadRequestException("Empty source payload.");
    }
    List<JavaSourceStringDto> invalidSources = sources.stream().filter(s -> isBlank(s.filename) || isBlank(s.sourcecode)).collect(toList());
    if (!invalidSources.isEmpty()) {
      throw new BadRequestException(
          String.format(
              "The following source files are missing file name or source code: ",
              invalidSources.stream().map(s -> s.filename).reduce((f1, f2) -> f1 + ", " + f2)));
    }
  }

  protected List<CompiledClassObject> compile(List<JavaSourceStringDto> sources) {
    return compiler.compile(sources.stream().map(source -> source.transfer()).collect(toList()));
  }
}
{'fraction_non_alphanumeric': 0.11454431960049938, 'fraction_numerical': 0.003121098626716604, 'mean_word_length': 4.564236111111111, 'pattern_counts': {'":': 0, '<': 12, '<?xml version=': 0, '>': 20, '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': '6814892', 'n_tokens_mistral': 899, 'n_tokens_neox': 898, 'n_words': 189}