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
e56e5073
Commit
e56e5073
authored
Mar 01, 2016
by
Roland Kluge
Browse files
Solve bug for node attribute-based constraints in pattern matcher
parent
c0ffc4b4
Changes
1
Hide whitespace changes
Inline
Side-by-side
src/de/tudarmstadt/maki/simonstrator/api/component/topology/VariableAssignment.java
View file @
e56e5073
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
.
linkBinding
.
get
(
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
.
linkBinding
.
get
(
edgeVariable
);
}
public
EdgeID
getLinkVariableBinding
(
final
String
linkVariableId
)
{
return
this
.
linkBinding
.
get
(
EdgeID
.
get
(
linkVariableId
));
}
public
UniqueID
getVariableBinding
(
UniqueID
variable
)
{
if
(
variable
instanceof
EdgeID
)
return
getLinkVariableBinding
((
EdgeID
)
variable
);
else
if
(
variable
instanceof
INodeID
)
return
getNodeVariableBinding
((
INodeID
)
variable
);
return
null
;
}
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
()
+
"]"
;
}
}
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