Class PyDefaultDict

All Implemented Interfaces:
Serializable, ConcurrentMap, Map, Traverseproc
Direct Known Subclasses:
PyDefaultDictDerived

public class PyDefaultDict extends PyDictionary implements Traverseproc
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.
See Also:
  • Field Details

    • TYPE

      public static final PyType TYPE
  • Constructor Details

    • PyDefaultDict

      public PyDefaultDict()
    • PyDefaultDict

      public PyDefaultDict(PyType subtype)
    • PyDefaultDict

      public PyDefaultDict(PyType subtype, Map<PyObject,PyObject> map)
  • Method Details

    • getMap

      public ConcurrentMap<PyObject,PyObject> getMap()
      Overrides:
      getMap in class PyDictionary
    • __missing__

      public PyObject __missing__(PyObject key)
    • __reduce__

      public PyObject __reduce__()
      Description copied from class: PyObject
      Used for pickling. Default implementation calls object___reduce__.
      Overrides:
      __reduce__ in class PyObject
      Returns:
      a tuple of (class, tuple)
    • copy

      public PyDictionary copy()
      Description copied from class: PyDictionary
      Return a shallow copy of the dictionary.
      Overrides:
      copy in class PyDictionary
    • toString

      public String toString()
      Overrides:
      toString in class PyDictionary
    • getDefaultFactory

      public PyObject getDefaultFactory()
    • setDefaultFactory

      public void setDefaultFactory(PyObject value)
    • delDefaultFactory

      public void delDefaultFactory()
    • __finditem__

      public PyObject __finditem__(PyObject key)
      Description copied from class: PyObject
      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.
      Overrides:
      __finditem__ in class PyDictionary
      Parameters:
      key - the key to lookup in this container
      Returns:
      the value corresponding to key or null if key is not found
    • get

      public PyObject get(PyObject key, PyObject defaultObj)
      Description copied from class: PyDictionary
      Return this[key] if the key exists in the mapping, defaultObj is returned otherwise.
      Overrides:
      get in class PyDictionary
      Parameters:
      key - the key to lookup in the dictionary.
      defaultObj - the value to return if the key does not exists in the mapping.
    • traverse

      public int traverse(Visitproc visit, Object arg)
      Description copied from interface: Traverseproc
      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.
      Specified by:
      traverse in interface Traverseproc
      Overrides:
      traverse in class PyDictionary
    • refersDirectlyTo

      public boolean refersDirectlyTo(PyObject ob)
      Description copied from interface: Traverseproc
      Optional operation. Should only be implemented if it is more efficient than calling Traverseproc.traverse(Visitproc, Object) with a visitproc that just watches out for ob. Must return false if ob is null.
      Specified by:
      refersDirectlyTo in interface Traverseproc
      Overrides:
      refersDirectlyTo in class PyDictionary