Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- sealed class GraphItem {
- data class Node(val x: Int, val y: Int) : GraphItem(), Comparable<Node> {
- companion object Factory {
- fun fromGraphObject(node: GraphObject): Node {
- return Node(
- node.attribute.getValueAt("tileX").toString().toInt(),
- node.attribute.getValueAt("tileY").toString().toInt()
- )
- }
- }
- override fun compareTo(other: Node) = compareValuesBy(this, other, { it.x }, { it.y })
- }
- data class Edge(val type: String, val source: Node, val target: Node) : GraphItem(), Comparable<Edge> {
- companion object Factory {
- fun fromGraphObject(node: GraphObject): Edge {
- val edge = node as Arc
- return Edge(node.type.name, Node.fromGraphObject(edge.source), Node.fromGraphObject(edge.target))
- }
- }
- override fun compareTo(other: Edge) = compareValuesBy(this, other, { it.type }, { it.source }, { it.target })
- }
- }
- fun Match.fingerprint(): String {
- var edges = mutableListOf<GraphItem.Edge>()
- var nodes = mutableListOf<GraphItem.Node>()
- codomain.asSequence().forEach {
- when {
- it.isArc -> edges.add(GraphItem.Edge.fromGraphObject(it))
- it.isNode -> nodes.add(GraphItem.Node.fromGraphObject(it))
- }
- }
- nodes = nodes.sorted() as MutableList<GraphItem.Node>
- edges = edges.sorted() as MutableList<GraphItem.Edge>
- var fingerprint = mutableListOf<GraphItem>()
- fingerprint.addAll(nodes)
- fingerprint.addAll(edges)
- return "$name ${fingerprint.joinToString()}}"
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement