diff --git a/core/src/net/sf/openrocket/gui/plot/Util.java b/core/src/net/sf/openrocket/gui/plot/Util.java new file mode 100644 index 000000000..81003aae4 --- /dev/null +++ b/core/src/net/sf/openrocket/gui/plot/Util.java @@ -0,0 +1,36 @@ +package net.sf.openrocket.gui.plot; + +import java.util.ArrayList; +import java.util.Collections; +import java.util.List; + +import net.sf.openrocket.document.Simulation; + +public abstract class Util { + + public static List generateSeriesLabels( Simulation simulation ) { + int size = simulation.getSimulatedData().getBranchCount(); + ArrayList stages = new ArrayList(size); + // we need to generate unique strings for each of the branches. Since the branch names are based + // on the stage name there is no guarantee they are unique. In order to address this, we first assume + // all the names are unique, then go through them looking for duplicates. + for (int i = 0; i < simulation.getSimulatedData().getBranchCount(); i++) { + stages.add(simulation.getSimulatedData().getBranch(i).getBranchName()); + } + // check for duplicates: + for( int i = 0; i< stages.size(); i++ ) { + String stagename = stages.get(i); + int numberDuplicates = Collections.frequency(stages, stagename); + if ( numberDuplicates > 1 ) { + int index = i; + int count = 1; + while( count <= numberDuplicates ) { + stages.set(index, stagename + "(" + count + ")" ); + count ++; + for( index++; index < stages.size() && !stagename.equals(stages.get(index)); index++ ); + } + } + } + return stages; + } +}