mirror of
https://github.com/wpilibsuite/allwpilib
synced 2026-06-21 01:01:43 +00:00
Implements AutoCloseable for types, replacing free() (#1048)
This commit is contained in:
committed by
Peter Johnson
parent
a2ecb1027a
commit
cbaff52850
@@ -78,7 +78,7 @@ public class AnalogCrossConnectTest extends AbstractInterruptTest {
|
||||
assertFalse("Analog trigger is in the window (2V, 3V)", trigger.getInWindow());
|
||||
assertFalse("Analog trigger is on", trigger.getTriggerState());
|
||||
|
||||
trigger.free();
|
||||
trigger.close();
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -95,7 +95,7 @@ public class AnalogCrossConnectTest extends AbstractInterruptTest {
|
||||
assertTrue("Analog trigger is not in the window (2V, 3V)", trigger.getInWindow());
|
||||
assertFalse("Analog trigger is on", trigger.getTriggerState());
|
||||
|
||||
trigger.free();
|
||||
trigger.close();
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -112,7 +112,7 @@ public class AnalogCrossConnectTest extends AbstractInterruptTest {
|
||||
assertFalse("Analog trigger is in the window (2V, 3V)", trigger.getInWindow());
|
||||
assertTrue("Analog trigger is not on", trigger.getTriggerState());
|
||||
|
||||
trigger.free();
|
||||
trigger.close();
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -167,9 +167,9 @@ public class AnalogCrossConnectTest extends AbstractInterruptTest {
|
||||
@Override
|
||||
void freeInterruptableSensorBase() {
|
||||
m_interruptTriggerOutput.cancelInterrupts();
|
||||
m_interruptTriggerOutput.free();
|
||||
m_interruptTriggerOutput.close();
|
||||
m_interruptTriggerOutput = null;
|
||||
m_interruptTrigger.free();
|
||||
m_interruptTrigger.close();
|
||||
m_interruptTrigger = null;
|
||||
}
|
||||
|
||||
|
||||
@@ -42,7 +42,7 @@ public class AnalogPotentiometerTest extends AbstractComsSetup {
|
||||
@After
|
||||
public void tearDown() throws Exception {
|
||||
m_potSource.reset();
|
||||
m_pot.free();
|
||||
m_pot.close();
|
||||
m_analogIO.teardown();
|
||||
}
|
||||
|
||||
|
||||
@@ -69,14 +69,14 @@ public class DigitalGlitchFilterTest extends AbstractComsSetup {
|
||||
filter3.remove(encoder5);
|
||||
filter3.remove(counter7);
|
||||
|
||||
input1.free();
|
||||
input2.free();
|
||||
input3.free();
|
||||
input4.free();
|
||||
encoder5.free();
|
||||
counter7.free();
|
||||
filter1.free();
|
||||
filter2.free();
|
||||
filter3.free();
|
||||
input1.close();
|
||||
input2.close();
|
||||
input3.close();
|
||||
input4.close();
|
||||
encoder5.close();
|
||||
counter7.close();
|
||||
filter1.close();
|
||||
filter2.close();
|
||||
filter3.close();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -189,7 +189,7 @@ public class MotorEncoderTest extends AbstractComsSetup {
|
||||
"PID loop did not reach setpoint within 10 seconds. The current error was" + pid
|
||||
.getError(), pid.onTarget());
|
||||
|
||||
pid.free();
|
||||
pid.close();
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -210,7 +210,7 @@ public class MotorEncoderTest extends AbstractComsSetup {
|
||||
"PID loop did not reach setpoint within 10 seconds. The error was: " + pid.getError(),
|
||||
pid.onTarget());
|
||||
|
||||
pid.free();
|
||||
pid.close();
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -63,13 +63,13 @@ public class PCMTest extends AbstractComsSetup {
|
||||
|
||||
@AfterClass
|
||||
public static void tearDownAfterClass() throws Exception {
|
||||
compressor.free();
|
||||
compressor.close();
|
||||
|
||||
fakePressureSwitch.free();
|
||||
fakeCompressor.free();
|
||||
fakePressureSwitch.close();
|
||||
fakeCompressor.close();
|
||||
|
||||
fakeSolenoid1.free();
|
||||
fakeSolenoid2.free();
|
||||
fakeSolenoid1.close();
|
||||
fakeSolenoid2.close();
|
||||
}
|
||||
|
||||
@Before
|
||||
@@ -145,8 +145,8 @@ public class PCMTest extends AbstractComsSetup {
|
||||
assertTrue("Solenoid #1 did not report on", solenoid1.get());
|
||||
assertTrue("Solenoid #2 did not report on", solenoid2.get());
|
||||
|
||||
solenoid1.free();
|
||||
solenoid2.free();
|
||||
solenoid1.close();
|
||||
solenoid2.close();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -177,7 +177,7 @@ public class PCMTest extends AbstractComsSetup {
|
||||
assertTrue("DoubleSolenoid did not report Reverse", solenoid.get() == DoubleSolenoid.Value
|
||||
.kReverse);
|
||||
|
||||
solenoid.free();
|
||||
solenoid.close();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -265,8 +265,8 @@ public class PCMTest extends AbstractComsSetup {
|
||||
assertFalse("Solenoid #1 did not report off", solenoid1.get());
|
||||
assertFalse("Solenoid #2 did not report off", solenoid2.get());
|
||||
|
||||
solenoid1.free();
|
||||
solenoid2.free();
|
||||
solenoid1.close();
|
||||
solenoid2.close();
|
||||
}
|
||||
|
||||
protected Logger getClassLogger() {
|
||||
|
||||
@@ -47,7 +47,7 @@ public class PDPTest extends AbstractComsSetup {
|
||||
|
||||
@AfterClass
|
||||
public static void tearDownAfterClass() throws Exception {
|
||||
pdp.free();
|
||||
pdp.close();
|
||||
pdp = null;
|
||||
me.teardown();
|
||||
me = null;
|
||||
|
||||
@@ -116,7 +116,7 @@ public class PIDTest extends AbstractComsSetup {
|
||||
public void tearDown() throws Exception {
|
||||
logger.fine("Teardown: " + me.getType());
|
||||
m_controller.disable();
|
||||
m_controller.free();
|
||||
m_controller.close();
|
||||
m_controller = null;
|
||||
me.reset();
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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