Proposed fix for JERSEY-2537

Proposed fix for the issues with replaceMatrix described in JERSEY-2537: `replaceMatrix(null)` removes semicolon if there are no matrix parameters, trailing slash is kept intact, and it only operates on the final path segment instead of the first.

Added test cases for URI variants I imagined could cause problems.