1.1 --- a/java/lang.py Thu Dec 09 02:17:22 2004 +0100
1.2 +++ b/java/lang.py Thu Dec 09 02:18:05 2004 +0100
1.3 @@ -91,6 +91,15 @@
1.4 # compareTo(self, o)
1.5 raise NotImplementedError, "compareTo"
1.6
1.7 +# NOTE: Establish a better exception hierarchy.
1.8 +
1.9 +class IllegalArgumentException(object):
1.10 + def __init__(self, *args):
1.11 + self.args = args
1.12 +
1.13 +setattr(IllegalArgumentException, "__init_____", IllegalArgumentException.__init__)
1.14 +setattr(IllegalArgumentException, "__init_____java__lang__String", IllegalArgumentException.__init__)
1.15 +
1.16 class String(object):
1.17
1.18 def init__empty(self):
1.19 @@ -127,70 +136,126 @@
1.20 raise NotImplementedError, "__init__"
1.21 # __init__(self, buffer)
1.22 raise NotImplementedError, "__init__"
1.23 +
1.24 def length(self):
1.25 return len(self.value)
1.26 + length___ = length
1.27 +
1.28 def charAt(self, index):
1.29 - return self.value[index]
1.30 + return ord(self.value[index])
1.31 + charAt____I_ = charAt
1.32 +
1.33 def getChars(self, srcBegin, srcEnd, dst, dstBegin):
1.34 raise NotImplementedError, "getChars"
1.35 + getChars____I_____I_____C__array_____I_ = getChars
1.36 +
1.37 def getBytes(self, *args):
1.38 # void getBytes(self, srcBegin, srcEnd, dst, dstBegin)
1.39 # byte[] getBytes(self, enc)
1.40 # byte[] getBytes(self)
1.41 raise NotImplementedError, "getBytes"
1.42 + getBytes___ = getBytes
1.43 + getBytes____I_____I_____B__array_____I_ = getBytes
1.44 +
1.45 def equals(self, anObject):
1.46 - raise NotImplementedError, "equals"
1.47 + return isinstance(anObject, self.__class__) and self.value == anObject.value
1.48 + equals___java__lang__Object = equals
1.49 +
1.50 def compareTo(self, obj):
1.51 - raise NotImplementedError, "compareTo"
1.52 - # NOTE: Comparator defined using private classes.
1.53 + if self.value < obj.value:
1.54 + return -1
1.55 + elif self.value == obj.value:
1.56 + return 0
1.57 + else:
1.58 + return 1
1.59 + compareTo___java__lang__String = compareTo
1.60 +
1.61 + # NOTE: Comparator defined using private classes. This implementation just
1.62 + # NOTE: uses Python's lower method.
1.63 def compareToIgnoreCase(self, str):
1.64 - raise NotImplementedError, "compareToIgnoreCase"
1.65 + value = self.value.lower()
1.66 + value2 = str.value.lower()
1.67 + if value < value2:
1.68 + return -1
1.69 + elif value == value2:
1.70 + return 0
1.71 + else:
1.72 + return 1
1.73 + compareToIgnoreCase___java__lang__String = compareToIgnoreCase
1.74 +
1.75 + # NOTE: Comparator defined using private classes. This implementation just
1.76 + # NOTE: uses Python's lower method.
1.77 + def equalsIgnoreCase(self, anotherString):
1.78 + value = self.value.lower()
1.79 + value2 = anotherString.value.lower()
1.80 + return value == value2
1.81 + equalsIgnoreCase___java__lang__String = equalsIgnoreCase
1.82 +
1.83 def regionMatches(self, *args):
1.84 # regionMatches(self, toffset, other, ooffset, len)
1.85 # regionMatches(self, ignoreCase, toffset, other, ooffset, len)
1.86 raise NotImplementedError, "regionMatches"
1.87 +
1.88 def startsWith(self, *args):
1.89 # startsWith(self, prefix, toffset)
1.90 # startsWith(self, prefix)
1.91 raise NotImplementedError, "startsWith"
1.92 +
1.93 def endsWith(self, suffix):
1.94 raise NotImplementedError, "endsWith"
1.95 +
1.96 def hashCode(self):
1.97 raise NotImplementedError, "hashCode"
1.98 - def indexOf(self, *args):
1.99 - # indexOf(self, ch)
1.100 - # indexOf(self, ch, fromIndex)
1.101 - # indexOf(self, str)
1.102 - # indexOf(self, str, fromIndex)
1.103 - raise NotImplementedError, "indexOf"
1.104 +
1.105 + def indexOf____I_(self, ch):
1.106 + return self.value.find(chr(ch))
1.107 +
1.108 + def indexOf____I_____I_(self, ch, fromIndex):
1.109 + return self.value.find(chr(ch), fromIndex)
1.110 +
1.111 + def indexOf___java__lang__String___(self, str):
1.112 + return self.value.find(str.value)
1.113 +
1.114 + def indexOf___java__lang__String____I_(self, str, fromIndex):
1.115 + return self.value.find(str.value, fromIndex)
1.116 +
1.117 def lastIndexOf(self, *args):
1.118 # lastIndexOf(self, ch)
1.119 # lastIndexOf(self, ch, fromIndex)
1.120 # lastIndexOf(self, str)
1.121 # lastIndexOf(self, str, fromIndex)
1.122 raise NotImplementedError, "lastIndexOf"
1.123 +
1.124 def substring(self, *args):
1.125 # substring(self, beginIndex)
1.126 # substring(self, beginIndex, endIndex)
1.127 raise NotImplementedError, "substring"
1.128 +
1.129 def concat(self, str):
1.130 raise NotImplementedError, "concat"
1.131 +
1.132 def replace(self, oldChar, newChar):
1.133 raise NotImplementedError, "replace"
1.134 +
1.135 def toLowerCase(self, *args):
1.136 # toLowerCase(self, locale)
1.137 # toLowerCase(self)
1.138 raise NotImplementedError, "toLowerCase"
1.139 +
1.140 def toUpperCase(self, *args):
1.141 # toUpperCase(self, locale)
1.142 # toUpperCase(self)
1.143 raise NotImplementedError, "toUpperCase"
1.144 +
1.145 def trim(self):
1.146 raise NotImplementedError, "trim"
1.147 +
1.148 def toString(self):
1.149 return self
1.150 +
1.151 def toCharArray(self):
1.152 raise NotImplementedError, "toCharArray"
1.153 +
1.154 def valueOf(self, *args):
1.155 # valueOf(self, obj)
1.156 # valueOf(self, data)
1.157 @@ -202,15 +267,17 @@
1.158 # valueOf(self, d)
1.159 raise NotImplementedError, "valueOf"
1.160 valueOf = staticmethod(valueOf)
1.161 +
1.162 def copyValueOf(self, *args):
1.163 # copyValueOf(self, data, offset, count)
1.164 # copyValueOf(self, data)
1.165 raise NotImplementedError, "copyValueOf"
1.166 copyValueOf = staticmethod(copyValueOf)
1.167 +
1.168 def intern(self):
1.169 raise NotImplementedError, "intern"
1.170
1.171 -setattr(String, "__init__$", String.init__empty)
1.172 -setattr(String, "__init__$java/lang/String", String.init__String)
1.173 +setattr(String, "__init_____", String.init__empty)
1.174 +setattr(String, "__init_____java__lang__String", String.init__String)
1.175
1.176 # vim: tabstop=4 expandtab shiftwidth=4