From ac1d6b698acb7f03fec2cd3395890b65ee0fd932 Mon Sep 17 00:00:00 2001 From: Daniel_M_Williams Date: Fri, 14 Aug 2020 18:22:54 -0400 Subject: [PATCH] [refactor] streamlined null checks in SymmetricComponent.get{Prev|Next}SymmetricComponent --- .../rocketcomponent/SymmetricComponent.java | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/core/src/net/sf/openrocket/rocketcomponent/SymmetricComponent.java b/core/src/net/sf/openrocket/rocketcomponent/SymmetricComponent.java index 13af68ebb..f9d059abc 100644 --- a/core/src/net/sf/openrocket/rocketcomponent/SymmetricComponent.java +++ b/core/src/net/sf/openrocket/rocketcomponent/SymmetricComponent.java @@ -577,17 +577,16 @@ public abstract class SymmetricComponent extends BodyComponent implements BoxBou * @return the previous SymmetricComponent, or null. */ public final SymmetricComponent getPreviousSymmetricComponent() { - if(null == this.parent) { + if((null == this.parent) || (null == this.parent.getParent())){ return null; } - final ComponentAssembly assembly = this.getAssembly(); // might be: (a) Rocket -- for Centerline/Axial stages // (b) BodyTube -- for Parallel Stages & PodSets - final RocketComponent grandParent = assembly.getParent(); + final RocketComponent grandParent = this.parent.getParent(); // note: this is not guaranteed to _contain_ a stage... but that we're _searching_ for one. - int searchParentIndex = grandParent.getChildPosition(assembly); // position of stage w/in parent + int searchParentIndex = grandParent.getChildPosition(this.parent); // position of stage w/in parent int searchSiblingIndex = this.parent.getChildPosition(this)-1; // guess at index of previous stage while( 0 <= searchParentIndex ) { @@ -615,17 +614,16 @@ public abstract class SymmetricComponent extends BodyComponent implements BoxBou * @return the next SymmetricComponent, or null. */ public final SymmetricComponent getNextSymmetricComponent() { - if(null == this.parent) { + if((null == this.parent) || (null == this.parent.getParent())){ return null; } - final ComponentAssembly assembly = this.getAssembly(); // might be: (a) Rocket -- for centerline stages // (b) BodyTube -- for Parallel Stages - final RocketComponent grandParent = assembly.getParent(); + final RocketComponent grandParent = this.parent.getParent(); // note: this is not guaranteed to _contain_ a stage... but that we're _searching_ for one. - int searchParentIndex = grandParent.getChildPosition(assembly); + int searchParentIndex = grandParent.getChildPosition(this.parent); int searchSiblingIndex = this.parent.getChildPosition(this) + 1; while(searchParentIndex < grandParent.getChildCount()) {