
package pl.edu.pw.mini.msi.knowledgerepresentation.engine;

import java.util.AbstractMap;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import pl.edu.pw.mini.msi.knowledgerepresentation.data.*;

/**
 * Created by rwyka on 5/10/15.
 */
public class EngineH {
    public List<AbstractMap<String, Fluent>> H;
    public List<AbstractMap<String, Fluent>> Hspecial;

    public EngineH(int t) {
        H = new ArrayList<AbstractMap<String, Fluent>>();
        Hspecial = new ArrayList<AbstractMap<String, Fluent>>();
        for(int i = 0; i < t; i++){
            H.add(new HashMap<String, Fluent>());
        }
    }

    public String toString(){
        String S = "";
        for(int i = 0; i < H.size(); i++){
            for(Fluent fl: H.get(i).values()){
                S += i + ". " + fl.toString() + "\n";
            }
        }
        return S;
    }

    public boolean Set(Fluent f, int t){
        boolean is = true;
        AbstractMap<String, Fluent> Map = H.get(t);
        boolean r = Map.containsKey(f.getName());
        Map.put(f.getName(), f);
        return r;
    }

    public void SetAlways(List<Fluent> fl){
        HashMap hm = new HashMap();
        for(Fluent f : fl){
            hm.put(f.getName(), f);
        }
        Hspecial.add(hm);
    }

    private int hist(Fluent f, int t){
        AbstractMap<String, Fluent> Map = H.get(t);
        if(Map.containsKey(f.getName())){
            return Map.get(f.getName()).value() == f.value() ? 1 : 0;
        }
        return -1;
    }

    public  boolean Is(Fluent f, int t){
        for(int time = t; time >=0; time--){
            int r = hist(f, time);
            if(r == 0)
                return false;
            else if (r == 1)
                return true;
        }
        return false;
    }

    public  boolean IsTrue(List<Fluent> fl, int t) {
        if (Hspecial.size() != 0) {
            HashMap<String, Fluent> hs = new HashMap<String, Fluent>();
            for (Fluent f : fl)
                hs.put(f.getName(), f);

            for (int i = 0; i < Hspecial.size(); i++) {
                if (Hspecial.get(i).equals(hs))
                    return true;
            }
        }

        for(Fluent f : fl){
            if(!Is(f, t))
                return false;
        }
        return true;
    }

    public EngineH clone(){
        EngineH n = new EngineH(H.size());
        for(int i = 0; i < H.size(); ++i){
            for(Fluent f : H.get(i).values()){
                n.H.get(i).put(f.getName(), f);
            }
        }

        for(int i = 0; i < Hspecial.size(); ++i){
            HashMap<String, Fluent> hmap = new HashMap<String, Fluent>();
            for(Fluent f : Hspecial.get(i).values()){
                hmap.put(f.getName(), f);
            }
            n.Hspecial.add(hmap);
        }

        return n;
    }


}

@@ -71,24 +71,16 @@
 va.util.
-Abstract
 Map;%0Aimp
@@ -149,24 +149,47 @@
 .util.List;%0A
+import java.util.Map;%0A%0A
 import pl.ed
@@ -310,32 +310,24 @@
 public List%3C
-Abstract
 Map%3CString, 
@@ -350,32 +350,24 @@
 public List%3C
-Abstract
 Map%3CString, 
@@ -444,35 +444,8 @@
 ist%3C
-AbstractMap%3CString, Fluent%3E
 %3E();
@@ -482,35 +482,8 @@
 ist%3C
-AbstractMap%3CString, Fluent%3E
 %3E();
@@ -549,30 +549,16 @@
 HashMap%3C
-String, Fluent
 %3E());%0A  
@@ -871,43 +871,8 @@
     
-boolean is = true;%0A        Abstract
 Map%3C
@@ -1063,23 +1063,35 @@
         
-HashMap
+Map%3CString, Fluent%3E
  hm = ne
@@ -1099,16 +1099,18 @@
  HashMap
+%3C%3E
 ();%0A    
@@ -1263,16 +1263,8 @@
     
-Abstract
 Map%3C
@@ -1969,43 +1969,48 @@
 or (
-int i = 0; i %3C Hspecial.size(); i++
+Map%3CString, Fluent%3E aHspecial : Hspecial
 ) %7B%0A
@@ -2021,32 +2021,33 @@
             if (
+a
 Hspecial.get(i).
@@ -2039,23 +2039,16 @@
 special.
-get(i).
 equals(h

Fix linter warnings