Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
Simonstrator
API
Commits
70c5bd28
Commit
70c5bd28
authored
Mar 01, 2016
by
Roland Kluge
Browse files
Bug fixes in VariableAssignment
parent
e56e5073
Changes
1
Hide whitespace changes
Inline
Side-by-side
src/de/tudarmstadt/maki/simonstrator/api/component/topology/VariableAssignment.java
View file @
70c5bd28
...
...
@@ -2,23 +2,28 @@ package de.tudarmstadt.maki.simonstrator.api.component.topology;
import
java.util.HashMap
;
import
java.util.Map
;
import
java.util.Map.Entry
;
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.DirectedEdge
;
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.INode
;
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
*/
public
final
class
VariableAssignment
{
private
final
BiMap
<
INodeID
,
INode
ID
>
nodeBinding
;
private
final
Map
<
EdgeID
,
Edge
ID
>
linkBinding
;
private
final
BiMap
<
INodeID
,
INode
>
nodeBinding
;
private
final
Map
<
EdgeID
,
I
Edge
>
linkBinding
;
public
VariableAssignment
()
{
this
.
nodeBinding
=
HashBiMap
.
create
();
...
...
@@ -32,6 +37,11 @@ public final class VariableAssignment {
}
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
);
}
...
...
@@ -40,10 +50,10 @@ public final class VariableAssignment {
}
public
INodeID
getNodeVariableBinding
(
final
String
key
)
{
return
nodeBinding
.
get
(
INodeID
.
get
(
key
));
return
nodeBinding
.
get
(
INodeID
.
get
(
key
))
.
getId
()
;
}
public
Set
<
Map
.
Entry
<
INodeID
,
INode
ID
>>
getNodeBindingEntrySet
()
{
public
Set
<
Entry
<
INodeID
,
INode
>>
getNodeBindingEntrySet
()
{
return
nodeBinding
.
entrySet
();
}
...
...
@@ -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
)
{
nodeBinding
.
put
(
nodeVariable
,
new
Node
(
value
));
}
public
void
bindNodeVariable
(
final
INodeID
nodeVariable
,
final
INode
value
)
{
nodeBinding
.
put
(
nodeVariable
,
value
);
}
...
...
@@ -77,16 +95,32 @@ public final class VariableAssignment {
* Returns whether there exists some variable that is bound by the given
* nodeId.
*/
@Deprecated
public
boolean
isBindingForSomeVariable
(
final
INodeID
bindingValue
)
{
return
nodeBinding
.
containsValu
e
(
bindingValue
);
return
nodeBinding
.
inverse
().
containsKey
(
new
Nod
e
(
bindingValue
)
)
;
}
public
boolean
isBindingForSomeVariable
(
final
INode
node
)
{
return
nodeBinding
.
inverse
().
containsKey
(
node
);
}
@Deprecated
// Use #getBindingLink
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
)
{
return
this
.
linkBinding
.
get
(
EdgeID
.
get
(
linkVariableId
));
return
this
.
linkBinding
.
get
(
EdgeID
.
get
(
linkVariableId
))
.
getId
()
;
}
public
UniqueID
getVariableBinding
(
UniqueID
variable
)
{
...
...
@@ -97,8 +131,8 @@ public final class VariableAssignment {
return
null
;
}
public
void
bindLinkVariable
(
final
EdgeID
linkVariable
,
final
EdgeID
edge
)
{
this
.
linkBinding
.
put
(
linkVariable
,
edge
);
public
void
bindLinkVariable
(
final
EdgeID
linkVariable
,
final
EdgeID
edge
Id
)
{
this
.
linkBinding
.
put
(
linkVariable
,
new
DirectedEdge
(
null
,
null
,
edge
Id
)
);
}
public
void
removeAllLinkBindings
()
{
...
...
@@ -145,7 +179,7 @@ public final class VariableAssignment {
@Override
public
String
toString
()
{
return
"V
ariableAssignment [nodeBinding
:"
+
this
.
nodeBinding
+
", link
Binding
: "
+
this
.
linkBinding
.
toString
()
return
"V
A [node vars
:"
+
this
.
nodeBinding
+
", link
vars
: "
+
this
.
linkBinding
.
toString
()
+
"]"
;
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment