use of jgnash.util.function.PayeePredicate in project jgnash by ccavanaugh.
the class RegisterTableController method handleFilterChange.
private void handleFilterChange() {
Predicate<Transaction> predicate = new ReconciledPredicate(account.get(), reconciledStateFilterComboBox.valueProperty().get().getReconciledState()).and(new TransactionAgePredicate(transactionAgeFilterComboBox.valueProperty().get().getChronoUnit(), transactionAgeFilterComboBox.valueProperty().get().getAge()));
if (memoFilterTextField != null) {
predicate = predicate.and(new MemoPredicate(memoFilterTextField.getText(), Options.regexForFiltersProperty().get()));
}
if (payeeFilterTextField != null) {
predicate = predicate.and(new PayeePredicate(payeeFilterTextField.getText(), Options.regexForFiltersProperty().get()));
}
predicate = predicate.and(new TagPredicate(tagPane.getSelectedTags()));
filteredTransactionList.setPredicate(predicate);
}
use of jgnash.util.function.PayeePredicate in project jgnash by ccavanaugh.
the class IncomeExpensePayeePieChartDialogController method createPieDataSet.
private ObservableList<PieChart.Data>[] createPieDataSet(@NotNull final Account account) {
@SuppressWarnings("unchecked") final ObservableList<PieChart.Data>[] chartData = new ObservableList[2];
chartData[CREDIT] = FXCollections.observableArrayList();
chartData[DEBIT] = FXCollections.observableArrayList();
final Map<String, BigDecimal> names = new HashMap<>();
final List<TranTuple> list = getTransactions(account, new ArrayList<>(), startDatePicker.getValue(), endDatePicker.getValue());
final CurrencyNode currency = account.getCurrencyNode();
// Create a list of predicates
final List<Predicate<Transaction>> predicates = getPayeeTextFields().stream().filter(textField -> !textField.getText().isEmpty()).map(textField -> new PayeePredicate(textField.getText(), Options.regexForFiltersProperty().get())).collect(Collectors.toList());
// Iterate through the list and add up filtered payees
for (final TranTuple tranTuple : list) {
final String payee = tranTuple.transaction.getPayee();
BigDecimal sum = tranTuple.transaction.getAmount(tranTuple.account);
sum = sum.multiply(tranTuple.account.getCurrencyNode().getExchangeRate(currency));
boolean keep = false;
if (predicates.isEmpty()) {
keep = true;
} else {
for (final Predicate<Transaction> predicate : predicates) {
if (predicate.test(tranTuple.transaction)) {
keep = true;
break;
}
}
}
if (keep) {
if (names.containsKey(payee)) {
sum = sum.add(names.get(payee));
}
names.put(payee, sum);
}
}
final Map<String, BigDecimal> sortedNames = CollectionUtils.sortMapByValue(names);
for (final Map.Entry<String, BigDecimal> entry : sortedNames.entrySet()) {
final PieChart.Data data = new PieChart.Data(truncateString(entry.getKey()), entry.getValue().abs().doubleValue());
// nodes are created lazily. Set the user data (Account) after the node is created
data.nodeProperty().addListener((observable, oldValue, newValue) -> newValue.setUserData(entry.getKey()));
if (entry.getValue().signum() == -1) {
chartData[DEBIT].add(data);
} else {
chartData[CREDIT].add(data);
}
}
return chartData;
}
Aggregations