001/* ----------------------------------------------------------------------------
002 * This file was automatically generated by SWIG (https://www.swig.org).
003 * Version 4.1.1
004 *
005 * Do not make changes to this file unless you know what you are doing - modify
006 * the SWIG interface file instead.
007 * ----------------------------------------------------------------------------- */
008
009package org.quantlib;
010
011public class Option extends Instrument implements org.quantlib.helpers.QuantLibJNIHelpers.AutoCloseable {
012  private transient long swigCPtr;
013  private transient boolean swigCMemOwnDerived;
014
015  protected Option(long cPtr, boolean cMemoryOwn) {
016    super(QuantLibJNI.Option_SWIGSmartPtrUpcast(cPtr), true);
017    swigCMemOwnDerived = cMemoryOwn;
018    swigCPtr = cPtr;
019  }
020
021  protected static long getCPtr(Option obj) {
022    return (obj == null) ? 0 : obj.swigCPtr;
023  }
024
025  protected void swigSetCMemOwn(boolean own) {
026    swigCMemOwnDerived = own;
027    super.swigSetCMemOwn(own);
028  }
029
030  @SuppressWarnings("deprecation")
031  protected void finalize() {
032    delete();
033  }
034
035  public synchronized void delete() {
036    if (swigCPtr != 0) {
037      if (swigCMemOwnDerived) {
038        swigCMemOwnDerived = false;
039        QuantLibJNI.delete_Option(swigCPtr);
040      }
041      swigCPtr = 0;
042    }
043    super.delete();
044  }
045
046  public Payoff payoff() {
047    long cPtr = QuantLibJNI.Option_payoff(swigCPtr, this);
048    return (cPtr == 0) ? null : new Payoff(cPtr, true);
049  }
050
051  public Exercise exercise() {
052    long cPtr = QuantLibJNI.Option_exercise(swigCPtr, this);
053    return (cPtr == 0) ? null : new Exercise(cPtr, true);
054  }
055
056  public final static class Type {
057    public final static Option.Type Put = new Option.Type("Put", QuantLibJNI.Option_Put_get());
058    public final static Option.Type Call = new Option.Type("Call", QuantLibJNI.Option_Call_get());
059
060    public final int swigValue() {
061      return swigValue;
062    }
063
064    public String toString() {
065      return swigName;
066    }
067
068    public static Type swigToEnum(int swigValue) {
069      if (swigValue < swigValues.length && swigValue >= 0 && swigValues[swigValue].swigValue == swigValue)
070        return swigValues[swigValue];
071      for (int i = 0; i < swigValues.length; i++)
072        if (swigValues[i].swigValue == swigValue)
073          return swigValues[i];
074      throw new IllegalArgumentException("No enum " + Type.class + " with value " + swigValue);
075    }
076
077    private Type(String swigName) {
078      this.swigName = swigName;
079      this.swigValue = swigNext++;
080    }
081
082    private Type(String swigName, int swigValue) {
083      this.swigName = swigName;
084      this.swigValue = swigValue;
085      swigNext = swigValue+1;
086    }
087
088    private Type(String swigName, Type swigEnum) {
089      this.swigName = swigName;
090      this.swigValue = swigEnum.swigValue;
091      swigNext = this.swigValue+1;
092    }
093
094    private static Type[] swigValues = { Put, Call };
095    private static int swigNext = 0;
096    private final int swigValue;
097    private final String swigName;
098  }
099
100}