Class Controller
- All Implemented Interfaces:
 IController
public class Controller extends java.lang.Object implements IController
IController implementation.
 In PureMVC, the Controller class follows the
 'Command and Controller' strategy, and assumes these
 responsibilities:
-  Remembering which 
ICommands are intended to handle whichINotifications. -  Registering itself as an 
IObserverwith theViewfor eachINotificationthat it has anICommandmapping for. -  Creating a new instance of the proper 
ICommandto handle a givenINotificationwhen notified by theView. -  Calling the 
ICommand'sexecutemethod, passing in theINotification. 
Your application must register ICommands with the
 Controller.
The simplest way is to subclass Facade,
 and use its initializeController method to add your
 registrations.
- See Also:
 View,Observer,Notification,SimpleCommand,MacroCommand
- 
Field Summary
Fields Modifier and Type Field Description protected java.util.concurrent.ConcurrentMap<java.lang.String,java.util.function.Supplier<ICommand>>commandMapprotected static IControllerinstanceprotected java.lang.StringSINGLETON_MSGprotected IViewview - 
Constructor Summary
Constructors Constructor Description Controller()Constructor. - 
Method Summary
Modifier and Type Method Description voidexecuteCommand(INotification notification)If anICommandhas previously been registered to handle a the givenINotification, then it is executed.static IControllergetInstance(java.util.function.Supplier<IController> factory)ControllerSingleton Factory method.booleanhasCommand(java.lang.String notificationName)Check if a Command is registered for a given NotificationvoidinitializeController()Initialize the SingletonControllerinstance.voidregisterCommand(java.lang.String notificationName, java.util.function.Supplier<ICommand> commandSupplier)Register a particularICommandclass as the handler for a particularINotification.voidremoveCommand(java.lang.String notificationName)Remove a previously registeredICommandtoINotificationmapping. 
- 
Field Details
- 
view
 - 
commandMap
protected java.util.concurrent.ConcurrentMap<java.lang.String,java.util.function.Supplier<ICommand>> commandMap - 
instance
 - 
SINGLETON_MSG
protected final java.lang.String SINGLETON_MSG- See Also:
 - Constant Field Values
 
 
 - 
 - 
Constructor Details
- 
Controller
public Controller()Constructor.This
IControllerimplementation is a Singleton, so you should not call the constructor directly, but instead call the static Singleton Factory methodController.getInstance()- Throws:
 java.lang.Error- Error if Singleton instance has already been constructed
 
 - 
 - 
Method Details
- 
initializeController
public void initializeController()Initialize the Singleton
Controllerinstance.Called automatically by the constructor.
Note that if you are using a subclass of
Viewin your application, you should also subclassControllerand override theinitializeControllermethod in the following way:// ensure that the Controller is talking to my IView implementation override public function initializeController( ) : void { view = MyView.getInstance(() -> new MyView()); } - 
getInstance
ControllerSingleton Factory method.- Parameters:
 factory- controller supplier function- Returns:
 - the Singleton instance of 
Controller 
 - 
executeCommand
If an
ICommandhas previously been registered to handle a the givenINotification, then it is executed.- Specified by:
 executeCommandin interfaceIController- Parameters:
 notification- anINotification
 - 
registerCommand
public void registerCommand(java.lang.String notificationName, java.util.function.Supplier<ICommand> commandSupplier)Register a particular
ICommandclass as the handler for a particularINotification.If an
ICommandhas already been registered to handleINotifications with this name, it is no longer used, the newICommandis used instead.The Observer for the new ICommand is only created if this the first time an ICommand has been regisered for this Notification name.
- Specified by:
 registerCommandin interfaceIController- Parameters:
 notificationName- the name of theINotificationcommandSupplier- theClassof theICommand
 - 
removeCommand
public void removeCommand(java.lang.String notificationName)Remove a previously registered
ICommandtoINotificationmapping.- Specified by:
 removeCommandin interfaceIController- Parameters:
 notificationName- the name of theINotificationto remove theICommandmapping for
 - 
hasCommand
public boolean hasCommand(java.lang.String notificationName)Check if a Command is registered for a given Notification
- Specified by:
 hasCommandin interfaceIController- Parameters:
 notificationName- notification name- Returns:
 - whether a Command is currently registered for the given 
notificationName. 
 
 -