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
FieldsModifier and TypeFieldDescriptionstatic Comparator<Rectangle> The comparator used to sort the elements of this List. -
Constructor Summary
ConstructorsConstructorDescriptionConstruct an initially emptyRectListManager.RectListManager(int capacity) Construct an initially emptyRectListManager, with initialcapacity.Construct aRectListManagerfrom anotherRectListManager(data is copied).RectListManager(Rectangle rect) Construct aRectListManagerwith one rectangleRectListManager(Rectangle[] rects) Construct aRectListManagerfrom an Array ofRectanglesRectListManager(Rectangle[] rects, int off, int sz) Construct aRectListManagerfrom an Array ofRectanglesRectListManager(Collection<?> rects) Construct aRectListManagerfrom a Collection of Rectangles -
Method Summary
Modifier and TypeMethodDescriptionvoidadd(RectListManager rlm) Adds the contents ofrlmto this RectListManager.booleanEnsures that this collection contains the specified elementprotected voidEnsures that this collection contains the specified element l is the lower bound index for insertion r is upper bound index for insertion.booleanaddAll(Collection<? extends Rectangle> c) voidclear()clone()StandardObjectclone method.booleanbooleanbooleancontainsAll(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.voiddump()voidensureCapacity(int sz) protected voidinsertRects(Rectangle[] rects, int srcPos, int dstPos, int len) booleanisEmpty()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).voidmergeRects(int overhead, int lineOverhead) booleanRemoves a single instance of the specified Rectangle from this collection, if it is present.booleanRemoves a single instance of the specified element from this collection, if it is present.booleanremoveAll(RectListManager rlm) booleanremoveAll(Collection<?> c) booleanretainAll(RectListManager rlm) booleanretainAll(Collection<?> c) intsize()Returns the number of elements currently stored in this collection.protected voidvoidsubtract(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, waitMethods 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 aRectListManagerfrom a Collection of Rectangles- Parameters:
rects- Collection that must only contain rectangles.
-
RectListManager
Construct aRectListManagerfrom an Array ofRectangles- Parameters:
rects- Array ofRectangles, must not contain any null entries.
-
RectListManager
Construct aRectListManagerfrom 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 aRectListManagerfrom anotherRectListManager(data is copied).- Parameters:
rlm- RectListManager to copy.
-
RectListManager
Construct aRectListManagerwith 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
StandardObjectclone method.- Overrides:
clonein 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:
sizein interfaceCollection<Rectangle>
-
isEmpty
public boolean isEmpty()Returns true if this collection contains no elements.- Specified by:
isEmptyin interfaceCollection<Rectangle>
-
clear
public void clear()- Specified by:
clearin 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:
toArrayin 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:
toArrayin 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:
addin 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:
addAllin interfaceCollection<Rectangle>
-
contains
- Specified by:
containsin interfaceCollection<Rectangle>
-
containsAll
Returns true if this collection contains all of the elements in the specified collection.- Specified by:
containsAllin interfaceCollection<Rectangle>
-
containsAll
-
remove
Removes a single instance of the specified element from this collection, if it is present.- Specified by:
removein 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:
removeAllin interfaceCollection<Rectangle>
-
removeAll
-
retainAll
- Specified by:
retainAllin interfaceCollection<Rectangle>
-
retainAll
-
add
Adds the contents ofrlmto 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)
-