Class UnexpectedElementException

  • All Implemented Interfaces:
    java.io.Serializable

    public class UnexpectedElementException
    extends java.lang.RuntimeException
    Thrown when attempting to consume a stream element of unexpected types.
    Since:
    0.7.0
    See Also:
    Stream.consume(Stream.ElementType...), Serialized Form
    • Field Summary

      Fields 
      Modifier and Type Field Description
      private Stream.ElementType<?>[] expected
      The array of the expected element types.
      private int position
      The position of the unexpected element in the stream.
      private java.lang.Object unexpected
      The unexpected element in the stream.
    • Constructor Summary

      Constructors 
      Constructor Description
      UnexpectedElementException​(java.lang.Object element, int position, Stream.ElementType<?>... expected)
      Constructs a UnexpectedElementException instance with the unexpected element and the expected types.
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      Stream.ElementType<?>[] getExpectedElementTypes()
      Gets the expected element types.
      int getPosition()
      Gets the position of the unexpected element.
      java.lang.Object getUnexpectedElement()
      Gets the unexpected element.
      java.lang.String toString()
      Returns the string representation of this exception containing the information about the unexpected element and, if available, about the expected types.
      • Methods inherited from class java.lang.Throwable

        addSuppressed, fillInStackTrace, getCause, getLocalizedMessage, getMessage, getStackTrace, getSuppressed, initCause, printStackTrace, printStackTrace, printStackTrace, setStackTrace
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
    • Field Detail

      • unexpected

        private final java.lang.Object unexpected
        The unexpected element in the stream.
      • position

        private final int position
        The position of the unexpected element in the stream.
      • expected

        private final Stream.ElementType<?>[] expected
        The array of the expected element types.
    • Constructor Detail

      • UnexpectedElementException

        UnexpectedElementException​(java.lang.Object element,
                                   int position,
                                   Stream.ElementType<?>... expected)
        Constructs a UnexpectedElementException instance with the unexpected element and the expected types.
        Parameters:
        element - the unexpected element in the stream
        position - the position of the unexpected element
        expected - an array of the expected element types
    • Method Detail

      • getUnexpectedElement

        public java.lang.Object getUnexpectedElement()
        Gets the unexpected element.
        Returns:
        the unexpected element
      • getPosition

        public int getPosition()
        Gets the position of the unexpected element.
        Returns:
        the position of the unexpected element
      • getExpectedElementTypes

        public Stream.ElementType<?>[] getExpectedElementTypes()
        Gets the expected element types.
        Returns:
        an array of expected element types
      • toString

        public java.lang.String toString()
        Returns the string representation of this exception containing the information about the unexpected element and, if available, about the expected types.
        Overrides:
        toString in class java.lang.Throwable
        Returns:
        the string representation of this exception