Demostration of Fluent interfaces / TDD / Functional idioms applied with OOPS
A simple application to parse digits (from Pipes and underscores) and display the digit/number formed by the digit.
The application will take a input stream (can be a file) having Raw Account Numbers (probably read from a digital machine) formed by pipes and underscores, with one account number on each line.
Each entry in the file is 4 lines long, and each line has 27 characters. The first 3 lines of each entry contain an account number written using pipes and underscores, and the fourth line is blank. Each account number should have 9 digits, all of which should be in the range 0-9. A normal file contains around 500 entries.
Any digit which can't be interpreted will be replaced by a question mark '?' and will become invalid
Checksum of each account number should be divisible by 11 (account is valid if checksum % 11 == 0)
account number: 3 4 5 8 8 2 8 6 5 position names: d9 d8 d7 d6 d5 d4 d3 d2 d1 checksum calculation: (d1+2*d2+3*d3 +..+9*d9)
final String FILE_NAME = "data.txt"; try (FileInputStream dataFile = new FileInputStream(FILE_NAME)) { Accounts .from(dataFile) .forEach(System.out::println); }
String rawAccountNumbers = " _ _ _ _ _ _ _ \n" + " | _| _||_||_ |_ ||_||_|\n\r" + " ||_ _| | _||_| ||_| _|\n\r" + " \n" + " _ _ _ _ _ _ _ _ \n" + " | _| _||_ |_ |_ ||_|| |\n\r" + " | _| _| _||_||_| ||_||_|\n\r" + " "; Collection accounts = Accounts.from(new ByteArrayInputStream(rawAccountNumbers.getBytes())); assertThat(accounts, hasAccountsInOrder("123456789", "133566780"));
This is a implementation of first three stories of the code kata hosted at http://codingdojo.org/cgi-bin/index.pl?KataBankOCR
Please visit the link for more details