M
Mikhail Teterin
Hello!
For some reason, I can not properly compare a string to an enum, even when
there is supposed to be a match:
I declare the enum as follows:
private enum Currency {
USD ("USDAM3L", "US"),
EUR ("EURAB6E", "DE"),
GBP ("GBPSB6L", "GB");
String swapsymbol, ricroot;
Currency(String _swapsymbol, String _ricroot)
{
swapsymbol = _swapsymbol;
ricroot = _ricroot;
}
}
I then run through it as:
String swapsymbol = null;
for (Currency currency : Currency.values()) {
if (bond.currency.equals(currency)) {
swapsymbol = currency.swapsymbol;
break;
} else {
System.err.println(">" + currency + "< did not match >"
+ bond.currency + "<");
}
}
if (swapsymbol == null) {
System.exit(0);
throw new Exception("Can not find swap-symbol " +
"for currency " + bond.currency);
}
This results in the following output:
As you can see, it failed to notice, that "EUR" equals "EUR" for some
reason. Can anyone, please, help? Thanks!
-mi
For some reason, I can not properly compare a string to an enum, even when
there is supposed to be a match:
I declare the enum as follows:
private enum Currency {
USD ("USDAM3L", "US"),
EUR ("EURAB6E", "DE"),
GBP ("GBPSB6L", "GB");
String swapsymbol, ricroot;
Currency(String _swapsymbol, String _ricroot)
{
swapsymbol = _swapsymbol;
ricroot = _ricroot;
}
}
I then run through it as:
String swapsymbol = null;
for (Currency currency : Currency.values()) {
if (bond.currency.equals(currency)) {
swapsymbol = currency.swapsymbol;
break;
} else {
System.err.println(">" + currency + "< did not match >"
+ bond.currency + "<");
}
}
if (swapsymbol == null) {
System.exit(0);
throw new Exception("Can not find swap-symbol " +
"for currency " + bond.currency);
}
This results in the following output:
>USD< did not match >EUR<
>EUR< did not match >EUR<
>GBP< did not match >EUR<
As you can see, it failed to notice, that "EUR" equals "EUR" for some
reason. Can anyone, please, help? Thanks!
-mi