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;
/*www.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;
/**
* LogicAnd is a Criteria subclass that serves as a container to hold multiple
* Criteria. The key difference between LogicAnd and LogicOr is the criteriaMet()
* method. As the name implies, LogicAnd's criteriaMet() method evaluates if ALL
* of the Criteria it holds are met.
*/publicclass LogicAnd extends Criteria {
private List<Criteria> criteria;
public LogicAnd(List<Criteria> crit) {
this.criteria = crit;
}
publicboolean criteriaMet() {
for(Criteria c : criteria) {
if (!c.criteriaMet())
return false;
}
return true;
}
publicstatic LogicAnd fromXML(Node node, HashMap<String, ProcedureElement> elts) throws ProcedureParseException {
if(!node.getNodeName().equals("and"))
thrownew ProcedureParseException("LogicAnd 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("LogicAnd no arguments to <or>");
elsereturnnew LogicAnd(crits);
}
}