package edu.sc.seis.sod.subsetter.origin;
import java.util.Iterator;
import org.w3c.dom.Element;
import edu.iris.Fissures.event.EventAttrImpl;
import edu.iris.Fissures.event.OriginImpl;
import edu.sc.seis.fissuresUtil.cache.CacheEvent;
import edu.sc.seis.sod.ConfigurationException;
import edu.sc.seis.sod.status.ShortCircuit;
import edu.sc.seis.sod.status.StringTree;
import edu.sc.seis.sod.status.StringTreeBranch;
/**
* This subsetter is used to specify a sequence of OriginANDSubsetters. This subsetter is accepted only when all the
* subsetters forming the sequence are accepted.
*<pre>
* <originAND>
* <description>take any global 6.5 or better EQ</description>
* <magnitudeRange>
* <magType>mb</magType>
* <min>4.5</min>
* </magnitudeRange>
* <eventArea>
* <globalArea/>
* </eventArea>
* </originAND>
*
* (or)
*
* <originAND>
* <description>take any 4.5 or better EQ in the southeast</description>
* <eventArea>
* <boxArea>
* <latitudeRange>
* <min>28</min>
* <max>38</max>
* </latitudeRange>
* <longitudeRange>
* <min>-85</min>
* <max>-75</max>
* </longitudeRange>
* </boxArea>
* </eventArea>
* <magnitudeRange>
* <magType>mb</magType>
* <min>4.5</min>
* </magnitudeRange>
* </originAND>
*
* (or)
*
* <originAND>
* <originAND>
* <catalog><value>BIGQUAKE</value></catalog>
* <catalog><value>BIGQUAKE</value></catalog>
* <catalog><value>BIGQUAKE</value></catalog>
* </originAND>
* <originArrayAND>
* <originNOT>
* <magnitudeRange>
* <magType>mb</magType>
* <min>7</min>
* <max>10</max>
* </magnitudeRange>
* </originNOT>
* </originArrayAND>
*
* </originAND>
*</pre>
*/
public final class OriginAND extends EventLogicalSubsetter
implements OriginSubsetter {
public OriginAND (Element config) throws ConfigurationException {
super(config);
}
public StringTree accept(CacheEvent event, EventAttrImpl eventAttr, OriginImpl e) throws Exception{
Iterator it = filterList.iterator();
StringTree[] result = new StringTree[filterList.size()];
int i=0;
while (it.hasNext()) {
OriginSubsetter filter = (OriginSubsetter)it.next();
result[i] = filter.accept(event, eventAttr, e);
if ( ! result[i].isSuccess()) {
for(int j = i + 1; j < result.length; j++) {
result[j] = new ShortCircuit(filterList.get(j));
}
return new StringTreeBranch(this, false, result);
}
i++;
}
return new StringTreeBranch(this, true, result);
}
}// OriginAND