View Javadoc

1   // RelationProblem.java, created Jul 3, 2004 1:44:46 PM by joewhaley
2   // Copyright (C) 2004 John Whaley <jwhaley@alum.mit.edu>
3   // Licensed under the terms of the GNU LGPL; see COPYING for details.
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/*<Relation,RelationFact>*/ relationFacts;
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          /* (non-Javadoc)
39           * @see net.sf.bddbddb.dataflow.Problem.Fact#join(net.sf.bddbddb.dataflow.Problem.Fact)
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          /* (non-Javadoc)
60           * @see net.sf.bddbddb.dataflow.Problem.Fact#copy(net.sf.bddbddb.IterationList)
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          /* (non-Javadoc)
80           * @see java.lang.Object#hashCode()
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          /* (non-Javadoc)
95           * @see java.lang.Object#equals(java.lang.Object)
96           */
97          public boolean equals(Object o) {
98              return equals((RelationFacts) o);
99          }
100 
101         /* (non-Javadoc)
102          * @see net.sf.bddbddb.dataflow.Problem.Fact#setLocation(net.sf.bddbddb.IterationList)
103          */
104         public void setLocation(IterationList loc) {
105             //System.out.println("Setting location of "+System.identityHashCode(this)+" to "+loc);
106             this.location = loc;
107         }
108 
109         /* (non-Javadoc)
110          * @see net.sf.bddbddb.dataflow.Problem.Fact#getLocation()
111          */
112         public IterationList getLocation() {
113             return location;
114         }
115     }
116     public static abstract class RelationFact implements Fact {
117     }
118 }