From 6c67c2266ad5f48646538ceea6c23a3428796f2b Mon Sep 17 00:00:00 2001 From: Kevin Ruland Date: Thu, 19 Apr 2012 16:03:48 +0000 Subject: [PATCH] Change implementation of compatible types so they can be declared. Because of the circular references, they cannot be declared in constructor arguments. --- .../sf/openrocket/preset/ComponentPreset.java | 28 ++++++++----------- 1 file changed, 11 insertions(+), 17 deletions(-) diff --git a/core/src/net/sf/openrocket/preset/ComponentPreset.java b/core/src/net/sf/openrocket/preset/ComponentPreset.java index 9ee7c0096..d10a88b74 100644 --- a/core/src/net/sf/openrocket/preset/ComponentPreset.java +++ b/core/src/net/sf/openrocket/preset/ComponentPreset.java @@ -93,35 +93,29 @@ public class ComponentPreset implements Comparable { ComponentPreset.OUTER_DIAMETER, ComponentPreset.LENGTH} ); - - Type[] compatibleTypes; TypedKey[] displayedColumns; Type( TypedKey[] displayedColumns) { - compatibleTypes = new Type[1]; - compatibleTypes[0] = this; this.displayedColumns = displayedColumns; } - Type( Type[] t, TypedKey[] displayedColumns ) { - - compatibleTypes = new Type[t.length+1]; - compatibleTypes[0] = this; - for( int i=0; i getCompatibleTypes() { + return compatibleTypeMap.get(Type.this); } public TypedKey[] getDisplayedColumns() { return displayedColumns; } + + private static Map> compatibleTypeMap = new HashMap>(); + static { + compatibleTypeMap.put( BODY_TUBE, Arrays.asList( BODY_TUBE, TUBE_COUPLER) ); + compatibleTypeMap.put( TUBE_COUPLER, Arrays.asList( BODY_TUBE,TUBE_COUPLER) ); + compatibleTypeMap.put( CENTERING_RING, Arrays.asList( CENTERING_RING, ENGINE_BLOCK ) ); + compatibleTypeMap.put( NOSE_CONE, Arrays.asList( NOSE_CONE, TRANSITION)); + } + } public final static TypedKey MANUFACTURER = new TypedKey("Manufacturer", Manufacturer.class);