public class NotificationFilterSupport extends Object implements NotificationFilter
NotificationFilter
接口的实现。在通知类型属性上进行过滤。
管理已启用的通知类型的列表。一种方法允许用户启用/禁用所需的许多通知类型。
然后,在向注册一个筛选器的侦听器发送通知之前,通知广播器将此通知类型与由该筛选器启用的所有通知类型进行比较。只有当它的筛选器允许此通知类型时,才向侦听器发送通知。
例子:
听者NotificationFilterSupport myFilter = new NotificationFilterSupport(); myFilter.enableType("my_example.my_type"); myBroadcaster.addListener(myListener, myFilter, null);
myListener
只会收到通知,其类型为/启动“my_example。my_type”。
Constructor and Description |
---|
NotificationFilterSupport() |
Modifier and Type | Method and Description |
---|---|
void |
disableAllTypes()
禁用所有通知类型。
|
void |
disableType(String prefix)
从前缀列表中移除给定的前缀。
|
void |
enableType(String prefix)
启用所有通知类型,其中的类型将从指定的前缀发送到侦听器开始。
|
Vector<String> |
getEnabledTypes()
获取此筛选器的所有已启用的通知类型。
|
boolean |
isNotificationEnabled(Notification notification)
在向侦听器发送指定的通知之前调用。
|
public boolean isNotificationEnabled(Notification notification)
true
。
isNotificationEnabled
接口
NotificationFilter
notification
的通知送达。
true
如果通知应发送给听众,
false
否则。
public void enableType(String prefix) throws IllegalArgumentException
例子:
注意:// Enables all notifications the type of which starts with "my_example" to be sent. myFilter.enableType("my_example"); // Enables all notifications the type of which is "my_example.my_type" to be sent. myFilter.enableType("my_example.my_type");
myFilter.enableType("my_example.*");
将没有任何通知类型匹配。
prefix
-前缀。
IllegalArgumentException
-前缀参数为空。
public void disableType(String prefix)
prefix
-前缀。
public void disableAllTypes()
Submit a bug or feature
For further API reference and developer documentation, see Java SE Documentation. That documentation contains more detailed, developer-targeted descriptions, with conceptual overviews, definitions of terms, workarounds, and working code examples.
Copyright © 1993, 2014, Oracle and/or its affiliates. All rights reserved.