Implements AutoCloseable for types, replacing free() (#1048)

This commit is contained in:
Thad House
2018-05-22 23:33:17 -07:00
committed by Peter Johnson
parent a2ecb1027a
commit cbaff52850
58 changed files with 242 additions and 171 deletions

View File

@@ -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;
}

View File

@@ -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();
}
}

View File

@@ -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;
}