javaclass

java/util.py

114:2420bedaf184
2005-01-10 Paul Boddie Moved the lang module contents into the lang package. Fixed various java.lang and java.io circular imports by introducing a java.lang._object module. Corrected various base classes (object -> java.lang.Object, Exception -> java.lang.Exception) and fixed raising of exceptions in certain cases. Added reflection capabilities.
     1 #!/usr/bin/env python     2      3 import java.lang     4      5 # Interfaces.     6      7 class Collection(java.lang.Object):     8     pass     9     10 class Iterator(java.lang.Object):    11     pass    12     13 class List(java.lang.Object):    14     pass    15     16 class Map(java.lang.Object):    17     pass    18     19 class Set(Collection):    20     pass    21     22 # Abstract classes.    23     24 class AbstractMap(Map):    25     pass    26     27 class Dictionary(java.lang.Object):    28     pass    29     30 # Exceptions.    31     32 class NoSuchElementException(java.lang.Exception):    33     pass    34     35 # Special Python classes.    36     37 class _Iterator(Iterator):    38     def __init__(self, iterator):    39         self.iterator = iterator    40         self.current = None    41     42     def hasNext(self):    43         if self.current is None:    44             try:    45                 self.current = self.iterator.next()    46             except StopIteration:    47                 self.current = None    48                 return 0    49         return 1    50     hasNext___ = hasNext    51     52     def next(self):    53         if self.hasNext():    54             current = self.current    55             self.current = None    56             return current    57         raise Exception, NoSuchElementException()    58     next___ = next    59     60 # Classes.    61     62 class EventObject(java.lang.Object):    63     def __init__(self, source):    64         self.source = source    65     def getSource(self):    66         return self.source    67     def toString(self):    68         # NOTE: Use Python conventions.    69         return str(self)    70     71 class Hashtable(Dictionary):    72     def __init__(self, *args):    73         # NOTE: To be implemented.    74         pass    75     76 setattr(Hashtable, "__init_____", Hashtable.__init__)    77     78 class HashMap(AbstractMap):    79     def __init__(self, *args):    80         self.d = {}    81     82     def init_____java__util__Map(self, map):    83         self.d = {}    84         iterator = map.keySet().iterator()    85         while iterator.hasNext():    86             key = iterator.next()    87             value = map.get(key)    88             self.d[key] = value    89     90     def get(self, key):    91         return self.d[key]    92     get___java__lang__Object = get    93     94     def keySet(self):    95         return HashSet(self.d.keys())    96     keySet___ = keySet    97     98     def put(self, key, value):    99         self.d[key] = value   100     put___java__lang__Object___java__lang__Object = put   101    102     # Python helper methods.   103    104     def __getitem__(self, key):   105         return self.d[key]   106    107     def __setitem__(self, key, value):   108         self.d[key] = value   109    110     def keys(self):   111         return self.d.keys()   112    113     def values(self):   114         return self.d.values()   115    116     def items(self):   117         return self.d.items()   118    119 setattr(HashMap, "__init_____", HashMap.__init__)   120 setattr(HashMap, "__init_____java__util__Map", HashMap.init_____java__util__Map)   121    122 class HashSet(Set):   123     def __init__(self):   124         self.s = []   125    126     def iterator(self):   127         return _Iterator(iter(self.s))   128     iterator___ = iterator   129    130 setattr(HashSet, "__init_____", HashSet.__init__)   131    132 class ResourceBundle(java.lang.Object):   133     def __init__(self, *args):   134         # NOTE: To be implemented.   135         pass   136    137     def getBundle(self, *args):   138         # getBundle(self, baseName)   139         # getBundle(self, baseName, locale)   140         # getBundle(self, baseName, locale, loader)   141         # NOTE: Obviously not the correct implementation.   142         return ResourceBundle(args)   143     getBundle = staticmethod(getBundle)   144     getBundle___java__lang__String = getBundle   145     getBundle___java__lang__String___java__util__Locale = getBundle   146     getBundle___java__lang__String___java__util__Locale___java__lang__ClassLoader = getBundle   147    148     def getObject(self, key):   149         # NOTE: To be implemented.   150         return None   151     getObject___java__lang__String = getObject   152    153     def getString(self, key):   154         # NOTE: To be implemented.   155         return None   156     getString___java__lang__String = getString   157    158     def getStringArray(self, key):   159         # NOTE: To be implemented.   160         return None   161     getStringArray___java__lang__String = getStringArray   162    163     def getLocale(self, key):   164         # NOTE: To be implemented.   165         return None   166     getLocale___ = getLocale   167    168 class AbstractCollection(Collection):   169     pass   170    171 class AbstractList(AbstractCollection, List):   172     pass   173    174 class Vector(AbstractList):   175     pass   176    177 # vim: tabstop=4 expandtab shiftwidth=4