Skip to content

Commit da84997

Browse files
committed
Updated JavaClass and JavaObject according to original project
1 parent e0de18e commit da84997

File tree

1 file changed

+38
-0
lines changed

1 file changed

+38
-0
lines changed

javaobj.py

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -230,6 +230,23 @@ def __repr__(self):
230230
"""
231231
return "[{0:s}:0x{1:X}]".format(self.name, self.serialVersionUID)
232232

233+
def __eq__(self, other):
234+
"""
235+
Equality test between two Java classes
236+
237+
:param other: Other JavaClass to test
238+
:return: True if both classes share the same fields and name
239+
"""
240+
if not isinstance(other, type(self)):
241+
return False
242+
243+
return (self.name == other.name and
244+
self.serialVersionUID == other.serialVersionUID and
245+
self.flags == other.flags and
246+
self.fields_names == other.fields_names and
247+
self.fields_types == other.fields_types and
248+
self.superclass == other.superclass)
249+
233250

234251
class JavaObject(object):
235252
"""
@@ -263,11 +280,32 @@ def __repr__(self):
263280
name = self.classdesc.name
264281
return "<javaobj:{0}>".format(name)
265282

283+
def __eq__(self, other):
284+
"""
285+
Equality test between two Java classes
286+
287+
:param other: Other JavaClass to test
288+
:return: True if both classes share the same fields and name
289+
"""
290+
if not isinstance(other, type(self)):
291+
return False
292+
293+
res = (self.classdesc == other.classdesc and
294+
self.annotations == other.annotations)
295+
if not res:
296+
return False
297+
298+
for name in self.classdesc.fields_names:
299+
if not (getattr(self, name) == getattr(other, name)):
300+
return False
301+
return True
302+
266303
def copy(self, new_object):
267304
"""
268305
Returns a shallow copy of this object
269306
"""
270307
new_object.classdesc = self.classdesc
308+
new_object.annotations = self.annotations
271309

272310
for name in self.classdesc.fields_names:
273311
new_object.__setattr__(name, getattr(self, name))

0 commit comments

Comments
 (0)