1
2
3
4 package net.sf.bddbddb.order;
5
6 import java.util.Collection;
7 import java.util.Iterator;
8 import java.util.LinkedList;
9 import net.sf.bddbddb.Attribute;
10 import net.sf.bddbddb.FindBestDomainOrder;
11 import net.sf.bddbddb.InferenceRule;
12 import net.sf.bddbddb.Variable;
13
14 /***
15 * VarToAttribTranslator
16 *
17 * @author jwhaley
18 * @version $Id: VarToAttribTranslator.java 364 2004-10-31 14:13:49Z joewhaley $
19 */
20 public class VarToAttribTranslator implements OrderTranslator {
21
22 InferenceRule ir;
23
24 public VarToAttribTranslator(InferenceRule ir) {
25 this.ir = ir;
26 }
27
28 public Order translate(Order o) {
29 if (FindBestDomainOrder.TRACE > 3) System.out.print("Translating "+o);
30 LinkedList result = new LinkedList();
31 for (Iterator i = o.iterator(); i.hasNext(); ) {
32 Object a = i.next();
33 if (a instanceof Collection) {
34 Collection result2 = new LinkedList();
35 for (Iterator j = ((Collection) a).iterator(); j.hasNext(); ) {
36 Variable a2 = (Variable) j.next();
37 Attribute b2 = ir.getAttribute(a2);
38 if (b2 != null) result2.add(b2);
39 }
40 if (result2.size() > 1) {
41 result.add(result2);
42 } else if (!result2.isEmpty()) {
43 result.add(result2.iterator().next());
44 }
45 } else {
46 Attribute b = ir.getAttribute((Variable) a);
47 if (b != null) result.add(b);
48 }
49 }
50 if (FindBestDomainOrder.TRACE > 3) System.out.println(" -> "+result);
51 return new Order(result);
52 }
53
54 }