Java Code Examples for java.util.concurrent.CopyOnWriteArrayList#contains()

The following examples show how to use java.util.concurrent.CopyOnWriteArrayList#contains() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ObserverManager.java    From android-downloader with Apache License 2.0 6 votes vote down vote up
/**
 * 给某一个任务注册一个监听器
 *
 * @param taskId
 *         任务ID
 * @param observer
 *         监听器
 */
@Override
public void registerObserver(String taskId, Observer observer) {
    CopyOnWriteArrayList<Observer> observerList;
    if (taskObservers.containsKey(taskId)) {
        observerList = taskObservers.get(taskId);
        if (observerList == null) {
            observerList = new CopyOnWriteArrayList<>();
        }
    } else {
        observerList = new CopyOnWriteArrayList<>();
    }
    if (observerList.contains(observer)) {
        return;
    }
    observerList.add(observer);
    taskObservers.put(taskId, observerList);
}
 
Example 2
Source File: SubsciberMethodHunter.java    From AndroidEventBus with Apache License 2.0 6 votes vote down vote up
/**
 * 按照EventType存储订阅者列表,这里的EventType就是事件类型,一个事件对应0到多个订阅者.
 * 
 * @param event 事件
 * @param method 订阅方法对象
 * @param subscriber 订阅者
 */
private void subscibe(EventType event, TargetMethod method, Object subscriber) {
    CopyOnWriteArrayList<Subscription> subscriptionLists = mSubcriberMap.get(event);
    if (subscriptionLists == null) {
        subscriptionLists = new CopyOnWriteArrayList<Subscription>();
    }

    Subscription newSubscription = new Subscription(subscriber, method);
    if (subscriptionLists.contains(newSubscription)) {
        return;
    }

    subscriptionLists.add(newSubscription);
    // 将事件类型key和订阅者信息存储到map中
    mSubcriberMap.put(event, subscriptionLists);
}
 
Example 3
Source File: DriverManager.java    From dragonwell8_jdk with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Removes the specified driver from the {@code DriverManager}'s list of
 * registered drivers.
 * <p>
 * If a {@code null} value is specified for the driver to be removed, then no
 * action is taken.
 * <p>
 * If a security manager exists and its {@code checkPermission} denies
 * permission, then a {@code SecurityException} will be thrown.
 * <p>
 * If the specified driver is not found in the list of registered drivers,
 * then no action is taken.  If the driver was found, it will be removed
 * from the list of registered drivers.
 * <p>
 * If a {@code DriverAction} instance was specified when the JDBC driver was
 * registered, its deregister method will be called
 * prior to the driver being removed from the list of registered drivers.
 *
 * @param driver the JDBC Driver to remove
 * @exception SQLException if a database access error occurs
 * @throws SecurityException if a security manager exists and its
 * {@code checkPermission} method denies permission to deregister a driver.
 *
 * @see SecurityManager#checkPermission
 */
@CallerSensitive
public static synchronized void deregisterDriver(Driver driver)
    throws SQLException {
    if (driver == null) {
        return;
    }

    SecurityManager sec = System.getSecurityManager();
    if (sec != null) {
        sec.checkPermission(DEREGISTER_DRIVER_PERMISSION);
    }

    println("DriverManager.deregisterDriver: " + driver);

    DriverInfo aDriver = new DriverInfo(driver, null);
    CopyOnWriteArrayList<DriverInfo> drivers = getRegisteredDrivers();
    if (drivers.contains(aDriver)) {
        if (isDriverAllowed(driver, Reflection.getCallerClass())) {
            DriverInfo di = drivers.get(drivers.indexOf(aDriver));
             // If a DriverAction was specified, Call it to notify the
             // driver that it has been deregistered
             if(di.action() != null) {
                 di.action().deregister();
             }
             drivers.remove(aDriver);
        } else {
            // If the caller does not have permission to load the driver then
            // throw a SecurityException.
            throw new SecurityException();
        }
    } else {
        println("    couldn't find driver to unload");
    }
}
 
Example 4
Source File: ObserverManager.java    From android-downloader with Apache License 2.0 5 votes vote down vote up
/**
 * 给某一个任务移除某一个监听器
 *
 * @param taskId
 *         任务ID
 * @param observer
 *         监听器
 */
@Override
public void removeObserver(String taskId, Observer observer) {
    if (taskObservers.containsKey(taskId)) {
        CopyOnWriteArrayList<Observer> observerList = taskObservers.get(taskId);
        if (observerList != null && observerList.contains(observer)) {
            observerList.remove(observer);
        }
    }
}
 
Example 5
Source File: Device.java    From neatle with MIT License 5 votes vote down vote up
@Override
public void addCharacteristicsChangedListener(UUID characteristicsUUID, CharacteristicsChangedListener listener) {
    synchronized (lock) {
        CopyOnWriteArrayList<CharacteristicsChangedListener> list = changeListeners.get(characteristicsUUID);
        if (list == null) {
            list = new CopyOnWriteArrayList<>();
            list.add(listener);
            changeListeners.put(characteristicsUUID, list);
        } else if (!list.contains(listener)) {
            list.add(listener);
        }
    }
}
 
Example 6
Source File: XulSubscriberMethodHunter.java    From starcor.xul with GNU Lesser General Public License v3.0 5 votes vote down vote up
/**
 * 按照MessageType存储订阅者列表,这里的MessageType就是消息类型,一个消息对应0到多个订阅者.
 *
 * @param xulMessage   消息
 * @param subscription 订阅者对象
 */
private void subscribe(XulMessage xulMessage, XulSubscription subscription) {
    CopyOnWriteArrayList<XulSubscription> xulSubscriptionLists = _subscriberMap.get(xulMessage);
    if (xulSubscriptionLists == null) {
        xulSubscriptionLists = new CopyOnWriteArrayList<XulSubscription>();
    }

    if (xulSubscriptionLists.contains(subscription)) {
        return;
    }

    xulSubscriptionLists.add(subscription);
    // 将消息类型key和订阅者信息存储到map中
    _subscriberMap.put(xulMessage, xulSubscriptionLists);
}