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 Money implements org.quantlib.helpers.QuantLibJNIHelpers.AutoCloseable {
012  private transient long swigCPtr;
013  protected transient boolean swigCMemOwn;
014
015  protected Money(long cPtr, boolean cMemoryOwn) {
016    swigCMemOwn = cMemoryOwn;
017    swigCPtr = cPtr;
018  }
019
020  protected static long getCPtr(Money obj) {
021    return (obj == null) ? 0 : obj.swigCPtr;
022  }
023
024  protected static long swigRelease(Money obj) {
025    long ptr = 0;
026    if (obj != null) {
027      if (!obj.swigCMemOwn)
028        throw new RuntimeException("Cannot release ownership as memory is not owned");
029      ptr = obj.swigCPtr;
030      obj.swigCMemOwn = false;
031      obj.delete();
032    }
033    return ptr;
034  }
035
036  @SuppressWarnings("deprecation")
037  protected void finalize() {
038    delete();
039  }
040
041  public synchronized void delete() {
042    if (swigCPtr != 0) {
043      if (swigCMemOwn) {
044        swigCMemOwn = false;
045        QuantLibJNI.delete_Money(swigCPtr);
046      }
047      swigCPtr = 0;
048    }
049  }
050
051  public Money(Currency currency, double value) {
052    this(QuantLibJNI.new_Money__SWIG_0(Currency.getCPtr(currency), currency, value), true);
053  }
054
055  public Money(double value, Currency currency) {
056    this(QuantLibJNI.new_Money__SWIG_1(value, Currency.getCPtr(currency), currency), true);
057  }
058
059  public Currency currency() {
060    return new Currency(QuantLibJNI.Money_currency(swigCPtr, this), false);
061  }
062
063  public double value() {
064    return QuantLibJNI.Money_value(swigCPtr, this);
065  }
066
067  public Money rounded() {
068    return new Money(QuantLibJNI.Money_rounded(swigCPtr, this), true);
069  }
070
071  public Money add() {
072    return new Money(QuantLibJNI.Money_add__SWIG_0(swigCPtr, this), true);
073  }
074
075  public Money subtract() {
076    return new Money(QuantLibJNI.Money_subtract__SWIG_0(swigCPtr, this), true);
077  }
078
079  public Money add(Money m) {
080    return new Money(QuantLibJNI.Money_add__SWIG_1(swigCPtr, this, Money.getCPtr(m), m), true);
081  }
082
083  public Money subtract(Money m) {
084    return new Money(QuantLibJNI.Money_subtract__SWIG_1(swigCPtr, this, Money.getCPtr(m), m), true);
085  }
086
087  public Money multiply(double x) {
088    return new Money(QuantLibJNI.Money_multiply(swigCPtr, this, x), true);
089  }
090
091  public Money divide(double x) {
092    return new Money(QuantLibJNI.Money_divide__SWIG_0(swigCPtr, this, x), true);
093  }
094
095  public double divide(Money m) {
096    return QuantLibJNI.Money_divide__SWIG_1(swigCPtr, this, Money.getCPtr(m), m);
097  }
098
099  public int compare(Money other) {
100    return QuantLibJNI.Money_compare(swigCPtr, this, Money.getCPtr(other), other);
101  }
102
103  public String toString() {
104    return QuantLibJNI.Money_toString(swigCPtr, this);
105  }
106
107  public static void setConversionType(Money.ConversionType type) {
108    QuantLibJNI.Money_setConversionType(type.swigValue());
109  }
110
111  public static void setBaseCurrency(Currency c) {
112    QuantLibJNI.Money_setBaseCurrency(Currency.getCPtr(c), c);
113  }
114
115  public final static class ConversionType {
116    public final static Money.ConversionType NoConversion = new Money.ConversionType("NoConversion");
117    public final static Money.ConversionType BaseCurrencyConversion = new Money.ConversionType("BaseCurrencyConversion");
118    public final static Money.ConversionType AutomatedConversion = new Money.ConversionType("AutomatedConversion");
119
120    public final int swigValue() {
121      return swigValue;
122    }
123
124    public String toString() {
125      return swigName;
126    }
127
128    public static ConversionType swigToEnum(int swigValue) {
129      if (swigValue < swigValues.length && swigValue >= 0 && swigValues[swigValue].swigValue == swigValue)
130        return swigValues[swigValue];
131      for (int i = 0; i < swigValues.length; i++)
132        if (swigValues[i].swigValue == swigValue)
133          return swigValues[i];
134      throw new IllegalArgumentException("No enum " + ConversionType.class + " with value " + swigValue);
135    }
136
137    private ConversionType(String swigName) {
138      this.swigName = swigName;
139      this.swigValue = swigNext++;
140    }
141
142    private ConversionType(String swigName, int swigValue) {
143      this.swigName = swigName;
144      this.swigValue = swigValue;
145      swigNext = swigValue+1;
146    }
147
148    private ConversionType(String swigName, ConversionType swigEnum) {
149      this.swigName = swigName;
150      this.swigValue = swigEnum.swigValue;
151      swigNext = this.swigValue+1;
152    }
153
154    private static ConversionType[] swigValues = { NoConversion, BaseCurrencyConversion, AutomatedConversion };
155    private static int swigNext = 0;
156    private final int swigValue;
157    private final String swigName;
158  }
159
160}