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

The following examples show how to use java.util.concurrent.CopyOnWriteArrayList#remove() . 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: doRandomGivenPercentMutants.java    From muJava with Apache License 2.0 6 votes vote down vote up
/**
 * Gets the minimal tests.
 * 
 * @param testSets
 *            the test sets
 * @return the minimal tests
 */
private static CopyOnWriteArrayList<ArrayList<String>> getMinimalTests(CopyOnWriteArrayList<ArrayList<String>> testSets) {
	CopyOnWriteArrayList<ArrayList<String>> result = new CopyOnWriteArrayList<>();
	List<ArrayList<String>> testSets2 = new CopyOnWriteArrayList<ArrayList<String>>();
	List<ArrayList<String>> testSets3 = new CopyOnWriteArrayList<ArrayList<String>>();
	testSets2.addAll(testSets);
	testSets3.addAll(testSets);
	for (ArrayList<String> test : testSets3) {
		for (ArrayList<String> test2 : testSets2) {
			if (test.containsAll(test2) && !test2.containsAll(test)) {
				testSets.remove(test);
				testSets2.remove(test);
				testSets3.remove(test);
				System.out.println("remove test "+test);
				break;
			}
		}
	}
	result.addAll(testSets);
	return result;
}
 
Example 2
Source File: LocalTaskLauncher.java    From spring-cloud-deployer-local with Apache License 2.0 6 votes vote down vote up
private void pruneTaskInstanceHistory(String taskDefinitionName, String taskLaunchId) {
	CopyOnWriteArrayList<String> oldTaskInstanceIds = taskInstanceHistory.get(taskDefinitionName);
	if (oldTaskInstanceIds == null) {
		oldTaskInstanceIds = new CopyOnWriteArrayList<>();
		taskInstanceHistory.put(taskDefinitionName, oldTaskInstanceIds);
	}

	for (String oldTaskInstanceId : oldTaskInstanceIds) {
		TaskInstance oldTaskInstance = running.get(oldTaskInstanceId);
		if (oldTaskInstance != null && oldTaskInstance.getState() != LaunchState.running
				&& oldTaskInstance.getState() != LaunchState.launching) {
			running.remove(oldTaskInstanceId);
			oldTaskInstanceIds.remove(oldTaskInstanceId);
		} else {
			oldTaskInstanceIds.remove(oldTaskInstanceId);
		}
	}
	oldTaskInstanceIds.add(taskLaunchId);
}
 
Example 3
Source File: CommandListener.java    From Android-SDK with MIT License 6 votes vote down vote up
public void removeCommandListener( AsyncCallback<Command> callback )
{
  final CopyOnWriteArrayList<T> subscriptionHolder = getSubscriptionHolder();
  for( T messagingSubscription : subscriptionHolder )
  {
    if( messagingSubscription.getCallback().usersCallback() == callback )
    {
      //we can do it because it is CopyOnWriteArrayList so we iterate through the copy
      subscriptionHolder.remove( messagingSubscription );

      if( isConnected() )
      {
        rtClient.unsubscribe( messagingSubscription.getId() );
      }
    }
  }
}
 
Example 4
Source File: Bootstrap.java    From windup with Eclipse Public License 1.0 6 votes vote down vote up
private boolean executePhase(CommandPhase phase, CopyOnWriteArrayList<Command> commands)
{
    for (Command command : commands)
    {
        if (phase.equals(command.getPhase()))
        {
            commands.remove(command);
            if (command instanceof FurnaceDependent)
                ((FurnaceDependent) command).setFurnace(furnace);

            CommandResult result = command.execute();
            if (CommandResult.EXIT.equals(result))
                return false;
        }
    }
    return true;
}
 
Example 5
Source File: Device.java    From neatle with MIT License 6 votes vote down vote up
@Override
@SuppressWarnings("PMD.CompareObjectsWithEquals")
public void removeCharacteristicsChangedListener(UUID characteristicsUUID, CharacteristicsChangedListener listener) {
    boolean checkIdle;
    synchronized (lock) {
        CopyOnWriteArrayList<CharacteristicsChangedListener> list = changeListeners.get(characteristicsUUID);
        if (list != null) {
            list.remove(listener);
            if (list.isEmpty()) {
                changeListeners.remove(characteristicsUUID);
            }
        }
        checkIdle = currentCallback == DO_NOTHING_CALLBACK && queue.isEmpty() && queue.isEmpty();
    }
    if (checkIdle) {
        disconnectOnIdle();
    }
}
 
Example 6
Source File: MQTT_PVConn.java    From phoebus with Eclipse Public License 1.0 6 votes vote down vote up
public void unsubscribeTopic (String topicStr, MQTT_PV pv) throws Exception
{
    if (!connect())
    {
        PV.logger.log(Level.WARNING, "Could not unsubscribe to mqtt topic \"" + topicStr
                + "\" due to no broker connection");
        throw new Exception("MQTT unsubscribe failed: no broker connection");
    }

    final CopyOnWriteArrayList<MQTT_PV> pvs = subscribers.get(topicStr);
    if (pvs == null)
    {
        PV.logger.log(Level.WARNING, "Could not unsubscribe to mqtt topic \"" + topicStr
                + "\" due to no internal record of topic");
        throw new Exception("MQTT unsubscribe failed: no topic record");
    }

    pvs.remove(pv);
    if (pvs.isEmpty())
    {
        subscribers.remove(topicStr);
        myClient.unsubscribe(topicStr);
        if (subscribers.isEmpty())
            disconnect();
    }
}
 
Example 7
Source File: BaseRecycleAdapter.java    From FimiX8-RE with MIT License 6 votes vote down vote up
public void remoteItem(int position) {
    MediaModel mediaModel = (MediaModel) this.modelList.get(position);
    String localPath = mediaModel.getFileLocalPath();
    String formateDate = mediaModel.getFormatDate();
    this.modelNoHeadList.remove(mediaModel);
    this.modelList.remove(mediaModel);
    if (this.stateHashMap != null && localPath != null) {
        CopyOnWriteArrayList<T> internalList = (CopyOnWriteArrayList) this.stateHashMap.get(formateDate);
        if (internalList != null) {
            Iterator it = internalList.iterator();
            while (it.hasNext()) {
                MediaModel cacheModel = (MediaModel) it.next();
                if (cacheModel != null && localPath.equals(cacheModel.getFileLocalPath())) {
                    internalList.remove(cacheModel);
                }
            }
            if (internalList.size() < this.internalListBound) {
                this.modelList.remove(internalList.get(0));
            }
        }
    }
}
 
Example 8
Source File: CopyOnWriteListTest.java    From syncer with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@Test
public void removeVisitedInFor() throws Exception {
  CopyOnWriteArrayList<Integer> l = prepareList();
  int c = l.size();
  for (Integer integer : l) {
    if (integer == 2) {
      l.remove(2 - 1);
    }
    c--;
  }
  Assert.assertEquals(c, 0);
}
 
Example 9
Source File: ColumnTypeDetector.java    From tablesaw with Apache License 2.0 5 votes vote down vote up
/**
 * Returns a predicted ColumnType derived by analyzing the given list of undifferentiated strings
 * read from a column in the file and applying the given Locale and options
 */
private ColumnType detectType(List<String> valuesList, ReadOptions options) {

  CopyOnWriteArrayList<AbstractColumnParser<?>> parsers =
      new CopyOnWriteArrayList<>(getParserList(typeArray, options));

  CopyOnWriteArrayList<ColumnType> typeCandidates = new CopyOnWriteArrayList<>(typeArray);

  boolean hasNonMissingValues = false;

  for (String s : valuesList) {
    for (AbstractColumnParser<?> parser : parsers) {
      if (!parser.isMissing(s)) {
        hasNonMissingValues = true;
        if (!parser.canParse(s)) { // we can skip this test if we know the value is missing
          typeCandidates.remove(parser.columnType());
          parsers.remove(parser);
        }
      }
    }
  }
  if (hasNonMissingValues) {
    return selectType(typeCandidates);
  } else {
    // the last type in the typeArray is the default
    return typeArray.get(typeArray.size() - 1);
  }
}
 
Example 10
Source File: RpcClientInvokerCache.java    From jim-framework with Apache License 2.0 5 votes vote down vote up
public static void removeHandler(RpcClientInvoker handler) {

        CopyOnWriteArrayList<RpcClientInvoker> connectedHandlersClone = getConnectedHandlersClone();
        connectedHandlersClone.remove(handler);
        connectedHandlers=connectedHandlersClone;

        CopyOnWriteArrayList<RpcClientInvoker> notConnectedHandlersClone = getNotConnectedHandlersClone();
        notConnectedHandlersClone.add(handler);
        notConnectedHandlers=notConnectedHandlersClone;
        logger.info("handler removed:localAddress{},remoteAddress{}",handler.getChannel().localAddress(),handler.getChannel().remoteAddress());
    }
 
Example 11
Source File: ColumnTypeDetector.java    From tablesaw with Apache License 2.0 5 votes vote down vote up
/**
 * Returns a predicted ColumnType derived by analyzing the given list of undifferentiated strings
 * read from a column in the file and applying the given Locale and options
 */
private ColumnType detectType(List<String> valuesList, ReadOptions options) {

  CopyOnWriteArrayList<AbstractColumnParser<?>> parsers =
      new CopyOnWriteArrayList<>(getParserList(typeArray, options));

  CopyOnWriteArrayList<ColumnType> typeCandidates = new CopyOnWriteArrayList<>(typeArray);

  boolean hasNonMissingValues = false;

  for (String s : valuesList) {
    for (AbstractColumnParser<?> parser : parsers) {
      if (!parser.isMissing(s)) {
        hasNonMissingValues = true;
        if (!parser.canParse(s)) { // we can skip this test if we know the value is missing
          typeCandidates.remove(parser.columnType());
          parsers.remove(parser);
        }
      }
    }
  }
  if (hasNonMissingValues) {
    return selectType(typeCandidates);
  } else {
    // the last type in the typeArray is the default
    return typeArray.get(typeArray.size() - 1);
  }
}
 
Example 12
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 13
Source File: CopyOnWriteListTest.java    From syncer with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@Test
public void removeCurrentInFor() throws Exception {
  CopyOnWriteArrayList<Integer> l = prepareList();
  int c = l.size();
  for (Integer integer : l) {
    if (integer == 2) {
      l.remove(2);
    }
    c--;
  }
  Assert.assertEquals(c, 0);
}
 
Example 14
Source File: UnwrappedWeakReferenceTest.java    From cloudhopper-commons with Apache License 2.0 5 votes vote down vote up
@Test
public void usage() throws Exception {
    Object o = new Object();
    
    // verify WeakReference does not work correctly with CopyOnWriteArrayList
    WeakReference ref0 = new WeakReference(o);
    WeakReference ref1 = new WeakReference(o);
    CopyOnWriteArrayList<WeakReference> cowal = new CopyOnWriteArrayList<WeakReference>();
    cowal.addIfAbsent(ref0);
    cowal.addIfAbsent(ref1);
    
    // if it didn't work, size is 2
    Assert.assertEquals(2, cowal.size());
    
    // use our impl now
    ref0 = new UnwrappedWeakReference(o);
    ref1 = new UnwrappedWeakReference(o);
    cowal = new CopyOnWriteArrayList<WeakReference>();
    cowal.addIfAbsent(ref0);
    cowal.addIfAbsent(ref1);
    
    Assert.assertEquals(1, cowal.size());
    
    Assert.assertTrue(cowal.contains(ref0));
    
    cowal.remove(ref1);
    
    Assert.assertEquals(0, cowal.size());
}
 
Example 15
Source File: Solution.java    From JavaRushTasks with MIT License 5 votes vote down vote up
public static void main(String... args) {    //it's correct line
    CopyOnWriteArrayList<String> list = new CopyOnWriteArrayList();
    list.add("A");
    list.add("B");
    list.add("C");
    list.remove("B");
    List<String> collection = Arrays.asList(new String[]{"B", "C", "D", "B"});

    list.addAllAbsent(collection);

    for (String string : list) {
        System.out.println(string);
    }
}
 
Example 16
Source File: PluginPackageManagerNative.java    From Neptune with Apache License 2.0 5 votes vote down vote up
@Override
public void onActionComplete(PluginLiteInfo info, int resultCode) throws RemoteException {
    String pkgName = info.packageName;
    PluginDebugLog.installFormatLog(TAG, "onActionComplete with %s, resultCode: %d", pkgName, resultCode);
    if (sActionMap.containsKey(pkgName)) {
        final CopyOnWriteArrayList<Action> actions = sActionMap.get(pkgName);
        if (actions == null) {
            return;
        }

        synchronized (actions) {  // Action列表加锁同步
            PluginDebugLog.installFormatLog(TAG, "%s has %d action in list!", pkgName, actions.size());
            if (actions.size() > 0) {
                Action finishedAction = actions.remove(0);
                if (finishedAction != null) {
                    PluginDebugLog.installFormatLog(TAG,
                            "get and remove first action:%s ", finishedAction.toString());
                }

                if (actions.isEmpty()) {
                    PluginDebugLog.installFormatLog(TAG,
                            "onActionComplete remove empty action list of %s", pkgName);
                    sActionMap.remove(pkgName);
                } else {
                    // 执行下一个Action操作,不能同步,否则容易出现栈溢出
                    executeNextAction(actions, pkgName);
                }
            }
        }
    }
}
 
Example 17
Source File: PluginPackageManagerNative.java    From Neptune with Apache License 2.0 5 votes vote down vote up
/**
 * 执行等待中的Action
 */
private static void executePendingAction() {
    PluginDebugLog.runtimeLog(TAG, "executePendingAction start....");
    for (Map.Entry<String, CopyOnWriteArrayList<Action>> entry : sActionMap.entrySet()) {
        if (entry != null) {
            final CopyOnWriteArrayList<Action> actions = entry.getValue();
            if (actions == null) {
                continue;
            }

            synchronized (actions) {  // Action列表加锁同步
                PluginDebugLog.installFormatLog(TAG, "execute %d pending actions!", actions.size());
                Iterator<Action> iterator = actions.iterator();
                while (iterator.hasNext()) {
                    Action action = iterator.next();
                    if (action.meetCondition()) {
                        PluginDebugLog.installFormatLog(TAG, "start doAction for pending action %s", action.toString());
                        action.doAction();
                        break;
                    } else {
                        PluginDebugLog.installFormatLog(TAG, "remove deprecate pending action from action list for %s", action.toString());
                        actions.remove(action);  // CopyOnWriteArrayList在遍历过程中不能使用iterator删除元素
                    }
                }
            }
        }
    }
}
 
Example 18
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 19
Source File: BaseRecycleAdapter.java    From FimiX8-RE with MIT License 5 votes vote down vote up
public void updateDeleteItem(int position) {
    MediaModel mediaModel = (MediaModel) this.modelList.get(position);
    if (mediaModel != null) {
        String formateDate = mediaModel.getFormatDate();
        String localPath = mediaModel.getFileLocalPath();
        this.modelList.remove(position);
        notifyItemRemoved(position);
        if (!(this.stateHashMap == null || localPath == null)) {
            CopyOnWriteArrayList<T> internalList = (CopyOnWriteArrayList) this.stateHashMap.get(formateDate);
            if (internalList != null) {
                Iterator it = internalList.iterator();
                while (it.hasNext()) {
                    MediaModel cacheModel = (MediaModel) it.next();
                    if (cacheModel != null && localPath.equals(cacheModel.getFileLocalPath())) {
                        internalList.remove(cacheModel);
                    }
                }
                if (internalList.size() < this.internalListBound) {
                    if (internalList.size() < this.internalListBound) {
                        if (position - 1 < this.modelList.size()) {
                            this.modelList.remove(position - 1);
                            notifyItemRemoved(position - 1);
                            notifyItemRangeRemoved(position, this.modelList.size() - position);
                        } else {
                            this.modelList.remove(this.modelList.size() - 1);
                            notifyItemRemoved(this.modelList.size() - 1);
                        }
                    }
                    judgeIsNoData();
                    return;
                }
            }
        }
        judgeIsNoData();
        notifyItemRangeRemoved(position, this.modelList.size() - position);
    }
}
 
Example 20
Source File: RTServiceImpl.java    From Android-SDK with MIT License 4 votes vote down vote up
private <T extends Result> void removeEventListeners( T callback, CopyOnWriteArrayList<T> listeners )
{
  listeners.remove( callback );
}