Methods Summary |
---|
protected boolean | decide(java.lang.Object element)
if (decider != null) {
try {
boolean okToAdd = decider.decide(element);
return okToAdd;
}
catch(Exception e) {
_log.warn("decider ["+decider+"] encountered an error while decide adding element ["+element+"], element will be ignored, it will not appeared in subseted iterator", e);
return false;
}
}
return true;
|
public java.lang.String | execute()
if (source == null) {
LogFactory.getLog(SubsetIteratorFilter.class.getName()).warn("Source is null returning empty set.");
return ERROR;
}
// Make source transformations
source = getIterator(source);
// Calculate iterator filter
if (source instanceof Iterator) {
iterator = (Iterator) source;
// Read away <start> items
for (int i = 0; (i < start) && iterator.hasNext(); i++) {
iterator.next();
}
// now let Decider decide if element should be added (if a decider exist)
if (decider != null) {
List list = new ArrayList();
while(iterator.hasNext()) {
Object currentElement = iterator.next();
if (decide(currentElement)) {
list.add(currentElement);
}
}
iterator = list.iterator();
}
} else if (source.getClass().isArray()) {
ArrayList list = new ArrayList(((Object[]) source).length);
Object[] objects = (Object[]) source;
int len = objects.length;
if (count >= 0) {
len = start + count;
if (len > objects.length) {
len = objects.length;
}
}
for (int j = start; j < len; j++) {
if (decide(objects[j])) {
list.add(objects[j]);
}
}
count = -1; // Don't have to check this in the iterator code
iterator = list.iterator();
}
if (iterator == null) {
throw new IllegalArgumentException("Source is not an iterator:" + source);
}
return SUCCESS;
|
public boolean | hasNext()
return (iterator == null) ? false : (iterator.hasNext() && ((count < 0) || (currentCount < count)));
|
public java.lang.Object | next()
currentCount++;
return iterator.next();
|
public void | remove()
iterator.remove();
|
public void | setCount(int aCount)
this.count = aCount;
|
public void | setDecider(org.apache.struts2.util.SubsetIteratorFilter$Decider aDecider)
this.decider = aDecider;
|
public void | setSource(java.lang.Object anIterator)
source = anIterator;
|
public void | setStart(int aStart)
this.start = aStart;
|