Class PyUtilities


  • public final class PyUtilities
    extends java.lang.Object
    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      static boolean isSequence​(org.python.core.PyObject pyObject)
      Predicate that returns true if the provided object is a sequence, per Java convention - meaning, strings are not considered sequences.
      static boolean isString​(org.python.core.PyObject pyObject)
      Simple predicate that returns true if the provided object is a Python string (ie, inherits from PyBaseString.
      static java.util.stream.Stream<org.python.core.PyObject> stream​(org.python.core.PyObject pyObject)
      Stream items from pyObject.
      static java.util.stream.Stream<org.apache.commons.lang3.tuple.Pair<org.python.core.PyObject,​org.python.core.PyObject>> streamEntries​(org.python.core.PyObject pyObject)
      Stream entries from pyObject, in a key: value Pair.
      static <T> java.util.stream.Collector<T,​java.lang.Object,​org.python.core.PyDictionary> toPyDictionary​(java.util.function.Function<T,​?> keyExtractor, java.util.function.Function<T,​?> valueExtractor)
      Collect a stream of T into a new PyDictionary.
      static java.util.stream.Collector<org.python.core.PyObject,​java.lang.Object,​org.python.core.PyList> toPyList()
      Collect a stream into a new PyList.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Method Detail

      • isString

        public static boolean isString​(org.python.core.PyObject pyObject)
        Simple predicate that returns true if the provided object is a Python string (ie, inherits from PyBaseString.
      • isSequence

        public static boolean isSequence​(org.python.core.PyObject pyObject)
        Predicate that returns true if the provided object is a sequence, per Java convention - meaning, strings are not considered sequences.
      • stream

        public static java.util.stream.Stream<org.python.core.PyObject> stream​(org.python.core.PyObject pyObject)
        Stream items from pyObject. Per Python behavior, will stream characters one-by-one in a string.
        Throws:
        org.python.core.PyException - TypeError if provided PyObject is not iterable.
      • streamEntries

        public static java.util.stream.Stream<org.apache.commons.lang3.tuple.Pair<org.python.core.PyObject,​org.python.core.PyObject>> streamEntries​(org.python.core.PyObject pyObject)
        Stream entries from pyObject, in a key: value Pair.
        Throws:
        org.python.core.PyException - TypeError if provided PyObject is not iterable.
        java.lang.IllegalArgumentException - if provided PyObject is not a mapping type.
      • toPyList

        public static java.util.stream.Collector<org.python.core.PyObject,​java.lang.Object,​org.python.core.PyList> toPyList()
        Collect a stream into a new PyList.
      • toPyDictionary

        public static <T> java.util.stream.Collector<T,​java.lang.Object,​org.python.core.PyDictionary> toPyDictionary​(java.util.function.Function<T,​?> keyExtractor,
                                                                                                                                 java.util.function.Function<T,​?> valueExtractor)
        Collect a stream of T into a new PyDictionary.
        Type Parameters:
        T - The incoming type, eg Map.Entry or Pair.
        Parameters:
        keyExtractor - The key extractor, eg Map.Entry.getKey(). Should not return a PyObject directly.
        valueExtractor - The value extractor, eg Map.Entry.getValue(). Should not return a PyObject directly.
        Returns:
        a new PyDictionary.