TemplateRegionParser refactoring for better maintability. Tests for #167/#168

The refactoring includes a number of changes:

* Avoids unneeded collections conversions
* Move common functionality into helper classes
* Removed a lot of immutability and imperative code in favour of pure/functional code where it made sense.
* Got rid of the LazyCache class (the old behavior is now emulated by
  creating a new instance of `TemplateRegionsComputer` when calling
  `TemplateRegionParser.reset`).
* Cleaned up several of the methods in the PartitionHelper class.
* A few other small things here and there.

There are now three new TemplateRegionParser tests that cover #167 and #168