Issue1181404
Created on 2005-04-12.11:30:09 by archon55, last changed 2007-12-02.22:25:09 by cgroves.
File name |
Uploaded |
Description |
Edit |
Remove |
PyDictionary.java
|
archon55,
2005-04-12.11:30:10
|
PyDictionary.java |
|
|
CVS_diff.txt
|
archon55,
2005-04-14.08:38:29
|
pydicitonary diff |
|
|
pydict.txt
|
archon55,
2005-05-20.10:23:56
|
PyDictionary CVS diff file |
|
|
msg2438 (view) |
Author: Mike_G (archon55) |
Date: 2005-04-12.11:30:09 |
|
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
|
msg2439 (view) |
Author: Brian Zimmer (bzimmer) |
Date: 2005-04-14.02:38:18 |
|
Logged In: YES
user_id=37674
This patch needs to be broken up into smaller units of work.
Please separate the changes for PyDictionary and Iterator
into two separate patches. Also, please complete the
implementation of all Iterator methods before submitting the
patch. It's not acceptable for hasNext() to return true
without regard to the actual state of the iterator.
Please also use cvs diff to submit the patch as a diff file.
It's much easier to manage and it allows for a simpler upload.
|
msg2440 (view) |
Author: Mike_G (archon55) |
Date: 2005-04-14.08:38:29 |
|
Logged In: YES
user_id=1186138
Ok, here is the CVS PyDictionary diff result requested. At
this point it is not clear whether or not implementing
java.util.Iterator on Python iterators is desired or
requested therefore it won't be addressed.
If there is no interest in calling java iterator methods
from jython then it does not make sense. It is simple to
just create a java collection with the underlying jython
collection then iterate from there.
Mike
|
msg2441 (view) |
Author: Brian Zimmer (bzimmer) |
Date: 2005-05-15.16:59:44 |
|
Logged In: YES
user_id=37674
This patch does not address enough of the issues in to warrant being
applied. As stated, simple unittests fail and the semantics of Map are
not implemented, such as collections backing the true data structure.
|
msg2442 (view) |
Author: Mike_G (archon55) |
Date: 2005-05-20.10:23:52 |
|
Logged In: YES
user_id=1186138
Per the requirements, this patch for PyDictionary now uses
the map as a backing collection. Any change to the
PyDictionary (Map) will be now reflected in any references
to the underlying key set, entry set and values collections.
Also, the put/putAll methods ensure that all objects put
into the PyDictionary are PyObjects.
Mike G.
|
msg2443 (view) |
Author: Charlie Groves (cgroves) |
Date: 2007-12-02.22:25:09 |
|
http://jython.org/patches/1817565 does this with more functionality.
|
|
Date |
User |
Action |
Args |
2005-04-12 11:30:09 | archon55 | create | |
|