public static class ConnectedObjectScanner.MaskElementCounter extends java.lang.Object implements ConnectedObjectScanner.ElementVisitor
The simplest implementation of
It is also a good example for possible cloning in your code.
This class works with some bit matrix, named mask and specified in the constructor's argument.
It should have the same dimensions, as the matrix, scanned by the connected objects scanner:
(If this condition is not fulfilled,
visit method can throw unexpected
The only thing, performed by
visit method of this class, is increasing
some internal long counter by 1. You can read this counter by
This counter is zero after instantiating this object and can be cleared by
So, this class allows to count the number of unit elements of the mask, lying at the same positions as the elements of some connected object of the scanned matrix.
This class is not thread-safe, but is thread-compatible and can be synchronized manually, if multithread access is necessary.
|Modifier and Type||Field and Description|
The internal counter, stored in this object and returned by
|Constructor and Description|
Creates new instance of this class with the specified mask matrix.
|Modifier and Type||Method and Description|
Returns the internal counter: the value of
Returns the reference to mask matrix.
Resets the internal
This implementation increases the internal
mask- the mask matrix, unit elements of which (corresponding the some unit elements of the scanned matrix) should be counted.
java.lang.NullPointerException- if the argument is null.
public void visit(long coordinatesInMatrix, long indexInArray)
counterby 1, if the bit of the mask with the specified coordinates is 1.
More precisely, this method does the following:
public void reset()
Usually this method should be called before scanning new connected object via
ConnectedObjectScanner.clear(ArrayContext, ConnectedObjectScanner.ElementVisitor, long, boolean)
public long counter()