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