Skip to content

Commit

Permalink
Add typed Message.getMessageObserver(Class).
Browse files Browse the repository at this point in the history
Signed-off-by: Achim Kraus <[email protected]>
  • Loading branch information
Achim Kraus committed Feb 4, 2022
1 parent 931b202 commit f0b0a30
Showing 1 changed file with 27 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1308,6 +1308,7 @@ public void setProtectFromOffload() {
* Returns the observers registered for this message.
*
* @return an immutable list of the registered observers.
* @see #getMessageObservers(Class)
* @see #addMessageObserver(MessageObserver)
* @see #addMessageObserver(int, MessageObserver)
* @see #addMessageObservers(List)
Expand All @@ -1321,6 +1322,32 @@ public List<MessageObserver> getMessageObservers() {
}
}

/**
* Returns the observer of the provided type registered for this message.
*
* @param type type of observers
* @return the registered observers of that type, or {@code null}, if not
* available.
* @see #getMessageObservers()
* @see #addMessageObserver(MessageObserver)
* @see #addMessageObserver(int, MessageObserver)
* @see #addMessageObservers(List)
* @see #removeMessageObserver(MessageObserver)
* @since 3.3
*/
@SuppressWarnings("unchecked")
public <T extends MessageObserver> T getMessageObserver(Class<T> type) {
List<MessageObserver> list = unmodifiableMessageObserversFacade;
if (null != list) {
for (MessageObserver obs : list) {
if (type.isInstance(obs)) {
return (T) obs;
}
}
}
return null;
}

/**
* Adds the specified message observer.
*
Expand Down

0 comments on commit f0b0a30

Please sign in to comment.