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 Swap extends Instrument implements org.quantlib.helpers.QuantLibJNIHelpers.AutoCloseable {
012  private transient long swigCPtr;
013  private transient boolean swigCMemOwnDerived;
014
015  protected Swap(long cPtr, boolean cMemoryOwn) {
016    super(QuantLibJNI.Swap_SWIGSmartPtrUpcast(cPtr), true);
017    swigCMemOwnDerived = cMemoryOwn;
018    swigCPtr = cPtr;
019  }
020
021  protected static long getCPtr(Swap 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_Swap(swigCPtr);
040      }
041      swigCPtr = 0;
042    }
043    super.delete();
044  }
045
046  public Swap(Leg firstLeg, Leg secondLeg) {
047    this(QuantLibJNI.new_Swap__SWIG_0(Leg.getCPtr(firstLeg), firstLeg, Leg.getCPtr(secondLeg), secondLeg), true);
048  }
049
050  public Swap(LegVector legs, BoolVector payer) {
051    this(QuantLibJNI.new_Swap__SWIG_1(LegVector.getCPtr(legs), legs, BoolVector.getCPtr(payer), payer), true);
052  }
053
054  public long numberOfLegs() {
055    return QuantLibJNI.Swap_numberOfLegs(swigCPtr, this);
056  }
057
058  public Date startDate() {
059    return new Date(QuantLibJNI.Swap_startDate(swigCPtr, this), true);
060  }
061
062  public Date maturityDate() {
063    return new Date(QuantLibJNI.Swap_maturityDate(swigCPtr, this), true);
064  }
065
066  public Leg leg(long i) {
067    return new Leg(QuantLibJNI.Swap_leg(swigCPtr, this, i), false);
068  }
069
070  public double legNPV(long j) {
071    return QuantLibJNI.Swap_legNPV(swigCPtr, this, j);
072  }
073
074  public double legBPS(long k) {
075    return QuantLibJNI.Swap_legBPS(swigCPtr, this, k);
076  }
077
078  public double startDiscounts(long j) {
079    return QuantLibJNI.Swap_startDiscounts(swigCPtr, this, j);
080  }
081
082  public double endDiscounts(long j) {
083    return QuantLibJNI.Swap_endDiscounts(swigCPtr, this, j);
084  }
085
086  public double npvDateDiscount() {
087    return QuantLibJNI.Swap_npvDateDiscount(swigCPtr, this);
088  }
089
090  public boolean payer(long j) {
091    return QuantLibJNI.Swap_payer(swigCPtr, this, j);
092  }
093
094  public final static class Type {
095    public final static Swap.Type Receiver = new Swap.Type("Receiver", QuantLibJNI.Swap_Receiver_get());
096    public final static Swap.Type Payer = new Swap.Type("Payer", QuantLibJNI.Swap_Payer_get());
097
098    public final int swigValue() {
099      return swigValue;
100    }
101
102    public String toString() {
103      return swigName;
104    }
105
106    public static Type swigToEnum(int swigValue) {
107      if (swigValue < swigValues.length && swigValue >= 0 && swigValues[swigValue].swigValue == swigValue)
108        return swigValues[swigValue];
109      for (int i = 0; i < swigValues.length; i++)
110        if (swigValues[i].swigValue == swigValue)
111          return swigValues[i];
112      throw new IllegalArgumentException("No enum " + Type.class + " with value " + swigValue);
113    }
114
115    private Type(String swigName) {
116      this.swigName = swigName;
117      this.swigValue = swigNext++;
118    }
119
120    private Type(String swigName, int swigValue) {
121      this.swigName = swigName;
122      this.swigValue = swigValue;
123      swigNext = swigValue+1;
124    }
125
126    private Type(String swigName, Type swigEnum) {
127      this.swigName = swigName;
128      this.swigValue = swigEnum.swigValue;
129      swigNext = this.swigValue+1;
130    }
131
132    private static Type[] swigValues = { Receiver, Payer };
133    private static int swigNext = 0;
134    private final int swigValue;
135    private final String swigName;
136  }
137
138}