ExceptionSet.java

/**
* Copyright 2010,2021 Nikolas S Boyd.
Permission is granted to copy this work provided this copyright statement is retained in all copies.

*/
package Hoot.Exceptions;

import Hoot.Runtime.Functions.*;
import Hoot.Runtime.Faces.*;
import Hoot.Runtime.Values.*;
import Hoot.Runtime.Blocks.*;
import Smalltalk.Core.*;
import Smalltalk.Blocks.*;
import Smalltalk.Magnitudes.*;
import Hoot.Behaviors.*;
import Hoot.Behaviors.Nil;
import Hoot.Behaviors.Object;
import Hoot.Behaviors.True;
import Hoot.Behaviors.False;
import Hoot.Behaviors.Boolean;
import Hoot.Magnitudes.*;
import Hoot.Magnitudes.Integer;
import Hoot.Magnitudes.Character;
import Hoot.Magnitudes.Float;
import Hoot.Magnitudes.Double;
import Hoot.Collections.*;
import Hoot.Collections.String;
import java.util.HashSet;
import Hoot.Collections.Set;
import Smalltalk.Core.Posit;
import Smalltalk.Core.Subject;
import Smalltalk.Exceptions.*;

public class ExceptionSet extends Object implements ExceptionalSet
{

  public static Metaclass type() { return (Metaclass)Metaclass.$class; }
  @Override public Metaclass $class() { return (Metaclass)Metaclass.$class; }
  public static class Metaclass extends Object.Metaclass implements ExceptionalSet.Metatype
  {
    static final ExceptionSet.Metaclass $class = new ExceptionSet.Metaclass();
    public Metaclass() {
      this(ExceptionSet.Metaclass.class);
    }

    public Metaclass(java.lang.Class aClass) {
      super(aClass);
    }

    @Override public java.lang.Class outerClass() { return ExceptionSet.class; }


    /**
     * @return 
     */
    public   ExceptionSet with(final ExceptionSelector.Metatype exceptionClass)
    {
      java.lang.String exitID = "ExceptionSetMetatype>>with";
      Frame f0 = new Frame(exitID);
      return f0.evaluate(() -> {
      return (ExceptionSet)f0.exit(exitID, (new ExceptionSet().append(exceptionClass)));
      });
    }
  }


  protected HashSet<ExceptionSelector.Metatype> exceptions = new HashSet();

  /**
   * @return 
   */
  public   ExceptionSet append(final ExceptionSelector.Metatype exceptionClass)
  {
    java.lang.String exitID = "ExceptionSet>>append";
    Frame f0 = new Frame(exitID);
    exceptions.add(exceptionClass);
    return (ExceptionSet)this;
  }

  /**
   * @return 
   */
  public   Boolean handles(final SignaledException anException)
  {
    java.lang.String exitID = "ExceptionSet>>handles";
    Frame f0 = new Frame(exitID);
    return (Boolean)Boolean.from(Closure.with(f2 -> {
      ExceptionDescription.Metatype exceptionClass = f2.getValue(0).value();
      anException.isKindOf(exceptionClass).primitiveBoolean();
    }, "exceptionClass").testWithEach(exceptions));
  }
}