This application is a simple command line playlist demo app that consumes a json playlist, accepts a limited set of operations to be performed and produces an output file.
This project is written in kotlin
and leverages gradle
build tools. As such there are a few things you'll need to get started if you'd like to compile the code. For convience reasons I've also included a prebuilt executable jar file. If you'd like to skip to just running the application skip over to Running the application.
- If for some reason you aren't running some semi-recent version of JRE to get it here
- Install
kotlin
$ brew install kotlin
*Or if you aren't down with homebrew
there's a few alternatives here
The application takes 3 parameters to run:
- A mixtape data file ->
mixtape.json
- A change file ->
changefile.json
- An output file (you can name it whatever you want but the output will be json format)
Currently missing req'd files or malformed json will cause a program exit but it will do its best to handle permutations from currently supported operations which include:
1. Add an existing song to an existing playlist.
2. Add a new playlist for an existing user; the playlist should contain at least one existing song.
3. Remove an existing playlist.
$ java -jar mixtape.jar mixtape.json changefile.json <your_output_file_name.json>
$ ./gradlew run --args='mixtape.json changefile.json <your_output_file_name.json>'
Obviously this solution doesn't scale paricularly well. File I/O is expensive, as is array-based lookups and the footprint of doing everything in memory has the potential to blow up and/or really slow down.
Lets assume this app has the live offline without any connectivity to the real world. We could:
- Convert
mixtape.json
to a db file instead of shoving it all into an array allowing for less memory overhead and performant lookups - We could do the same for
changefile.json
and chunk it up into a temp db - Changes could be processed/written one entry at a time or paginated in chunks via the db for negligable memory footprint
- The same iterative approach could be done with the output file - writing one entry at a time, or for less overall fetches we could leverage a paginated solution
Assuming the app has internet connectivity:
Mixtape.json
lives in the cloud- The client could leverage a sync'ing mechanism to keep its local db when offline. I'd probably leverage a library off the shelf for this like Firebase
- Depending on size/complexity of change files I may opt to offload the processing to a server somewhere and push the updated mixtape back to the device once complete.