public class IlvBufferedGraphicEnumeration extends Object implements IlvGraphicEnumeration
IlvGraphic
) in
a buffered way. Unless explicitly specified, all graphic enumerations
delivered by JViews classes are unbuffered, hence they do not allow
concurrent modifications. For instance, if you enumerate the objects
contained in a layer while adding or removing objects of the same layer,
a ConcurrentModificationException
is thrown.
By adding or removing objects while enumerating, the enumeration itself
would reach an undefined state. For instance, the following example is
incorrect:
IlvGraphicEnumeration e = manager.getObjects(); while (e.hasMoreElements()) { // it is not allowed to remove objects while enumerating in unbuffered way manager.removeObject(e.nextElement(), true); }However, if you use a buffered enumeration, all objects are first copied into a buffer, and you enumerate only over the objects in the buffer. In this case, you can add and remove objects safely while enumerating. The following example is correct:
IlvGraphicEnumeration e = new IlvBufferedGraphicEnumeration(manager.getObjects()); while (e.hasMoreElements()) { // it is safe to remove objects while enumerating in buffered way manager.removeObject(e.nextElement(), true); }Note that when using
IlvBufferedGraphicEnumeration
, you
enumerate the objects that were present at the time point when the
enumeration was allocated. If you add an object later while enumerating,
the object will not appear in the enumeration because it was not present
in the enumeration when the enumeration was allocated.
IlvGraphicEnumeration
Constructor and Description |
---|
IlvBufferedGraphicEnumeration(IlvGraphicEnumeration e)
Creates a new
IlvBufferedGraphicEnumeration . |
Modifier and Type | Method and Description |
---|---|
boolean |
hasMoreElements()
Tests if the enumeration contains more elements.
|
IlvGraphic |
nextElement()
Returns the next graphic object of the enumeration.
|
public IlvBufferedGraphicEnumeration(IlvGraphicEnumeration e)
IlvBufferedGraphicEnumeration
.e
- The graphic enumeration you want to be buffered.public boolean hasMoreElements()
hasMoreElements
in interface IlvGraphicEnumeration
public IlvGraphic nextElement()
nextElement
in interface IlvGraphicEnumeration
NoSuchElementException
- if there are no more existing elements.© Copyright 2024 Rogue Wave Software, Inc., a Perforce company.. All Rights Reserved.