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