Class ShapeVisitor.Builder<R>

  • Type Parameters:
    R - Return value from each case.
    All Implemented Interfaces:
    software.amazon.smithy.utils.SmithyBuilder<ShapeVisitor<R>>
    Enclosing interface:
    ShapeVisitor<R>

    public static final class ShapeVisitor.Builder<R>
    extends java.lang.Object
    implements software.amazon.smithy.utils.SmithyBuilder<ShapeVisitor<R>>
    Creates a ShapeVisitor used to dispatch to functions based on a model type.
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      ShapeVisitor<R> build()  
      ShapeVisitor<R> orElse​(R defaultValue)
      Return a value for all unhandled nodes.
      ShapeVisitor<R> orElseGet​(java.util.function.Function<Shape,​R> f)
      Register a case for unhandled shapes and builds the Cases.
      ShapeVisitor<R> orElseGet​(java.util.function.Supplier<R> f)
      Register a case for unhandled shapes and builds the Cases.
      ShapeVisitor<R> orElseThrow​(java.lang.RuntimeException e)
      Register a case for unhandled shapes that throws an exception.
      <T extends Shape>
      ShapeVisitor.Builder<R>
      when​(java.lang.Class<T> type, java.util.function.Function<T,​R> f)
      Invoked when a specific shape type is encountered.
      • Methods inherited from class java.lang.Object

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

      • build

        public ShapeVisitor<R> build()
        Specified by:
        build in interface software.amazon.smithy.utils.SmithyBuilder<R>
      • orElseGet

        public ShapeVisitor<R> orElseGet​(java.util.function.Function<Shape,​R> f)
        Register a case for unhandled shapes and builds the Cases.
        Parameters:
        f - Function to use for unhandled visitor.
        Returns:
        Returns the built ShapeVisitor
      • orElseGet

        public ShapeVisitor<R> orElseGet​(java.util.function.Supplier<R> f)
        Register a case for unhandled shapes and builds the Cases.
        Parameters:
        f - Supplier to use for unhandled visitor.
        Returns:
        Returns the built ShapeVisitor
      • orElse

        public ShapeVisitor<R> orElse​(R defaultValue)
        Return a value for all unhandled nodes.
        Parameters:
        defaultValue - Default value to return for unhandled visitor.
        Returns:
        Returns the built ShapeVisitor
      • orElseThrow

        public ShapeVisitor<R> orElseThrow​(java.lang.RuntimeException e)
        Register a case for unhandled shapes that throws an exception.
        Parameters:
        e - Exception to throw if an unhandled case is encountered.
        Returns:
        Returns the built ShapeVisitor
      • when

        public <T extends ShapeShapeVisitor.Builder<R> when​(java.lang.Class<T> type,
                                                              java.util.function.Function<T,​R> f)
        Invoked when a specific shape type is encountered.
        Type Parameters:
        T - The shape type being handled.
        Parameters:
        type - Shape type to handle.
        f - Function that accepts the shape and returns R.
        Returns:
        Returns the visitor builder.