Class MessageLocationFilter<D>

Type Parameters:
D - the document identifier type.
All Implemented Interfaces:
MessageReceiver<SimpleMessage<D>>

public class MessageLocationFilter<D> extends MessagePasser<SimpleMessage<D>>
A filter which propagates only those messages which lie in particular location regions. Those are given by a dynamic list of positives. The list contains triples (String, fromLine, toLine), with both line numbers meant as inclusive. Only the line numbers of locations are compared. The string must appear as a suffix of "String.valueOf()" of the document id. (This seems a crude method, but is well-proven in practice.) All public add/remove methods of filter elements convert internally to this format.

A dynamic boolean value determines whether to pass or suppress location-less messages.

A further boolean value determines whether an empty positive list of regions means to let pass all or none of the messages with location info.

  • Field Details

    • regions

      protected Set<MessageLocationFilter<D>.Region> regions
      Set of all enabled reagions.
    • locationLess

      protected boolean locationLess
      Whether messages without locations are let pass.
    • emptyList

      protected boolean emptyList
      Whether no region set means to let pass every message.
  • Constructor Details

    • MessageLocationFilter

      public MessageLocationFilter(@Opt @Opt MessageReceiver<SimpleMessage<D>> d, boolean emptyList, boolean locationLess)
      Only constructor.
      Parameters:
      d - the target of all messages passed.
      emptyList - whether no regions in the list means to let pass every message.
      locationLess - whether messages without locations are let pass.
  • Method Details

    • removeAll

      public MessageLocationFilter<D> removeAll()
      Clear all selected regions. Depending on emptyList this can mean to let pass all or none messages with locations.
      Returns:
      this instance, for method chaining.
    • setPassLocationLess

      public MessageLocationFilter<D> setPassLocationLess(boolean ll)
      Set whether a message without any location passes the filter.
      Parameters:
      ll - the new value of that flag.
      Returns:
      this instance, for method chaining.
    • setEmptyList

      public MessageLocationFilter<D> setEmptyList(boolean el)
      Set whether an empty location list means to let pass all messages with locations. Otherwise no messages with locations are let pass.
      Parameters:
      el - the new value of that flag.
      Returns:
      this instance, for method chaining.
    • addRegion

      void addRegion(MessageLocationFilter<D>.Region reg)
      Add a region object to the list of passing regions.
      Parameters:
      reg - region to add to the filter.
    • addRegion

      public MessageLocationFilter<D>.Region addRegion(String docId, int from, int to)
      Add a region with the given parameters to the list of passing locations.
      Parameters:
      docId - a required suffix of the string value of the document id
      from - the starting line number.
      to - the ending line number, inclusive.
      Returns:
      the constructed region object, for easy later removal.
    • addRegion

      public MessageLocationFilter<D>.Region addRegion(D docId, int from, int to)
      Add a region with the given parameters to the list of passing locations.
      Parameters:
      docId - the document id
      from - the starting line number.
      to - the ending line number, inclusive.
      Returns:
      the constructed region object, for easy later removal.
    • addRegion

      public MessageLocationFilter<D>.Region addRegion(Location<D> loc)
      Add a region with the given parameters to the list of passing locations.
      Parameters:
      loc - the only location in the new region.
      Returns:
      the constructed region object, for easy later removal.
    • removeRegion

      void removeRegion(MessageLocationFilter<D>.Region reg)
      Remove the given region from the list of passed regions. If contained, only one occurence of this region is removed.
      Parameters:
      reg - the region to remove.
    • removeRegion

      public void removeRegion(String docId, int from, int to)
      Remove the given region from the list of passed regions. If contained, only one occurence of this region is removed.
      Parameters:
      docId - the document id
      from - the starting line number.
      to - the ending line number, inclisive.
    • removeRegion

      public void removeRegion(D docId, int from, int to)
      Remove the given region from the list of passed regions. If contained, only one occurence of this region is removed.
      Parameters:
      docId - the document id
      from - the starting line number.
      to - the ending line number, inclisive.
    • removeRegion

      public void removeRegion(Location<D> loc)
      Remove the given region from the list of passed regions. If contained, only one occurence of this region is removed.
      Parameters:
      loc - the location for which (a previously added) singleton region shall be removed.
    • match

      public boolean match(Location<D> loc)
      Test whether the location is completely contained in one of the regions. The regions have start and end line numbers; both are included. The string representation of the document id must only end with the specified String. (As a heuristics, it may also end with the string plus an appended double quote.)
      Parameters:
      loc - the location to test
      Returns:
      the test verdict
    • receive

      public void receive(SimpleMessage<D> m)
      Pass the message to the SingleSender.drain, if the filter criterion is met.
      Specified by:
      receive in interface MessageReceiver<D>
      Overrides:
      receive in class MessagePasser<SimpleMessage<D>>
      Parameters:
      m - message to propagate.
    • dump

      public void dump(PrintStream p)
      Prints the complete filter state. Primely for debug purposes.
      Parameters:
      p - print stream for the text output.