Class CommentEventsCollector

java.lang.Object
org.snakeyaml.engine.v2.comments.CommentEventsCollector

public class CommentEventsCollector extends Object
Used by the Composer and Emitter to collect comment events so that they can be used at a later point in the process.
  • Field Details

    • eventSource

      private final Queue<Event> eventSource
    • expectedCommentTypes

      private final CommentType[] expectedCommentTypes
    • commentLineList

      private List<CommentLine> commentLineList
  • Constructor Details

    • CommentEventsCollector

      public CommentEventsCollector(Parser parser, CommentType... expectedCommentTypes)
      Constructor used to collect comment events emitted by a Parser.
      Parameters:
      parser - the event source.
      expectedCommentTypes - the comment types expected. Any comment types not included are not collected.
    • CommentEventsCollector

      public CommentEventsCollector(Queue<Event> eventSource, CommentType... expectedCommentTypes)
      Constructor used to collect events emitted by the Serializer.
      Parameters:
      eventSource - the event source.
      expectedCommentTypes - the comment types expected. Any comment types not included are not collected.
  • Method Details

    • isEventExpected

      private boolean isEventExpected(Event event)
      Determine if the event is a comment of one of the expected types set during construction.
      Parameters:
      event - the event to test.
      Returns:
      true if the events is a comment of the expected type; Otherwise, false.
    • collectEvents

      public CommentEventsCollector collectEvents()
      Collect all events of the expected type (set during construction) starting with the top event on the event source. Collection stops as soon as a non comment or comment of the unexpected type is encountered.
      Returns:
      this object.
    • collectEvents

      public Event collectEvents(Event event)
      Collect all events of the expected type (set during construction) starting with event provided as an argument and continuing with the top event on the event source. Collection stops as soon as a non comment or comment of the unexpected type is encountered.
      Parameters:
      event - the first event to attempt to collect.
      Returns:
      the event provided as an argument, if it is not collected; Otherwise, null
    • collectEventsAndPoll

      public Event collectEventsAndPoll(Event event)
      Collect all events of the expected type (set during construction) starting with event provided as an argument and continuing with the top event on the event source. Collection stops as soon as a non comment or comment of the unexpected type is encountered.
      Parameters:
      event - the first event to attempt to collect.
      Returns:
      the event provided as an argument, if it is not collected; Otherwise, the first event that is not collected.
    • consume

      public List<CommentLine> consume()
      Return the events collected and reset the collector.
      Returns:
      the events collected.
    • isEmpty

      public boolean isEmpty()
      Test if the collector contains any collected events.
      Returns:
      true if it does; Otherwise, false