Skip to content
This repository was archived by the owner on Feb 16, 2026. It is now read-only.

Make all closable items implement AutoClosable#317

Merged
thenetworkgrinch merged 2 commits intoYet-Another-Software-Suite:devfrom
kytpbs:close
Feb 5, 2025
Merged

Make all closable items implement AutoClosable#317
thenetworkgrinch merged 2 commits intoYet-Another-Software-Suite:devfrom
kytpbs:close

Conversation

@kytpbs
Copy link

@kytpbs kytpbs commented Feb 5, 2025

This is for unit testing support in the future

Implements AutoClosable on all IMUs, Motorsand **_Some_**Encoders`

Encoder Exceptions:

  • SparkFlexEncoder
  • SparkMaxEncoder
  • TalonSRXEncoder
  • ThriftyNovaEncoder

Due to these encoders being closed with the motors themselves and not implementing AutoClosable themselves, they have an empty comment explaining that in their close method

@thenetworkgrinch
Copy link
Contributor

Why do you make the wrapper classes implement AutoClosable?

@kytpbs
Copy link
Author

kytpbs commented Feb 5, 2025

To provide a “clean slate” for each test, we need to have a function to destroy the object and free all hardware allocations. In Java, this is done by implementing the AutoCloseable interface and its .close() method, destroying each member object by calling the member’s .close() method - an object without a .close() method probably doesn’t need to be closed.

- From WPILIB docs explanation

Implementing AutoClosable is the advised way of making objects closable. since it also supports try-with-resources and it is also how close is done in WPILIB. You can look at the docs of AutoCloseable here: https://docs.oracle.com/javase/8/docs/api/java/lang/AutoCloseable.html

@thenetworkgrinch
Copy link
Contributor

Thank you for this! I hope to add Unit tests one day and this is a great step in that direction!

@thenetworkgrinch thenetworkgrinch merged commit d44ce44 into Yet-Another-Software-Suite:dev Feb 5, 2025
@kytpbs kytpbs mentioned this pull request Feb 5, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants