[wpilibj] Add Preferences.getNetworkTable() #7962
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Use case: Our team has a shared library that includes wrapper APIs for the
Java Preferences API. The wrapper API adds a topic (with a topic name starting
with ".") where it stores non-persistent data that is used for validation.
The code for our wrapper API is here.
The unit tests for those classes use Preferences.setNetworkTableInstance()
to ensure that the tests are isolated. Since there is no current API to get
the current preference table, our wrapper APIs either have to take in a
NetworkTableInstance (which makes the classes less simple to use) or our code
to add these internal topics needs to use the default network table instance (making the
tests not completely isolated).
Providing an API to get the NetworkTable used by Preferences would allow our
API to remain simple and our tests to be truly isolated. It doesn't appear
to be something that would be hard to maintain.
I reviewed the C++ and Python APIs, and they appear to not have an equivalent
to setNetworkTableInstance() so this PR only updates the Java API.