1 #!/usr/bin/env python 2 3 class Character(object): 4 def __init__(self, value): 5 raise NotImplementedError, "__init__" 6 def charValue(self): 7 raise NotImplementedError, "charValue" 8 def hashCode(self): 9 raise NotImplementedError, "hashCode" 10 def equals(self, anObject): 11 raise NotImplementedError, "equals" 12 def toString(self): 13 raise NotImplementedError, "toString" 14 def isLowerCase(self, ch): 15 raise NotImplementedError, "isLowerCase" 16 isLowerCase = staticmethod(isLowerCase) 17 def isUpperCase(self, ch): 18 raise NotImplementedError, "isUpperCase" 19 isUpperCase = staticmethod(isUpperCase) 20 def isTitleCase(self, ch): 21 raise NotImplementedError, "isTitleCase" 22 isTitleCase = staticmethod(isTitleCase) 23 def isDigit(self, ch): 24 raise NotImplementedError, "isDigit" 25 isDigit = staticmethod(isDigit) 26 def isDefined(self, ch): 27 raise NotImplementedError, "isDefined" 28 isDefined = staticmethod(isDefined) 29 def isLetter(self, ch): 30 raise NotImplementedError, "isLetter" 31 isLetter = staticmethod(isLetter) 32 def isLetterOrDigit(self, ch): 33 raise NotImplementedError, "isLetterOrDigit" 34 isLetterOrDigit = staticmethod(isLetterOrDigit) 35 def isJavaLetter(self, ch): 36 raise NotImplementedError, "isJavaLetter" 37 isJavaLetter = staticmethod(isJavaLetter) 38 def isJavaLetterOrDigit(self, ch): 39 raise NotImplementedError, "isJavaLetterOrDigit" 40 isJavaLetterOrDigit = staticmethod(isJavaLetterOrDigit) 41 def isJavaIdentifierStart(self, ch): 42 raise NotImplementedError, "isJavaIdentifierStart" 43 isJavaIdentifierStart = staticmethod(isJavaIdentifierStart) 44 def isJavaIdentifierPart(self, ch): 45 raise NotImplementedError, "isJavaIdentifierPart" 46 isJavaIdentifierPart = staticmethod(isJavaIdentifierPart) 47 def isUnicodeIdentifierStart(self, ch): 48 raise NotImplementedError, "isUnicodeIdentifierStart" 49 isUnicodeIdentifierStart = staticmethod(isUnicodeIdentifierStart) 50 def isUnicodeIdentifierPart(self, ch): 51 raise NotImplementedError, "isUnicodeIdentifierPart" 52 isUnicodeIdentifierPart = staticmethod(isUnicodeIdentifierPart) 53 def isIdentifierIgnorable(self, ch): 54 raise NotImplementedError, "isIdentifierIgnorable" 55 isIdentifierIgnorable = staticmethod(isIdentifierIgnorable) 56 def toLowerCase(self, ch): 57 raise NotImplementedError, "toLowerCase" 58 toLowerCase = staticmethod(toLowerCase) 59 def toUpperCase(self, ch): 60 raise NotImplementedError, "toUpperCase" 61 toUpperCase = staticmethod(toUpperCase) 62 def toTitleCase(self, ch): 63 raise NotImplementedError, "toTitleCase" 64 toTitleCase = staticmethod(toTitleCase) 65 def digit(self, ch, radix): 66 raise NotImplementedError, "digit" 67 digit = staticmethod(digit) 68 def getNumericValue(self, ch): 69 raise NotImplementedError, "getNumericValue" 70 getNumericValue = staticmethod(getNumericValue) 71 def isSpace(self, ch): 72 raise NotImplementedError, "isSpace" 73 isSpace = staticmethod(isSpace) 74 def isSpaceChar(self, ch): 75 raise NotImplementedError, "isSpaceChar" 76 isSpaceChar = staticmethod(isSpaceChar) 77 def isWhitespace(self, ch): 78 raise NotImplementedError, "isWhitespace" 79 isWhitespace = staticmethod(isWhitespace) 80 def isISOControl(self, ch): 81 raise NotImplementedError, "isISOControl" 82 isISOControl = staticmethod(isISOControl) 83 def getType(self, ch): 84 raise NotImplementedError, "getType" 85 getType = staticmethod(getType) 86 def forDigit(self, ch, radix): 87 raise NotImplementedError, "forDigit" 88 forDigit = staticmethod(forDigit) 89 def compareTo(self, *args): 90 # compareTo(self, anotherCharacter) 91 # compareTo(self, o) 92 raise NotImplementedError, "compareTo" 93 94 # NOTE: Establish a better exception hierarchy. 95 96 class IllegalArgumentException(object): 97 def __init__(self, *args): 98 self.args = args 99 100 setattr(IllegalArgumentException, "__init_____", IllegalArgumentException.__init__) 101 setattr(IllegalArgumentException, "__init_____java__lang__String", IllegalArgumentException.__init__) 102 103 class String(object): 104 105 def init__empty(self): 106 self.value = u"" 107 108 def init__String(self, obj): 109 self.value = obj.value 110 111 def __init__(self, *args): 112 # Python string initialisation: 113 if len(args) == 1 and isinstance(args[0], str): 114 self.value = unicode(args[0]) 115 return 116 elif len(args) == 1 and isinstance(args[0], unicode): 117 self.value = args[0] 118 return 119 # __init__(self) 120 elif len(args) == 0: 121 self.__init__empty() 122 return 123 # __init__(self, original) 124 elif len(args) == 1 and isinstance(args[0], String): 125 self.__init__String(args[0]) 126 return 127 # __init__(self, value) 128 # __init__(self, value, offset, count) 129 # __init__(self, ascii, hibyte, offset, count) 130 # __init__(self, ascii, hibyte) 131 # __init__(self, bytes, offset, length, enc) 132 # __init__(self, bytes, enc) 133 # __init__(self, bytes, offset, length) 134 # __init__(self, bytes) 135 elif len(args) >= 1 and isinstance(args[0], list): 136 raise NotImplementedError, "__init__" 137 # __init__(self, buffer) 138 raise NotImplementedError, "__init__" 139 140 def length(self): 141 return len(self.value) 142 length___ = length 143 144 def charAt(self, index): 145 return ord(self.value[index]) 146 charAt____I_ = charAt 147 148 def getChars(self, srcBegin, srcEnd, dst, dstBegin): 149 raise NotImplementedError, "getChars" 150 getChars____I_____I_____C__array_____I_ = getChars 151 152 def getBytes(self, *args): 153 # void getBytes(self, srcBegin, srcEnd, dst, dstBegin) 154 # byte[] getBytes(self, enc) 155 # byte[] getBytes(self) 156 raise NotImplementedError, "getBytes" 157 getBytes___ = getBytes 158 getBytes____I_____I_____B__array_____I_ = getBytes 159 160 def equals(self, anObject): 161 return isinstance(anObject, self.__class__) and self.value == anObject.value 162 equals___java__lang__Object = equals 163 164 def compareTo(self, obj): 165 if self.value < obj.value: 166 return -1 167 elif self.value == obj.value: 168 return 0 169 else: 170 return 1 171 compareTo___java__lang__String = compareTo 172 173 # NOTE: Comparator defined using private classes. This implementation just 174 # NOTE: uses Python's lower method. 175 def compareToIgnoreCase(self, str): 176 value = self.value.lower() 177 value2 = str.value.lower() 178 if value < value2: 179 return -1 180 elif value == value2: 181 return 0 182 else: 183 return 1 184 compareToIgnoreCase___java__lang__String = compareToIgnoreCase 185 186 # NOTE: Comparator defined using private classes. This implementation just 187 # NOTE: uses Python's lower method. 188 def equalsIgnoreCase(self, anotherString): 189 value = self.value.lower() 190 value2 = anotherString.value.lower() 191 return value == value2 192 equalsIgnoreCase___java__lang__String = equalsIgnoreCase 193 194 def regionMatches(self, *args): 195 # regionMatches(self, toffset, other, ooffset, len) 196 # regionMatches(self, ignoreCase, toffset, other, ooffset, len) 197 raise NotImplementedError, "regionMatches" 198 199 def startsWith(self, *args): 200 # startsWith(self, prefix, toffset) 201 # startsWith(self, prefix) 202 raise NotImplementedError, "startsWith" 203 204 def endsWith(self, suffix): 205 raise NotImplementedError, "endsWith" 206 207 def hashCode(self): 208 raise NotImplementedError, "hashCode" 209 210 def indexOf____I_(self, ch): 211 return self.value.find(chr(ch)) 212 213 def indexOf____I_____I_(self, ch, fromIndex): 214 return self.value.find(chr(ch), fromIndex) 215 216 def indexOf___java__lang__String___(self, str): 217 return self.value.find(str.value) 218 219 def indexOf___java__lang__String____I_(self, str, fromIndex): 220 return self.value.find(str.value, fromIndex) 221 222 def lastIndexOf(self, *args): 223 # lastIndexOf(self, ch) 224 # lastIndexOf(self, ch, fromIndex) 225 # lastIndexOf(self, str) 226 # lastIndexOf(self, str, fromIndex) 227 raise NotImplementedError, "lastIndexOf" 228 229 def substring(self, *args): 230 # substring(self, beginIndex) 231 # substring(self, beginIndex, endIndex) 232 raise NotImplementedError, "substring" 233 234 def concat(self, str): 235 raise NotImplementedError, "concat" 236 237 def replace(self, oldChar, newChar): 238 raise NotImplementedError, "replace" 239 240 def toLowerCase(self, *args): 241 # toLowerCase(self, locale) 242 # toLowerCase(self) 243 raise NotImplementedError, "toLowerCase" 244 245 def toUpperCase(self, *args): 246 # toUpperCase(self, locale) 247 # toUpperCase(self) 248 raise NotImplementedError, "toUpperCase" 249 250 def trim(self): 251 raise NotImplementedError, "trim" 252 253 def toString(self): 254 return self 255 256 def toCharArray(self): 257 raise NotImplementedError, "toCharArray" 258 259 def valueOf(self, *args): 260 # valueOf(self, obj) 261 # valueOf(self, data) 262 # valueOf(self, data, offset, count) 263 # valueOf(self, b) 264 # valueOf(self, c) 265 # valueOf(self, l) 266 # valueOf(self, f) 267 # valueOf(self, d) 268 raise NotImplementedError, "valueOf" 269 valueOf = staticmethod(valueOf) 270 271 def copyValueOf(self, *args): 272 # copyValueOf(self, data, offset, count) 273 # copyValueOf(self, data) 274 raise NotImplementedError, "copyValueOf" 275 copyValueOf = staticmethod(copyValueOf) 276 277 def intern(self): 278 raise NotImplementedError, "intern" 279 280 setattr(String, "__init_____", String.init__empty) 281 setattr(String, "__init_____java__lang__String", String.init__String) 282 283 # vim: tabstop=4 expandtab shiftwidth=4