//The "heart" of the order matcher....ensures rules are applied correctly and the order //book is updated properly package fauxExchange; import java.util.Vector; class RuleManager { //--[ Constructors ]-------- public RuleManager(){} //--[ MemberDate ]---------- private Vector rules = new Vector(); //--[MemberMethods ]--------- public void addRule(Rule r){ rules.addElement(r); } //not implemented yet...maybe useful later public void deleteRule(Rule r){ rules.removeElement(r); } /** * This method applies each rule owned by this manager * in order. Each rule is applied continually until either * the rule does not match for a trade or the order * has a size of zero (all shared have been matched) * * The next rule is applied if it exists and the size * of the order is not 0. */ public void applyRules (OrderBook ob, Order o) throws TradeClosedException { // Iterator to iterate across rules java.util.Iterator rulesIter = rules.iterator(); while (rulesIter.hasNext() && (o == null || o.getSize() != 0)){ Rule r = (Rule)rulesIter.next(); while (r.fitsCriteria(ob, o)){ // This may throw a TradeClosedException. If so, the trade // is not published and no further rules are processed. The // order book state is maintained Trade t = r.processRule (ob, o); if (t == null){ break; } else { // Must publish trade here! ob.publishTrade(t); } if (o == null || o.getSize() == 0) break; } } return; } } //end class