Change the semantics of MaterialHolder.getXXXMaterial( Material ), instead of returning the material used as the argument if the material is not in the map, it returns null. This make the methods more similar to standard hash collections.
This commit is contained in:
parent
89ff888c27
commit
1a6b3e471b
@ -1,8 +1,5 @@
|
|||||||
package net.sf.openrocket.preset.loader;
|
package net.sf.openrocket.preset.loader;
|
||||||
|
|
||||||
import java.util.Collections;
|
|
||||||
import java.util.Map;
|
|
||||||
|
|
||||||
import net.sf.openrocket.material.Material;
|
import net.sf.openrocket.material.Material;
|
||||||
import net.sf.openrocket.preset.TypedKey;
|
import net.sf.openrocket.preset.TypedKey;
|
||||||
import net.sf.openrocket.preset.TypedPropertyMap;
|
import net.sf.openrocket.preset.TypedPropertyMap;
|
||||||
@ -29,8 +26,8 @@ public class LineMaterialColumnParser extends BaseColumnParser {
|
|||||||
|
|
||||||
Material.Line myMaterial = new Material.Line(columnData, 0.0, true);
|
Material.Line myMaterial = new Material.Line(columnData, 0.0, true);
|
||||||
|
|
||||||
myMaterial = materialMap.getLineMaterial(myMaterial);
|
Material.Line m = materialMap.getLineMaterial(myMaterial);
|
||||||
props.put(param, myMaterial);
|
props.put(param, m!=null? m : myMaterial);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,8 +1,5 @@
|
|||||||
package net.sf.openrocket.preset.loader;
|
package net.sf.openrocket.preset.loader;
|
||||||
|
|
||||||
import java.util.Collections;
|
|
||||||
import java.util.Map;
|
|
||||||
|
|
||||||
import net.sf.openrocket.material.Material;
|
import net.sf.openrocket.material.Material;
|
||||||
import net.sf.openrocket.preset.ComponentPreset;
|
import net.sf.openrocket.preset.ComponentPreset;
|
||||||
import net.sf.openrocket.preset.TypedKey;
|
import net.sf.openrocket.preset.TypedKey;
|
||||||
@ -32,9 +29,9 @@ public class MaterialColumnParser extends BaseColumnParser {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
Material.Bulk m = new Material.Bulk(columnData, 0.0, true);
|
Material.Bulk tmpMaterial = new Material.Bulk(columnData, 0.0, true);
|
||||||
m = materialMap.getBulkMaterial(m);
|
Material.Bulk m = materialMap.getBulkMaterial(tmpMaterial);
|
||||||
props.put(param, m);
|
props.put(param, m!= null ? m : tmpMaterial);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -31,9 +31,22 @@ public class MaterialHolder {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public Material getMaterial ( Material material ) {
|
||||||
|
switch ( material.getType() ) {
|
||||||
|
case BULK:
|
||||||
|
return getBulkMaterial( (Material.Bulk)material );
|
||||||
|
case SURFACE:
|
||||||
|
return getSurfaceMaterial( (Material.Surface) material, null );
|
||||||
|
case LINE:
|
||||||
|
return getLineMaterial( (Material.Line) material );
|
||||||
|
default:
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public Material.Bulk getBulkMaterial( Material.Bulk material ) {
|
public Material.Bulk getBulkMaterial( Material.Bulk material ) {
|
||||||
Material.Bulk m = bulkMaterials.get( material.getName() );
|
Material.Bulk m = bulkMaterials.get( material.getName() );
|
||||||
return (m==null) ? material : m;
|
return m;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Material.Surface getSurfaceMaterial( Material.Surface material, Double thickness ) {
|
public Material.Surface getSurfaceMaterial( Material.Surface material, Double thickness ) {
|
||||||
@ -44,7 +57,7 @@ public class MaterialHolder {
|
|||||||
// Try to see if we can convert a bulk material.
|
// Try to see if we can convert a bulk material.
|
||||||
if ( thickness == null ) {
|
if ( thickness == null ) {
|
||||||
// if we have no thickness, there is nothing we can do
|
// if we have no thickness, there is nothing we can do
|
||||||
return material;
|
return null;
|
||||||
}
|
}
|
||||||
String thicknessName = UnitGroup.UNITS_LENGTH.getUnit("mm").toString(thickness);
|
String thicknessName = UnitGroup.UNITS_LENGTH.getUnit("mm").toString(thickness);
|
||||||
String convertedMaterialName = material.getName() + "(" + thicknessName + ")";
|
String convertedMaterialName = material.getName() + "(" + thicknessName + ")";
|
||||||
@ -55,7 +68,7 @@ public class MaterialHolder {
|
|||||||
Material.Bulk bulk = bulkMaterials.get(material.getName() );
|
Material.Bulk bulk = bulkMaterials.get(material.getName() );
|
||||||
|
|
||||||
if ( bulk == null ) {
|
if ( bulk == null ) {
|
||||||
return material;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Ok, now we have a thickness and a bulk material of the correct name,
|
// Ok, now we have a thickness and a bulk material of the correct name,
|
||||||
@ -71,7 +84,7 @@ public class MaterialHolder {
|
|||||||
|
|
||||||
public Material.Line getLineMaterial( Material.Line material ) {
|
public Material.Line getLineMaterial( Material.Line material ) {
|
||||||
Material.Line m = lineMaterials.get( material.getName() );
|
Material.Line m = lineMaterials.get( material.getName() );
|
||||||
return (m==null) ? material : m;
|
return m;
|
||||||
}
|
}
|
||||||
|
|
||||||
public int size() {
|
public int size() {
|
||||||
|
@ -42,10 +42,10 @@ public class ParachuteLoader extends BaseComponentLoader {
|
|||||||
|
|
||||||
// Fix the material since some files use bulk materials for streamers.
|
// Fix the material since some files use bulk materials for streamers.
|
||||||
Double thickness = props.get( ComponentPreset.THICKNESS );
|
Double thickness = props.get( ComponentPreset.THICKNESS );
|
||||||
Material.Surface material = (Material.Surface) props.get( ComponentPreset.MATERIAL );
|
Material.Surface myMaterial = (Material.Surface) props.get( ComponentPreset.MATERIAL );
|
||||||
|
|
||||||
material = materials.getSurfaceMaterial(material, thickness);
|
Material.Surface m = materials.getSurfaceMaterial(myMaterial, thickness);
|
||||||
props.put(ComponentPreset.MATERIAL, material);
|
props.put(ComponentPreset.MATERIAL, m!=null ? m : myMaterial);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -49,11 +49,11 @@ public class StreamerLoader extends BaseComponentLoader {
|
|||||||
|
|
||||||
// Fix the material since some files use bulk materials for streamers.
|
// Fix the material since some files use bulk materials for streamers.
|
||||||
Double thickness = props.get( ComponentPreset.THICKNESS );
|
Double thickness = props.get( ComponentPreset.THICKNESS );
|
||||||
Material.Surface material = (Material.Surface) props.get( ComponentPreset.MATERIAL );
|
Material.Surface myMaterial = (Material.Surface) props.get( ComponentPreset.MATERIAL );
|
||||||
|
|
||||||
material = materials.getSurfaceMaterial(material, thickness);
|
Material.Surface m = materials.getSurfaceMaterial(myMaterial, thickness);
|
||||||
|
|
||||||
props.put(ComponentPreset.MATERIAL, material);
|
props.put(ComponentPreset.MATERIAL, m!=null? m : myMaterial);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -25,8 +25,8 @@ public class SurfaceMaterialColumnParser extends BaseColumnParser {
|
|||||||
}
|
}
|
||||||
|
|
||||||
Material.Surface myMaterial = new Material.Surface(columnData, 0.0, true);
|
Material.Surface myMaterial = new Material.Surface(columnData, 0.0, true);
|
||||||
myMaterial = materialMap.getSurfaceMaterial(myMaterial, null);
|
Material.Surface m = materialMap.getSurfaceMaterial(myMaterial, null);
|
||||||
props.put(param, myMaterial);
|
props.put(param, m!=null ? m : myMaterial);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user