Class PyDeque

  • All Implemented Interfaces:
    java.io.Serializable, Traverseproc
    Direct Known Subclasses:
    PyDequeDerived

    public class PyDeque
    extends PyObject
    implements Traverseproc
    PyDeque - This class implements the functionalities of Deque data structure. Deques are a generalization of stacks and queues (the name is pronounced 'deck' and is short for 'double-ended queue'). Deques support thread-safe, memory efficient appends and pops from either side of the deque with approximately the same O(1) performance in either direction. Though list objects support similar operations, they are optimized for fast fixed-length operations and incur O(n) memory movement costs for pop(0) and insert(0, v) operations which change both the size and position of the underlying data representation. collections.deque([iterable[, maxlen]]) - returns a new deque object initialized left-to-right (using append()) with data from iterable. If iterable is not specified, the new deque is empty. If maxlen is not specified or is None, deques may grow to an arbitrary length. Otherwise, the deque is bounded to the specified maximum length. Once a bounded length deque is full, when new items are added, a corresponding number of items are discarded from the opposite end.
    See Also:
    Serialized Form
    • Field Detail

      • TYPE

        public static final PyType TYPE
    • Constructor Detail

      • PyDeque

        public PyDeque()
      • PyDeque

        public PyDeque​(PyType subType)
    • Method Detail

      • deque___init__

        public final void deque___init__​(PyObject[] args,
                                         java.lang.String[] kwds)
      • getMaxlen

        public PyObject getMaxlen()
        If maxlen is not specified or is None, deques may grow to an arbitrary length. Otherwise, the deque is bounded to the specified maximum length.
      • setMaxlen

        public void setMaxlen​(PyObject o)
      • deque_append

        public final void deque_append​(PyObject obj)
        Add obj to the right side of the deque.
      • deque_appendleft

        public final void deque_appendleft​(PyObject obj)
        Add obj to the left side of the deque.
      • deque_clear

        public final void deque_clear()
        Remove all elements from the deque leaving it with length 0.
      • deque_extend

        public final void deque_extend​(PyObject iterable)
        Extend the right side of the deque by appending elements from the iterable argument.
      • deque_extendleft

        public final void deque_extendleft​(PyObject iterable)
        Extend the left side of the deque by appending elements from iterable. Note, the series of left appends results in reversing the order of elements in the iterable argument.
      • deque_pop

        public final PyObject deque_pop()
        Remove and return an element from the right side of the deque. If no elements are present, raises an IndexError.
      • deque_popleft

        public final PyObject deque_popleft()
        Remove and return an element from the left side of the deque. If no elements are present, raises an IndexError.
      • deque_remove

        public final PyObject deque_remove​(PyObject value)
        Removed the first occurrence of value. If not found, raises a ValueError.
      • deque_count

        public final PyObject deque_count​(PyObject x)
        Count the number of deque elements equal to x.
      • deque_rotate

        public final void deque_rotate​(int steps)
        Rotate the deque n steps to the right. If n is negative, rotate to the left. Rotating one step to the right is equivalent to: d.appendleft(d.pop()).
      • deque_reverse

        public final PyObject deque_reverse()
        Reverse the elements of the deque in-place and then return None.
        Returns:
        Py.None
      • toString

        public java.lang.String toString()
        Overrides:
        toString in class PyObject
      • __len__

        public int __len__()
        Description copied from class: PyObject
        Equivalent to the standard Python __len__ method. Part of the mapping discipline.
        Overrides:
        __len__ in class PyObject
        Returns:
        the length of the object
      • __nonzero__

        public boolean __nonzero__()
        Description copied from class: PyObject
        Equivalent to the standard Python __nonzero__ method. Returns whether of not a given PyObject is considered true.
        Overrides:
        __nonzero__ in class PyObject
      • __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 PyObject
        Parameters:
        key - the key to lookup in this container
        Returns:
        the value corresponding to key or null if key is not found
      • __setitem__

        public void __setitem__​(PyObject index,
                                PyObject value)
        Description copied from class: PyObject
        Equivalent to the standard Python __setitem__ method.
        Overrides:
        __setitem__ in class PyObject
        Parameters:
        index - the key whose value will be set
        value - the value to set this key to
      • __delitem__

        public void __delitem__​(PyObject key)
        Description copied from class: PyObject
        Equivalent to the standard Python __delitem__ method.
        Overrides:
        __delitem__ in class PyObject
        Parameters:
        key - the key to be removed from the container
      • __iter__

        public PyObject __iter__()
        Description copied from class: PyObject
        Return an iterator that is used to iterate the element of this sequence. From version 2.2, this method is the primary protocol for looping over sequences.

        If a PyObject subclass should support iteration based in the __finditem__() method, it must supply an implementation of __iter__() like this:

         public PyObject __iter__() {
             return new PySequenceIter(this);
         }
         
        When iterating over a python sequence from java code, it should be done with code like this:
         for (PyObject item : seq.asIterable()) {
             // Do somting with item
         }
         
        Overrides:
        __iter__ in class PyObject
      • __eq__

        public PyObject __eq__​(PyObject o)
        Description copied from class: PyObject
        Equivalent to the standard Python __eq__ method.
        Overrides:
        __eq__ in class PyObject
        Parameters:
        o - the object to compare this with.
        Returns:
        the result of the comparison.
      • __ne__

        public PyObject __ne__​(PyObject o)
        Description copied from class: PyObject
        Equivalent to the standard Python __ne__ method.
        Overrides:
        __ne__ in class PyObject
        Parameters:
        o - the object to compare this with.
        Returns:
        the result of the comparison.
      • __lt__

        public PyObject __lt__​(PyObject o)
        Description copied from class: PyObject
        Equivalent to the standard Python __lt__ method.
        Overrides:
        __lt__ in class PyObject
        Parameters:
        o - the object to compare this with.
        Returns:
        the result of the comparison.
      • __le__

        public PyObject __le__​(PyObject o)
        Description copied from class: PyObject
        Equivalent to the standard Python __le__ method.
        Overrides:
        __le__ in class PyObject
        Parameters:
        o - the object to compare this with.
        Returns:
        the result of the comparison.
      • __gt__

        public PyObject __gt__​(PyObject o)
        Description copied from class: PyObject
        Equivalent to the standard Python __gt__ method.
        Overrides:
        __gt__ in class PyObject
        Parameters:
        o - the object to compare this with.
        Returns:
        the result of the comparison.
      • __ge__

        public PyObject __ge__​(PyObject o)
        Description copied from class: PyObject
        Equivalent to the standard Python __ge__ method.
        Overrides:
        __ge__ in class PyObject
        Parameters:
        o - the object to compare this with.
        Returns:
        the result of the comparison.
      • __iadd__

        public PyObject __iadd__​(PyObject o)
        Description copied from class: PyObject
        Equivalent to the standard Python __iadd__ method.
        Overrides:
        __iadd__ in class PyObject
        Parameters:
        o - the object to perform this binary operation with (the right-hand operand).
        Returns:
        the result of the iadd, or null if this operation is not defined
      • __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)
      • refersDirectlyTo

        public boolean refersDirectlyTo​(PyObject ob)
                                 throws java.lang.UnsupportedOperationException
        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
        Throws:
        java.lang.UnsupportedOperationException