dict object. The Java API is provided directly
by the base class implementing Map, while the Python API
has been implemented on top of the Java one.
| Modifier and Type | Class and Description |
|---|---|
| private class | PyDict.EntrySetImpl
An instance of this class is returned by
|
| private class | PyDict.EntrySetIteratorImpl
An instance of this class is returned by
|
| pack-priv static interface | PyDict.Key
A |
| pack-priv static class | PyDict.KeyHolder
This is a wrapper that gives Python semantics to objects used as keys. |
| pack-priv static enum | PyDict.MergeMode
Modes for use with |
| Modifier and Type | Field and Description |
|---|---|
| private static final String | |
| private static final String | |
| private static final String | |
| private final LinkedHashMap | map
The dictionary as a hash map preserving insertion order. |
| public static final PyType | TYPE
The type of Python object this class implements. |
| protected final PyType | type
The Python type of this instance. |
| Access | Constructor and Description |
|---|---|
| protected | |
| protected < key type of incoming map K, value type of incoming map V> | |
| public |
| Modifier and Type | Method and Description |
|---|---|
| private void | |
| private Object | |
| private Object | |
| private Object | |
| private Object | |
| private void | |
| private boolean | |
| public Set | entrySet()
Implements abstract java. Implements java. Set view of the mappings contained in this map.
|
| pack-priv static PyDict | Returns: a newdictarray containing key-value pairs stack, int index of first key start, int number of pairs count)Create a |
| public static PyDict | Returns: newdictspecifying key-value pairs to enter tuples)Create a |
| public Object | Returns: value atkey or null if not foundwhose associated value is to be returned key)Overrides java. Implements java. Map.get to give keys Python semantics.
|
| public PyType | |
| pack-priv final Object | Returns: found object ornullfinal mapping to search builtins, String to find key)Optimised get on this |
| pack-priv void | |
| pack-priv void | mergeFromSeq(Object
sequence of KV pairs to merge seq, PyDict.merge policy modeUpdate this dictionary from a sequence of key-value pairs, in the chosen mode. |
| private void | mergeObject(Object
a mapping to merge in src, PyDict.what to do about duplicates modeMerge the mapping |
| private void | mergeSingle(Object
key k, Object value v, PyDict.what to do about duplicates modeMerge a key-value pair into this |
| public Object | Returns: previous value associatedwith which the specified value is to be associated key, Object to be associated value)Overrides java. Implements java. Map.put to give keys Python semantics.
|
| public Object | Returns: previous value associatedwith which the specified value is to be associated key, Object to be associated value)Overrides default java. Map.putIfAbsent to give keys Python semantics.
|
| public static boolean | Returns: whether equalto test equal key,to test equal other)Convenience function for Python objects that implement
|
| public static int | Returns: the hashto hash keyConvenience function for Python objects that implement
|
| private static PyDict. | |
| public String | |
| pack-priv void |
| CANNOT_CONVERT_SEQ | back to summary |
|---|---|
| private static final String CANNOT_CONVERT_SEQ | |
| ELEMENT_N | back to summary |
|---|---|
| private static final String ELEMENT_N | |
| KV_TUPLE_LENGTH | back to summary |
|---|---|
| private static final String KV_TUPLE_LENGTH | |
| map | back to summary |
|---|---|
| private final LinkedHashMap<PyDict. The dictionary as a hash map preserving insertion order. | |
| TYPE | back to summary |
|---|---|
| public static final PyType TYPE The type of Python object this class implements. | |
| type | back to summary |
|---|---|
| protected final PyType type The Python type of this instance. | |
| PyDict | back to summary |
|---|---|
| protected PyDict(PyType type) Construct an empty dictionary of a specified Python sub-class of
| |
| PyDict | back to summary |
|---|---|
| protected <K, V> PyDict(PyType type, Map<K, V> map) Construct a dictionary of a specified Python sub-class of
| |
| PyDict | back to summary |
|---|---|
| public PyDict() Construct an empty | |
| __delitem__ | back to summary |
|---|---|
private void __delitem__(Object key)
| |
| __eq__ | back to summary |
|---|---|
private Object __eq__(Object o)
| |
| __getitem__ | back to summary |
|---|---|
private Object __getitem__(Object key)
| |
| __ne__ | back to summary |
|---|---|
private Object __ne__(Object o)
| |
| __repr__ | back to summary |
|---|---|
private Object __repr__() throws Throwable
| |
| __setitem__ | back to summary |
|---|---|
private void __setitem__(Object key, Object value)
| |
| compareEQ | back to summary |
|---|---|
| private boolean compareEQ(PyDict other) Compare this dictionary with the other
| |
| entrySet | back to summary |
|---|---|
| public Set Implements abstract java. Implements java. Doc from java. Returns a | |
| fromKeyValuePairs | back to summary |
|---|---|
| pack-priv static PyDict fromKeyValuePairs(Object[] stack, int start, int count) Create a
a new | |
| fromKeyValuePairs | back to summary |
|---|---|
| public static PyDict fromKeyValuePairs(PyTuple... tuples) Create a | |
| get | back to summary |
|---|---|
| public Object get(Object key) Overrides java. Implements java. Override | |
| getType | back to summary |
|---|---|
| public PyType getType() Implements org. Doc from org. The Python | |
| loadGlobal | back to summary |
|---|---|
| pack-priv final Object loadGlobal(Map<Object, Object> builtins, String key) Optimised get on this found object or | |
| merge | back to summary |
|---|---|
| pack-priv void merge(Object o, PyDict. Merge the contents of another mapping into this dictionary allowing replacement of matching keys only as specified. | |
| mergeFromSeq | back to summary |
|---|---|
| pack-priv void mergeFromSeq(Object seq, PyDict. Update this dictionary from a sequence of key-value pairs, in the
chosen mode. The sequence is any iterable object producing
iterable objects of length 2, typically a | |
| mergeObject | back to summary |
|---|---|
| private void mergeObject(Object src, PyDict. Merge the mapping
| |
| mergeSingle | back to summary |
|---|---|
| private void mergeSingle(Object k, Object v, PyDict. Merge a key-value pair into this
| |
| put | back to summary |
|---|---|
| public Object put(Object key, Object value) Overrides java. Implements java. Override
previous value associated | |
| putIfAbsent | back to summary |
|---|---|
| public Object putIfAbsent(Object key, Object value) Overrides default java. Override
previous value associated | |
| pythonEquals | back to summary |
|---|---|
| public static boolean pythonEquals(PyDict. Convenience function for Python objects that implement
whether equal
| |
| pythonHash | back to summary |
|---|---|
| public static int pythonHash(PyDict. Convenience function for Python objects that implement
| |
| toKey | back to summary |
|---|---|
| private static PyDict. Turn an object into a
| |
| toString | back to summary |
|---|---|
| public String toString() Overrides java. Doc from java. Returns a string representation of this map. The string representation
consists of a list of key-value mappings in the order returned by the
map's | |
| update | back to summary |
|---|---|
| pack-priv void update(Object o) Update the dictionary with the contents of another mapping
object, allowing replacement of matching keys. This supports the
| |
PyDict#entrySet(), and provides the view of the entries
in the PyDict mentioned there.
It is probably also the backing for a dict_keys.
| Access | Constructor and Description |
|---|---|
| private |
| Modifier and Type | Method and Description |
|---|---|
| public Iterator | iterator()
Implements abstract java. Implements java. |
| public int | size()
Implements abstract java. Implements java. |
| EntrySetImpl | back to summary |
|---|---|
| private EntrySetImpl() | |
| iterator | back to summary |
|---|---|
| public Iterator Implements abstract java. Implements java. Doc from java. Returns an iterator over the elements in this set. The elements are returned in no particular order (unless this set is an instance of some class that provides a guarantee). | |
| size | back to summary |
|---|---|
| public int size() Implements abstract java. Implements java. Doc from java. Returns the number of elements in this set (its cardinality). If this
set contains more than
| |
EntrySetImpl#iterator(). It is backed by an iterator on
the underlying map, and its job is to return an entry in
which the PyDict#Key has been replaced with its contained
object, the true key at the Python level.
| Modifier and Type | Field and Description |
|---|---|
| private final Iterator | mapIterator
Backing iterator on the "real" implementation. |
| Access | Constructor and Description |
|---|---|
| private |
| Modifier and Type | Method and Description |
|---|---|
| public boolean | |
| public Map. | |
| public void | remove()
Overrides default java. |
| mapIterator | back to summary |
|---|---|
| private final Iterator<Map. Backing iterator on the "real" implementation. | |
| EntrySetIteratorImpl | back to summary |
|---|---|
| private EntrySetIteratorImpl() | |
| hasNext | back to summary |
|---|---|
| public boolean hasNext() Implements java. Doc from java. Returns
| |
| next | back to summary |
|---|---|
| public Map. Implements java. Doc from java. Returns the next element in the iteration. The difference from the underlying
| |
| remove | back to summary |
|---|---|
| public void remove() Overrides default java. Doc from java. Removes from the underlying collection the last element returned
by this iterator (optional operation). This method can be called
only once per call to The behavior of an iterator is unspecified if the underlying collection is modified while the iteration is in progress in any way other than by calling this method, unless an overriding class has specified a concurrent modification policy.
The behavior of an iterator is unspecified if this method is called
after a call to the
| |
PyDict is a Map<Object, Object>, but contains a
private implementation of java.utilMap<Key, Object>. We
use this class Key so that when Java needs key hashes or
comparisons, it receives the hash or comparison that Python would
produce. An object with the Key interface defines the
standard Java hashCode() and equals() to return
the answers Python would give for __hash__ and
__eq__.
Some implementations of Python objects (e.g. the
PyUnicode implementation of str) implement
PyDict.Key, and can give Python semantics to hash and
comparison directly. Other implementations (e.g. a Java
String implementation of str) have to be wrapped
in a KeyHolder that implements PyDict.Key.
Conversely, when any method requires the keys of a Python
dict, the Key must yield up the original Python
object it contains.
An implementation of a Python type that allows Python sub-classes
must respect re-definition of the corresponding special methods.
This is best done by by calling abstract API
Abstract#hash(Object), etc..
| Modifier and Type | Method and Description |
|---|---|
| public boolean | |
| public default Object | Returns: the underlying key object (by defaultthis)If this object is a holder for the actual key, return the actual key. |
| public int | hashCode()
Python objects that implement the interface |
| equals | back to summary |
|---|---|
| public boolean equals(Object other) throws PyException Python objects that implement the interface
@Override
public int equals(Object obj) throws PyException {
return PyDict.pythonEquals(this, obj);
}
Objects that provide their own specialised implementation
of equals, receiving a Key a object as the
other argument, must dereference it with get()
and work on those contents. An idiom like this may be used:
@Override
public boolean equals(Object other) {
if (other instanceof PyDict.Key)
other = ((PyDict.Key) other).get();
// ... rest of implementation
}
| |
| get | back to summary |
|---|---|
| public default Object get() If this object is a holder for the actual key, return the actual
key. By default, return
| |
| hashCode | back to summary |
|---|---|
| public int hashCode() throws PyException Python objects that implement the interface
@Override
public int hashCode() throws PyException {
return PyDict.pythonHash(this);
}
Where it is known __hash__ cannot have been
redefined, object implementations may have a shorter option.
| |
Object.hashCode and
Object.equals, and direct them to Python __hash__
and __eq__.
| Modifier and Type | Field and Description |
|---|---|
| private final Object | key
The actual key this object is holding. |
| Access | Constructor and Description |
|---|---|
| pack-priv |
| Modifier and Type | Method and Description |
|---|---|
| public boolean | equals(Object
the reference object with which to compare. other)Overrides java. Implements org. __eq__ definitions on objects offered as
keys.
|
| public Object | get()
Overrides default org. Key object.
|
| public int | hashCode()
Overrides java. Implements org. Key, define
this method so that calls from Java libraries to
Object.hashCode() receive the hash defined by Python.
|
| public String |
| key | back to summary |
|---|---|
| private final Object key The actual key this object is holding. | |
| KeyHolder | back to summary |
|---|---|
| pack-priv KeyHolder(Object key) Create a key on the given object Python
| |
| equals | back to summary |
|---|---|
| public boolean equals(Object other) throws PyException Overrides java. Implements org. Impose Python
| |
| get | back to summary |
|---|---|
| public Object get() Overrides default org. Return the actual object held by this
| |
| hashCode | back to summary |
|---|---|
| public int hashCode() Overrides java. Implements org. Doc from org. Python objects that implement the interface
@Override
public int hashCode() throws PyException {
return PyDict.pythonHash(this);
}
Where it is known __hash__ cannot have been
redefined, object implementations may have a shorter option.
| |
| toString | back to summary |
|---|---|
| public String toString() Overrides java. Doc from java. Returns a string representation of the object. | |
merge(Object, MergeMode).
| Modifier and Type | Field and Description |
|---|---|
| public static final PyDict. | IF_ABSENT
Ignore the operation if the key is already in the map. |
| public static final PyDict. | PUT
Overwrite any existing entry with the same key. |
| public static final PyDict. |
| Access | Constructor and Description |
|---|---|
| private |
| Modifier and Type | Method and Description |
|---|---|
| public static PyDict. | |
| public static PyDict. |
| IF_ABSENT | back to summary |
|---|---|
| public static final PyDict. Ignore the operation if the key is already in the map. (CPython mode 0: first occurrence wins). | |
| PUT | back to summary |
|---|---|
| public static final PyDict. Overwrite any existing entry with the same key. (CPython mode 1: last occurrence wins). | |
| UNIQUE | back to summary |
|---|---|
| public static final PyDict. Raise a | |
| MergeMode | back to summary |
|---|---|
| private MergeMode() | |
| valueOf | back to summary |
|---|---|
| public static PyDict. | |
| values | back to summary |
|---|---|
| public static PyDict. | |