Skip to content

Commit

Permalink
use new Java features for readability and brevity
Browse files Browse the repository at this point in the history
  • Loading branch information
mathisdt committed Oct 7, 2021
1 parent 49e1af6 commit a59ef6d
Showing 1 changed file with 17 additions and 45 deletions.
62 changes: 17 additions & 45 deletions src/main/java/org/zephyrsoft/hibiscuswatcher/Starter.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package org.zephyrsoft.hibiscuswatcher;

import java.util.List;
import java.util.stream.Collectors;

import org.kohsuke.args4j.CmdLineException;
import org.kohsuke.args4j.CmdLineParser;
Expand All @@ -16,74 +15,47 @@ public class Starter {
@Option(name = "--url", required = true, metaVar = "<URL>", usage = "URL of the XML-RPC services of Hibiscus")
private String url = null;

@Option(name = "--username", required = false, metaVar = "<LOGIN>",
usage = "username to access the XML-RPC services at the given URL, defaults to 'admin'")
@Option(name = "--username", required = false, metaVar = "<LOGIN>", usage = "username to access the XML-RPC services at the given URL, defaults to 'admin'")
private String username = "admin";

@Option(name = "--password", required = true, metaVar = "<PASSWORD>",
usage = "password to access the XML-RPC services at the given URL")
@Option(name = "--password", required = true, metaVar = "<PASSWORD>", usage = "password to access the XML-RPC services at the given URL")
private String password = null;

@Option(
name = "--single",
required = false,
usage = "get all single postings of all accounts and generate the more detailed postings report (which also contains the balances)")
@Option(name = "--single", required = false, usage = "get all single postings of all accounts and generate the more detailed postings report (which also contains the balances)")
private boolean singlePostings = false;

@Option(
name = "--balances",
required = false,
usage = "get the balances of all accounts")
@Option(name = "--balances", required = false, usage = "get the balances of all accounts")
private boolean balances = false;

@Option(
name = "--low",
required = false,
usage = "check if the balance of an account is below a minimum account")
@Option(name = "--low", required = false, usage = "check if the balance of an account is below a minimum account")
private boolean lowBalance = false;

@Option(name = "--low-account",
required = false,
metaVar = "<ACCOUNT>",
usage = "account(s) for --low (multiple times allowed)")
@Option(name = "--low-account", required = false, metaVar = "<ACCOUNT>", usage = "account(s) for --low (multiple times allowed)")
private List<String> lowAccounts = null;

@Option(name = "--only-account",
required = false,
metaVar = "<ACCOUNT>",
usage = "account(s) for --balances or --single (multiple times allowed)")
@Option(name = "--only-account", required = false, metaVar = "<ACCOUNT>", usage = "account(s) for --balances or --single (multiple times allowed)")
private List<String> onlyAccounts = null;

@Option(name = "--low-minimum",
required = false,
metaVar = "<WHOLE NUMBER>",
usage = "minimum amount for --low")
@Option(name = "--low-minimum", required = false, metaVar = "<WHOLE NUMBER>", usage = "minimum amount for --low")
private Double lowMinimum = null;

@Option(
name = "--days",
required = false,
metaVar = "<DAYS>",
usage = "go back this amount of days for fetching the postings, e.g. 7 (the default) - this option is only effective in single postings mode!")
@Option(name = "--days", required = false, metaVar = "<DAYS>", usage = "go back this amount of days for fetching the postings, e.g. 7 (the default) - this option is only effective in single postings mode!")
private int daysToFetchInSingleMode = 7;

@Option(name = "--no-positive", required = false,
usage = "do not get single postings which contain a positive amount of money")
@Option(name = "--no-positive", required = false, usage = "do not get single postings which contain a positive amount of money")
private boolean noPositive = false;

@Option(name = "--no-negative", required = false,
usage = "do not get single postings which contain a negative amount of money")
@Option(name = "--no-negative", required = false, usage = "do not get single postings which contain a negative amount of money")
private boolean noNegative = false;

@Option(name = "--no-sum", required = false,
usage = "do not print a sum")
@Option(name = "--no-sum", required = false, usage = "do not print a sum")
private boolean noSum = false;

public static void main(String[] args) {
public static void main(final String[] args) {
new Starter(args);
}

private Starter(String[] args) {
private Starter(final String[] args) {
CmdLineParser parser = new CmdLineParser(this);
try {
parser.parseArgument(args);
Expand All @@ -102,7 +74,7 @@ private Starter(String[] args) {
.filter(account -> onlyAccounts == null
|| onlyAccounts.isEmpty()
|| onlyAccounts.contains(account.getIban()))
.collect(Collectors.toList());
.toList();
// generate report and print it to stdout
System.out.println(Reporter.generatePostingsReport(accounts));
}
Expand All @@ -114,7 +86,7 @@ private Starter(String[] args) {
.filter(account -> onlyAccounts == null
|| onlyAccounts.isEmpty()
|| onlyAccounts.contains(account.getIban()))
.collect(Collectors.toList());
.toList();
// generate report and print it to stdout
System.out.println(Reporter.generateBalancesReport(accounts, !noSum));
}
Expand All @@ -127,7 +99,7 @@ private Starter(String[] args) {
}
}

public static void die(String message) {
public static void die(final String message) {
if (message != null) {
System.err.println(message);
}
Expand Down

0 comments on commit a59ef6d

Please sign in to comment.