GP-71: Prepping for source release.

This commit is contained in:
Dan 2020-12-10 09:39:41 -05:00
parent ddbfbfe198
commit 8201baef2b
2705 changed files with 305722 additions and 53 deletions

View file

@ -0,0 +1,55 @@
'''
Classes corresponding to common Java collection types
These are not ports by any means of the corresponding Java types.
Instead, they just populate the same name space so that exporting need
not map things over. I also use them as convenient places to implement
a common interface.
'''
from java.lang import Object
class Collection(Object):
@classmethod
def validate(cls, val, **targs):
E = cls.resolve_targs(Collection, **targs)['E']
if not hasattr(val, '__iter__') or not hasattr(val, '__len__'):
raise ValueError(
"Value for %s must behave list a collection " +
"(__iter__ and __len__)")
for e in val:
E.validate(e)
@classmethod
def subst_targs(cls, E):
return {}
class List(Collection):
@classmethod
def validate(cls, val, **targs):
E = cls.resolve_targs(List, **targs)['E']
if not hasattr(val, '__getitem__') or not hasattr(val, '__len__'):
raise ValueError(
"Value for %s must behave list a list " +
"(__getitem__ and __len__)")
for e in val:
E.validate(e)
@classmethod
def subst_targs(cls, E):
return dict(E=E)
@classmethod
def add_to(cls, l, item):
l.append(item)
class ArrayList(List):
@classmethod
def new(cls):
return list()