java.lang.Object
io.sf.carte.echosvg.ext.awt.geom.RectListManager
- All Implemented Interfaces:
Iterable<Rectangle>
,Collection<Rectangle>
RectListManager is a class to manage a list of rectangular regions. This
class contains methods to add new rectangles to the List, to merge rectangles
in the list (based on a cost function), and functions to subract one
RectListManager from another. The main purpose of this class is to manage
dirty regions on a display (for this reason it uses Rectangle not
Rectangle2D).
-
Field Summary
Modifier and TypeFieldDescriptionstatic Comparator
<Rectangle> The comparator used to sort the elements of this List. -
Constructor Summary
ConstructorDescriptionConstruct an initially emptyRectListManager
.RectListManager
(int capacity) Construct an initially emptyRectListManager
, with initialcapacity
.Construct aRectListManager
from anotherRectListManager
(data is copied).RectListManager
(Rectangle rect) Construct aRectListManager
with one rectangleRectListManager
(Rectangle[] rects) Construct aRectListManager
from an Array ofRectangles
RectListManager
(Rectangle[] rects, int off, int sz) Construct aRectListManager
from an Array ofRectangles
RectListManager
(Collection<?> rects) Construct aRectListManager
from a Collection of Rectangles -
Method Summary
Modifier and TypeMethodDescriptionvoid
add
(RectListManager rlm) Adds the contents ofrlm
to this RectListManager.boolean
Ensures that this collection contains the specified elementprotected void
Ensures that this collection contains the specified element l is the lower bound index for insertion r is upper bound index for insertion.boolean
addAll
(Collection<? extends Rectangle> c) void
clear()
clone()
StandardObject
clone method.boolean
boolean
boolean
containsAll
(Collection<?> c) Returns true if this collection contains all of the elements in the specified collection.copy()
Similar to clone only strongly typed TODO Java 5: The use of covariant return types on clone() can eliminate this method.void
dump()
void
ensureCapacity
(int sz) protected void
insertRects
(Rectangle[] rects, int srcPos, int dstPos, int len) boolean
isEmpty()
Returns true if this collection contains no elements.iterator()
Returns an iterator over the elements in this collectionReturns a list iterator of the elements in this list (in proper sequence).void
mergeRects
(int overhead, int lineOverhead) boolean
Removes a single instance of the specified Rectangle from this collection, if it is present.boolean
Removes a single instance of the specified element from this collection, if it is present.boolean
removeAll
(RectListManager rlm) boolean
removeAll
(Collection<?> c) boolean
retainAll
(RectListManager rlm) boolean
retainAll
(Collection<?> c) int
size()
Returns the number of elements currently stored in this collection.protected void
void
subtract
(RectListManager rlm, int overhead, int lineOverhead) Object[]
toArray()
Object[]
fill the given array a with values from my internalrects
. when a is not large enough, a new array is allocated, filled and returned. the method works only, when a is a Object[] or a Rectange[].Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Methods inherited from interface java.util.Collection
equals, hashCode, parallelStream, removeIf, spliterator, stream, toArray
-
Field Details
-
comparator
The comparator used to sort the elements of this List. Sorts on x value of Rectangle.
-
-
Constructor Details
-
RectListManager
Construct aRectListManager
from a Collection of Rectangles- Parameters:
rects
- Collection that must only contain rectangles.
-
RectListManager
Construct aRectListManager
from an Array ofRectangles
- Parameters:
rects
- Array ofRectangles
, must not contain any null entries.
-
RectListManager
Construct aRectListManager
from an Array ofRectangles
- Parameters:
rects
- Array ofRectangles
, must not contain any null entries in the range [off, off+sz-1].off
- The offset to start copying from in rects.sz
- The number of entries to copy from rects.
-
RectListManager
Construct aRectListManager
from anotherRectListManager
(data is copied).- Parameters:
rlm
- RectListManager to copy.
-
RectListManager
Construct aRectListManager
with one rectangle- Parameters:
rect
- The rectangle to put in this rlm.
-
RectListManager
public RectListManager()Construct an initially emptyRectListManager
. -
RectListManager
public RectListManager(int capacity) Construct an initially emptyRectListManager
, with initialcapacity
.- Parameters:
capacity
- The inital capacity for the list. Setting this appropriately can save reallocations.
-
-
Method Details
-
dump
public void dump() -
getBounds
-
clone
StandardObject
clone method.- Overrides:
clone
in classObject
- Throws:
CloneNotSupportedException
-
copy
Similar to clone only strongly typed TODO Java 5: The use of covariant return types on clone() can eliminate this method. -
size
public int size()Returns the number of elements currently stored in this collection.- Specified by:
size
in interfaceCollection<Rectangle>
-
isEmpty
public boolean isEmpty()Returns true if this collection contains no elements.- Specified by:
isEmpty
in interfaceCollection<Rectangle>
-
clear
public void clear()- Specified by:
clear
in interfaceCollection<Rectangle>
-
iterator
Returns an iterator over the elements in this collection -
listIterator
Returns a list iterator of the elements in this list (in proper sequence). -
toArray
- Specified by:
toArray
in interfaceCollection<Rectangle>
-
toArray
fill the given array a with values from my internalrects
. when a is not large enough, a new array is allocated, filled and returned. the method works only, when a is a Object[] or a Rectange[]. When this is not the case, the a[] is just cleared.- Specified by:
toArray
in interfaceCollection<Rectangle>
- Parameters:
a
- array to fill (must not be null!)- Returns:
- the content of rects, either in a[] or a fresh array.
-
add
Ensures that this collection contains the specified element- Specified by:
add
in interfaceCollection<Rectangle>
- Parameters:
rect
- The rectangle to add
-
add
Ensures that this collection contains the specified element l is the lower bound index for insertion r is upper bound index for insertion.- Parameters:
rect
- The rectangle to addl
- the lowest possible index for a rect with greater 'x' coord.r
- the highest possible index for a rect with greater 'x' coord.
-
addAll
- Specified by:
addAll
in interfaceCollection<Rectangle>
-
contains
- Specified by:
contains
in interfaceCollection<Rectangle>
-
containsAll
Returns true if this collection contains all of the elements in the specified collection.- Specified by:
containsAll
in interfaceCollection<Rectangle>
-
containsAll
-
remove
Removes a single instance of the specified element from this collection, if it is present.- Specified by:
remove
in interfaceCollection<Rectangle>
- Parameters:
o
- Object to remove an matching instance of.
-
remove
Removes a single instance of the specified Rectangle from this collection, if it is present.- Parameters:
rect
- Rectangle to remove an matching instance of.
-
removeAll
- Specified by:
removeAll
in interfaceCollection<Rectangle>
-
removeAll
-
retainAll
- Specified by:
retainAll
in interfaceCollection<Rectangle>
-
retainAll
-
add
Adds the contents ofrlm
to this RectListManager. No collapsing of rectangles is done here the contents are simply added (you should generally call 'mergeRects' some time after this operation before using the contents of this RectListManager.- Parameters:
rlm
- The RectListManager to add the contents of.
-
mergeRects
public void mergeRects(int overhead, int lineOverhead) -
subtract
-
splitRect
-
insertRects
-
ensureCapacity
public void ensureCapacity(int sz)
-