Upgrade codebase to Java 11

This commit is contained in:
Neil Balch 2019-10-28 08:56:05 -07:00
parent 0509f9e8ec
commit f26e3afcf3
4 changed files with 125 additions and 126 deletions

2
.idea/misc.xml generated
View File

@ -46,7 +46,7 @@
</profile-state> </profile-state>
</entry> </entry>
</component> </component>
<component name="ProjectRootManager" version="2" languageLevel="JDK_1_7" project-jdk-name="1.8" project-jdk-type="JavaSDK"> <component name="ProjectRootManager" version="2" languageLevel="JDK_1_7" default="false" project-jdk-name="11" project-jdk-type="JavaSDK">
<output url="file://$PROJECT_DIR$/out" /> <output url="file://$PROJECT_DIR$/out" />
</component> </component>
</project> </project>

View File

@ -1,10 +1,9 @@
<component name="ProjectRunConfigurationManager"> <component name="ProjectRunConfigurationManager">
<configuration default="false" name="Openrocket UI Jar" type="JarApplication" factoryName="JAR Application"> <configuration default="false" name="Openrocket UI Jar" type="JarApplication">
<extension name="coverage" enabled="false" merge="false" sample_coverage="true" runner="idea" />
<option name="JAR_PATH" value="build/jar/OpenRocket.jar" /> <option name="JAR_PATH" value="build/jar/OpenRocket.jar" />
<option name="ALTERNATIVE_JRE_PATH" /> <option name="ALTERNATIVE_JRE_PATH_ENABLED" value="true" />
<envs /> <option name="ALTERNATIVE_JRE_PATH" value="11" />
<method> <method v="2">
<option name="BuildArtifacts" enabled="true"> <option name="BuildArtifacts" enabled="true">
<artifact name="openrocket:jar" /> <artifact name="openrocket:jar" />
</option> </option>

View File

@ -9,16 +9,16 @@ import net.sf.openrocket.util.Transformation;
/** /**
* *
* @author teyrana (aka Daniel Williams) <equipoise@gmail.com> * @author teyrana (aka Daniel Williams) <equipoise@gmail.com>
* *
*/ */
public class InstanceMap extends HashMap<RocketComponent, ArrayList<InstanceContext>> { public class InstanceMap extends HashMap<RocketComponent, ArrayList<InstanceContext>> {
// =========== Public Functions ======================== // =========== Public Functions ========================
// public InstanceMap() {} // public InstanceMap() {}
public int count(final RocketComponent key) { public int count(final RocketComponent key) {
if(containsKey(key)){ if(containsKey(key)){
return get(key).size(); return get(key).size();
@ -26,12 +26,12 @@ public class InstanceMap extends HashMap<RocketComponent, ArrayList<InstanceCont
return 0; return 0;
} }
} }
public void emplace(final RocketComponent component, boolean active, int number, final Transformation xform) { public void emplace(final RocketComponent component, boolean active, int number, final Transformation xform) {
final RocketComponent key = component; final RocketComponent key = component;
if(!containsKey(component)) { if(!containsKey(component)) {
put(key, new ArrayList<>()); put(key, new ArrayList<InstanceContext>());
} }
final InstanceContext context = new InstanceContext(component, active, number, xform); final InstanceContext context = new InstanceContext(component, active, number, xform);
@ -41,7 +41,7 @@ public class InstanceMap extends HashMap<RocketComponent, ArrayList<InstanceCont
public List<InstanceContext> getInstanceContexts(final RocketComponent key) { public List<InstanceContext> getInstanceContexts(final RocketComponent key) {
return get(key); return get(key);
} }
// this is primarily for debugging. // this is primarily for debugging.
@Override @Override
public String toString() { public String toString() {
@ -53,21 +53,21 @@ public class InstanceMap extends HashMap<RocketComponent, ArrayList<InstanceCont
final ArrayList<InstanceContext> contexts = entry.getValue(); final ArrayList<InstanceContext> contexts = entry.getValue();
buffer.append(String.format("....[% 2d]:[%s]\n", outerIndex, key.getName())); buffer.append(String.format("....[% 2d]:[%s]\n", outerIndex, key.getName()));
outerIndex++; outerIndex++;
int innerIndex = 0; int innerIndex = 0;
for(InstanceContext ctxt: contexts ) { for(InstanceContext ctxt: contexts ) {
buffer.append(String.format("........[@% 2d][% 2d] %s\n", innerIndex, ctxt.instanceNumber, ctxt.getLocation().toPreciseString())); buffer.append(String.format("........[@% 2d][% 2d] %s\n", innerIndex, ctxt.instanceNumber, ctxt.getLocation().toPreciseString()));
innerIndex++; innerIndex++;
} }
} }
return buffer.toString(); return buffer.toString();
} }
// =========== Instance Member Variables ======================== // =========== Instance Member Variables ========================
// =========== Private Instance Functions ======================== // =========== Private Instance Functions ========================
} }

View File

@ -17,8 +17,8 @@ import net.sf.openrocket.util.TestRockets;
import net.sf.openrocket.util.BaseTestCase.BaseTestCase; import net.sf.openrocket.util.BaseTestCase.BaseTestCase;
public class FlightConfigurationTest extends BaseTestCase { public class FlightConfigurationTest extends BaseTestCase {
private final static double EPSILON = MathUtil.EPSILON*1E3; private final static double EPSILON = MathUtil.EPSILON*1E3;
/** /**
* Empty rocket (no components) specific configuration tests * Empty rocket (no components) specific configuration tests
*/ */
@ -26,12 +26,12 @@ public class FlightConfigurationTest extends BaseTestCase {
public void testEmptyRocket() { public void testEmptyRocket() {
Rocket r1 = TestRockets.makeEstesAlphaIII(); Rocket r1 = TestRockets.makeEstesAlphaIII();
FlightConfiguration config = r1.getSelectedConfiguration(); FlightConfiguration config = r1.getSelectedConfiguration();
FlightConfiguration configClone = config.clone(); FlightConfiguration configClone = config.clone();
assertTrue(config.getRocket() == configClone.getRocket()); assertTrue(config.getRocket() == configClone.getRocket());
} }
@Test @Test
public void testFlightConfigurationRocketLength() { public void testFlightConfigurationRocketLength() {
@ -55,13 +55,13 @@ public class FlightConfigurationTest extends BaseTestCase {
double actualReferenceArea = config.getReferenceArea(); double actualReferenceArea = config.getReferenceArea();
assertEquals("source config reference area doesn't match: ", expectedReferenceArea, actualReferenceArea, EPSILON); assertEquals("source config reference area doesn't match: ", expectedReferenceArea, actualReferenceArea, EPSILON);
} }
@Test @Test
public void testCloneBasic() { public void testCloneBasic() {
Rocket rkt1 = TestRockets.makeBeta(); Rocket rkt1 = TestRockets.makeBeta();
FlightConfiguration config1 = rkt1.getSelectedConfiguration(); FlightConfiguration config1 = rkt1.getSelectedConfiguration();
// preconditions // preconditions
config1.setAllStages(); config1.setAllStages();
int expectedStageCount = 2; int expectedStageCount = 2;
@ -79,10 +79,10 @@ public class FlightConfigurationTest extends BaseTestCase {
assertEquals("source config reference area doesn't match: ", expectedReferenceArea, actualReferenceArea, EPSILON); assertEquals("source config reference area doesn't match: ", expectedReferenceArea, actualReferenceArea, EPSILON);
// vvvv test target vvvv // vvvv test target vvvv
FlightConfiguration config2= config1.clone(); FlightConfiguration config2= config1.clone();
// ^^^^ test target ^^^^ // ^^^^ test target ^^^^
// postconditions // postconditions
expectedStageCount = 2; expectedStageCount = 2;
actualStageCount = config2.getActiveStageCount(); actualStageCount = config2.getActiveStageCount();
@ -95,7 +95,7 @@ public class FlightConfigurationTest extends BaseTestCase {
assertEquals("source config reference area doesn't match: ", expectedReferenceArea, config2.getReferenceArea(), EPSILON); assertEquals("source config reference area doesn't match: ", expectedReferenceArea, config2.getReferenceArea(), EPSILON);
} }
/** /**
* Test flight configuration ID methods * Test flight configuration ID methods
*/ */
@ -107,11 +107,11 @@ public class FlightConfigurationTest extends BaseTestCase {
int actualStageCount; int actualStageCount;
int expectedMotorCount; int expectedMotorCount;
int actualMotorCount; int actualMotorCount;
// test that cloned configurations operate independently: // test that cloned configurations operate independently:
// change #1, test clone #2 -- verify that cloned configurations change independent. // change #1, test clone #2 -- verify that cloned configurations change independent.
config1.setAllStages(); config1.setAllStages();
// vvvv test target vvvv // vvvv test target vvvv
FlightConfiguration config2 = config1.clone(); FlightConfiguration config2 = config1.clone();
// ^^^^ test target ^^^^ // ^^^^ test target ^^^^
config1.clearAllStages(); config1.clearAllStages();
@ -123,7 +123,7 @@ public class FlightConfigurationTest extends BaseTestCase {
expectedMotorCount = 0; expectedMotorCount = 0;
actualMotorCount = config1.getActiveMotors().size(); actualMotorCount = config1.getActiveMotors().size();
assertThat("active motor count doesn't match", actualMotorCount, equalTo(expectedMotorCount)); assertThat("active motor count doesn't match", actualMotorCount, equalTo(expectedMotorCount));
// postcondition: config #2 // postcondition: config #2
expectedStageCount = 2; expectedStageCount = 2;
actualStageCount = config2.getActiveStageCount(); actualStageCount = config2.getActiveStageCount();
@ -132,7 +132,7 @@ public class FlightConfigurationTest extends BaseTestCase {
actualMotorCount = config2.getActiveMotors().size(); actualMotorCount = config2.getActiveMotors().size();
assertThat("active motor count doesn't match", actualMotorCount, equalTo(expectedMotorCount)); assertThat("active motor count doesn't match", actualMotorCount, equalTo(expectedMotorCount));
} }
/** /**
* Single stage rocket specific configuration tests * Single stage rocket specific configuration tests
*/ */
@ -140,39 +140,39 @@ public class FlightConfigurationTest extends BaseTestCase {
public void testSingleStageRocket() { public void testSingleStageRocket() {
Rocket r1 = TestRockets.makeEstesAlphaIII(); Rocket r1 = TestRockets.makeEstesAlphaIII();
FlightConfiguration config = r1.getSelectedConfiguration(); FlightConfiguration config = r1.getSelectedConfiguration();
// test explicitly setting only first stage active // test explicitly setting only first stage active
config.clearAllStages(); config.clearAllStages();
config.setOnlyStage(0); config.setOnlyStage(0);
// test that getStageCount() returns correct value // test that getStageCount() returns correct value
int expectedStageCount = 1; int expectedStageCount = 1;
int stageCount = config.getStageCount(); int stageCount = config.getStageCount();
assertTrue("stage count doesn't match", stageCount == expectedStageCount); assertTrue("stage count doesn't match", stageCount == expectedStageCount);
expectedStageCount = 1; expectedStageCount = 1;
stageCount = config.getActiveStageCount(); stageCount = config.getActiveStageCount();
assertThat("active stage count doesn't match", stageCount, equalTo(expectedStageCount)); assertThat("active stage count doesn't match", stageCount, equalTo(expectedStageCount));
// test explicitly setting all stages up to first stage active // test explicitly setting all stages up to first stage active
config.setOnlyStage(0); config.setOnlyStage(0);
// test explicitly setting all stages active // test explicitly setting all stages active
config.setAllStages(); config.setAllStages();
} }
/** /**
* Single stage rocket specific configuration tests * Single stage rocket specific configuration tests
*/ */
@Test @Test
public void testDefaultConfigurationIsEmpty() { public void testDefaultConfigurationIsEmpty() {
Rocket r1 = TestRockets.makeEstesAlphaIII(); Rocket r1 = TestRockets.makeEstesAlphaIII();
// don't change the configuration: // don't change the configuration:
FlightConfiguration defaultConfig = r1.getSelectedConfiguration(); FlightConfiguration defaultConfig = r1.getSelectedConfiguration();
assertThat( "Empty configuration has motors! it should be empty!", r1.getEmptyConfiguration().getActiveMotors().size(), equalTo(0)); assertThat( "Empty configuration has motors! it should be empty!", r1.getEmptyConfiguration().getActiveMotors().size(), equalTo(0));
assertThat( "Default configuration is not the empty configuration. It should be!", defaultConfig.getActiveMotors().size(), equalTo(0)); assertThat( "Default configuration is not the empty configuration. It should be!", defaultConfig.getActiveMotors().size(), equalTo(0));
} }
@Test @Test
@ -197,15 +197,15 @@ public class FlightConfigurationTest extends BaseTestCase {
public void testMotorConfigurations() { public void testMotorConfigurations() {
/* Setup */ /* Setup */
Rocket rkt = TestRockets.makeEstesAlphaIII(); Rocket rkt = TestRockets.makeEstesAlphaIII();
InnerTube smmt = (InnerTube)rkt.getChild(0).getChild(1).getChild(2); InnerTube smmt = (InnerTube)rkt.getChild(0).getChild(1).getChild(2);
int expectedMotorCount = 5; int expectedMotorCount = 5;
int actualMotorCount = smmt.getMotorCount(); int actualMotorCount = smmt.getMotorCount();
assertThat("number of motor configurations doesn't match.", actualMotorCount, equalTo(expectedMotorCount)); assertThat("number of motor configurations doesn't match.", actualMotorCount, equalTo(expectedMotorCount));
} }
@Test @Test
public void testFlightConfigurationGetters(){ public void testFlightConfigurationGetters(){
Rocket rkt = TestRockets.makeEstesAlphaIII(); Rocket rkt = TestRockets.makeEstesAlphaIII();
@ -224,7 +224,7 @@ public class FlightConfigurationTest extends BaseTestCase {
rkt.getFlightConfigurationByIndex(4); rkt.getFlightConfigurationByIndex(4);
rkt.getFlightConfigurationByIndex(5, true); rkt.getFlightConfigurationByIndex(5, true);
} }
@Test(expected=java.lang.IndexOutOfBoundsException.class) @Test(expected=java.lang.IndexOutOfBoundsException.class)
public void testGetFlightConfigurationOutOfBounds(){ public void testGetFlightConfigurationOutOfBounds(){
@ -235,84 +235,84 @@ public class FlightConfigurationTest extends BaseTestCase {
int actualConfigCount = rkt.getConfigurationCount(); int actualConfigCount = rkt.getConfigurationCount();
assertThat("number of loaded configuration counts doesn't actually match.", actualConfigCount, equalTo(expectedConfigCount)); assertThat("number of loaded configuration counts doesn't actually match.", actualConfigCount, equalTo(expectedConfigCount));
// this SHOULD throw an exception -- // this SHOULD throw an exception --
// it's out of bounds on, and no configuration exists at index 5. // it's out of bounds on, and no configuration exists at index 5.
rkt.getFlightConfigurationByIndex(5); rkt.getFlightConfigurationByIndex(5);
} }
/** /**
* Multi stage rocket specific configuration tests * Multi stage rocket specific configuration tests
*/ */
@Test @Test
public void testMultiStageRocket() { public void testMultiStageRocket() {
/* Setup */ /* Setup */
Rocket rkt = TestRockets.makeBeta(); Rocket rkt = TestRockets.makeBeta();
FlightConfiguration config = rkt.getSelectedConfiguration(); FlightConfiguration config = rkt.getSelectedConfiguration();
int expectedStageCount; int expectedStageCount;
int stageCount; int stageCount;
expectedStageCount = 2; expectedStageCount = 2;
stageCount = config.getStageCount(); stageCount = config.getStageCount();
assertThat("stage count doesn't match", stageCount, equalTo(expectedStageCount)); assertThat("stage count doesn't match", stageCount, equalTo(expectedStageCount));
config.clearAllStages(); config.clearAllStages();
assertThat(" clear all stages: check #0: ", config.isStageActive(0), equalTo(false)); assertThat(" clear all stages: check #0: ", config.isStageActive(0), equalTo(false));
assertThat(" clear all stages: check #1: ", config.isStageActive(1), equalTo(false)); assertThat(" clear all stages: check #1: ", config.isStageActive(1), equalTo(false));
// test explicitly setting only first stage active // test explicitly setting only first stage active
config.setOnlyStage(0); config.setOnlyStage(0);
expectedStageCount = 1; expectedStageCount = 1;
stageCount = config.getActiveStageCount(); stageCount = config.getActiveStageCount();
assertThat("active stage count doesn't match", stageCount, equalTo(expectedStageCount)); assertThat("active stage count doesn't match", stageCount, equalTo(expectedStageCount));
assertThat(" setting single stage active: ", config.isStageActive(0), equalTo(true)); assertThat(" setting single stage active: ", config.isStageActive(0), equalTo(true));
// test explicitly setting all stages up to second stage active // test explicitly setting all stages up to second stage active
config.setOnlyStage(1); config.setOnlyStage(1);
assertThat("Setting single stage active: ", config.isStageActive(0), equalTo(false)); assertThat("Setting single stage active: ", config.isStageActive(0), equalTo(false));
assertThat("Setting single stage active: ", config.isStageActive(1), equalTo(true)); assertThat("Setting single stage active: ", config.isStageActive(1), equalTo(true));
config.clearStage(0); config.clearStage(0);
assertThat(" deactivate stage #0: ", config.isStageActive(0), equalTo(false)); assertThat(" deactivate stage #0: ", config.isStageActive(0), equalTo(false));
assertThat(" active stage #1: ", config.isStageActive(1), equalTo(true)); assertThat(" active stage #1: ", config.isStageActive(1), equalTo(true));
// test explicitly setting all two stages active // test explicitly setting all two stages active
config.setAllStages(); config.setAllStages();
assertThat(" activate all stages: check stage #0: ", config.isStageActive(0), equalTo(true)); assertThat(" activate all stages: check stage #0: ", config.isStageActive(0), equalTo(true));
assertThat(" activate all stages: check stage #1: ", config.isStageActive(1), equalTo(true)); assertThat(" activate all stages: check stage #1: ", config.isStageActive(1), equalTo(true));
// test toggling single stage // test toggling single stage
config.setAllStages(); config.setAllStages();
config.toggleStage(0); config.toggleStage(0);
assertThat(" toggle stage #0: ", config.isStageActive(0), equalTo(false)); assertThat(" toggle stage #0: ", config.isStageActive(0), equalTo(false));
config.toggleStage(0); config.toggleStage(0);
assertThat(" toggle stage #0: ", config.isStageActive(0), equalTo(true)); assertThat(" toggle stage #0: ", config.isStageActive(0), equalTo(true));
config.toggleStage(0); config.toggleStage(0);
assertThat(" toggle stage #0: ", config.isStageActive(0), equalTo(false)); assertThat(" toggle stage #0: ", config.isStageActive(0), equalTo(false));
} }
/** /**
* Multi stage rocket specific configuration tests * Multi stage rocket specific configuration tests
*/ */
@Test @Test
public void testMotorClusters() { public void testMotorClusters() {
/* Setup */ /* Setup */
Rocket rkt = TestRockets.makeBeta(); Rocket rkt = TestRockets.makeBeta();
FlightConfiguration config = rkt.getSelectedConfiguration(); FlightConfiguration config = rkt.getSelectedConfiguration();
config.clearAllStages(); config.clearAllStages();
int expectedMotorCount = 0; int expectedMotorCount = 0;
int actualMotorCount = config.getActiveMotors().size(); int actualMotorCount = config.getActiveMotors().size();
assertThat("active motor count doesn't match", actualMotorCount, equalTo(expectedMotorCount)); assertThat("active motor count doesn't match", actualMotorCount, equalTo(expectedMotorCount));
config.setOnlyStage(0); config.setOnlyStage(0);
expectedMotorCount = 1; expectedMotorCount = 1;
actualMotorCount = config.getActiveMotors().size(); actualMotorCount = config.getActiveMotors().size();
@ -328,7 +328,7 @@ public class FlightConfigurationTest extends BaseTestCase {
actualMotorCount = config.getActiveMotors().size(); actualMotorCount = config.getActiveMotors().size();
assertThat("active motor count doesn't match: ", actualMotorCount, equalTo(expectedMotorCount)); assertThat("active motor count doesn't match: ", actualMotorCount, equalTo(expectedMotorCount));
} }
@Test @Test
public void testIterateComponents() { public void testIterateComponents() {
Rocket rocket = TestRockets.makeFalcon9Heavy(); Rocket rocket = TestRockets.makeFalcon9Heavy();
@ -336,21 +336,21 @@ public class FlightConfigurationTest extends BaseTestCase {
selected.clearAllStages(); selected.clearAllStages();
selected.toggleStage(2); selected.toggleStage(2);
// vvvv Test Target vvvv // vvvv Test Target vvvv
InstanceMap instances = selected.getActiveInstances(); InstanceMap instances = selected.getActiveInstances();
// ^^^^ Test Target ^^^^ // ^^^^ Test Target ^^^^
// Payload Stage // Payload Stage
final AxialStage coreStage = (AxialStage)rocket.getChild(1); final AxialStage coreStage = (AxialStage)rocket.getChild(1);
{ // Core Stage { // Core Stage
final List<InstanceContext> coreStageContextList = instances.getInstanceContexts(coreStage); final List<InstanceContext> coreStageContextList = instances.getInstanceContexts(coreStage);
final InstanceContext coreStageContext = coreStageContextList.get(0); final InstanceContext coreStageContext = coreStageContextList.get(0);
assertThat(coreStageContext.component.getClass(), equalTo(AxialStage.class)); assertThat((Class<AxialStage>) coreStageContext.component.getClass(), equalTo(AxialStage.class));
assertThat(coreStageContext.component.getID(), equalTo(rocket.getChild(1).getID())); assertThat(coreStageContext.component.getID(), equalTo(rocket.getChild(1).getID()));
assertThat(coreStageContext.component.getInstanceCount(), equalTo(1)); assertThat(coreStageContext.component.getInstanceCount(), equalTo(1));
final Coordinate coreLocation = coreStageContext.getLocation(); final Coordinate coreLocation = coreStageContext.getLocation();
assertEquals(coreLocation.x, 0.564, EPSILON); assertEquals(coreLocation.x, 0.564, EPSILON);
assertEquals(coreLocation.y, 0.0, EPSILON); assertEquals(coreLocation.y, 0.0, EPSILON);
assertEquals(coreLocation.z, 0.0, EPSILON); assertEquals(coreLocation.z, 0.0, EPSILON);
@ -363,77 +363,77 @@ public class FlightConfigurationTest extends BaseTestCase {
final ParallelStage boosterStage = (ParallelStage)coreStage.getChild(0).getChild(0); final ParallelStage boosterStage = (ParallelStage)coreStage.getChild(0).getChild(0);
final List<InstanceContext> boosterStageContextList = instances.getInstanceContexts(boosterStage); final List<InstanceContext> boosterStageContextList = instances.getInstanceContexts(boosterStage);
final InstanceContext boosterStage0Context = boosterStageContextList.get(0); final InstanceContext boosterStage0Context = boosterStageContextList.get(0);
assertThat(boosterStage0Context.component.getClass(), equalTo(ParallelStage.class)); assertThat((Class<ParallelStage>) boosterStage0Context.component.getClass(), equalTo(ParallelStage.class));
assertThat(boosterStage0Context.component.getID(), equalTo(boosterStage.getID())); assertThat(boosterStage0Context.component.getID(), equalTo(boosterStage.getID()));
assertThat(boosterStage0Context.instanceNumber, equalTo(0)); assertThat(boosterStage0Context.instanceNumber, equalTo(0));
{ {
final Coordinate loc = boosterStage0Context.getLocation(); final Coordinate loc = boosterStage0Context.getLocation();
assertEquals(loc.x, 0.484, EPSILON); assertEquals(loc.x, 0.484, EPSILON);
assertEquals(loc.y, 0.077, EPSILON); assertEquals(loc.y, 0.077, EPSILON);
assertEquals(loc.z, 0.0, EPSILON); assertEquals(loc.z, 0.0, EPSILON);
} }
final InstanceContext boosterStage1Context = boosterStageContextList.get(1); final InstanceContext boosterStage1Context = boosterStageContextList.get(1);
assertThat(boosterStage1Context.component.getClass(), equalTo(ParallelStage.class)); assertThat((Class<ParallelStage>) boosterStage1Context.component.getClass(), equalTo(ParallelStage.class));
assertThat(boosterStage1Context.component.getID(), equalTo(boosterStage.getID())); assertThat(boosterStage1Context.component.getID(), equalTo(boosterStage.getID()));
assertThat(boosterStage1Context.instanceNumber, equalTo(1)); assertThat(boosterStage1Context.instanceNumber, equalTo(1));
{ {
final Coordinate loc = boosterStage1Context.getLocation(); final Coordinate loc = boosterStage1Context.getLocation();
assertEquals(loc.x, 0.484, EPSILON); assertEquals(loc.x, 0.484, EPSILON);
assertEquals(loc.y, -0.077, EPSILON); assertEquals(loc.y, -0.077, EPSILON);
assertEquals(loc.z, 0.0, EPSILON); assertEquals(loc.z, 0.0, EPSILON);
} }
{ // Booster Body: { // Booster Body:
final BodyTube boosterBody = (BodyTube)boosterStage.getChild(1); final BodyTube boosterBody = (BodyTube)boosterStage.getChild(1);
final List<InstanceContext> boosterBodyContextList = instances.getInstanceContexts(boosterBody); final List<InstanceContext> boosterBodyContextList = instances.getInstanceContexts(boosterBody);
// this is the instance number rocket-wide // this is the instance number rocket-wide
final InstanceContext boosterBodyContext = boosterBodyContextList.get(1); final InstanceContext boosterBodyContext = boosterBodyContextList.get(1);
// this is the instance number per-parent // this is the instance number per-parent
assertThat(boosterBodyContext.instanceNumber, equalTo(0)); assertThat(boosterBodyContext.instanceNumber, equalTo(0));
assertThat(boosterBodyContext.component.getClass(), equalTo(BodyTube.class)); assertThat((Class<BodyTube>) boosterBodyContext.component.getClass(), equalTo(BodyTube.class));
final Coordinate bodyTubeLocation = boosterBodyContext.getLocation(); final Coordinate bodyTubeLocation = boosterBodyContext.getLocation();
assertEquals(bodyTubeLocation.x, 0.564, EPSILON); assertEquals(bodyTubeLocation.x, 0.564, EPSILON);
assertEquals(bodyTubeLocation.y, -0.077, EPSILON); assertEquals(bodyTubeLocation.y, -0.077, EPSILON);
assertEquals(bodyTubeLocation.z, 0.0, EPSILON); assertEquals(bodyTubeLocation.z, 0.0, EPSILON);
{ // Booster::Motor Tubes ( x2 x4) { // Booster::Motor Tubes ( x2 x4)
final InnerTube boosterMMT = (InnerTube)boosterBody.getChild(0); final InnerTube boosterMMT = (InnerTube)boosterBody.getChild(0);
final List<InstanceContext> mmtContextList = instances.getInstanceContexts(boosterMMT); final List<InstanceContext> mmtContextList = instances.getInstanceContexts(boosterMMT);
assertEquals(8, mmtContextList.size()); assertEquals(8, mmtContextList.size());
final InstanceContext motorTubeContext0 = mmtContextList.get(4); final InstanceContext motorTubeContext0 = mmtContextList.get(4);
assertThat(motorTubeContext0.component.getClass(), equalTo(InnerTube.class)); assertThat((Class<InnerTube>) motorTubeContext0.component.getClass(), equalTo(InnerTube.class));
assertThat(motorTubeContext0.instanceNumber, equalTo(0)); assertThat(motorTubeContext0.instanceNumber, equalTo(0));
final Coordinate motorTube0Location = motorTubeContext0.getLocation(); final Coordinate motorTube0Location = motorTubeContext0.getLocation();
assertEquals(motorTube0Location.x, 1.214, EPSILON); assertEquals(motorTube0Location.x, 1.214, EPSILON);
assertEquals(motorTube0Location.y, -0.062, EPSILON); assertEquals(motorTube0Location.y, -0.062, EPSILON);
assertEquals(motorTube0Location.z, -0.015, EPSILON); assertEquals(motorTube0Location.z, -0.015, EPSILON);
final InstanceContext motorTubeContext1 = mmtContextList.get(5); final InstanceContext motorTubeContext1 = mmtContextList.get(5);
assertThat(motorTubeContext1.component.getClass(), equalTo(InnerTube.class)); assertThat((Class<InnerTube>) motorTubeContext1.component.getClass(), equalTo(InnerTube.class));
assertThat(motorTubeContext1.instanceNumber, equalTo(1)); assertThat(motorTubeContext1.instanceNumber, equalTo(1));
final Coordinate motorTube1Location = motorTubeContext1.getLocation(); final Coordinate motorTube1Location = motorTubeContext1.getLocation();
assertEquals(motorTube1Location.x, 1.214, EPSILON); assertEquals(motorTube1Location.x, 1.214, EPSILON);
assertEquals(motorTube1Location.y, -0.092, EPSILON); assertEquals(motorTube1Location.y, -0.092, EPSILON);
assertEquals(motorTube1Location.z, -0.015, EPSILON); assertEquals(motorTube1Location.z, -0.015, EPSILON);
final InstanceContext motorTubeContext2 = mmtContextList.get(6); final InstanceContext motorTubeContext2 = mmtContextList.get(6);
assertThat(motorTubeContext2.component.getClass(), equalTo(InnerTube.class)); assertThat((Class<InnerTube>) motorTubeContext2.component.getClass(), equalTo(InnerTube.class));
assertThat(motorTubeContext2.instanceNumber, equalTo(2)); assertThat(motorTubeContext2.instanceNumber, equalTo(2));
final Coordinate motorTube2Location = motorTubeContext2.getLocation(); final Coordinate motorTube2Location = motorTubeContext2.getLocation();
assertEquals(motorTube2Location.x, 1.214, EPSILON); assertEquals(motorTube2Location.x, 1.214, EPSILON);
assertEquals(motorTube2Location.y, -0.092, EPSILON); assertEquals(motorTube2Location.y, -0.092, EPSILON);
assertEquals(motorTube2Location.z, 0.015, EPSILON); assertEquals(motorTube2Location.z, 0.015, EPSILON);
final InstanceContext motorTubeContext3 = mmtContextList.get(7); final InstanceContext motorTubeContext3 = mmtContextList.get(7);
assertThat(motorTubeContext3.component.getClass(), equalTo(InnerTube.class)); assertThat((Class<InnerTube>) motorTubeContext3.component.getClass(), equalTo(InnerTube.class));
assertThat(motorTubeContext3.instanceNumber, equalTo(3)); assertThat(motorTubeContext3.instanceNumber, equalTo(3));
final Coordinate motorTube3Location = motorTubeContext3.getLocation(); final Coordinate motorTube3Location = motorTubeContext3.getLocation();
assertEquals(motorTube3Location.x, 1.214, EPSILON); assertEquals(motorTube3Location.x, 1.214, EPSILON);
assertEquals(motorTube3Location.y, -0.062, EPSILON); assertEquals(motorTube3Location.y, -0.062, EPSILON);
assertEquals(motorTube3Location.z, 0.015, EPSILON); assertEquals(motorTube3Location.z, 0.015, EPSILON);
@ -442,54 +442,54 @@ public class FlightConfigurationTest extends BaseTestCase {
final FinSet fins = (FinSet)boosterBody.getChild(1); final FinSet fins = (FinSet)boosterBody.getChild(1);
final List<InstanceContext> finContextList = instances.getInstanceContexts(fins); final List<InstanceContext> finContextList = instances.getInstanceContexts(fins);
assertEquals(6, finContextList.size()); assertEquals(6, finContextList.size());
final InstanceContext boosterFinContext0 = finContextList.get(3); final InstanceContext boosterFinContext0 = finContextList.get(3);
assertThat(boosterFinContext0.component.getClass(), equalTo(TrapezoidFinSet.class)); assertThat((Class<TrapezoidFinSet>) boosterFinContext0.component.getClass(), equalTo(TrapezoidFinSet.class));
assertThat(boosterFinContext0.instanceNumber, equalTo(0)); assertThat(boosterFinContext0.instanceNumber, equalTo(0));
final Coordinate boosterFin0Location = boosterFinContext0.getLocation(); final Coordinate boosterFin0Location = boosterFinContext0.getLocation();
assertEquals(boosterFin0Location.x, 1.044, EPSILON); assertEquals(boosterFin0Location.x, 1.044, EPSILON);
assertEquals(boosterFin0Location.y, -0.104223611, EPSILON); assertEquals(boosterFin0Location.y, -0.104223611, EPSILON);
assertEquals(boosterFin0Location.z, -0.027223611, EPSILON); assertEquals(boosterFin0Location.z, -0.027223611, EPSILON);
final InstanceContext boosterFinContext1 = finContextList.get(4); final InstanceContext boosterFinContext1 = finContextList.get(4);
assertThat(boosterFinContext1.component.getClass(), equalTo(TrapezoidFinSet.class)); assertThat((Class<TrapezoidFinSet>) boosterFinContext1.component.getClass(), equalTo(TrapezoidFinSet.class));
assertThat(boosterFinContext1.instanceNumber, equalTo(1)); assertThat(boosterFinContext1.instanceNumber, equalTo(1));
final Coordinate boosterFin1Location = boosterFinContext1.getLocation(); final Coordinate boosterFin1Location = boosterFinContext1.getLocation();
assertEquals(boosterFin1Location.x, 1.044, EPSILON); assertEquals(boosterFin1Location.x, 1.044, EPSILON);
assertEquals(boosterFin1Location.y, -0.03981186, EPSILON); assertEquals(boosterFin1Location.y, -0.03981186, EPSILON);
assertEquals(boosterFin1Location.z, -0.00996453, EPSILON); assertEquals(boosterFin1Location.z, -0.00996453, EPSILON);
final InstanceContext boosterFinContext2 = finContextList.get(5); final InstanceContext boosterFinContext2 = finContextList.get(5);
assertThat(boosterFinContext2.component.getClass(), equalTo(TrapezoidFinSet.class)); assertThat((Class<TrapezoidFinSet>) boosterFinContext2.component.getClass(), equalTo(TrapezoidFinSet.class));
assertThat(boosterFinContext2.instanceNumber, equalTo(2)); assertThat(boosterFinContext2.instanceNumber, equalTo(2));
final Coordinate boosterFin2Location = boosterFinContext2.getLocation(); final Coordinate boosterFin2Location = boosterFinContext2.getLocation();
assertEquals(boosterFin2Location.x, 1.044, EPSILON); assertEquals(boosterFin2Location.x, 1.044, EPSILON);
assertEquals(boosterFin2Location.y, -0.08696453, EPSILON); assertEquals(boosterFin2Location.y, -0.08696453, EPSILON);
assertEquals(boosterFin2Location.z, 0.03718814, EPSILON); assertEquals(boosterFin2Location.z, 0.03718814, EPSILON);
} }
} }
} }
} }
@Test @Test
public void testIterateCoreComponents_AllStagesActive() { public void testIterateCoreComponents_AllStagesActive() {
Rocket rocket = TestRockets.makeFalcon9Heavy(); Rocket rocket = TestRockets.makeFalcon9Heavy();
FlightConfiguration selected = rocket.getSelectedConfiguration(); FlightConfiguration selected = rocket.getSelectedConfiguration();
selected.setAllStages(); selected.setAllStages();
// vvvv Test Target vvvv // vvvv Test Target vvvv
ArrayList<RocketComponent> components = selected.getCoreComponents(); ArrayList<RocketComponent> components = selected.getCoreComponents();
// ^^^^ Test Target ^^^^ // ^^^^ Test Target ^^^^
assertThat(components.size(), equalTo(10)); assertThat(components.size(), equalTo(10));
final AxialStage payloadStage = (AxialStage)components.get(0); final AxialStage payloadStage = (AxialStage)components.get(0);
assertThat(payloadStage.getName(), equalTo("Payload Fairing Stage")); assertThat(payloadStage.getName(), equalTo("Payload Fairing Stage"));
final AxialStage coreStage = (AxialStage)components.get(1); final AxialStage coreStage = (AxialStage)components.get(1);
assertThat(coreStage.getName(), equalTo("Core Stage")); assertThat(coreStage.getName(), equalTo("Core Stage"));
@ -499,7 +499,7 @@ public class FlightConfigurationTest extends BaseTestCase {
assertThat(components.get(3).getName(), equalTo("PL Fairing Body")); assertThat(components.get(3).getName(), equalTo("PL Fairing Body"));
assertThat(components.get(4), instanceOf(Transition.class)); assertThat(components.get(4), instanceOf(Transition.class));
assertThat(components.get(5), instanceOf(BodyTube.class)); assertThat(components.get(5), instanceOf(BodyTube.class));
assertThat(components.get(5).getName(), equalTo("Upper Stage Body")); assertThat(components.get(5).getName(), equalTo("Upper Stage Body"));
@ -508,11 +508,11 @@ public class FlightConfigurationTest extends BaseTestCase {
assertThat(components.get(7), instanceOf(BodyTube.class)); assertThat(components.get(7), instanceOf(BodyTube.class));
assertThat(components.get(7).getName(), equalTo("Core Stage Body")); assertThat(components.get(7).getName(), equalTo("Core Stage Body"));
assertThat(components.get(8), instanceOf(Parachute.class)); assertThat(components.get(8), instanceOf(Parachute.class));
assertThat(components.get(9), instanceOf(ShockCord.class)); assertThat(components.get(9), instanceOf(ShockCord.class));
} }
@Test @Test
public void testIterateCoreComponents_ActiveOnly() { public void testIterateCoreComponents_ActiveOnly() {
Rocket rocket = TestRockets.makeFalcon9Heavy(); Rocket rocket = TestRockets.makeFalcon9Heavy();
@ -520,30 +520,30 @@ public class FlightConfigurationTest extends BaseTestCase {
selected.clearAllStages(); selected.clearAllStages();
selected.toggleStage(2); // booster only. selected.toggleStage(2); // booster only.
// vvvv Test Target vvvv // vvvv Test Target vvvv
ArrayList<RocketComponent> components = selected.getCoreComponents(); ArrayList<RocketComponent> components = selected.getCoreComponents();
// ^^^^ Test Target ^^^^ // ^^^^ Test Target ^^^^
assertThat(components.size(), equalTo(0)); assertThat(components.size(), equalTo(0));
// ================================= // =================================
selected.clearAllStages(); selected.clearAllStages();
selected.toggleStage(1); // booster only. selected.toggleStage(1); // booster only.
// vvvv Test Target vvvv // vvvv Test Target vvvv
components = selected.getCoreComponents(); components = selected.getCoreComponents();
// ^^^^ Test Target ^^^^ // ^^^^ Test Target ^^^^
assertThat(components.size(), equalTo(2)); assertThat(components.size(), equalTo(2));
final AxialStage coreStage = (AxialStage)components.get(0); final AxialStage coreStage = (AxialStage)components.get(0);
assertThat(coreStage.getName(), equalTo("Core Stage")); assertThat(coreStage.getName(), equalTo("Core Stage"));
assertThat(components.get(1), instanceOf(BodyTube.class)); assertThat(components.get(1), instanceOf(BodyTube.class));
assertThat(components.get(1).getName(), equalTo("Core Stage Body")); assertThat(components.get(1).getName(), equalTo("Core Stage Body"));
} }
} }