Commit 4418a90d authored by Alexander Frömmgen's avatar Alexander Frömmgen
Browse files

Tossa reverse VariableAssignment

parent badf8c71
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<modelVersion>4.0.0</modelVersion>
<groupId>maki</groupId>
<artifactId>simonstrator-api</artifactId>
<version>2.4</version>
<name>Simonstrator-API</name>
<build>
<sourceDirectory>src</sourceDirectory>
<resources>
<resource>
<directory>src</directory>
<excludes>
<exclude>**/*.java</exclude>
</excludes>
</resource>
</resources>
<plugins>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.1</version>
<configuration>
<source>1.7</source>
<target>1.7</target>
</configuration>
</plugin>
</plugins>
</build>
<repositories>
<!-- uk maven central, since the local central server is slow as hell -->
<repository>
<id>uk.maven.org</id>
<url>http://uk.maven.org/maven2</url>
</repository>
<!-- simonstrator-repository -->
<repository>
<id>simonstrator</id>
<url>https://dev.kom.e-technik.tu-darmstadt.de/mvn/</url>
</repository>
</repositories>
<dependencies>
<dependency>
<groupId>com.esotericsoftware</groupId>
<artifactId>kryonet</artifactId>
<version>2.22.0-RC1</version>
</dependency>
</dependencies>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<modelVersion>4.0.0</modelVersion>
<groupId>maki</groupId>
<artifactId>simonstrator-api</artifactId>
<version>2.4</version>
<name>Simonstrator-API</name>
<build>
<sourceDirectory>src</sourceDirectory>
<resources>
<resource>
<directory>src</directory>
<excludes>
<exclude>**/*.java</exclude>
</excludes>
</resource>
</resources>
<plugins>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.1</version>
<configuration>
<source>1.7</source>
<target>1.7</target>
</configuration>
</plugin>
</plugins>
</build>
<repositories>
<!-- uk maven central, since the local central server is slow as hell -->
<repository>
<id>uk.maven.org</id>
<url>http://uk.maven.org/maven2</url>
</repository>
<!-- simonstrator-repository -->
<repository>
<id>simonstrator</id>
<url>https://dev.kom.e-technik.tu-darmstadt.de/mvn/</url>
</repository>
</repositories>
<dependencies>
<dependency>
<groupId>com.esotericsoftware</groupId>
<artifactId>kryonet</artifactId>
<version>2.22.0-RC1</version>
</dependency>
<dependency>
<groupId>com.google.guava</groupId>
<artifactId>guava</artifactId>
<version>18.0</version>
</dependency>
</dependencies>
</project>
\ No newline at end of file
package de.tudarmstadt.maki.simonstrator.api.component.topology;
import java.util.HashMap;
import java.util.Map;
import de.tudarmstadt.maki.simonstrator.api.common.UniqueID;
import de.tudarmstadt.maki.simonstrator.api.common.graph.EdgeID;
import de.tudarmstadt.maki.simonstrator.api.common.graph.IElement;
import de.tudarmstadt.maki.simonstrator.api.common.graph.INodeID;
/**
* This class represents a binding of pattern variables to graph elements
*/
public final class VariableAssignment {
private final Map<INodeID, INodeID> nodeBinding;
private final Map<EdgeID, EdgeID> linkBinding;
public VariableAssignment() {
this.nodeBinding = new HashMap<>();
this.linkBinding = new HashMap<>();
}
public VariableAssignment(final VariableAssignment other) {
this();
this.nodeBinding.putAll(other.nodeBinding);
this.linkBinding.putAll(other.linkBinding);
}
public INodeID getNodeVariableBinding(final INodeID variable) {
return this.nodeBinding.get(variable);
}
public INodeID getNodeVariableBinding(final String key) {
return nodeBinding.get(INodeID.get(key));
}
public void bindVariable(UniqueID variable, IElement candidate) {
if (variable instanceof INodeID) {
this.bindNodeVariable((INodeID) variable, (INodeID) candidate);
} else if (variable instanceof EdgeID) {
this.bindLinkVariable((EdgeID) variable, (EdgeID) candidate);
} else {
throw new IllegalArgumentException("Cannot handle variable type: " + variable);
}
}
public void bindNodeVariable(final INodeID nodeVariable, final INodeID value) {
nodeBinding.put(nodeVariable, value);
}
public void unbindNodeVariable(final INodeID nodeVariable) {
nodeBinding.remove(nodeVariable);
}
public boolean isBound(final INodeID variable) {
return nodeBinding.containsKey(variable);
}
public boolean isUnbound(final INodeID variable) {
return !this.isBound(variable);
}
/**
* Returns whether there exists some variable that is bound by the given
* nodeId.
*/
public boolean isBindingForSomeVariable(final INodeID bindingValue) {
return nodeBinding.containsValue(bindingValue);
}
public EdgeID getLinkVariableBinding(final EdgeID edgeVariable) {
return this.getLinkVariableBinding(edgeVariable);
}
public EdgeID getLinkVariableBinding(final String linkVariableId) {
return this.linkBinding.get(EdgeID.get(linkVariableId));
}
public void bindLinkVariable(final EdgeID linkVariable, final EdgeID edge) {
this.linkBinding.put(linkVariable, edge);
}
public void removeAllLinkBindings() {
this.linkBinding.clear();
}
@Override
public int hashCode() {
final int prime = 31;
int result = 1;
result = prime * result + ((linkBinding == null) ? 0 : linkBinding.hashCode());
result = prime * result + ((nodeBinding == null) ? 0 : nodeBinding.hashCode());
return result;
}
@Override
public boolean equals(final Object obj) {
if (this == obj) {
return true;
}
if (obj == null) {
return false;
}
if (getClass() != obj.getClass()) {
return false;
}
final VariableAssignment other = (VariableAssignment) obj;
if (linkBinding == null) {
if (other.linkBinding != null) {
return false;
}
} else if (!linkBinding.equals(other.linkBinding)) {
return false;
}
if (nodeBinding == null) {
if (other.nodeBinding != null) {
return false;
}
} else if (!nodeBinding.equals(other.nodeBinding)) {
return false;
}
return true;
}
@Override
public String toString() {
return "VariableAssignment [nodeBinding:" + this.nodeBinding + ", linkBinding: " + this.linkBinding.toString()
+ "]";
}
}
package de.tudarmstadt.maki.simonstrator.api.component.topology;
import java.util.HashMap;
import java.util.Map;
import java.util.Set;
import com.google.common.collect.BiMap;
import com.google.common.collect.HashBiMap;
import de.tudarmstadt.maki.simonstrator.api.common.UniqueID;
import de.tudarmstadt.maki.simonstrator.api.common.graph.EdgeID;
import de.tudarmstadt.maki.simonstrator.api.common.graph.IElement;
import de.tudarmstadt.maki.simonstrator.api.common.graph.INodeID;
/**
* This class represents a binding of pattern variables to graph elements
*/
public final class VariableAssignment {
private final BiMap<INodeID, INodeID> nodeBinding;
private final Map<EdgeID, EdgeID> linkBinding;
public VariableAssignment() {
this.nodeBinding = HashBiMap.create();
this.linkBinding = new HashMap<>();
}
public VariableAssignment(final VariableAssignment other) {
this();
this.nodeBinding.putAll(other.nodeBinding);
this.linkBinding.putAll(other.linkBinding);
}
public INodeID getNodeVariableBinding(final INodeID variable) {
return this.nodeBinding.get(variable);
}
public INodeID getInverseVariableBinding(final INodeID variable) {
return this.nodeBinding.inverse().get(variable);
}
public INodeID getNodeVariableBinding(final String key) {
return nodeBinding.get(INodeID.get(key));
}
public Set<Map.Entry<INodeID, INodeID>> getNodeBindingEntrySet() {
return nodeBinding.entrySet();
}
public void bindVariable(UniqueID variable, IElement candidate) {
if (variable instanceof INodeID) {
this.bindNodeVariable((INodeID) variable, (INodeID) candidate);
} else if (variable instanceof EdgeID) {
this.bindLinkVariable((EdgeID) variable, (EdgeID) candidate);
} else {
throw new IllegalArgumentException("Cannot handle variable type: " + variable);
}
}
public void bindNodeVariable(final INodeID nodeVariable, final INodeID value) {
nodeBinding.put(nodeVariable, value);
}
public void unbindNodeVariable(final INodeID nodeVariable) {
nodeBinding.remove(nodeVariable);
}
public boolean isBound(final INodeID variable) {
return nodeBinding.containsKey(variable);
}
public boolean isUnbound(final INodeID variable) {
return !this.isBound(variable);
}
/**
* Returns whether there exists some variable that is bound by the given
* nodeId.
*/
public boolean isBindingForSomeVariable(final INodeID bindingValue) {
return nodeBinding.containsValue(bindingValue);
}
public EdgeID getLinkVariableBinding(final EdgeID edgeVariable) {
return this.getLinkVariableBinding(edgeVariable);
}
public EdgeID getLinkVariableBinding(final String linkVariableId) {
return this.linkBinding.get(EdgeID.get(linkVariableId));
}
public void bindLinkVariable(final EdgeID linkVariable, final EdgeID edge) {
this.linkBinding.put(linkVariable, edge);
}
public void removeAllLinkBindings() {
this.linkBinding.clear();
}
@Override
public int hashCode() {
final int prime = 31;
int result = 1;
result = prime * result + ((linkBinding == null) ? 0 : linkBinding.hashCode());
result = prime * result + ((nodeBinding == null) ? 0 : nodeBinding.hashCode());
return result;
}
@Override
public boolean equals(final Object obj) {
if (this == obj) {
return true;
}
if (obj == null) {
return false;
}
if (getClass() != obj.getClass()) {
return false;
}
final VariableAssignment other = (VariableAssignment) obj;
if (linkBinding == null) {
if (other.linkBinding != null) {
return false;
}
} else if (!linkBinding.equals(other.linkBinding)) {
return false;
}
if (nodeBinding == null) {
if (other.nodeBinding != null) {
return false;
}
} else if (!nodeBinding.equals(other.nodeBinding)) {
return false;
}
return true;
}
@Override
public String toString() {
return "VariableAssignment [nodeBinding:" + this.nodeBinding + ", linkBinding: " + 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