Module hw06

Class Visitor2

java.lang.Object
provided.basicVisitorFW.visitors.Visitor2
All Implemented Interfaces:
IVisitor

public class Visitor2 extends Object implements IVisitor
A visitor that sets the paint cmd in the VisitorDemoModel to a cmd that draws various shapes. The params is assumed to be a single value, a reference to a function that takes a function that takes a Graphics object. That is, param[0] = a Consumer<Consumer<Graphics>> object. This function will install the given Consumer<Graphics> function into the model. The view calls to the model to use the installed command when painting. When the host is a HostA, the installed Consumer<Graphics> draws a blue oval on the screen. When the host is a HostB, the installed Consumer<Graphics> draws a red rectangle on the screen. When the host is a HostC, the installed Consumer<Graphics> draws a green rounded rectangle on the screen. Returns a string saying what it did.
Author:
swong
  • Constructor Details

    • Visitor2

      public Visitor2()
  • Method Details

    • caseHostA

      public Object caseHostA(HostA host, Object... params)
      Description copied from interface: IVisitor
      Case for HostA
      Specified by:
      caseHostA in interface IVisitor
      Parameters:
      host - The HostA instance
      params - Optional input parameters
      Returns:
      The result of processing HostA with the given parameters.
    • caseHostB

      public Object caseHostB(HostB host, Object... params)
      Description copied from interface: IVisitor
      Case for HostB
      Specified by:
      caseHostB in interface IVisitor
      Parameters:
      host - The HostB instance
      params - Optional input parameters
      Returns:
      The result of processing HostB with the given parameters.
    • caseHostC

      public Object caseHostC(HostC host, Object... params)
      Description copied from interface: IVisitor
      Case for HostC
      Specified by:
      caseHostC in interface IVisitor
      Parameters:
      host - The HostC instance
      params - Optional input parameters
      Returns:
      The result of processing HostC with the given parameters.
    • toString

      public String toString()
      Overrides:
      toString in class Object