Package eu.bandm.tools.message
Class MessageLocationFilter<D>
java.lang.Object
eu.bandm.tools.message.SingleSender<SimpleMessage<D>>
eu.bandm.tools.message.MessagePasser<SimpleMessage<D>>
eu.bandm.tools.message.MessageLocationFilter<D>
- Type Parameters:
D
- the document identifier type.
- All Implemented Interfaces:
MessageReceiver<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.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionclass
Reification of a region specification to let pass. -
Field Summary
FieldsModifier and TypeFieldDescriptionprotected boolean
Whether no region set means to let pass every message.protected boolean
Whether messages without locations are let pass.protected Set
<MessageLocationFilter<D>.Region> Set of all enabled reagions.Fields inherited from class eu.bandm.tools.message.SingleSender
drain
-
Constructor Summary
ConstructorsConstructorDescriptionMessageLocationFilter
(@Opt MessageReceiver<SimpleMessage<D>> d, boolean emptyList, boolean locationLess) Only constructor. -
Method Summary
Modifier and TypeMethodDescriptionAdd a region with the given parameters to the list of passing locations.Add a region with the given parameters to the list of passing locations.(package private) void
Add a region object to the list of passing regions.Add a region with the given parameters to the list of passing locations.void
dump
(PrintStream p) Prints the complete filter state.boolean
Test whether the location is completely contained in one of the regions.void
receive
(SimpleMessage<D> m) Pass the message to theSingleSender.drain
, if the filter criterion is met.Clear all selected regions.void
removeRegion
(D docId, int from, int to) Remove the given region from the list of passed regions.void
removeRegion
(Location<D> loc) Remove the given region from the list of passed regions.(package private) void
Remove the given region from the list of passed regions.void
removeRegion
(String docId, int from, int to) Remove the given region from the list of passed regions.setEmptyList
(boolean el) Set whether an empty location list means to let pass all messages with locations.setPassLocationLess
(boolean ll) Set whether a message without any location passes the filter.Methods inherited from class eu.bandm.tools.message.SingleSender
getDrain, getReceiver, send, setDrain, setReceiver
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Methods inherited from interface eu.bandm.tools.message.MessageReceiver
ifSubcriticalThen, ifSubcriticalThen, ifSubcriticalThenElse
-
Field Details
-
regions
Set of all enabled reagions. -
locationLess
protected boolean locationLessWhether messages without locations are let pass. -
emptyList
protected boolean emptyListWhether 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
Clear all selected regions. Depending onemptyList
this can mean to let pass all or none messages with locations.- Returns:
- this instance, for method chaining.
-
setPassLocationLess
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
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
Add a region object to the list of passing regions.- Parameters:
reg
- region to add to the filter.
-
addRegion
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 idfrom
- the starting line number.to
- the ending line number, inclusive.- Returns:
- the constructed region object, for easy later removal.
-
addRegion
Add a region with the given parameters to the list of passing locations.- Parameters:
docId
- the document idfrom
- the starting line number.to
- the ending line number, inclusive.- Returns:
- the constructed region object, for easy later removal.
-
addRegion
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
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
Remove the given region from the list of passed regions. If contained, only one occurence of this region is removed.- Parameters:
docId
- the document idfrom
- the starting line number.to
- the ending line number, inclisive.
-
removeRegion
Remove the given region from the list of passed regions. If contained, only one occurence of this region is removed.- Parameters:
docId
- the document idfrom
- the starting line number.to
- the ending line number, inclisive.
-
removeRegion
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
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
Pass the message to theSingleSender.drain
, if the filter criterion is met.- Specified by:
receive
in interfaceMessageReceiver<D>
- Overrides:
receive
in classMessagePasser<SimpleMessage<D>>
- Parameters:
m
- message to propagate.
-
dump
Prints the complete filter state. Primely for debug purposes.- Parameters:
p
- print stream for the text output.
-