Commit 70c5bd28 authored by Roland Kluge's avatar Roland Kluge
Browse files

Bug fixes in VariableAssignment

parent e56e5073
...@@ -2,23 +2,28 @@ package de.tudarmstadt.maki.simonstrator.api.component.topology; ...@@ -2,23 +2,28 @@ package de.tudarmstadt.maki.simonstrator.api.component.topology;
import java.util.HashMap; import java.util.HashMap;
import java.util.Map; import java.util.Map;
import java.util.Map.Entry;
import java.util.Set; import java.util.Set;
import com.google.common.collect.BiMap; import com.google.common.collect.BiMap;
import com.google.common.collect.HashBiMap; import com.google.common.collect.HashBiMap;
import de.tudarmstadt.maki.simonstrator.api.common.UniqueID; import de.tudarmstadt.maki.simonstrator.api.common.UniqueID;
import de.tudarmstadt.maki.simonstrator.api.common.graph.DirectedEdge;
import de.tudarmstadt.maki.simonstrator.api.common.graph.EdgeID; import de.tudarmstadt.maki.simonstrator.api.common.graph.EdgeID;
import de.tudarmstadt.maki.simonstrator.api.common.graph.IEdge;
import de.tudarmstadt.maki.simonstrator.api.common.graph.IElement; import de.tudarmstadt.maki.simonstrator.api.common.graph.IElement;
import de.tudarmstadt.maki.simonstrator.api.common.graph.INode;
import de.tudarmstadt.maki.simonstrator.api.common.graph.INodeID; import de.tudarmstadt.maki.simonstrator.api.common.graph.INodeID;
import de.tudarmstadt.maki.simonstrator.api.common.graph.Node;
/** /**
* This class represents a binding of pattern variables to graph elements * This class represents a binding of pattern variables to graph elements
*/ */
public final class VariableAssignment { public final class VariableAssignment {
private final BiMap<INodeID, INodeID> nodeBinding; private final BiMap<INodeID, INode> nodeBinding;
private final Map<EdgeID, EdgeID> linkBinding; private final Map<EdgeID, IEdge> linkBinding;
public VariableAssignment() { public VariableAssignment() {
this.nodeBinding = HashBiMap.create(); this.nodeBinding = HashBiMap.create();
...@@ -32,6 +37,11 @@ public final class VariableAssignment { ...@@ -32,6 +37,11 @@ public final class VariableAssignment {
} }
public INodeID getNodeVariableBinding(final INodeID variable) { public INodeID getNodeVariableBinding(final INodeID variable) {
INode binding = this.nodeBinding.get(variable);
return binding != null ? binding.getId() : null;
}
public INode getBindingNodeForNodeVariable(final INodeID variable) {
return this.nodeBinding.get(variable); return this.nodeBinding.get(variable);
} }
...@@ -40,10 +50,10 @@ public final class VariableAssignment { ...@@ -40,10 +50,10 @@ public final class VariableAssignment {
} }
public INodeID getNodeVariableBinding(final String key) { public INodeID getNodeVariableBinding(final String key) {
return nodeBinding.get(INodeID.get(key)); return nodeBinding.get(INodeID.get(key)).getId();
} }
public Set<Map.Entry<INodeID, INodeID>> getNodeBindingEntrySet() { public Set<Entry<INodeID, INode>> getNodeBindingEntrySet() {
return nodeBinding.entrySet(); return nodeBinding.entrySet();
} }
...@@ -57,7 +67,15 @@ public final class VariableAssignment { ...@@ -57,7 +67,15 @@ public final class VariableAssignment {
} }
} }
/**
* @deprecated Use {@link #bindNodeVariable(INodeID, INode)} instead
*/
@Deprecated
public void bindNodeVariable(final INodeID nodeVariable, final INodeID value) { public void bindNodeVariable(final INodeID nodeVariable, final INodeID value) {
nodeBinding.put(nodeVariable, new Node(value));
}
public void bindNodeVariable(final INodeID nodeVariable, final INode value) {
nodeBinding.put(nodeVariable, value); nodeBinding.put(nodeVariable, value);
} }
...@@ -77,16 +95,32 @@ public final class VariableAssignment { ...@@ -77,16 +95,32 @@ public final class VariableAssignment {
* Returns whether there exists some variable that is bound by the given * Returns whether there exists some variable that is bound by the given
* nodeId. * nodeId.
*/ */
@Deprecated
public boolean isBindingForSomeVariable(final INodeID bindingValue) { public boolean isBindingForSomeVariable(final INodeID bindingValue) {
return nodeBinding.containsValue(bindingValue); return nodeBinding.inverse().containsKey(new Node(bindingValue));
} }
public boolean isBindingForSomeVariable(final INode node) {
return nodeBinding.inverse().containsKey(node);
}
@Deprecated // Use #getBindingLink
public EdgeID getLinkVariableBinding(final EdgeID edgeVariable) { public EdgeID getLinkVariableBinding(final EdgeID edgeVariable) {
return this.linkBinding.get(edgeVariable); for (final EdgeID linkVariable : this.linkBinding.keySet())
{
if (linkVariable.equals(edgeVariable))
return this.linkBinding.get(linkVariable).getId();
}
return null;
}
public EdgeID getBindingLink(final EdgeID linkVariable) {
return this.linkBinding.get(linkVariable).getId();
} }
@Deprecated
public EdgeID getLinkVariableBinding(final String linkVariableId) { public EdgeID getLinkVariableBinding(final String linkVariableId) {
return this.linkBinding.get(EdgeID.get(linkVariableId)); return this.linkBinding.get(EdgeID.get(linkVariableId)).getId();
} }
public UniqueID getVariableBinding(UniqueID variable) { public UniqueID getVariableBinding(UniqueID variable) {
...@@ -97,8 +131,8 @@ public final class VariableAssignment { ...@@ -97,8 +131,8 @@ public final class VariableAssignment {
return null; return null;
} }
public void bindLinkVariable(final EdgeID linkVariable, final EdgeID edge) { public void bindLinkVariable(final EdgeID linkVariable, final EdgeID edgeId) {
this.linkBinding.put(linkVariable, edge); this.linkBinding.put(linkVariable, new DirectedEdge(null, null, edgeId));
} }
public void removeAllLinkBindings() { public void removeAllLinkBindings() {
...@@ -145,7 +179,7 @@ public final class VariableAssignment { ...@@ -145,7 +179,7 @@ public final class VariableAssignment {
@Override @Override
public String toString() { public String toString() {
return "VariableAssignment [nodeBinding:" + this.nodeBinding + ", linkBinding: " + this.linkBinding.toString() return "VA [node vars:" + this.nodeBinding + ", link vars: " + this.linkBinding.toString()
+ "]"; + "]";
} }
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment