E
- the class of the iterated objectspublic abstract class AbstractObjectIterator<E extends AbstractObject> extends java.lang.Object implements java.util.Iterator<E>, ObjectProvider<E>
abstract objects
.
It provides methods for getting objects by their position, ID, data-equality, locator or
ObjectMatcher
.
All methods are implemented in a "stream" fashion, i.e.
only the Iterator.next()
method is used to accomplish all the getting methods.
Note that iterator cannot go back, so for example the get-by-id
method will only find the object if it has not been skipped in the iterator before.
Constructor and Description |
---|
AbstractObjectIterator() |
Modifier and Type | Method and Description |
---|---|
static <T extends LocalAbstractObject> |
emptyIterator()
Returns an iterator on a single object.
|
abstract E |
getCurrentObject()
Returns an object returned by the last call to
Iterator.next() . |
static <T extends LocalAbstractObject> |
getIterator(java.util.Iterator<T> iterator)
Returns an AbstractObjectItator created over a standard iterator.
|
GenericMatchingObjectList<E> |
getMatchingObjects(ObjectMatcher<? super E> matcher)
Returns matching objects.
|
GenericMatchingObjectList<E> |
getMatchingObjects(ObjectMatcher<? super E> matcher,
boolean removeMatching)
Returns matching objects.
|
GenericMatchingObjectList<E> |
getMatchingObjects(ObjectMatcher<? super E> matcher,
boolean removeMatching,
int whoStays)
Returns matching objects.
|
GenericMatchingObjectList<E> |
getMatchingObjects(ObjectMatcher<? super E> matcher,
boolean removeMatching,
int[] whoStays)
Get matching objects
Method returns all objects that satisfy the matching constraints specified by matcher and deletes matching
objects from the bucket when required.
|
E |
getObjectByAnyLocator(java.util.Set<java.lang.String> locatorURIs,
boolean removeFound)
Returns the first instance of object, that has one of the specified locators.
|
E |
getObjectByData(LocalAbstractObject object)
Returns the first instance of object, that has data equal to the provided object.
|
E |
getObjectByLocator(java.lang.String locatorURI)
Returns the first instance of object, that has the specified locator.
|
E |
getObjectByLocator(java.lang.String locatorURI,
boolean prefix)
Returns the first instance of object, that has the specified locator.
|
E |
getObjectByLocatorRegexp(java.lang.String locatorRegexp)
Returns the first instance of object with a locator that matches the
given regular expression.
|
E |
getObjectByPosition(int position)
Returns an instance of object on the position of
position from the current object. |
E |
getRandomObject()
Returns a randomly chosen object from the objects remaining in this iterator.
|
AbstractObjectList<E> |
getRandomObjects(int count,
boolean unique)
Returns a list containing randomly chosen objects from the objects remaining in this iterator.
|
AbstractObjectIterator<E> |
provideObjects()
Returns an iterator over the
provided objects. |
static <T extends LocalAbstractObject> |
singleton(T object)
Returns an iterator on a single object.
|
AbstractObjectIterator<E> |
skip(int cnt)
Skip the passed number of objects in the iterator.
|
public abstract E getCurrentObject() throws java.util.NoSuchElementException
Iterator.next()
.Iterator.next()
java.util.NoSuchElementException
- if Iterator.next()
has not been called yetpublic E getObjectByPosition(int position) throws java.util.NoSuchElementException
position
from the current object.
Specifically, next() is called position
times and then the current object is returned.
That is, position 0 means current object, 1 means the next object, etc.position
- the position from the current objectposition
from the current objectjava.util.NoSuchElementException
- if such an object cannot be found.public E getObjectByData(LocalAbstractObject object) throws java.util.NoSuchElementException
object
- the object to match the data againstjava.util.NoSuchElementException
- if such an object cannot be found.public final E getObjectByLocator(java.lang.String locatorURI) throws java.util.NoSuchElementException
locatorURI
- the locator of the object that we are searching forjava.util.NoSuchElementException
- if there is no object with the specified locatorpublic final E getObjectByLocator(java.lang.String locatorURI, boolean prefix) throws java.util.NoSuchElementException
locatorURI
- the locator of the object that we are searching forprefix
- flag whether the locatorURI
is treated as prefixjava.util.NoSuchElementException
- if there is no object with the specified locatorpublic final E getObjectByLocatorRegexp(java.lang.String locatorRegexp) throws java.util.NoSuchElementException
locatorRegexp
- the regular expression for matching the locators of objects that we are searching forjava.util.NoSuchElementException
- if there is no object with the specified locatorpublic E getObjectByAnyLocator(java.util.Set<java.lang.String> locatorURIs, boolean removeFound) throws java.util.NoSuchElementException
locatorURIs
- the set of locators that we are searching forremoveFound
- if true the locators which were found are removed from the locatorURIs set, otherwise, locatorURIs is not touchedjava.util.NoSuchElementException
- if there is no object with any of the specified locatorspublic E getRandomObject() throws java.util.NoSuchElementException
java.util.NoSuchElementException
- if this iterator has no objects leftpublic AbstractObjectList<E> getRandomObjects(int count, boolean unique)
count
- the number of objects to returnunique
- flag if the returned list contains each object only onceAbstractObjectList.randomList(int, boolean, java.util.List, java.util.Iterator)
public AbstractObjectIterator<E> provideObjects()
provided
objects.
This implementation of the ObjectProvider
interface returns itself as an iterator.provideObjects
in interface ObjectProvider<E extends AbstractObject>
provided
objectspublic GenericMatchingObjectList<E> getMatchingObjects(ObjectMatcher<? super E> matcher) throws java.util.NoSuchElementException, OccupationLowException, FilterRejectException
ObjectMatcher.match(T)
method in the matcher returns non-zero when applied on them.matcher
- The matching condition implemented in the ObjectMatcher interface.java.util.NoSuchElementException
- if deletion reported it or if this method is called after next was called.FilterRejectException
- if deletion of a matching object was rejected by a filter (in case this is an iterator of LocalFilteredBucket).OccupationLowException
- if deletion of matching objects caused too low an occupation of bucket than allowed.public GenericMatchingObjectList<E> getMatchingObjects(ObjectMatcher<? super E> matcher, boolean removeMatching) throws java.util.NoSuchElementException, OccupationLowException, FilterRejectException
ObjectMatcher.match(T)
method in the matcher returns non-zero when applied on them)
and deletes matching objects from the bucket when required.matcher
- The matching condition implemented in the ObjectMatcher interface.removeMatching
- Matching objects are also deleted from the bucket.java.util.NoSuchElementException
- if deletion reported it or if this method is called after next was called.FilterRejectException
- if deletion of a matching object was rejected by a filter (in case this is an iterator of LocalFilteredBucket).OccupationLowException
- if deletion of matching objects caused too low an occupation of bucket than allowed.public GenericMatchingObjectList<E> getMatchingObjects(ObjectMatcher<? super E> matcher, boolean removeMatching, int whoStays) throws java.util.NoSuchElementException, OccupationLowException, FilterRejectException
ObjectMatcher.match(T)
returns value different from whoStays.matcher
- The matching condition implemented in the ObjectMatcher interface.removeMatching
- Matching objects are also deleted from the bucket.whoStays
- Identification of a partition whose objects stay in this bucket.ObjectMatcher.match(T)
is not equal
to whoStays
when applied on them)java.util.NoSuchElementException
- if deletion reported it or if this method is called after next was called.FilterRejectException
- if deletion of a matching object was rejected by a filter (in case this is an iterator of LocalFilteredBucket).OccupationLowException
- if deletion of matching objects caused too low an occupation of bucket than allowed.public GenericMatchingObjectList<E> getMatchingObjects(ObjectMatcher<? super E> matcher, boolean removeMatching, int[] whoStays) throws java.util.NoSuchElementException, OccupationLowException, FilterRejectException
matcher
- The matching condition implemented in the ObjectMatcher interface.removeMatching
- Matching objects are also deleted from the bucket.whoStays
- An array of identifications of partitions whose objects stay in this bucket.java.util.NoSuchElementException
- if deletion reported it or if this method is called after next was called.FilterRejectException
- if deletion of a matching object was rejected by a filter (in case this is an iterator of LocalFilteredBucket).OccupationLowException
- if deletion of matching objects caused too low an occupation of bucket than allowed.public static <T extends LocalAbstractObject> AbstractObjectIterator<T> singleton(T object)
T
- the class of the object returned by the iteratorobject
- the object returned by the iteratorpublic static <T extends LocalAbstractObject> AbstractObjectIterator<T> emptyIterator()
T
- the class of the object returned by the iteratorobject
- the object returned by the iteratorpublic static <T extends LocalAbstractObject> AbstractObjectIterator<T> getIterator(java.util.Iterator<T> iterator)
T
- the class of the object returned by the iteratoriterator
- the standard iteratorpublic AbstractObjectIterator<E> skip(int cnt) throws java.util.NoSuchElementException
cnt
- number of objects to skipthis
java.util.NoSuchElementException
- if there are fewer objects than cnt
remaining.