Compare commits
No commits in common. "main" and "JCash" have entirely different histories.
|
@ -4,8 +4,6 @@
|
||||||
|
|
||||||
Draft program for the Java class of semester 2. The goal was to simulate basic cash machine that can read customer data from a `.csv` file and let the user view the data with crude forms of authentication.
|
Draft program for the Java class of semester 2. The goal was to simulate basic cash machine that can read customer data from a `.csv` file and let the user view the data with crude forms of authentication.
|
||||||
|
|
||||||
> This project was graded with 100,0 out of 100,0 points
|
|
||||||
|
|
||||||
## Overview
|
## Overview
|
||||||
|
|
||||||
The program can read `.csv` file from disk and allows the user login to an account specified.
|
The program can read `.csv` file from disk and allows the user login to an account specified.
|
||||||
|
|
|
@ -6,8 +6,6 @@ import me.teridax.jcash.banking.accounts.Owner;
|
||||||
import me.teridax.jcash.decode.StringDecoder;
|
import me.teridax.jcash.decode.StringDecoder;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.nio.charset.Charset;
|
|
||||||
import java.nio.charset.StandardCharsets;
|
|
||||||
import java.nio.file.Files;
|
import java.nio.file.Files;
|
||||||
import java.nio.file.Path;
|
import java.nio.file.Path;
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
|
@ -25,13 +23,6 @@ public final class BankingManagementSystem {
|
||||||
* Separator used to separate columns of CSV files
|
* Separator used to separate columns of CSV files
|
||||||
*/
|
*/
|
||||||
private static final String SEPARATOR = ";";
|
private static final String SEPARATOR = ";";
|
||||||
/**
|
|
||||||
* Charsets to try when decoding the source file
|
|
||||||
*/
|
|
||||||
private static final Charset[] ENCODINGS = {
|
|
||||||
StandardCharsets.UTF_8,
|
|
||||||
Charset.forName("windows-1252")
|
|
||||||
};
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A set of banks
|
* A set of banks
|
||||||
|
@ -85,7 +76,7 @@ public final class BankingManagementSystem {
|
||||||
LOGGER.fine("parsing banking management system from file: " + Objects.toString(file, "null"));
|
LOGGER.fine("parsing banking management system from file: " + Objects.toString(file, "null"));
|
||||||
try {
|
try {
|
||||||
var bms = new BankingManagementSystem();
|
var bms = new BankingManagementSystem();
|
||||||
var content = getSource(file);
|
var content = Files.readString(file);
|
||||||
|
|
||||||
// read line by line
|
// read line by line
|
||||||
// and skip the first line
|
// and skip the first line
|
||||||
|
@ -123,33 +114,15 @@ public final class BankingManagementSystem {
|
||||||
|
|
||||||
return bms;
|
return bms;
|
||||||
|
|
||||||
|
} catch (IOException e) {
|
||||||
|
LOGGER.severe("Could not read file: " + file + " due to: " + e.getMessage());
|
||||||
|
throw new IllegalArgumentException("Could not read file " + file, e);
|
||||||
} catch (IllegalArgumentException | NullPointerException e) {
|
} catch (IllegalArgumentException | NullPointerException e) {
|
||||||
LOGGER.severe("Could not parse file: " + file + " due to: " + e.getMessage());
|
LOGGER.severe("Could not parse file: " + file + " due to: " + e.getMessage());
|
||||||
throw new IllegalArgumentException("Could not parse file " + file, e);
|
throw new IllegalArgumentException("Could not parse file " + file, e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Attempts to read the entire file into a string.
|
|
||||||
* This method tires out all encodings in {@link #ENCODINGS}
|
|
||||||
* @param file the file to read
|
|
||||||
* @throws IllegalArgumentException if the file cannot be read
|
|
||||||
* @return the content of the file
|
|
||||||
*/
|
|
||||||
private static String getSource(Path file) throws IllegalArgumentException {
|
|
||||||
Exception lastException = null;
|
|
||||||
for (var encoding : ENCODINGS) {
|
|
||||||
try {
|
|
||||||
return Files.readString(file, encoding);
|
|
||||||
} catch (IOException e) {
|
|
||||||
LOGGER.severe("Could not read file: " + file + " due to: " + e.getMessage());
|
|
||||||
lastException = e;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
assert lastException != null;
|
|
||||||
throw new IllegalArgumentException("Invalid encoding, or IO exception: " + lastException.getMessage());
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Return a bank with the given blz.
|
* Return a bank with the given blz.
|
||||||
*
|
*
|
||||||
|
|
Loading…
Reference in New Issue