Top Description Inners Fields Constructors Methods
org.python.modules._collections

public Class PyDefaultDict

extends PyDictionary
implements Traverseproc
Class Inheritance
All Implemented Interfaces
org.python.core.Traverseproc
Known Direct Subclasses
org.python.modules._collections.PyDefaultDictDerived
Annotations
@ExposedType
name:collections.defaultdict
Imports
java.util.Map, java.util.concurrent.ConcurrentMap, com.google.common.cache.CacheBuilder, .CacheLoader, .LoadingCache, org.python.core.BuiltinDocs, .Py, .PyDictionary, .PyException, .PyObject, .PyTuple, .PyType, .Traverseproc, .Visitproc, org.python.expose.ExposedDelete, .ExposedGet, .ExposedMethod, .ExposedNew, .ExposedSet, .ExposedType

PyDefaultDict - This is a subclass of the builtin dict(PyDictionary) class. It supports one additional method __missing__ and adds one writable instance variable defaultFactory. The remaining functionality is the same as for the dict class. collections.defaultdict([defaultFactory[, ...]]) - returns a new dictionary-like object. The first argument provides the initial value for the defaultFactory attribute; it defaults to None. All remaining arguments are treated the same as if they were passed to the dict constructor, including keyword arguments.

Nested and Inner Type Summary

Modifier and TypeClass and Description
private static class

Field Summary

Modifier and TypeField and Description
private final LoadingCache<PyObject, PyObject>
private PyObject
defaultFactory

This attribute is used by the __missing__ method; it is initialized from the first argument to the constructor, if present, or to None, if absent.

public static final PyType

Constructor Summary

AccessConstructor and Description
public
public
public

Method Summary

Modifier and TypeMethod and Description
public PyObject
__finditem__(PyObject
the key to lookup in this container
key
)

Overrides org.python.core.PyDictionary.__finditem__.

Very similar to the standard Python __getitem__ method.

public PyObject
public PyObject
__reduce__()

Overrides org.python.core.PyObject.__reduce__.

Used for pickling.

public PyDictionary
copy()

Overrides org.python.core.PyDictionary.copy.

Return a shallow copy of the dictionary.

protected final PyObject
pack-priv final void
pack-priv final PyObject
defaultdict___missing__(PyObject key)

This method does NOT call __setitem__ instead it relies on the fact that it is called within the context of `CacheLoader#load` to actually insert the value into the dict.

pack-priv final PyObject
pack-priv final PyDefaultDict
pack-priv final String
public void
public PyObject
get(PyObject
the key to lookup in the dictionary.
key
,
PyObject
the value to return if the key does not exists in the mapping.
defaultObj
)

Overrides org.python.core.PyDictionary.get.

Return this[key] if the key exists in the mapping, defaultObj is returned otherwise.

public PyObject
public ConcurrentMap<PyObject, PyObject>
public boolean
public void
public String
toString()

Overrides org.python.core.PyDictionary.toString.

Returns a string representation of the object.

public int
traverse(Visitproc visit, Object arg)

Overrides org.python.core.PyDictionary.traverse.

Implements org.python.core.Traverseproc.traverse.

Traverses all directly contained PyObjects.

Inherited from org.python.core.PyDictionary:
__cmp____contains____delitem____eq____finditem____iter____len____ne____nonzero____setitem__clearcontainsKeycontainsValuedict___getitem__dict___init__entrySetequalsfromkeysfromkeysgetgethas_keyhashCodeisEmptyisMappingTypeisSequenceTypeitemsiteritemsiterkeysitervalueskeyskeySetmergemergeFromKeysmergeFromSeqpoppoppopitemputputAllputIfAbsentpyKeySetremoveremovereplacereplacesetdefaultsetdefaultsizeupdateupdateCommonvaluesviewitemsviewkeysviewvalues

Field Detail

backingMapback to summary
private final LoadingCache<PyObject, PyObject> backingMap
defaultFactoryback to summary
private PyObject defaultFactory

This attribute is used by the __missing__ method; it is initialized from the first argument to the constructor, if present, or to None, if absent.

TYPEback to summary
public static final PyType TYPE

Hides org.python.core.PyDictionary.TYPE.

Constructor Detail

PyDefaultDictback to summary
public PyDefaultDict()
PyDefaultDictback to summary
public PyDefaultDict(PyType subtype)
PyDefaultDictback to summary
public PyDefaultDict(PyType subtype, Map<PyObject, PyObject> map)

Method Detail

__finditem__back to summary
public PyObject __finditem__(PyObject key)

Overrides org.python.core.PyDictionary.__finditem__.

Doc from org.python.core.PyObject.__finditem__.

Very similar to the standard Python __getitem__ method. Instead of throwing a KeyError if the item isn't found, this just returns null. Classes that wish to implement __getitem__ should override this method instead (with the appropriate semantics.

Parameters
key:PyObject

the key to lookup in this container

Returns:PyObject

the value corresponding to key or null if key is not found

Annotations
@Override

__missing__back to summary
public PyObject __missing__(PyObject key)
__reduce__back to summary
public PyObject __reduce__()

Overrides org.python.core.PyObject.__reduce__.

Doc from org.python.core.PyObject.__reduce__.

Used for pickling. Default implementation calls object___reduce__.

Returns:PyObject

a tuple of (class, tuple)

Annotations
@Override

copyback to summary
public PyDictionary copy()

Overrides org.python.core.PyDictionary.copy.

Doc from org.python.core.PyDictionary.copy.

Return a shallow copy of the dictionary.

Annotations
@Override
defaultdict___getitem__back to summary
protected final PyObject defaultdict___getitem__(PyObject key)
Annotations
@ExposedMethod
doc:x.__getitem__(y) <==> x[y]
defaultdict___init__back to summary
pack-priv final void defaultdict___init__(PyObject[] args, String[] kwds)
Annotations
@ExposedMethod
@ExposedNew
defaultdict___missing__back to summary
pack-priv final PyObject defaultdict___missing__(PyObject key)

This method does NOT call __setitem__ instead it relies on the fact that it is called within the context of `CacheLoader#load` to actually insert the value into the dict.

Annotations
@ExposedMethod
defaultdict___reduce__back to summary
pack-priv final PyObject defaultdict___reduce__()
Annotations
@ExposedMethod
defaultdict_copyback to summary
pack-priv final PyDefaultDict defaultdict_copy()
Annotations
@ExposedMethod
names:copy, __copy__
defaultdict_toStringback to summary
pack-priv final String defaultdict_toString()
Annotations
@ExposedMethod
names:__repr__
delDefaultFactoryback to summary
public void delDefaultFactory()
Annotations
@ExposedDelete
name:default_factory
getback to summary
public PyObject get(PyObject key, PyObject defaultObj)

Overrides org.python.core.PyDictionary.get.

Doc from org.python.core.PyDictionary.get.

Return this[key] if the key exists in the mapping, defaultObj is returned otherwise.

Parameters
key:PyObject

the key to lookup in the dictionary.

defaultObj:PyObject

the value to return if the key does not exists in the mapping.

getDefaultFactoryback to summary
public PyObject getDefaultFactory()
Annotations
@ExposedGet
name:default_factory
getMapback to summary
public ConcurrentMap<PyObject, PyObject> getMap()

Overrides org.python.core.PyDictionary.getMap.

refersDirectlyToback to summary
public boolean refersDirectlyTo(PyObject ob)

Overrides org.python.core.PyDictionary.refersDirectlyTo.

Implements org.python.core.Traverseproc.refersDirectlyTo.

Doc from org.python.core.Traverseproc.refersDirectlyTo.

Optional operation. Should only be implemented if it is more efficient than calling traverse(Visitproc, Object) with a visitproc that just watches out for ob. Must return false if ob is null.

Annotations
@Override
setDefaultFactoryback to summary
public void setDefaultFactory(PyObject value)
Annotations
@ExposedSet
name:default_factory
toStringback to summary
public String toString()

Overrides org.python.core.PyDictionary.toString.

Doc from java.lang.Object.toString.

Returns a string representation of the object. Satisfying this method's contract implies a non-null result must be returned.

Returns:String

a string representation of the object

Annotations
@Override

traverseback to summary
public int traverse(Visitproc visit, Object arg)

Overrides org.python.core.PyDictionary.traverse.

Implements org.python.core.Traverseproc.traverse.

Doc from org.python.core.Traverseproc.traverse.

Traverses all directly contained PyObjects. Like in CPython, arg must be passed unmodified to visit as its second parameter. If Visitproc#visit(PyObject, Object) returns nonzero, this return value must be returned immediately by traverse. Visitproc#visit(PyObject, Object) must not be called with a null PyObject-argument.

Annotations
@Override
org.python.modules._collections back to summary

private Class PyDefaultDict.MissingThrownException

extends RuntimeException
Class Inheritance

Field Summary

Modifier and TypeField and Description
pack-priv final RuntimeException

Constructor Summary

AccessConstructor and Description
pack-priv

Field Detail

thrownByMissingback to summary
pack-priv final RuntimeException thrownByMissing

Constructor Detail

MissingThrownExceptionback to summary
pack-priv MissingThrownException(RuntimeException thrownByMissing)