From 7b28923659b4f8efd8bb142949da885d944d6248 Mon Sep 17 00:00:00 2001 From: Daniel_M_Williams Date: Sat, 19 Jan 2019 12:45:50 -0500 Subject: [PATCH] [fix] converts getActiveComponent calls to getAllComponents - this clears the 'using a deprecated function' warning - more importantly, this clarifies what exactly the caller needs at each call site --- .../rocketcomponent/FlightConfiguration.java | 22 ++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) diff --git a/core/src/net/sf/openrocket/rocketcomponent/FlightConfiguration.java b/core/src/net/sf/openrocket/rocketcomponent/FlightConfiguration.java index 32b1b18ac..e7a42cc74 100644 --- a/core/src/net/sf/openrocket/rocketcomponent/FlightConfiguration.java +++ b/core/src/net/sf/openrocket/rocketcomponent/FlightConfiguration.java @@ -172,9 +172,29 @@ public class FlightConfiguration implements FlightConfigurableParameter getAllComponents() { + Queue toProcess = new ArrayDeque(); + toProcess.offer(this.rocket); + + ArrayList toReturn = new ArrayList<>(); + + while (!toProcess.isEmpty()) { + RocketComponent comp = toProcess.poll(); + + toReturn.add(comp); + for (RocketComponent child : comp.getChildren()) { + if (!(child instanceof AxialStage)) { + toProcess.offer(child); + } + } + } + + return toReturn; + } // this method is deprecated because it ignores instancing of parent components (e.g. Strapons or pods ) - // if you're calling this method, you're probably not getting the numbers you expect. + // depending on your context, this may or may not be what you want. + // recomend migrating to either: `getAllComponents` or `getActiveInstances` @Deprecated public Collection getActiveComponents() { Queue toProcess = new ArrayDeque(this.getActiveStages());