Class CommentChain<C extends Comment>

java.lang.Object
com.atlassian.bitbucket.comment.CommentChain<C>
All Implemented Interfaces:
Iterable<C>

public class CommentChain<C extends Comment> extends Object implements Iterable<C>
Performs a depth-first iteration given a starting set of comments. For example, consider the following comments:
 C1
   C1-R1
   C1-R2
 C2
   C2-R1
     C2-R1-R1
   C2-R2
     C2-R2-R1
       C2-R2-R1-R1
   C2-R3
 C3
 
new CommentChain(ImmutableList.of(c1, c2, c3)) would traverse the comments in the same order as reading that tree from the top to the bottom: C1 -> C1-R1 -> C1-R2 -> C2 -> C2-R1 -> C2-R1-R1 -> C2-R2 -> C2-R2-R1 -> C2-R2-R1-R1 -> C2-R3 -> C3 Notice that C2-R1-R1, the first reply to the first reply of the second comment, is traversed before C2-R2, the second reply to the second comment.

Note: This class supports any subtype C of Comment, under the assumption that all replies are consistently instances of C. Violating that assumption will result in ClassCastExceptions when iterating through the chain.

  • Method Details

    • of

      public static <C extends Comment> CommentChain<C> of(@Nonnull Iterable<C> rootComments)
      A convenience method for creating a new chain from the provided comments.
      Type Parameters:
      C - an implementation of Comment
      Parameters:
      rootComments - the comments to use when creating the chain
      Returns:
      a new chain
      Since:
      5.0
    • stream

      @Nonnull public Stream<C> stream()
      Returns:
      stream of the comment chain
      Since:
      4.1
    • iterator

      @Nonnull public Iterator<C> iterator()
      Specified by:
      iterator in interface Iterable<C extends Comment>