mirror of
https://github.com/wpilibsuite/allwpilib
synced 2026-07-03 03:01:44 +00:00
Implements AutoCloseable for types, replacing free() (#1048)
This commit is contained in:
committed by
Peter Johnson
parent
a2ecb1027a
commit
cbaff52850
@@ -64,8 +64,8 @@ public abstract class AnalogCrossConnectFixture implements ITestFixture {
|
||||
*/
|
||||
@Override
|
||||
public boolean teardown() {
|
||||
m_input.free();
|
||||
m_output.free();
|
||||
m_input.close();
|
||||
m_output.close();
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
@@ -80,8 +80,8 @@ public class DIOCrossConnectFixture implements ITestFixture {
|
||||
public boolean teardown() {
|
||||
logger.log(Level.FINE, "Begining teardown");
|
||||
if (m_allocated) {
|
||||
m_input.free();
|
||||
m_output.free();
|
||||
m_input.close();
|
||||
m_output.close();
|
||||
m_allocated = false;
|
||||
}
|
||||
return true;
|
||||
|
||||
@@ -99,8 +99,8 @@ public class FakeCounterFixture implements ITestFixture {
|
||||
@Override
|
||||
public boolean teardown() {
|
||||
logger.log(Level.FINE, "Begining teardown");
|
||||
m_counter.free();
|
||||
m_source.free();
|
||||
m_counter.close();
|
||||
m_source.close();
|
||||
if (m_allocated) { // Only tear down the dio if this class allocated it
|
||||
m_dio.teardown();
|
||||
m_allocated = false;
|
||||
|
||||
@@ -101,9 +101,9 @@ public class FakeEncoderFixture implements ITestFixture {
|
||||
@Override
|
||||
public boolean teardown() {
|
||||
logger.fine("Begining teardown");
|
||||
m_source.free();
|
||||
m_source.close();
|
||||
logger.finer("Source freed " + m_sourcePort[0] + ", " + m_sourcePort[1]);
|
||||
m_encoder.free();
|
||||
m_encoder.close();
|
||||
logger.finer("Encoder freed " + m_encoderPort[0] + ", " + m_encoderPort[1]);
|
||||
if (m_allocated) {
|
||||
m_dio1.teardown();
|
||||
|
||||
@@ -181,37 +181,37 @@ public abstract class MotorEncoderFixture<T extends SpeedController> implements
|
||||
if (!m_tornDown) {
|
||||
boolean wasNull = false;
|
||||
if (m_motor instanceof PWM && m_motor != null) {
|
||||
((PWM) m_motor).free();
|
||||
((PWM) m_motor).close();
|
||||
m_motor = null;
|
||||
} else if (m_motor == null) {
|
||||
wasNull = true;
|
||||
}
|
||||
if (m_encoder != null) {
|
||||
m_encoder.free();
|
||||
m_encoder.close();
|
||||
m_encoder = null;
|
||||
} else {
|
||||
wasNull = true;
|
||||
}
|
||||
if (m_counters[0] != null) {
|
||||
m_counters[0].free();
|
||||
m_counters[0].close();
|
||||
m_counters[0] = null;
|
||||
} else {
|
||||
wasNull = true;
|
||||
}
|
||||
if (m_counters[1] != null) {
|
||||
m_counters[1].free();
|
||||
m_counters[1].close();
|
||||
m_counters[1] = null;
|
||||
} else {
|
||||
wasNull = true;
|
||||
}
|
||||
if (m_alphaSource != null) {
|
||||
m_alphaSource.free();
|
||||
m_alphaSource.close();
|
||||
m_alphaSource = null;
|
||||
} else {
|
||||
wasNull = true;
|
||||
}
|
||||
if (m_betaSource != null) {
|
||||
m_betaSource.free();
|
||||
m_betaSource.close();
|
||||
m_betaSource = null;
|
||||
} else {
|
||||
wasNull = true;
|
||||
|
||||
@@ -84,9 +84,9 @@ public abstract class RelayCrossConnectFixture implements ITestFixture {
|
||||
@Override
|
||||
public boolean teardown() {
|
||||
if (!m_freed) {
|
||||
m_relay.free();
|
||||
m_inputOne.free();
|
||||
m_inputTwo.free();
|
||||
m_relay.close();
|
||||
m_inputOne.close();
|
||||
m_inputTwo.close();
|
||||
m_freed = true;
|
||||
} else {
|
||||
throw new RuntimeException("You attempted to free the "
|
||||
|
||||
@@ -92,22 +92,22 @@ public abstract class TiltPanCameraFixture implements ITestFixture {
|
||||
}
|
||||
|
||||
public void freeGyro() {
|
||||
m_gyro.free();
|
||||
m_gyro.close();
|
||||
m_gyro = null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean teardown() {
|
||||
m_tilt.free();
|
||||
m_tilt.close();
|
||||
m_tilt = null;
|
||||
m_pan.free();
|
||||
m_pan.close();
|
||||
m_pan = null;
|
||||
if (m_gyro != null) { //in case not freed during gyro tests
|
||||
m_gyro.free();
|
||||
m_gyro.close();
|
||||
m_gyro = null;
|
||||
}
|
||||
if (m_gyroParam != null) { //in case gyro tests failed before getting to this point
|
||||
m_gyroParam.free();
|
||||
m_gyroParam.close();
|
||||
m_gyroParam = null;
|
||||
}
|
||||
return true;
|
||||
|
||||
Reference in New Issue
Block a user