<commit_before>package org.smoothbuild.task.compute;

import static com.google.common.base.Preconditions.checkNotNull;

import org.smoothbuild.lang.function.def.DefinedFunction;
import org.smoothbuild.lang.function.nativ.NativeFunction;
import org.smoothbuild.lang.type.ArrayType;
import org.smoothbuild.lang.type.Type;
import org.smoothbuild.lang.value.Value;
import org.smoothbuild.message.base.CodeLocation;
import org.smoothbuild.task.base.TaskInput;
import org.smoothbuild.task.base.TaskOutput;
import org.smoothbuild.task.exec.ContainerImpl;

import com.google.common.hash.HashCode;

public class Computer {
  private final Algorithm algorithm;
  private final String name;
  private final boolean isInternal;
  private final boolean isCacheable;
  private final CodeLocation codeLocation;

  public Computer(Algorithm algorithm, String name, boolean isInternal, boolean isCacheable,
      CodeLocation codeLocation) {
    this.algorithm = algorithm;
    this.name = checkNotNull(name);
    this.isInternal = isInternal;
    this.isCacheable = isCacheable;
    this.codeLocation = checkNotNull(codeLocation);
  }

  public HashCode hash() {
    return algorithm.hash();
  }

  public Type resultType() {
    return algorithm.resultType();
  }

  public String name() {
    return name;
  }

  public boolean isInternal() {
    return isInternal;
  }

  public boolean isCacheable() {
    return isCacheable;
  }

  public CodeLocation codeLocation() {
    return codeLocation;
  }

  public TaskOutput execute(TaskInput input, ContainerImpl container) {
    return algorithm.execute(input, container);
  }

  public static Computer virtualComputer(DefinedFunction function, CodeLocation codeLocation) {
    return new Computer(new IdentityAlgorithm(function.type()), function.name().value(), false,
        true, codeLocation);
  }

  public static Computer nativeCallComputer(NativeFunction function, boolean isInternal,
      CodeLocation codeLocation) {
    return new Computer(new NativeCallAlgorithm(function), function.name().value(), isInternal,
        function.isCacheable(), codeLocation);
  }

  public static Computer arrayComputer(ArrayType arrayType, CodeLocation codeLocation) {
    return new Computer(new ArrayAlgorithm(arrayType), arrayType.name(), true, true,
        codeLocation);
  }

  public static Computer defaultValueComputer(Type type, Value value, CodeLocation codeLocation) {
    return new Computer(new ConstantAlgorithm(value), type.name(), true, true, codeLocation);
  }

  public static Computer constantComputer(Type type, Value value, CodeLocation codeLocation) {
    return new Computer(new ConstantAlgorithm(value), type.name(), true, false, codeLocation);
  }
}<commit_msg>moved Computer factory methods to top of the file<commit_after>package org.smoothbuild.task.compute;

import static com.google.common.base.Preconditions.checkNotNull;

import org.smoothbuild.lang.function.def.DefinedFunction;
import org.smoothbuild.lang.function.nativ.NativeFunction;
import org.smoothbuild.lang.type.ArrayType;
import org.smoothbuild.lang.type.Type;
import org.smoothbuild.lang.value.Value;
import org.smoothbuild.message.base.CodeLocation;
import org.smoothbuild.task.base.TaskInput;
import org.smoothbuild.task.base.TaskOutput;
import org.smoothbuild.task.exec.ContainerImpl;

import com.google.common.hash.HashCode;

public class Computer {
  private final Algorithm algorithm;
  private final String name;
  private final boolean isInternal;
  private final boolean isCacheable;
  private final CodeLocation codeLocation;

  public static Computer constantComputer(Type type, Value value, CodeLocation codeLocation) {
    return new Computer(new ConstantAlgorithm(value), type.name(), true, false, codeLocation);
  }

  public static Computer defaultValueComputer(Type type, Value value, CodeLocation codeLocation) {
    return new Computer(new ConstantAlgorithm(value), type.name(), true, true, codeLocation);
  }

  public static Computer arrayComputer(ArrayType arrayType, CodeLocation codeLocation) {
    return new Computer(new ArrayAlgorithm(arrayType), arrayType.name(), true, true, codeLocation);
  }

  public static Computer nativeCallComputer(NativeFunction function, boolean isInternal,
      CodeLocation codeLocation) {
    return new Computer(new NativeCallAlgorithm(function), function.name().value(), isInternal,
        function.isCacheable(), codeLocation);
  }

  public static Computer virtualComputer(DefinedFunction function, CodeLocation codeLocation) {
    return new Computer(new IdentityAlgorithm(function.type()), function.name().value(), false,
        true, codeLocation);
  }

  public Computer(Algorithm algorithm, String name, boolean isInternal, boolean isCacheable,
      CodeLocation codeLocation) {
    this.algorithm = algorithm;
    this.name = checkNotNull(name);
    this.isInternal = isInternal;
    this.isCacheable = isCacheable;
    this.codeLocation = checkNotNull(codeLocation);
  }

  public HashCode hash() {
    return algorithm.hash();
  }

  public Type resultType() {
    return algorithm.resultType();
  }

  public String name() {
    return name;
  }

  public boolean isInternal() {
    return isInternal;
  }

  public boolean isCacheable() {
    return isCacheable;
  }

  public CodeLocation codeLocation() {
    return codeLocation;
  }

  public TaskOutput execute(TaskInput input, ContainerImpl container) {
    return algorithm.execute(input, container);
  }
}
{'fraction_non_alphanumeric': 0.08967789165446559, 'fraction_numerical': 0.0, 'mean_word_length': 4.7953340402969244, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, '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': '4936703', 'n_tokens_mistral': 1474, 'n_tokens_neox': 1414, 'n_words': 386}