@@ -318,6 +318,13 @@ def __repr__(self):
318318 name = self .classdesc .name
319319 return "<javaobj:{0}>" .format (name )
320320
321+ def __hash__ (self ):
322+ """
323+ Each JavaObject we load must have a hash method to be accepted in sets
324+ and alike. The default hash is the memory address of the object.
325+ """
326+ return id (self )
327+
321328 def __eq__ (self , other ):
322329 """
323330 Equality test between two Java classes
@@ -1679,12 +1686,39 @@ def __extra_loading__(self, unmarshaller, ident=0):
16791686 if opid != 0 :
16801687 raise ValueError ("Should find 0x0, got {0:x}" .format (opid ))
16811688
1689+ class JavaSet (set , JavaObject ):
1690+ """
1691+ Python-Java set bridge type
1692+ """
1693+ def __init__ (self , unmarshaller ):
1694+ # type: (JavaObjectUnmarshaller) -> None
1695+ set .__init__ (self )
1696+ JavaObject .__init__ (self )
1697+
1698+ def __extra_loading__ (self , unmarshaller , ident = 0 ):
1699+ # type: (JavaObjectUnmarshaller, int) -> None
1700+ """
1701+ Loads the content of the map, written with a custom implementation
1702+ """
1703+ self .update (self .annotations [1 :])
1704+
1705+ class JavaTreeSet (JavaSet ):
1706+ def __extra_loading__ (self , unmarshaller , ident = 0 ):
1707+ # type: (JavaObjectUnmarshaller, int) -> None
1708+ """
1709+ Loads the content of the map, written with a custom implementation
1710+ """
1711+ # Annotation[1] == size of the set
1712+ self .update (self .annotations [2 :])
1713+
16821714 TYPE_MAPPER = {
16831715 "java.util.ArrayList" : JavaList ,
16841716 "java.util.LinkedList" : JavaList ,
16851717 "java.util.HashMap" : JavaMap ,
16861718 "java.util.LinkedHashMap" : JavaLinkedHashMap ,
16871719 "java.util.TreeMap" : JavaMap ,
1720+ "java.util.HashSet" : JavaSet ,
1721+ "java.util.TreeSet" : JavaTreeSet ,
16881722 }
16891723
16901724 def create (self , classdesc , unmarshaller = None ):
0 commit comments