Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow a currency pair to be converted to a set #1695

Merged
merged 1 commit into from
May 21, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
import org.joda.convert.ToString;

import com.google.common.collect.ImmutableMap;
import com.google.common.collect.ImmutableSet;
import com.opengamma.strata.collect.ArgChecker;

/**
Expand Down Expand Up @@ -292,6 +293,19 @@ public CurrencyPair toConventional() {
return isConventional() ? this : inverse();
}

/**
* Returns the set of currencies contains in the pair.
*
* @return the set of currencies, with iteration in conventional order
*/
public ImmutableSet<Currency> toSet() {
if (isConventional()) {
return ImmutableSet.of(base, counter);
} else {
return ImmutableSet.of(counter, base);
}
}

/**
* Gets the number of digits in the rate.
* <p>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@
import org.testng.annotations.DataProvider;
import org.testng.annotations.Test;

import com.google.common.collect.ImmutableSet;

/**
* Test {@link CurrencyPair}.
*/
Expand All @@ -46,6 +48,7 @@ public void test_of_CurrencyCurrency() {
assertEquals(test.getBase(), GBP);
assertEquals(test.getCounter(), USD);
assertEquals(test.isIdentity(), false);
assertEquals(test.toSet(), ImmutableSet.of(GBP, USD));
assertEquals(test.toString(), "GBP/USD");
}

Expand All @@ -54,6 +57,7 @@ public void test_of_CurrencyCurrency_reverseStandardOrder() {
assertEquals(test.getBase(), USD);
assertEquals(test.getCounter(), GBP);
assertEquals(test.isIdentity(), false);
assertEquals(test.toSet(), ImmutableSet.of(GBP, USD));
assertEquals(test.toString(), "USD/GBP");
}

Expand Down