61 lines
1.6 KiB
Java
61 lines
1.6 KiB
Java
|
|
package com.stephenschafer.budget;
|
||
|
|
|
||
|
|
import java.math.BigDecimal;
|
||
|
|
import java.math.RoundingMode;
|
||
|
|
import java.text.DateFormat;
|
||
|
|
import java.text.SimpleDateFormat;
|
||
|
|
|
||
|
|
import lombok.AllArgsConstructor;
|
||
|
|
import lombok.Getter;
|
||
|
|
import lombok.Setter;
|
||
|
|
import lombok.ToString;
|
||
|
|
|
||
|
|
@Getter
|
||
|
|
@Setter
|
||
|
|
@AllArgsConstructor
|
||
|
|
@ToString
|
||
|
|
class UnresolvedItem implements Comparable<UnresolvedItem> {
|
||
|
|
private final int year;
|
||
|
|
private final String source;
|
||
|
|
private final String description;
|
||
|
|
private final java.sql.Date date;
|
||
|
|
private final BigDecimal amount;
|
||
|
|
|
||
|
|
@Override
|
||
|
|
public int compareTo(final UnresolvedItem that) {
|
||
|
|
if (this.year < that.year) {
|
||
|
|
return -1;
|
||
|
|
}
|
||
|
|
if (this.year > that.year) {
|
||
|
|
return 1;
|
||
|
|
}
|
||
|
|
String thisSource = source;
|
||
|
|
if (thisSource == null) {
|
||
|
|
thisSource = "";
|
||
|
|
}
|
||
|
|
String thatSource = that.source;
|
||
|
|
if (thatSource == null) {
|
||
|
|
thatSource = "";
|
||
|
|
}
|
||
|
|
final int comparison = thisSource.compareTo(thatSource);
|
||
|
|
if (comparison != 0) {
|
||
|
|
return comparison;
|
||
|
|
}
|
||
|
|
String thisdescription = description;
|
||
|
|
if (thisdescription == null) {
|
||
|
|
thisdescription = "";
|
||
|
|
}
|
||
|
|
String thatdescription = that.description;
|
||
|
|
if (thatdescription == null) {
|
||
|
|
thatdescription = "";
|
||
|
|
}
|
||
|
|
return thisdescription.compareTo(thatdescription);
|
||
|
|
}
|
||
|
|
|
||
|
|
public String replace(final String string) {
|
||
|
|
final DateFormat df = new SimpleDateFormat("yyyy-MM-dd");
|
||
|
|
return string.replace("${year}", String.valueOf(year)).replace("${source}", source).replace(
|
||
|
|
"${description}", description).replace("${date}", df.format(date)).replace("${amount}",
|
||
|
|
amount.setScale(2, RoundingMode.HALF_UP).toPlainString());
|
||
|
|
}
|
||
|
|
}
|