From 79fda8aa8a7d682ac6bfd871021a7afd6711c2d6 Mon Sep 17 00:00:00 2001 From: richardgraham Date: Mon, 4 Jun 2012 05:56:24 +0000 Subject: [PATCH] Removed some debugging junk and fixed a null pointer exception. git-svn-id: https://openrocket.svn.sourceforge.net/svnroot/openrocket/trunk@742 180e2498-e6e9-4542-8430-84ac67f01cd8 --- .../openrocket/simulation/CustomExpression.java | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/core/src/net/sf/openrocket/simulation/CustomExpression.java b/core/src/net/sf/openrocket/simulation/CustomExpression.java index 1ca9bd08..6e829bb1 100644 --- a/core/src/net/sf/openrocket/simulation/CustomExpression.java +++ b/core/src/net/sf/openrocket/simulation/CustomExpression.java @@ -90,7 +90,7 @@ public class CustomExpression implements Cloneable{ * if no simulated data exists */ private FlightDataBranch getBranch() { - if ( sim == null || sim.getSimulatedData().getBranchCount() == 0){//sim.getSimulatedData().getBranch(0) == null) { + if ( sim == null || sim.getSimulatedData() == null || sim.getSimulatedData().getBranchCount() == 0){ return new FlightDataBranch(); } else { @@ -173,7 +173,7 @@ public class CustomExpression implements Cloneable{ // No characters that could mess things up saving etc for (char c : ",()[]{}<>".toCharArray()) - if (symbol.indexOf(c) != -1 ) + if (name.indexOf(c) != -1 ) return false; ArrayList names = getAllNames().clone(); @@ -223,7 +223,6 @@ public class CustomExpression implements Cloneable{ // Define the available variables as 0 for (FlightDataType type : getBranch().getTypes()){ - System.out.println( " " + type.getSymbol() ); builder.withVariable(type.getSymbol(), 0.0); } @@ -267,13 +266,17 @@ public class CustomExpression implements Cloneable{ * Returns the new flight data type corresponding to this calculated data */ public FlightDataType getType(){ - // Figure out priority from order in array so that customs expressions are always at the top - int totalExpressions = sim.getCustomExpressions().size(); - int p = -1*(totalExpressions-sim.getCustomExpressions().indexOf(this)); UnitGroup ug = new FixedUnitGroup(unit); FlightDataType type = FlightDataType.getType(name, symbol, ug); - type.setPriority(p); + + // If in a simulation, figure out priority from order in array so that customs expressions are always at the top + if (sim != null && sim.getCustomExpressions().contains(this)){ + int totalExpressions = sim.getCustomExpressions().size(); + int p = -1*(totalExpressions-sim.getCustomExpressions().indexOf(this)); + type.setPriority(p); + } + return type; } -- 2.30.2