Class PySequence

  • All Implemented Interfaces:
    java.io.Serializable
    Direct Known Subclasses:
    AstList, BaseBytes, Py2kBuffer, PyArray, PyBaseString, PyMemoryView, PySequenceList, PyXRange

    public abstract class PySequence
    extends PyObject
    The abstract superclass of PyObjects that implements a Sequence. Minimize the work in creating such objects. Method names are designed to make it possible for subclasses of PySequence to implement java.util.List. Subclasses must also implement get, getslice, and repeat methods. Subclasses that are mutable should also implement: set, setslice, del, and delRange.
    See Also:
    Serialized Form
    • Method Detail

      • __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
      • __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.
      • __finditem__

        public PyObject __finditem__​(int index)
        Description copied from class: PyObject
        A variant of the __finditem__ method which accepts a primitive int as the key. By default, this method will call __finditem__(PyObject key) with the appropriate args. The only reason to override this method is for performance.
        Overrides:
        __finditem__ in class PyObject
        Parameters:
        index - the key to lookup in this sequence.
        Returns:
        the value corresponding to key or null if key is not found.
        See Also:
        PyObject.__finditem__(PyObject)
      • __finditem__

        public PyObject __finditem__​(PyObject index)
        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:
        index - the key to lookup in this container
        Returns:
        the value corresponding to key or null if key is not found
      • __getitem__

        public PyObject __getitem__​(PyObject index)
        Description copied from class: PyObject
        Equivalent to the standard Python __getitem__ method. This method should not be overridden. Override the __finditem__ method instead.
        Overrides:
        __getitem__ in class PyObject
        Parameters:
        index - the key to lookup in this container.
        Returns:
        the value corresponding to that key.
        See Also:
        PyObject.__finditem__(PyObject)
      • __setitem__

        public void __setitem__​(int index,
                                PyObject value)
        Description copied from class: PyObject
        A variant of the __setitem__ method which accepts a primitive int as the key. By default, this will call __setitem__(PyObject key, PyObject value) with the appropriate args. The only reason to override this method is for performance.
        Overrides:
        __setitem__ in class PyObject
        Parameters:
        index - the key whose value will be set
        value - the value to set this key to
        See Also:
        PyObject.__setitem__(PyObject, PyObject)
      • __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 index)
        Description copied from class: PyObject
        Equivalent to the standard Python __delitem__ method.
        Overrides:
        __delitem__ in class PyObject
        Parameters:
        index - the key to be removed from the container
      • __tojava__

        public java.lang.Object __tojava__​(java.lang.Class<?> c)
                                    throws PyIgnoreMethodTag
        Description copied from class: PyObject
        Equivalent to the Jython __tojava__ method. Tries to coerce this object to an instance of the requested Java class. Returns the special object Py.NoConversion if this PyObject can not be converted to the desired Java class.
        Overrides:
        __tojava__ in class PyObject
        Parameters:
        c - the Class to convert this PyObject to.
        Throws:
        PyIgnoreMethodTag