<commit_before>package joshng.util.exceptions;

/**
 * User: josh
 * Date: 2/6/12
 * Time: 8:58 PM
 */

import com.google.common.base.Throwables;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.Lists;
import joshng.util.blocks.F2;
import joshng.util.collect.Maybe;

import java.util.Collections;
import java.util.List;

public interface MultiException {
  public static final F2<Throwable, MultiException, MultiException> COMBINER = new F2<Throwable, MultiException, MultiException>() {
    @Override
    public MultiException apply(Throwable input1, MultiException input2) {
      return input2.with(input1);
    }
  };

  MultiException with(Throwable toAdd);

  List<Throwable> getThrowables();

  Maybe<Throwable> getCombinedThrowable();

  <E extends Throwable> void throwIfException(Class<E> exceptionClass) throws E;

  void throwRuntimeIfAny();

  public static final MultiException Empty = new EmptyImpl();

  class EmptyImpl implements MultiException {
    private EmptyImpl() {
    }

    public MultiException with(Throwable toAdd) {
      if (toAdd instanceof MultiException) return (MultiException) toAdd;
      return new Single(toAdd);
    }

    public List<Throwable> getThrowables() {
      return ImmutableList.of();
    }

    @Override
    public Maybe<Throwable> getCombinedThrowable() {
      return Maybe.not();
    }

    public <E extends Throwable> void throwIfException(Class<E> exceptionClass) throws E {
    }

    public void throwRuntimeIfAny() {
    }
  }

  class Single implements MultiException {
    private final Throwable throwable;
<commit_msg>add some dubious default methods to MultiException<commit_after>package joshng.util.exceptions;

/**
 * User: josh
 * Date: 2/6/12
 * Time: 8:58 PM
 */

import com.google.common.base.Throwables;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.Lists;
import joshng.util.blocks.F2;
import joshng.util.collect.Maybe;

import java.util.Collections;
import java.util.List;

public interface MultiException {
  public static final F2<Throwable, MultiException, MultiException> COMBINER = new F2<Throwable, MultiException, MultiException>() {
    @Override
    public MultiException apply(Throwable input1, MultiException input2) {
      return input2.with(input1);
    }
  };

  MultiException with(Throwable toAdd);

  List<Throwable> getThrowables();

  Maybe<Throwable> getCombinedThrowable();

  <E extends Throwable> void throwIfException(Class<E> exceptionClass) throws E;

  void throwRuntimeIfAny();

  default MultiException collectExceptions(Iterable<? extends Runnable> runnables) {
    MultiException result = this;
    for (Runnable runnable : runnables) {
      result = result.consumeException(runnable);
    }
    return result;
  }

  default MultiException consumeException(Runnable runnable) {
    try {
      runnable.run();
      return this;
    } catch (Exception e) {
      return with(e);
    }
  }

  public static final MultiException Empty = new EmptyImpl();

  class EmptyImpl implements MultiException {
    private EmptyImpl() {
    }

    public MultiException with(Throwable toAdd) {
      if (toAdd instanceof MultiException) return (MultiException) toAdd;
      return new Single(toAdd);
    }

    public List<Throwable> getThrowables() {
      return ImmutableList.of();
    }

    @Override
    public Maybe<Throwable> getCombinedThrowable() {
      return Maybe.not();
    }

    public <E extends Throwable> void throwIfException(Class<E> exceptionClass) throws E {
    }

    public void throwRuntimeIfAny() {
    }
  }

  class Single implements MultiException {
    private final Throwable throwable;

{'fraction_non_alphanumeric': 0.09379235565193819, 'fraction_numerical': 0.007590132827324478, 'mean_word_length': 3.8938992042440317, 'pattern_counts': {'":': 0, '<': 24, '<?xml version=': 0, '>': 24, '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': '4737143', 'n_tokens_mistral': 1111, 'n_tokens_neox': 1058, 'n_words': 278}