]> gerrit.simantics Code Review - simantics/platform.git/blobdiff - bundles/org.simantics.db.layer0/src/org/simantics/db/layer0/scl/CompileValueRequest.java
Add hashCode and equals to AbstractExpressionCompilationRequest
[simantics/platform.git] / bundles / org.simantics.db.layer0 / src / org / simantics / db / layer0 / scl / CompileValueRequest.java
index 1eb01aa393b688d0809f95dbef56d3f2d848fda2..e0ed90a8977472ed5061c784e42f1c3e7519282b 100644 (file)
@@ -34,19 +34,15 @@ public class CompileValueRequest extends AbstractExpressionCompilationRequest<Co
     }
 
     protected final Resource relation;
-    protected final Resource component;
     protected final Resource literal;
 
-    public CompileValueRequest(Resource component, Resource literal, Resource relation) {
+    public CompileValueRequest(Resource literal, Resource relation) {
         this.relation = relation;
-        this.component = component;
         this.literal = literal;
     }
 
     public CompileValueRequest(ReadGraph graph, Variable context) throws DatabaseException {
-        this(context.getParent(graph).getRepresents(graph),
-                context.getRepresents(graph),
-                context.getPredicateResource(graph));
+        this(context.getRepresents(graph), context.getPredicateResource(graph));
     }
 
     public static Object compileAndEvaluate(ReadGraph graph, Variable context) throws DatabaseException {
@@ -66,12 +62,11 @@ public class CompileValueRequest extends AbstractExpressionCompilationRequest<Co
         }
     }
 
-    public static Function1<Object,Object> compile(ReadGraph graph, Resource component, Resource literal, Resource predicate) throws DatabaseException {
+    public static Function1<Object,Object> compile(ReadGraph graph, Resource literal, Resource predicate) throws DatabaseException {
         SCLContext sclContext = SCLContext.getCurrent();
         Object oldGraph = sclContext.get("graph");
         try {
-            Function1<Object,Object> exp = graph.syncRequest(new CompileValueRequest(component, literal, predicate),
-                    TransientCacheListener.instance());
+            Function1<Object,Object> exp = graph.syncRequest(new CompileValueRequest(literal, predicate), TransientCacheListener.instance());
             sclContext.put("graph", graph);
             return exp;
         } catch (DatabaseException e) {
@@ -134,4 +129,36 @@ public class CompileValueRequest extends AbstractExpressionCompilationRequest<Co
             return null;
     }
 
+    @Override
+    public int hashCode() {
+        final int prime = 31;
+        int result = 1;
+        result = prime * result + ((literal == null) ? 0 : literal.hashCode());
+        result = prime * result + ((relation == null) ? 0 : relation.hashCode());
+        return result;
+    }
+
+    @Override
+    public boolean equals(Object obj) {
+        if (this == obj)
+            return true;
+        if (obj == null)
+            return false;
+        if (getClass() != obj.getClass())
+            return false;
+        CompileValueRequest other = (CompileValueRequest) obj;
+        if (literal == null) {
+            if (other.literal != null)
+                return false;
+        } else if (!literal.equals(other.literal))
+            return false;
+        if (relation == null) {
+            if (other.relation != null)
+                return false;
+        } else if (!relation.equals(other.relation))
+            return false;
+        return true;
+    }
+
+
 }