mirror of
https://github.com/wpilibsuite/allwpilib
synced 2026-06-26 01:51:41 +00:00
Implements AutoCloseable for types, replacing free() (#1048)
This commit is contained in:
committed by
Peter Johnson
parent
a2ecb1027a
commit
cbaff52850
@@ -13,7 +13,7 @@ import edu.wpi.first.wpilibj.Timer;
|
||||
/**
|
||||
* Simulates an encoder for testing purposes.
|
||||
*/
|
||||
public class FakeCounterSource {
|
||||
public class FakeCounterSource implements AutoCloseable {
|
||||
private Thread m_task;
|
||||
private int m_count;
|
||||
private int m_milliSec;
|
||||
@@ -70,10 +70,10 @@ public class FakeCounterSource {
|
||||
/**
|
||||
* Destroy Object with minimum memory leak.
|
||||
*/
|
||||
public void free() {
|
||||
public void close() {
|
||||
m_task = null;
|
||||
if (m_allocated) {
|
||||
m_output.free();
|
||||
m_output.close();
|
||||
m_output = null;
|
||||
m_allocated = false;
|
||||
}
|
||||
|
||||
@@ -13,7 +13,7 @@ import edu.wpi.first.wpilibj.Timer;
|
||||
/**
|
||||
* Emulates a quadrature encoder.
|
||||
*/
|
||||
public class FakeEncoderSource {
|
||||
public class FakeEncoderSource implements AutoCloseable {
|
||||
private Thread m_task;
|
||||
private int m_count;
|
||||
private int m_milliSec;
|
||||
@@ -93,11 +93,11 @@ public class FakeEncoderSource {
|
||||
/**
|
||||
* Frees the resource.
|
||||
*/
|
||||
public void free() {
|
||||
public void close() {
|
||||
m_task = null;
|
||||
if (m_allocatedOutputs) {
|
||||
m_outputA.free();
|
||||
m_outputB.free();
|
||||
m_outputA.close();
|
||||
m_outputB.close();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -12,7 +12,7 @@ import edu.wpi.first.wpilibj.AnalogOutput;
|
||||
/**
|
||||
* A fake source to provide output to a {@link edu.wpi.first.wpilibj.interfaces.Potentiometer}.
|
||||
*/
|
||||
public class FakePotentiometerSource {
|
||||
public class FakePotentiometerSource implements AutoCloseable {
|
||||
private AnalogOutput m_output;
|
||||
private boolean m_initOutput;
|
||||
private double m_potMaxAngle;
|
||||
@@ -83,9 +83,9 @@ public class FakePotentiometerSource {
|
||||
/**
|
||||
* Frees the resouce.
|
||||
*/
|
||||
public void free() {
|
||||
public void close() {
|
||||
if (m_initOutput) {
|
||||
m_output.free();
|
||||
m_output.close();
|
||||
m_output = null;
|
||||
m_initOutput = false;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user