Search in sources :

Example 11 with ExchangeRate

use of name.abuchen.portfolio.money.ExchangeRate in project portfolio by buchen.

the class ExchangeRateWidget method update.

@Override
void update() {
    this.title.setText(getWidget().getLabel());
    ReportingPeriod period = get(ReportingPeriodConfig.class).getReportingPeriod();
    ExchangeRateTimeSeries series = get(ExchangeRateSeriesConfig.class).getSeries();
    Optional<ExchangeRate> rate = series.lookupRate(period.getEndDate());
    this.indicator.setText(series.getLabel() + ' ' + (rate.isPresent() ? Values.ExchangeRate.format(rate.get().getValue()) : '-'));
}
Also used : ReportingPeriod(name.abuchen.portfolio.snapshot.ReportingPeriod) ExchangeRate(name.abuchen.portfolio.money.ExchangeRate) ExchangeRateTimeSeries(name.abuchen.portfolio.money.ExchangeRateTimeSeries)

Example 12 with ExchangeRate

use of name.abuchen.portfolio.money.ExchangeRate in project portfolio by buchen.

the class ChainedExchangeRateTimeSeriesTest method testIfSomeRatesDoNotExist.

@Test
public void testIfSomeRatesDoNotExist() {
    ExchangeRateTimeSeriesImpl first = new ExchangeRateTimeSeriesImpl();
    first.addRate(new ExchangeRate(LocalDate.parse("2014-11-30"), BigDecimal.valueOf(1)));
    ExchangeRateTimeSeriesImpl second = new ExchangeRateTimeSeriesImpl();
    ChainedExchangeRateTimeSeries chained = new ChainedExchangeRateTimeSeries(first, second);
    assertThat(chained.lookupRate(LocalDate.parse("2014-11-30")).isPresent(), is(false));
}
Also used : ExchangeRate(name.abuchen.portfolio.money.ExchangeRate) Test(org.junit.Test)

Example 13 with ExchangeRate

use of name.abuchen.portfolio.money.ExchangeRate in project portfolio by buchen.

the class ExchangeRateTimeSeriesImplTest method testAddingOfExchangeRates.

@Test
public void testAddingOfExchangeRates() {
    ExchangeRateTimeSeriesImpl series = new ExchangeRateTimeSeriesImpl(null, "EUR", "USD");
    series.addRate(new ExchangeRate(LocalDate.parse("2014-12-01"), BigDecimal.valueOf(1)));
    series.addRate(new ExchangeRate(LocalDate.parse("2014-12-01"), BigDecimal.valueOf(2)));
    assertProperties(series);
}
Also used : ExchangeRate(name.abuchen.portfolio.money.ExchangeRate) Test(org.junit.Test)

Example 14 with ExchangeRate

use of name.abuchen.portfolio.money.ExchangeRate in project portfolio by buchen.

the class ExchangeRateTimeSeriesImplTest method testCreationFromTemplate.

@Test
public void testCreationFromTemplate() {
    ExchangeRateTimeSeriesImpl template = new ExchangeRateTimeSeriesImpl(null, "EUR", "USD");
    template.addRate(new ExchangeRate(LocalDate.parse("2014-12-01"), BigDecimal.valueOf(1)));
    template.addRate(new ExchangeRate(LocalDate.parse("2014-12-01"), BigDecimal.valueOf(2)));
    ExchangeRateTimeSeriesImpl series = new ExchangeRateTimeSeriesImpl(template);
    assertProperties(series);
}
Also used : ExchangeRate(name.abuchen.portfolio.money.ExchangeRate) Test(org.junit.Test)

Example 15 with ExchangeRate

use of name.abuchen.portfolio.money.ExchangeRate in project portfolio by buchen.

the class ExchangeRateTimeSeriesImplTest method testLookupOfExchangeRate.

@Test
public void testLookupOfExchangeRate() {
    ExchangeRateTimeSeriesImpl series = new ExchangeRateTimeSeriesImpl();
    series.addRate(new ExchangeRate(LocalDate.parse("2014-12-01"), BigDecimal.valueOf(1)));
    series.addRate(new ExchangeRate(LocalDate.parse("2014-12-02"), BigDecimal.valueOf(2)));
    series.addRate(new ExchangeRate(LocalDate.parse("2014-12-03"), BigDecimal.valueOf(3)));
    assertThat(series.lookupRate(LocalDate.parse("2014-11-30")).get().getValue(), is(BigDecimal.valueOf(1)));
    assertThat(series.lookupRate(LocalDate.parse("2014-12-01")).get().getValue(), is(BigDecimal.valueOf(1)));
    assertThat(series.lookupRate(LocalDate.parse("2014-12-02")).get().getValue(), is(BigDecimal.valueOf(2)));
    assertThat(series.lookupRate(LocalDate.parse("2014-12-03")).get().getValue(), is(BigDecimal.valueOf(3)));
    assertThat(series.lookupRate(LocalDate.parse("2014-12-04")).get().getValue(), is(BigDecimal.valueOf(3)));
}
Also used : ExchangeRate(name.abuchen.portfolio.money.ExchangeRate) Test(org.junit.Test)

Aggregations

ExchangeRate (name.abuchen.portfolio.money.ExchangeRate)23 Test (org.junit.Test)8 ExchangeRateTimeSeries (name.abuchen.portfolio.money.ExchangeRateTimeSeries)6 BigDecimal (java.math.BigDecimal)5 LocalDate (java.time.LocalDate)5 HashMap (java.util.HashMap)3 List (java.util.List)3 Column (name.abuchen.portfolio.ui.util.viewers.Column)3 ColumnLabelProvider (org.eclipse.jface.viewers.ColumnLabelProvider)3 Composite (org.eclipse.swt.widgets.Composite)3 File (java.io.File)2 MessageFormat (java.text.MessageFormat)2 ArrayList (java.util.ArrayList)2 Map (java.util.Map)2 Inject (javax.inject.Inject)2 CurrencyConverter (name.abuchen.portfolio.money.CurrencyConverter)2 Values (name.abuchen.portfolio.money.Values)2 Messages (name.abuchen.portfolio.ui.Messages)2 Colors (name.abuchen.portfolio.ui.util.Colors)2 ShowHideColumnHelper (name.abuchen.portfolio.ui.util.viewers.ShowHideColumnHelper)2