Converter { public static SampleNode convert(final Iterator<StackSampleElement> samples) { TIntObjectMap<SampleNode> index = new TIntObjectHashMap<>(); while (samples.hasNext()) { StackSampleElement asmp = samples.next(); SampleNode sn = new SampleNode(asmp.getCount()); SampleNode parent = index.get(asmp.getParentId()); if (parent != null) { Method m = asmp.getMethod(); parent.put(m, sn); } index.put(asmp.getId(), sn); } return index.get(0); } private  Converter(); static String createLabeledSsdump2FileName(final String baseFileName, final String label); static String getLabelFromSsdump2FileName(final String fileName); static SampleNode convert(final Iterator<StackSampleElement> samples); static void save(final File file, final SampleNode collected); @SuppressFBWarnings("NP_LOAD_OF_KNOWN_NULL_VALUE") static SampleNode load(final File file); static SampleNode load(@WillNotClose final InputStream fis); static void saveLabeledDumps(final File file, final Map<String, SampleNode> pcollected); @SuppressFBWarnings("NP_LOAD_OF_KNOWN_NULL_VALUE") static Map<String, SampleNode> loadLabeledDumps(final File file); static void loadLabels(final File file, final Consumer<String> labalsConsumer); @SuppressFBWarnings("NP_LOAD_OF_KNOWN_NULL_VALUE") @Nullable static SampleNode loadLabeledDump(final File file, final String label);  }
@Test public void test() { SampleNode testSample = testSample(); final List<StackSampleElement> samples = new ArrayList<>(); Converters.convert(Methods.ROOT, testSample, -1, 0, samples::add); SampleNode back = Converter.convert(samples.iterator()); Assert.assertEquals(testSample, back); }