fixed SoFi number handling

This commit is contained in:
Brian Long 2022-02-02 11:18:14 -05:00
parent 0e7571830c
commit 3980006a2c

View File

@ -1,5 +1,6 @@
package com.inteligr8.buxfer;
import java.text.NumberFormat;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
@ -50,14 +51,14 @@ public class SofiInvestTransaction implements ParsedTransaction {
this.throttle();
this.securities = this.estimateSecurites();
this.perSecurityPrice = this.estimatePrice(securities);
this.perSecurityPrice = this.estimatePrice(this.securities);
String action = Type.Buy.equals(type) ? "Bought" : "Sold";
this.description = new StringBuilder()
.append(action).append(' ')
.append(this.securities == null ? "NaN" : NumberFormatFactory.getSecuritiesFormatter().format(this.securities)).append(' ')
.append(this.getRange(NumberFormatFactory.getSecuritiesFormatter(), this.securities)).append(' ')
.append(this.symbol).append(" @ ")
.append(this.perSecurityPrice == null ? "NaN" : NumberFormatFactory.getPriceFormatter().format(this.perSecurityPrice)).toString();
.append(this.getRange(NumberFormatFactory.getPriceFormatter(), this.perSecurityPrice)).toString();
}
}
@ -159,5 +160,15 @@ public class SofiInvestTransaction implements ParsedTransaction {
else if (this.perSecurityPrice.isPoint()) return this.perSecurityPrice.getFrom().doubleValue();
else return this.perSecurityPrice.getMidpoint();
}
private String getRange(NumberFormat formatter, NumericRange<? extends Number> range) {
if (range == null) {
return "NaN";
} else if (range.isPoint()) {
return formatter.format(range.getFrom().doubleValue());
} else {
return formatter.format(range.getFrom().doubleValue()) + "-" + formatter.format(range.getTo().doubleValue());
}
}
}