- Open in IntelliJ
- Find the
Main
class in the project view undersrc/main/java
- Right click ->
Run Main.main()
http://localhost:4567/words
http://localhost:4567/events
- To make
Consumer
unit-testable, I'd extract use of the generator process into another class, so we can mock it. - I'd use Lombok, or just Scala (or Kotlin...), to make
Event
a simple data class (i.e. auto generate fields, setters, etc.) - I'd find or implement a
defaultdict
-style (from Python) type structure to use instead of theMap<String, Integer>
s inStats
, so we won't need theif (!map.contains(..)) map.put(thing, 0)
- Make
stats
not static inMain
, to make it more testable. - This is a bit out of scope, but holding the stats in memory won't scale for large distributions of event types and words, so we'd need some persistance there.
- Output responses in JSON, instead of strings, so it will be consumable by other services.
Honestly though, I would probably not do any of these things, since it's so little amount of code, and it fulfills the requirements and has good enough performance. In short: YAGNI :)