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 ExchangeRate implements org.quantlib.helpers.QuantLibJNIHelpers.AutoCloseable { 012 private transient long swigCPtr; 013 protected transient boolean swigCMemOwn; 014 015 protected ExchangeRate(long cPtr, boolean cMemoryOwn) { 016 swigCMemOwn = cMemoryOwn; 017 swigCPtr = cPtr; 018 } 019 020 protected static long getCPtr(ExchangeRate obj) { 021 return (obj == null) ? 0 : obj.swigCPtr; 022 } 023 024 protected static long swigRelease(ExchangeRate 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_ExchangeRate(swigCPtr); 046 } 047 swigCPtr = 0; 048 } 049 } 050 051 public ExchangeRate(Currency source, Currency target, double rate) { 052 this(QuantLibJNI.new_ExchangeRate(Currency.getCPtr(source), source, Currency.getCPtr(target), target, rate), true); 053 } 054 055 public Currency source() { 056 return new Currency(QuantLibJNI.ExchangeRate_source(swigCPtr, this), false); 057 } 058 059 public Currency target() { 060 return new Currency(QuantLibJNI.ExchangeRate_target(swigCPtr, this), false); 061 } 062 063 public ExchangeRate.Type type() { 064 return ExchangeRate.Type.swigToEnum(QuantLibJNI.ExchangeRate_type(swigCPtr, this)); 065 } 066 067 public double rate() { 068 return QuantLibJNI.ExchangeRate_rate(swigCPtr, this); 069 } 070 071 public Money exchange(Money amount) { 072 return new Money(QuantLibJNI.ExchangeRate_exchange(swigCPtr, this, Money.getCPtr(amount), amount), true); 073 } 074 075 public static ExchangeRate chain(ExchangeRate r1, ExchangeRate r2) { 076 return new ExchangeRate(QuantLibJNI.ExchangeRate_chain(ExchangeRate.getCPtr(r1), r1, ExchangeRate.getCPtr(r2), r2), true); 077 } 078 079 public final static class Type { 080 public final static ExchangeRate.Type Direct = new ExchangeRate.Type("Direct"); 081 public final static ExchangeRate.Type Derived = new ExchangeRate.Type("Derived"); 082 083 public final int swigValue() { 084 return swigValue; 085 } 086 087 public String toString() { 088 return swigName; 089 } 090 091 public static Type swigToEnum(int swigValue) { 092 if (swigValue < swigValues.length && swigValue >= 0 && swigValues[swigValue].swigValue == swigValue) 093 return swigValues[swigValue]; 094 for (int i = 0; i < swigValues.length; i++) 095 if (swigValues[i].swigValue == swigValue) 096 return swigValues[i]; 097 throw new IllegalArgumentException("No enum " + Type.class + " with value " + swigValue); 098 } 099 100 private Type(String swigName) { 101 this.swigName = swigName; 102 this.swigValue = swigNext++; 103 } 104 105 private Type(String swigName, int swigValue) { 106 this.swigName = swigName; 107 this.swigValue = swigValue; 108 swigNext = swigValue+1; 109 } 110 111 private Type(String swigName, Type swigEnum) { 112 this.swigName = swigName; 113 this.swigValue = swigEnum.swigValue; 114 swigNext = this.swigValue+1; 115 } 116 117 private static Type[] swigValues = { Direct, Derived }; 118 private static int swigNext = 0; 119 private final int swigValue; 120 private final String swigName; 121 } 122 123}