Message2438
This patch (PyDictionary only) is to support the
integration of the Java Collections API on Python
collection types.
Attached is the updated PyDictionary.java file that
implements the Map interface. PyDictionaryIter class
(defined in same file) implements the PyIterator class.
PyIterator now implements java.util.Iterator providing
next(), hasNext() features. This does not provide new
functionality only Java Collections API integrity.
Essentially, now you can simply use familiar java
methods to do this:
>>> pyd = {1:'one',2:'two',3:'three',4:'four',5:'five'}
>>> pyiter = pyd.iterkeys()
>>> while pyiter.hasNext():
... print pyiter.next()
...
5
4
3
2
1
>>> pyiter = pyd.itervalues()
>>> while pyiter.hasNext():
... print pyiter.next()
...
five
four
three
two
one
>>>
None of the java Map method impls were 'exposed' to
Jython so as to maintain Python features. This means
you cannot call a Map method on your PyDictionary
'dict' type. You'll get the following ERROR if you try:
>>> pyd.containsKey(1)
Traceback (innermost last):
File "<console>", line 1, in ?
AttributeError: 'dict' object has no attribute
'containsKey'
>>>
They can be easily 'exposed' to Jython if it is decided.
NOTE: When creating a new Map object and passing in the
PyDictionary to the ctor, the containsKey/containsValue
method do not return the correct answer. Also if you
create a new Map (e.g. HashMap) and do
addAll(PyDictionary) the containsKey/Value methods also
incorrectly answer. If you to a put on all the
PyDictionary keys/values individually into the Map
using put calls then, the containsKey/containsValue
return the correct response.
The impact of changing PyIterator to implement
java.util.Iterator lead to the class PyGenerator,
PyCallIter, PySequenceIter, PyStringMap to be changed
also since they are all now implementing Iterator. The
implementations are to be done still.
The dependent files will be submitted under the same
patch number.
Mike Garcia
|
|
Date |
User |
Action |
Args |
2008-02-20 17:18:28 | admin | link | issue1181404 messages |
2008-02-20 17:18:28 | admin | create | |
|