From 46facfca7c3787365e428514493aca06a2127c21 Mon Sep 17 00:00:00 2001 From: Maxime Puys Date: Fri, 14 Jul 2023 18:37:00 +0200 Subject: [PATCH] Added: __eq__ method for Mindmap and Node classes. Mindmap are compared by recursively comparing their nodes. Nodes are compared by comparing some of their attributes (plaintext, hyperlink, imagepath, details) and then recursively comparing their children. --- src/freeplane.py | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) diff --git a/src/freeplane.py b/src/freeplane.py index 1ca8eb2..35d903b 100644 --- a/src/freeplane.py +++ b/src/freeplane.py @@ -525,6 +525,15 @@ def __init__(self, _node3.attrib["BUILTIN"] = "yes" _node2.append(_node3) + + def __eq__(self, __value) -> bool: + """ + compares two mindmaps by recursively comparing their nodes + + :returns: bool + """ + return self.rootnode == __value.rootnode + # MAP @classmethod @@ -1138,6 +1147,33 @@ def __str__(self): return self.plaintext + def __eq__(self, __value) -> bool: + """ + compares two nodes by comparing some of their attributes and + recursively comparing their children + + supported attributes for comparison: plaintext, hyperlink, imagepath, details + + :returns: bool + """ + if self.plaintext != __value.plaintext: + return False + + if self.hyperlink != __value.hyperlink: + return False + + if self.imagepath != __value.imagepath: + return False + + if self.details != __value.details: + return False + + if len(self.children) != len(__value.children): + return False + + return all([self.children[i] == __value.children[i] for i in range(len(self.children))]) + + @property def is_detached_head(self): """