<commit_before>package org.smoothbuild.load;

import static java.lang.ClassLoader.getSystemClassLoader;
import static java.util.function.Function.identity;
import static org.smoothbuild.plugin.UnzipBlob.unzipBlob;
import static org.smoothbuild.run.eval.FileStruct.fileContent;
import static org.smoothbuild.run.eval.FileStruct.filePath;
import static org.smoothbuild.util.collect.Maps.computeIfAbsent;
import static org.smoothbuild.util.collect.Maps.toMap;
import static org.smoothbuild.util.reflect.ClassLoaders.mapClassLoader;

import java.io.IOException;
import java.util.HashMap;
import java.util.Map;

import javax.inject.Inject;
import javax.inject.Singleton;

import org.smoothbuild.bytecode.BytecodeF;
import org.smoothbuild.bytecode.obj.val.BlobB;
import org.smoothbuild.bytecode.obj.val.TupleB;
import org.smoothbuild.util.collect.Result;
import org.smoothbuild.util.io.DuplicateFileNameExc;
import org.smoothbuild.util.io.IllegalZipEntryFileNameExc;

import net.lingala.zip4j.exception.ZipException;

/**
 * This class is thread-safe.
 */
@Singleton
public class JarClassLoaderProv {
  private final BytecodeF bytecodeF;
  private final ClassLoader parentClassLoader;
  private final HashMap<BlobB, Result<ClassLoader>> cache;

  @Inject
  public JarClassLoaderProv(BytecodeF bytecodeF) {
    this(bytecodeF, getSystemClassLoader());
  }

  public JarClassLoaderProv(BytecodeF bytecodeF, ClassLoader parentClassLoader) {
    this.bytecodeF = bytecodeF;
    this.parentClassLoader = parentClassLoader;
    this.cache = new HashMap<>();
  }

  public synchronized Result<ClassLoader> classLoaderFor(BlobB jar) throws IOException {
    return computeIfAbsent(cache, jar, j -> newClassLoader(parentClassLoader, j));
  }

  private Result<ClassLoader> newClassLoader(ClassLoader parentClassLoader, BlobB jar)<commit_msg>refactored JarClassLoaderProv<commit_after>package org.smoothbuild.load;

import static java.lang.ClassLoader.getSystemClassLoader;
import static java.util.function.Function.identity;
import static org.smoothbuild.plugin.UnzipBlob.unzipBlob;
import static org.smoothbuild.run.eval.FileStruct.fileContent;
import static org.smoothbuild.run.eval.FileStruct.filePath;
import static org.smoothbuild.util.collect.Maps.computeIfAbsent;
import static org.smoothbuild.util.collect.Maps.toMap;
import static org.smoothbuild.util.reflect.ClassLoaders.mapClassLoader;

import java.io.IOException;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;

import javax.inject.Inject;
import javax.inject.Singleton;

import org.smoothbuild.bytecode.BytecodeF;
import org.smoothbuild.bytecode.obj.val.BlobB;
import org.smoothbuild.bytecode.obj.val.TupleB;
import org.smoothbuild.util.collect.Result;
import org.smoothbuild.util.io.DuplicateFileNameExc;
import org.smoothbuild.util.io.IllegalZipEntryFileNameExc;

import net.lingala.zip4j.exception.ZipException;

/**
 * This class is thread-safe.
 */
@Singleton
public class JarClassLoaderProv {
  private final BytecodeF bytecodeF;
  private final ClassLoader parentClassLoader;
  private final ConcurrentHashMap<BlobB, Result<ClassLoader>> cache;

  @Inject
  public JarClassLoaderProv(BytecodeF bytecodeF) {
    this(bytecodeF, getSystemClassLoader());
  }

  public JarClassLoaderProv(BytecodeF bytecodeF, ClassLoader parentClassLoader) {
    this.bytecodeF = bytecodeF;
    this.parentClassLoader = parentClassLoader;
    this.cache = new ConcurrentHashMap<>();
  }

  public Result<ClassLoader> classLoaderFor(BlobB jar) throws IOException {
    return computeIfAbsent(cache, jar, j -> newClassLoader(parentClassLoader, j));
  }

  private Result<ClassLoader> newClassLoader(ClassLoader parentClassLoader, BlobB jar)
{'fraction_non_alphanumeric': 0.09172077922077922, 'fraction_numerical': 0.0005411255411255411, 'mean_word_length': 6.082375478927203, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 15, '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': '4667584', 'n_tokens_mistral': 1136, 'n_tokens_neox': 1104, 'n_words': 215}