This repository includes a few short exercises, written in Java 8 SE with no 3rd party dependencies.
This readme describes the usage and assumptions for each task
The application should do the following
- Display a window that show the current time in the format of
hh:mm:ss - It should have a days until Christmas button which will show the number of days left until Christmas when clicked
- It should have a load CSV button which will load and display the contents of a CSV file
This is a JavaFX application.
- The current system time updates runs on a
singleThreadScheduledExecutorand the UI thread updates the front end usingPlatform.runLater. ChristmasUtilshandles logic for determining the number of days until Christmas. This class was build to be testable, and the tests are included in the source- Loading a large CSV is also possible. The CSV is paginated at 100k entries per load. The loading of new entries runs on a separate task and thread to prevent the front end from lagging. The UI gives the user an indication that the application is busy loading in the background. The CSV file should be present in
.\docs\1500000 Sales Records.csv. An error message will be shown otherwise. The CSV can be downloaded from here.
JUnithas to be added to the classpath to allow testing.1500000 Sales Records.csvmust be in.\docstest_sales.csvmust be in.\docs, this is used for running test cases.
The task is to create a POJO representing a person's CV. Include personal details, a list of qualifications and working history. The POJO should be immutable and not extendable.
Created a final (not extendable) and immutable POJO which represents a person's CV. The builder pattern ensures that the POJOs are umodifiable and Collections.unmodifiableList will prevent and modifications to the list of work history and qualifications.
Write a datastructure for a distance matrix (table). It should not have duplicated entries, for example JHB -> CPT is that same as CPT -> JHB. This datastructure must be as efficient as possible.
Implemented a Distance Table by extending a HashMap. The combination of two strings will form the new hashCode using string1.hashCode() + string2.hashCode(). Since the addition of integers are commutative the combined hash code for string1 + string2 = string2 + string1 allowing the distance between string1 and string2 to be persisted only once in the hash map. The data set is small enough to make hash collisions unlikely.
Sort a list using the given JAR.
Implemented cSorterImplementation. On instantiation, it will create a new file for logging and kick off a periodic thread to publish statistics (list size) every 700ms. To prevent ConcurrentModification exceptions a ReentrantLock was used. This is locked before modifying the list, and unlocked after the sorting finished. A thread safe data type CopyOnWriteArrayList was also used. On termination the scheduled thread is shutdown and the file output streams are closed.
The output is sorted and the statistics indicated ~1578 entries at the end of execution.
SortImplementation.jarhas to be included on the classpath.