[Bugfix] Fixes a few configuration bugs.

- Fixes out-of-date javadoc comments
- Fixes FlightConfigurationTest
  -- fixes TestRocket instantiation.
- Simplified FlightConfiguration class function API
-
This commit is contained in:
Daniel_M_Williams 2016-04-05 22:56:06 -04:00
parent 9c49b6336a
commit 5b687b5bcc
4 changed files with 51 additions and 58 deletions

View File

@ -22,23 +22,20 @@ public class FlightConfigurableParameterSet<E extends FlightConfigurableParamete
//private static final Logger log = LoggerFactory.getLogger(ParameterSet.class); //private static final Logger log = LoggerFactory.getLogger(ParameterSet.class);
protected final HashMap<FlightConfigurationId, E> map = new HashMap<FlightConfigurationId, E>(); protected final HashMap<FlightConfigurationId, E> map = new HashMap<FlightConfigurationId, E>();
protected static final FlightConfigurationId defaultValueId = FlightConfigurationId.DEFAULT_VALUE_FCID;
/** /**
* Construct a FlightConfiguration that has no overrides. * Construct a FlightConfiguration that has no overrides.
* *
* @param component the rocket component on which events are fired when the parameter values are changed * @param _defaultValue the first default value
* @param eventType the event type that will be fired on changes
*/ */
public FlightConfigurableParameterSet(E _defaultValue) { public FlightConfigurableParameterSet(E _defaultValue) {
this.map.put( defaultValueId, _defaultValue); this.map.put( FlightConfigurationId.DEFAULT_VALUE_FCID, _defaultValue);
} }
/** /**
* Construct a copy of an existing FlightConfigurationImpl. * Construct a copy of an existing FlightConfigurationImpl.
* *
* @param component the rocket component on which events are fired when the parameter values are changed * @param configSet the FlightConfigurableParameterSet to copy
* @param eventType the event type that will be fired on changes
*/ */
public FlightConfigurableParameterSet(FlightConfigurableParameterSet<E> configSet ){ public FlightConfigurableParameterSet(FlightConfigurableParameterSet<E> configSet ){
for (FlightConfigurationId key : configSet.map.keySet()) { for (FlightConfigurationId key : configSet.map.keySet()) {
@ -55,7 +52,7 @@ public class FlightConfigurableParameterSet<E extends FlightConfigurableParamete
* @return the default parameter value (never null) * @return the default parameter value (never null)
*/ */
public E getDefault(){ public E getDefault(){
return this.map.get( defaultValueId); return this.map.get( FlightConfigurationId.DEFAULT_VALUE_FCID );
} }
/** /**
@ -63,7 +60,7 @@ public class FlightConfigurableParameterSet<E extends FlightConfigurableParamete
*This is used in case a per-flight configuration override *This is used in case a per-flight configuration override
* has not been defined. * has not been defined.
* *
* @param value the parameter value (null not allowed) * @param nextDefaultValue the parameter value (null not allowed)
*/ */
public void setDefault(E nextDefaultValue) { public void setDefault(E nextDefaultValue) {
if (nextDefaultValue == null) { if (nextDefaultValue == null) {
@ -72,7 +69,7 @@ public class FlightConfigurableParameterSet<E extends FlightConfigurableParamete
if( this.isDefault(nextDefaultValue)){ if( this.isDefault(nextDefaultValue)){
return; return;
} }
this.map.put( defaultValueId, nextDefaultValue); this.map.put( FlightConfigurationId.DEFAULT_VALUE_FCID, nextDefaultValue);
} }
public boolean containsId( final FlightConfigurationId fcid){ public boolean containsId( final FlightConfigurationId fcid){
@ -98,7 +95,7 @@ public class FlightConfigurableParameterSet<E extends FlightConfigurableParamete
* This returns either the value specified for this flight config ID, * This returns either the value specified for this flight config ID,
* or the default value. * or the default value.
* *
* @param value the parameter to find * @param testValue the parameter to find
* @return the flight configuration ID * @return the flight configuration ID
*/ */
public FlightConfigurationId getId(E testValue) { public FlightConfigurationId getId(E testValue) {
@ -126,7 +123,7 @@ public class FlightConfigurableParameterSet<E extends FlightConfigurableParamete
+" than the stored values: "+index+"/"+this.map.size()); +" than the stored values: "+index+"/"+this.map.size());
} }
List<FlightConfigurationId> ids = this.getSortedConfigurationIDs(); List<FlightConfigurationId> ids = this.getIds();
FlightConfigurationId selectedId = ids.get(index); FlightConfigurationId selectedId = ids.get(index);
return this.map.get(selectedId); return this.map.get(selectedId);
} }
@ -149,14 +146,15 @@ public class FlightConfigurableParameterSet<E extends FlightConfigurableParamete
return toReturn; return toReturn;
} }
/** /**
* @return a sorted list of all the contained FlightConfigurationIDs * @return a sorted list of all the contained FlightConfigurationIDs
*/ */
public List<FlightConfigurationId> getSortedConfigurationIDs(){ public List<FlightConfigurationId> getIds(){
ArrayList<FlightConfigurationId> toReturn = new ArrayList<FlightConfigurationId>(); ArrayList<FlightConfigurationId> toReturn = new ArrayList<FlightConfigurationId>();
toReturn.addAll( this.map.keySet() ); toReturn.addAll( this.map.keySet() );
toReturn.remove( defaultValueId ); toReturn.remove( FlightConfigurationId.DEFAULT_VALUE_FCID );
// Java 1.8: // Java 1.8:
//toReturn.sort( null ); //toReturn.sort( null );
@ -166,21 +164,20 @@ public class FlightConfigurableParameterSet<E extends FlightConfigurableParamete
return toReturn; return toReturn;
} }
public List<FlightConfigurationId> getIds(){
return this.getSortedConfigurationIDs();
}
/** /**
* Set the parameter value for the provided flight configuration ID. * Set the parameter value for the provided flight configuration ID.
* This sets the override for this flight configuration ID. * This sets the override for this flight configuration ID.
* *
* @param id the flight configuration ID * @param fcid the flight configuration ID
* @param value the parameter value (null not allowed) * @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) { if ( nextValue == null) {
// null value means to delete this fcid // null value means to delete this fcid
this.map.remove(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{ }else{
this.map.put(fcid, nextValue); this.map.put(fcid, nextValue);
} }
@ -189,7 +186,7 @@ public class FlightConfigurableParameterSet<E extends FlightConfigurableParamete
} }
public boolean isDefault(E testVal) { public boolean isDefault( final E testVal) {
return (Utils.equals( this.getDefault(), testVal)); return (Utils.equals( this.getDefault(), testVal));
} }
@ -197,28 +194,24 @@ public class FlightConfigurableParameterSet<E extends FlightConfigurableParamete
* Return whether a specific flight configuration ID is using the * Return whether a specific flight configuration ID is using the
* default value. * default value.
* *
* @param id the flight configuration ID * @param fcid the flight configuration ID
* @return whether the default is being used * @return whether the default is being used
*/ */
public boolean isDefault( FlightConfigurationId fcid) { public boolean isDefault( final FlightConfigurationId fcid) {
return ( this.getDefault() == this.map.get(fcid)); return ( this.getDefault() == this.map.get(fcid));
} }
/** /**
* Reset a specific flight configuration ID to use the default parameter value. * Reset a specific flight configuration ID to use the default parameter value.
* *
* @param id the flight configuration ID * @param fcid the flight configuration ID
*/ */
public void reset( FlightConfigurationId fcid) { public void reset( final FlightConfigurationId fcid) {
if( fcid.isValid() ){ if( fcid.isValid() ){
set( fcid, null); set( fcid, null);
} }
} }
public void remove(){
reset();
}
/* /*
* Clears all configuration-specific settings -- meaning querying the parameter for any configuration will return the default value. * Clears all configuration-specific settings -- meaning querying the parameter for any configuration will return the default value.
*/ */
@ -241,7 +234,7 @@ public class FlightConfigurableParameterSet<E extends FlightConfigurableParamete
StringBuilder buf = new StringBuilder(); StringBuilder buf = new StringBuilder();
buf.append(String.format("====== Dumping ConfigurationSet<%s> (%d configurations)\n", this.getDefault().getClass().getSimpleName(), this.size() )); buf.append(String.format("====== Dumping ConfigurationSet<%s> (%d configurations)\n", this.getDefault().getClass().getSimpleName(), this.size() ));
final String fmt = " [%-12s]: %s\n"; final String fmt = " [%-12s]: %s\n";
for( FlightConfigurationId loopFCID : this.getSortedConfigurationIDs()){ for( FlightConfigurationId loopFCID : getIds()){
String shortKey = loopFCID.toShortKey(); String shortKey = loopFCID.toShortKey();
E inst = this.map.get(loopFCID); E inst = this.map.get(loopFCID);
if( this.isDefault(inst)){ if( this.isDefault(inst)){

View File

@ -577,7 +577,7 @@ public class Rocket extends RocketComponent {
} }
public List<FlightConfigurationId> getIds(){ public List<FlightConfigurationId> 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 <code>null</code> * Remove a flight configuration ID from the configuration IDs. The <code>null</code>
* ID cannot be removed, and an attempt to remove it will be silently ignored. * 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) { public void removeFlightConfigurationID(FlightConfigurationId fcid) {
checkState(); checkState();
@ -626,7 +626,7 @@ public class Rocket extends RocketComponent {
/** /**
* Check whether the given motor configuration ID has motors defined for it. * 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. * @return whether any motors are defined for it.
*/ */
public boolean hasMotors(FlightConfigurationId fcid) { 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. * 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 * @return FlightConfiguration instance
*/ */
public FlightConfiguration createFlightConfiguration(final FlightConfigurationId fcid) { 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. * 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 * @return a FlightConfiguration instance
*/ */
public FlightConfiguration getFlightConfiguration(final FlightConfigurationId fcid) { 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. * 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 * @return a FlightConfiguration instance
*/ */
public FlightConfiguration getFlightConfiguration(final int configIndex) { public FlightConfiguration getFlightConfiguration(final int configIndex) {
@ -723,8 +723,8 @@ public class Rocket extends RocketComponent {
* Associate the given ID and flight configuration. * Associate the given ID and flight configuration.
* <code>null</code> or an empty string. * <code>null</code> or an empty string.
* *
* @param id the flight configuration id * @param fcid the flight configuration id
* @param name the name for the flight configuration * @param newConfig new FlightConfiguration to store
*/ */
public void setFlightConfiguration(final FlightConfigurationId fcid, FlightConfiguration newConfig) { public void setFlightConfiguration(final FlightConfigurationId fcid, FlightConfiguration newConfig) {
checkState(); checkState();

View File

@ -384,7 +384,7 @@ public class TestRockets {
public static final Rocket makeEstesAlphaIII(){ public static final Rocket makeEstesAlphaIII(){
Rocket rocket = new Rocket(); Rocket rocket = new Rocket();
FlightConfigurationId fcid[] = new FlightConfigurationId[5]; FlightConfigurationId fcid[] = new FlightConfigurationId[5];
fcid[0] = rocket.getSelectedConfiguration().getFlightConfigurationID(); fcid[0] = new FlightConfigurationId();
rocket.createFlightConfiguration(fcid[0]); rocket.createFlightConfiguration(fcid[0]);
fcid[1] = new FlightConfigurationId(); fcid[1] = new FlightConfigurationId();
rocket.createFlightConfiguration(fcid[1]); rocket.createFlightConfiguration(fcid[1]);

View File

@ -138,7 +138,7 @@ public class ParameterSetTest extends BaseTestCase {
// testSet.getSortedConfigurationIDs() // testSet.getSortedConfigurationIDs()
// >> this function should ONLY return ids for the overrides // >> 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.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 @Test