Continuing with my bridging efforts, after the flip, we have code to map a Java Set to their Pythonic equivalents.
class SetSet(object):
def __init__(self):
from java.util import HashSet
self.wrapped = HashSet()
def __contains__(self, item):
return self.wrapped.contains(item)
def __eq__(self, other):
return self.wrapped.equals(other)
def __ne__(self, other):
return not self.__eq__(other)
def __hash__(self):
return self.wrapped.hashCode()
def __iter__(self):
try:
return self.iterator
except:
self.iterator = self.wrapped.iterator()
return self.iterator
def __len__(self):
return self.wrapped.size()
def __str__(self):
return self.wrapped.toString()
def discard(self,x):
return self.wrapped.remove(x)
def add(self, x):
return self.wrapped.add(x)



Leave a comment