chrsan/css-selectors — pull request #13 by void256 (2014-12-21 14:51:20+00:00)
Title: feat: GenericNodeSelector to support custom, non DOM trees more easily

Implementing a custom NodeSelector for custom node tree structures (that
are not DOM based) is possible but requires quite a bit of effort to
support all possible selector combinations.

However, the DOM implementation in the se.fishtank.css.selectors.dom
package solves a lot of these common problems already but is - of course
- very DOM specific.

This commit basically makes a generic version/copy of the dom package
with all of the specifics extracted into a GenericNodeAdapter interface.
The GenericNodeAdapter will provide all of the functionality that really
is specific to a Node tree and all the remaining Generic* classes
provide all of the common functionality that is shared between DOM and
other Node trees.

This way the user (or in this case, myself ;-) can use the NodeSelector
more easily with a custom node tree by simply providing an
implementation of the GenericNodeAdapter.

As a proof of concept I've provided a DOM implementation of
GenericNodeAdapter (GenericNodeAdapterDOM) and copied the test cases as
well, which pass without issues.

The GenericNodeAdapterDOM is eventually a little bit slower than the
original code since it requires some Lists and Maps to be instantiated
additonally (which was not required in the original DOM code). This is
because of the GenericNodeAdapter interface and it's way to communicate
to the rest of the system while keeping a good abstraction for the
interface. I'm not sure how much of a problem this really is but as far
as I see this is the only difference the "generic" version introduces.

I've left the original dom package as-is. Eventually it could be removed
in favour of the generic package in which case the "Generic*" could be
removed too. This way we don't have to maintain two packages in the
future but the original author is probably better to judge that :)