Copyright (c) 2010, Moca
All rights reserved.
The source code for Moca is licensed under the BSD license as follows:
Redistribution and use in source and binary forms, with or without modification, ...
If you think the Android project sana listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.
Java Source Code
package org.moca.procedure.branching;
/*fromwww.java2s.com*/import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import org.moca.procedure.ProcedureElement;
import org.moca.procedure.ProcedureParseException;
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;
/**
* LogicOr is a Criteria subclass that serves as a container to hold multiple
* Criteria. The key difference between LogicOr and LogicAnd is the criteriaMet()
* method. As the name implies, LogicOr's criteriaMet() method evaluates if ANY
* of the Criteria it holds are met.
*/publicclass LogicOr extends Criteria {
private List<Criteria> criteria;
public LogicOr(List<Criteria> crit) {
this.criteria = crit;
}
publicboolean criteriaMet() {
for(Criteria c : criteria) {
if (c.criteriaMet())
return true;
}
return false;
}
publicstatic LogicOr fromXML(Node node, HashMap<String, ProcedureElement> elts) throws ProcedureParseException {
if(!node.getNodeName().equals("or"))
thrownew ProcedureParseException("LogicOr got NodeName " + node.getNodeName());
NodeList children = node.getChildNodes();
List<Criteria> crits = new ArrayList<Criteria>();
for(int i=0; i<children.getLength();i++) {
Node child = children.item(i);
if(child.getNodeName().equals("Criteria") ||
child.getNodeName().equals("and") ||
child.getNodeName().equals("or") ||
child.getNodeName().equals("not")) {
crits.add(Criteria.switchOnCriteria(child, elts));
}
}
if (crits.size() == 0)
thrownew ProcedureParseException("LogicOr no arguments to <or>");
elsereturnnew LogicOr(crits);
}
}