Thoughts on Path Matching - microbean/microbean-settings GitHub Wiki

Path matching seems complicated so let's check some examples.

Case 1

Let's say we have a Context Path like this:

/:env=test;stability=bad/Car.class;value=myFavorite

And we get a Provider.Value back with a Path like this:

/:env=dev;stability=good/Car.class;value=myDailyDriver

Clearly the value path does not match the context path.

Takeaway: if a qualifier set S1 and another qualifier set S2 are disjoint—have no qualifier name-value pairs in common—then S1 does not match S2 and S2 does not match S1.

Case 2

Context path:

/:env=test;stability=bad/Car.class;value=myFavorite

Value path:

/:stability=bad/Car.class

This matches but in some very general way.

Takeaway: looking just at qualifiers, a set of qualifiers S1 matches another set of qualifiers S2 if S1 is a subset of S2.

Case 3

Context path:

/:env=test;stability=bad # i.e. just the root and nothing else; limiting case

Value path:

/:stability=bad # just the root

This one's interesting. Both have the same length (1). Both have the same type (the opaque root type). The context path has more qualifiers than the value path, but not just any qualifiers. Specifically it has a superset of the value path's qualifiers. So we have a match, but it's not as specific as it could be.

Takeaway: looking just at qualifiers, a value path matches a context path if it is a subset of the context path.

Case 4

Context path:

/:env=test;stability=bad # i.e. just the root and nothing else; limiting case

Value path:

/:env=prod # i.e. just the root and nothing else; limiting case

Here the qualifier sets are disjoint (they have nothing in common).

⚠️ **GitHub.com Fallback** ⚠️