SampleNode extends MethodMap<SampleNode> implements Serializable, StackSamples { public SampleNode(final int count, final int capacity) { super(capacity); this.sampleCount = count; } SampleNode(final int count, final int capacity);  SampleNode(final int count);  SampleNode(); static SampleNode createSampleNode(final StackTraceElement... stackTrace); static void addToSampleNode(final SampleNode node, final StackTraceElement... stackTrace); @Override TMap<Method, SampleNode> getSubNodes(); static SampleNode clone(final SampleNode node); @Nullable static SampleNode aggregateNullable(@Nullable final SampleNode node1, @Nullable final SampleNode node2); static SampleNode aggregate(final SampleNode node1, final SampleNode node2); @Nullable @SuppressFBWarnings("CFS_CONFUSING_FUNCTION_SEMANTICS") // this is why this is called unsafe. static SampleNode aggregateNullableUnsafe(@Nullable final SampleNode node1,
          @Nullable final SampleNode node2); void add(final SampleNode other); @Override int getSampleCount(); @Override String toString(); int height(); int getNrNodes(); @Nullable SampleNode filteredBy(final Predicate<Method> predicate); @Override void writeJsonTo(final Appendable appendable); void writeTo(final Method m, final Appendable appendable); void writeD3JsonTo(final Appendable appendable); void writeD3JsonFormatTo(final Method m, final Appendable appendable); static void traverse(final Method m, final SampleNode node, final Invocation handler); static void traverse(final Method m, final SampleNode node, final Invocation handler,
          final boolean breadthFirst); static void traverse(final Method m, final SampleNode node, final Invocation handler,
          final Function<Deque, TraversalData> func); static Pair<Method, SampleNode> parse(@WillNotClose final Reader r); static void parseInto(@WillNotClose final Reader r, final SampleNode root); static void parseInto(final JsonParser jsonP, final SampleNode parentNode); static Pair<Method, SampleNode> parseD3Json(@WillNotClose final Reader r); @Override int hashCode(); @Override boolean equals(final Object obj); void writeExternal(final ObjectOutput out); void readExternal(final ObjectInput in);  }
@Test @SuppressFBWarnings("PRMC_POSSIBLY_REDUNDANT_METHOD_CALLS") public void testSampleNode() throws IOException { LOG.debug("sample"); StackTraceElement[] st1 = new StackTraceElement[3]; st1[0] = new StackTraceElement("C1", "m1", "C1.java", 10); st1[1] = new StackTraceElement("C1", "m2", "C1.java", 11); st1[2] = new StackTraceElement("C1", "m3", "C1.java", 12); SampleNode node1 = SampleNode.createSampleNode(st1); LOG.debug("Node 1", node1); Assert.assertEquals(4, node1.getNrNodes()); StackTraceElement[] st2 = new StackTraceElement[1]; st2[0] = new StackTraceElement("C1", "m1", "C1.java", 10); SampleNode.addToSampleNode(node1, st2); LOG.debug("Node 1", node1); Assert.assertEquals(5, node1.getNrNodes()); StackTraceElement[] st3 = new StackTraceElement[3]; st3[0] = new StackTraceElement("C2", "m1", "C2.java", 10); st3[1] = new StackTraceElement("C2", "m2", "C2.java", 11); st3[2] = new StackTraceElement("C2", "m3", "C2.java", 12); SampleNode.addToSampleNode(node1, st3); LOG.debug("Node 1", node1); StackTraceElement[] st4 = new StackTraceElement[3]; st4[0] = new StackTraceElement("C1", "m1", "C1.java", 10); st4[1] = new StackTraceElement("C1", "m2", "C1.java", 11); st4[2] = new StackTraceElement("C1", "m4", "C1.java", 14); SampleNode.addToSampleNode(node1, st4); SampleNode.addToSampleNode(node1, st1); LOG.debug("Node 1", node1); SampleNode agg = SampleNode.aggregate(node1, node1); LOG.debug("n1 + n2", agg); Assert.assertEquals(node1.getSampleCount() * 2, agg.getSampleCount()); final Method method = Methods.getMethod("C1", "m3"); Assert.assertEquals(node1.getSubNodes().get(method).getSampleCount() * 2, agg.getSubNodes().get(method).getSampleCount()); StringBuilder sb = new StringBuilder(); node1.writeTo(sb); LOG.debug("Serialized String", sb); SampleNode into = new SampleNode(); SampleNode.parseInto(new StringReader(sb.toString()), into); Pair<Method, SampleNode> parsed = SampleNode.parse(new StringReader(sb.toString())); Assert.assertEquals(node1, parsed.getSecond()); Assert.assertEquals(node1, Objects.clone(node1)); Assert.assertEquals(node1, into); SampleNode node1Clone = SampleNode.clone(node1); Assert.assertEquals(node1, node1Clone); node1Clone.addToCount(5); Assert.assertNotEquals(node1, node1Clone); StringBuilder sb2 = new StringBuilder(); node1.writeD3JsonTo(sb2); LOG.debug("Serialized D3 String", sb2); Pair<Method, SampleNode> parsed2 = SampleNode.parseD3Json(new StringReader(sb2.toString())); Assert.assertEquals(node1, parsed2.getSecond()); SampleNode.traverse(parsed.getFirst(), parsed.getSecond(), (f, t, s) -> { LOG.debug("{} -> {} sampled {} times", f, t, s); return true; }); }