1
2
3
4 package net.sf.bddbddb.dataflow;
5
6 import java.util.HashMap;
7 import java.util.Iterator;
8 import java.util.Map;
9 import net.sf.bddbddb.IterationList;
10 import net.sf.bddbddb.Relation;
11
12 /***
13 * RelationProblem
14 *
15 * @author John Whaley
16 * @version $Id: RelationProblem.java 328 2004-10-16 02:45:30Z joewhaley $
17 */
18 public abstract class RelationProblem extends Problem {
19 public Fact getBoundary() {
20 return new RelationFacts();
21 }
22 public static class RelationFacts implements Fact {
23 public Map
24 IterationList location;
25
26 public RelationFacts create() {
27 return new RelationFacts();
28 }
29
30 public RelationFacts() {
31 initialize();
32 }
33
34 public void initialize() {
35 relationFacts = new HashMap();
36 }
37
38
39
40
41 public Fact join(Fact fact) {
42 RelationFacts result = create();
43 result.relationFacts.putAll(this.relationFacts);
44 RelationFacts that = (RelationFacts) fact;
45 for (Iterator i = that.relationFacts.entrySet().iterator(); i.hasNext(); ) {
46 Map.Entry e = (Map.Entry) i.next();
47 Relation r = (Relation) e.getKey();
48 RelationFact f = (RelationFact) e.getValue();
49 RelationFact old = (RelationFact) result.relationFacts.put(r, f);
50 if (old != null) {
51 f = (RelationFact) f.join(old);
52 result.relationFacts.put(r, f);
53 }
54 }
55 result.location = location;
56 return result;
57 }
58
59
60
61
62 public Fact copy(IterationList loc) {
63 RelationFacts that = create();
64 that.relationFacts.putAll(this.relationFacts);
65 that.location = loc;
66 return that;
67 }
68
69 /***
70 * Returns the fact associated with a relation.
71 *
72 * @param r relation
73 * @return the fact for this relation
74 */
75 public RelationFact getFact(Relation r) {
76 return (RelationFact) relationFacts.get(r);
77 }
78
79
80
81
82 public int hashCode() {
83 return relationFacts.hashCode();
84 }
85
86 /***
87 * @param that the other collection of relation facts
88 * @return true if all relation facts are equal
89 */
90 public boolean equals(RelationFacts that) {
91 return relationFacts.equals(that.relationFacts);
92 }
93
94
95
96
97 public boolean equals(Object o) {
98 return equals((RelationFacts) o);
99 }
100
101
102
103
104 public void setLocation(IterationList loc) {
105
106 this.location = loc;
107 }
108
109
110
111
112 public IterationList getLocation() {
113 return location;
114 }
115 }
116 public static abstract class RelationFact implements Fact {
117 }
118 }