diff --git a/core/src/net/sf/openrocket/rocketcomponent/FlightConfigurableParameterSet.java b/core/src/net/sf/openrocket/rocketcomponent/FlightConfigurableParameterSet.java index 504d9752a..57002c737 100644 --- a/core/src/net/sf/openrocket/rocketcomponent/FlightConfigurableParameterSet.java +++ b/core/src/net/sf/openrocket/rocketcomponent/FlightConfigurableParameterSet.java @@ -22,23 +22,20 @@ public class FlightConfigurableParameterSet map = new HashMap(); - protected static final FlightConfigurationId defaultValueId = FlightConfigurationId.DEFAULT_VALUE_FCID; - + /** * Construct a FlightConfiguration that has no overrides. * - * @param component the rocket component on which events are fired when the parameter values are changed - * @param eventType the event type that will be fired on changes + * @param _defaultValue the first default value */ public FlightConfigurableParameterSet(E _defaultValue) { - this.map.put( defaultValueId, _defaultValue); + this.map.put( FlightConfigurationId.DEFAULT_VALUE_FCID, _defaultValue); } /** * Construct a copy of an existing FlightConfigurationImpl. * - * @param component the rocket component on which events are fired when the parameter values are changed - * @param eventType the event type that will be fired on changes + * @param configSet the FlightConfigurableParameterSet to copy */ public FlightConfigurableParameterSet(FlightConfigurableParameterSet configSet ){ for (FlightConfigurationId key : configSet.map.keySet()) { @@ -55,7 +52,7 @@ public class FlightConfigurableParameterSet ids = this.getSortedConfigurationIDs(); + List ids = this.getIds(); FlightConfigurationId selectedId = ids.get(index); return this.map.get(selectedId); } @@ -149,38 +146,38 @@ public class FlightConfigurableParameterSet getSortedConfigurationIDs(){ - ArrayList toReturn = new ArrayList(); - - toReturn.addAll( this.map.keySet() ); - toReturn.remove( defaultValueId ); - // Java 1.8: - //toReturn.sort( null ); - - // Java 1.7: - Collections.sort(toReturn); - - return toReturn; - } - - public List getIds(){ - return this.getSortedConfigurationIDs(); + + /** + * @return a sorted list of all the contained FlightConfigurationIDs + */ + public List getIds(){ + ArrayList toReturn = new ArrayList(); + + toReturn.addAll( this.map.keySet() ); + toReturn.remove( FlightConfigurationId.DEFAULT_VALUE_FCID ); + // Java 1.8: + //toReturn.sort( null ); + + // Java 1.7: + Collections.sort(toReturn); + + return toReturn; } /** * Set the parameter value for the provided flight configuration ID. * This sets the override for this flight configuration ID. * - * @param id the flight configuration ID - * @param value the parameter value (null not allowed) + * @param fcid the flight configuration ID + * @param nextValue the parameter value (null not allowed) */ - public void set(FlightConfigurationId fcid, E nextValue) { + public void set( final FlightConfigurationId fcid, E nextValue) { if ( nextValue == null) { - // null value means to delete this fcid - this.map.remove(fcid); + // null value means to delete this fcid + this.map.remove(fcid); + }else if( FlightConfigurationId.DEFAULT_VALUE_FCID == fcid ){ + // if a user wants to set the default value, make them do it explicitly with .setDefaultValue(...) + return; }else{ this.map.put(fcid, nextValue); } @@ -189,7 +186,7 @@ public class FlightConfigurableParameterSet (%d configurations)\n", this.getDefault().getClass().getSimpleName(), this.size() )); final String fmt = " [%-12s]: %s\n"; - for( FlightConfigurationId loopFCID : this.getSortedConfigurationIDs()){ + for( FlightConfigurationId loopFCID : getIds()){ String shortKey = loopFCID.toShortKey(); E inst = this.map.get(loopFCID); if( this.isDefault(inst)){ diff --git a/core/src/net/sf/openrocket/rocketcomponent/Rocket.java b/core/src/net/sf/openrocket/rocketcomponent/Rocket.java index 605647764..31f3b41fb 100644 --- a/core/src/net/sf/openrocket/rocketcomponent/Rocket.java +++ b/core/src/net/sf/openrocket/rocketcomponent/Rocket.java @@ -577,7 +577,7 @@ public class Rocket extends RocketComponent { } public List getIds(){ - return configSet.getSortedConfigurationIDs(); + return configSet.getIds(); } @@ -594,7 +594,7 @@ public class Rocket extends RocketComponent { * Remove a flight configuration ID from the configuration IDs. The null * ID cannot be removed, and an attempt to remove it will be silently ignored. * - * @param id the flight configuration ID to remove + * @param fcid the flight configuration ID to remove */ public void removeFlightConfigurationID(FlightConfigurationId fcid) { checkState(); @@ -626,7 +626,7 @@ public class Rocket extends RocketComponent { /** * Check whether the given motor configuration ID has motors defined for it. * - * @param id the FlightConfigurationID containing the motor (may be invalid). + * @param fcid the FlightConfigurationID containing the motor (may be invalid). * @return whether any motors are defined for it. */ public boolean hasMotors(FlightConfigurationId fcid) { @@ -655,7 +655,7 @@ public class Rocket extends RocketComponent { /** * Return a flight configuration. If the supplied id does not have a specific instance, the default is returned. * - * @param id the flight configuration id + * @param fcid the flight configuration id * @return FlightConfiguration instance */ public FlightConfiguration createFlightConfiguration(final FlightConfigurationId fcid) { @@ -678,7 +678,7 @@ public class Rocket extends RocketComponent { /** * Return a flight configuration. If the supplied id does not have a specific instance, the default is returned. * - * @param id the flight configuration id + * @param fcid the flight configuration id * @return a FlightConfiguration instance */ public FlightConfiguration getFlightConfiguration(final FlightConfigurationId fcid) { @@ -689,7 +689,7 @@ public class Rocket extends RocketComponent { /** * Return a flight configuration. If the supplied index is out of bounds, an exception is thrown. * - * @param id the flight configuration index number + * @param configIndex the flight configuration index number * @return a FlightConfiguration instance */ public FlightConfiguration getFlightConfiguration(final int configIndex) { @@ -723,8 +723,8 @@ public class Rocket extends RocketComponent { * Associate the given ID and flight configuration. * null or an empty string. * - * @param id the flight configuration id - * @param name the name for the flight configuration + * @param fcid the flight configuration id + * @param newConfig new FlightConfiguration to store */ public void setFlightConfiguration(final FlightConfigurationId fcid, FlightConfiguration newConfig) { checkState(); diff --git a/core/src/net/sf/openrocket/util/TestRockets.java b/core/src/net/sf/openrocket/util/TestRockets.java index 42ed39af6..9e3896bad 100644 --- a/core/src/net/sf/openrocket/util/TestRockets.java +++ b/core/src/net/sf/openrocket/util/TestRockets.java @@ -384,7 +384,7 @@ public class TestRockets { public static final Rocket makeEstesAlphaIII(){ Rocket rocket = new Rocket(); FlightConfigurationId fcid[] = new FlightConfigurationId[5]; - fcid[0] = rocket.getSelectedConfiguration().getFlightConfigurationID(); + fcid[0] = new FlightConfigurationId(); rocket.createFlightConfiguration(fcid[0]); fcid[1] = new FlightConfigurationId(); rocket.createFlightConfiguration(fcid[1]); diff --git a/core/test/net/sf/openrocket/rocketcomponent/ParameterSetTest.java b/core/test/net/sf/openrocket/rocketcomponent/ParameterSetTest.java index cafd84817..763c4a9c1 100644 --- a/core/test/net/sf/openrocket/rocketcomponent/ParameterSetTest.java +++ b/core/test/net/sf/openrocket/rocketcomponent/ParameterSetTest.java @@ -138,7 +138,7 @@ public class ParameterSetTest extends BaseTestCase { // testSet.getSortedConfigurationIDs() // >> this function should ONLY return ids for the overrides assertThat("getIds() broken!\n"+testSet.toDebug(), testSet.getIds().size(), equalTo( testSet.size())); - assertThat("getIds() broken!\n"+testSet.toDebug(), testSet.getSortedConfigurationIDs().size(), equalTo( testSet.getIds().size() ) ); + assertThat("getIds() broken!\n"+testSet.toDebug(), testSet.getIds().size(), equalTo( testSet.getIds().size() ) ); } @Test