Package com.iizix
Class GenericListener<LISTENER_INTERFACE>
java.lang.Object
com.iizix.GenericListener<LISTENER_INTERFACE>
- Direct Known Subclasses:
- ServerConfigFile
Class to handle generic listeners in a thread-safe manner.
- Author:
- Christopher Mindus
- Constructor SummaryConstructors
- Method SummaryModifier and TypeMethodDescription- boolean- addListener- (LISTENER_INTERFACE listener) Adds a new listener.- boolean- clear()Clears all the listeners.- void- forEach- (Consumer<? super LISTENER_INTERFACE> action) Performs the given action for all listeners.- booleanChecks if there are any current listeners.Gets a the listeners array.- boolean- removeListener- (LISTENER_INTERFACE listener) Removes a listener.
- Constructor Details- GenericListenerConstructs the listener.- Parameters:
- clazz- The class instance of the listener interface.
 
 
- Method Details- addListenerAdds a new listener. Calling this method multiple times with the same listener will have no effect (but to return false).- Parameters:
- listener- The listener to add.
- Returns:
- trueif the listener was added,- falseotherwise (nothing changed).
- Throws:
- NullPointerException- If the- listeneris- null.
 
- removeListenerRemoves a listener.- Parameters:
- listener- The listener to remove.
- Returns:
- trueif- listeneris successfully removed,- falseotherwise, i.e. if not previous an added listener instance.
 
- hasListenerspublic boolean hasListeners()Checks if there are any current listeners.- Returns:
- true if listeners are present, false otherwise.
 
- clearpublic boolean clear()Clears all the listeners.- Returns:
- true for cleared, false if no listeners were present.
 
- listenersGets a the listeners array.- Returns:
- A cached array of the listeners (do not modify the array).
 
- forEachPerforms the given action for all listeners. The call to the action is done inside a try-catch and logs potential exceptions.- The default implementation behaves as if: - for ( Listener listener: listeners() ) action.accept(listener);- Parameters:
- action- The action to be performed for each listener.
- Throws:
- NullPointerException- if the specified action is- null.