a bug fix...
[IRC.git] / Robust / src / Util / Lattice.java
index 16c8936940414b957c8a51d44ccd690e5e5f6e1a..0418d237b3d7645a3fbf0582fe4d18350cb58098 100644 (file)
@@ -40,6 +40,17 @@ public class Lattice<T> {
     return table;
   }
 
+  public void setTable(Map<T, Set<T>> in) {
+    Set<T> keySet = in.keySet();
+    for (Iterator iterator = keySet.iterator(); iterator.hasNext();) {
+      T key = (T) iterator.next();
+      Set<T> setIn = in.get(key);
+      Set<T> newSet = new HashSet<T>();
+      newSet.addAll(setIn);
+      table.put(key, newSet);
+    }
+  }
+
   public boolean put(T key) {
     if (table.containsKey(key)) {
       return false;
@@ -55,10 +66,15 @@ public class Lattice<T> {
   }
 
   public boolean put(T key, T value) {
+
+    if (isComparable(key, value) && isGreaterThan(key, value)) {
+      // this relation already exists
+      return false;
+    }
+
     Set<T> s;
 
     Set<T> topNeighbor = table.get(top);
-
     if (table.containsKey(key)) {
       s = table.get(key);
     } else {
@@ -79,7 +95,9 @@ public class Lattice<T> {
       }
 
       // if value is already connected with top, it is no longer to be
-      topNeighbor.remove(value);
+      if (!key.equals(top)) {
+        topNeighbor.remove(value);
+      }
 
       // if key is already connected with bottom,, it is no longer to be
       if (!value.equals(getBottomItem())) {