Example usage for java.util List removeAll

List of usage examples for java.util List removeAll

Introduction

In this page you can find the example usage for java.util List removeAll.

Prototype

boolean removeAll(Collection<?> c);

Source Link

Document

Removes from this list all of its elements that are contained in the specified collection (optional operation).

Usage

From source file:io.milton.http.annotated.AnnotationResourceFactory.java

/**
 * Removes the LockHolder from memory and also from the parent which
 * contains it (if loaded)//from w w w.j  a va2 s.co  m
 *
 * @param parent
 * @param name
 */
public void removeLockHolder(AnnoCollectionResource parent, String name) {
    List<LockHolder> list = getTempResourcesForParent(parent);
    Iterator<LockHolder> it = list.iterator();
    List<LockHolder> toRemove = new ArrayList<LockHolder>();
    while (it.hasNext()) {
        LockHolder o = it.next();
        if (o.getName().equals(name)) {
            toRemove.add(o);
            //it.remove();
        }
    }
    list.removeAll(toRemove);
    parent.removeLockHolder(name);
}

From source file:com.google.i18n.addressinput.common.FormatInterpreter.java

private void applyFieldOrderOverrides(String regionCode, List<AddressField> fieldOrder) {
    List<AddressField> customFieldOrder = formOptions.getCustomFieldOrder(regionCode);
    if (customFieldOrder == null) {
        return;// www  .  j av a2  s .  c  o m
    }

    // We can assert that fieldOrder and customFieldOrder contain no duplicates.
    // We know this by the construction above and in FormOptions but we still have to think
    // about fields in the custom ordering which aren't visible (the loop below will fail if
    // a non-visible field appears in the custom ordering). However in that case it's safe to
    // just ignore the extraneous field.
    Set<AddressField> nonVisibleCustomFields = EnumSet.copyOf(customFieldOrder);
    nonVisibleCustomFields.removeAll(fieldOrder);
    if (nonVisibleCustomFields.size() > 0) {
        // Local mutable copy to remove non visible fields - this shouldn't happen often.
        customFieldOrder = new ArrayList<AddressField>(customFieldOrder);
        customFieldOrder.removeAll(nonVisibleCustomFields);
    }
    // It is vital for this loop to work correctly that every element in customFieldOrder
    // appears in fieldOrder exactly once.
    for (int fieldIdx = 0, customIdx = 0; fieldIdx < fieldOrder.size(); fieldIdx++) {
        if (customFieldOrder.contains(fieldOrder.get(fieldIdx))) {
            fieldOrder.set(fieldIdx, customFieldOrder.get(customIdx++));
        }
    }
}

From source file:com.microsoft.alm.plugin.idea.tfvc.core.TFSCheckinEnvironment.java

@Nullable
public List<VcsException> scheduleUnversionedFilesForAddition(final List<VirtualFile> files) {
    // TODO: schedule parent folders? (Jetbrains)
    final List<VcsException> exceptions = new ArrayList<VcsException>();
    try {/*  ww  w .j  a  v a 2s  . com*/
        final List<String> filesToAddPaths = new ArrayList<String>(files.size());
        for (final VirtualFile file : files) {
            filesToAddPaths.add(file.getPath());
        }
        final List<String> successfullyAdded = CommandUtils.addFiles(myVcs.getServerContext(false),
                filesToAddPaths);

        // mark files as dirty so that they refresh in local changes tab
        for (final String path : successfullyAdded) {
            final VirtualFile file = VersionControlPath.getVirtualFile(path);
            if (file != null && file.isValid()) {
                TfsFileUtil.markFileDirty(myVcs.getProject(), file);
            }
        }

        //check all files were added
        if (successfullyAdded.size() != filesToAddPaths.size()) {
            // remove all added files from original list of files to add to give us which files weren't added
            filesToAddPaths.removeAll(successfullyAdded);
            exceptions.add(new VcsException(TfPluginBundle.message(TfPluginBundle.KEY_TFVC_ADD_ERROR,
                    StringUtils.join(filesToAddPaths, ", "))));
        }
    } catch (RuntimeException e) {
        exceptions.add(new VcsException(e));
    }
    return exceptions;
}

From source file:com.ery.dimport.daemon.TaskManager.java

private void checkTaskAndWriteLog(boolean force) throws KeeperException, IOException {
    if (!master.isActiveMaster())
        return;/*w  w  w  .j  av a2  s . c  o  m*/
    List<String> taskIDS = new ArrayList<String>(allTask.keySet());
    for (String taskId : taskIDS) {
        TaskInfo taskInfo = allTask.get(taskId);
        Map<String, List<LogHostRunInfoPO>> map = allTaskInfo.get(taskId);
        if (map == null || map.size() == 0) {
            if (taskInfo.START_TIME.getTime() > 1000000) {
                if (System.currentTimeMillis() - taskInfo.START_TIME.getTime() > 600000) {
                    LOG.warn(":" + taskId + " ?");
                    synchronized (allTask) {
                        allTask.remove(taskId);
                    }
                    ZKUtil.deleteNodeRecursively(watcher, watcher.dimportRunTaskNode + "/" + taskId);
                    taskInfo.END_TIME = new Date(System.currentTimeMillis());
                    taskInfo.HOST_SIZE = 0;
                    taskInfo.IS_ALL_SUCCESS = 0;
                    taskInfo.FILE_NUMBER = 0;
                    LOG.warn(":" + taskId + " ?" + taskInfo);
                    master.logWriter.updateLog(taskInfo);// task
                }
            }
            continue;
        }
        boolean isAllEnd = true;
        boolean isAllSuccess = true;
        // if (taskInfo.hosts == null)
        Map<String, Integer> hosts = new HashMap<String, Integer>();
        taskInfo.FILE_NUMBER = 0;
        for (String hostName : map.keySet()) {
            List<LogHostRunInfoPO> allFiles = map.get(hostName);
            taskInfo.FILE_NUMBER += allFiles.size();
            hosts.put(hostName, 0);
            if (allFiles.size() == 0) {
                isAllEnd = false;
                isAllSuccess = false;
                continue;
            }
            for (LogHostRunInfoPO fileInfo : allFiles) {
                if (taskInfo.START_TIME.getTime() < 10000 && fileInfo.START_TIME.getTime() > 0) {
                    if (LOG.isDebugEnabled())
                        LOG.debug(":" + taskInfo);
                    taskInfo.START_TIME = fileInfo.START_TIME;
                } else if (taskInfo.START_TIME.getTime() > fileInfo.START_TIME.getTime()) {
                    if (LOG.isDebugEnabled())
                        LOG.debug(":" + taskInfo);
                    taskInfo.START_TIME = fileInfo.START_TIME;
                }
                if (!master.getServerManager().getOnlineServers().containsKey(hostName)) {// ???
                    if (fileInfo.START_TIME.getTime() == 0)
                        fileInfo.START_TIME = new Date(System.currentTimeMillis() - 1000);
                    fileInfo.END_TIME = new Date(System.currentTimeMillis());
                    fileInfo.RETURN_CODE = -4;
                    fileInfo.ERROR_MSG = "?";
                    isAllEnd = true;
                    master.logWriter.updateLog(fileInfo);// 
                }
                if ((fileInfo.START_TIME.getTime() > 0 && fileInfo.END_TIME.getTime() > 0
                        && fileInfo.END_TIME.getTime() > fileInfo.START_TIME.getTime())) {// ?
                    if (fileInfo.RETURN_CODE != 0) {
                        isAllSuccess = false;
                    }
                } else {
                    isAllSuccess = false;
                    isAllEnd = false;
                    if (force) {
                        if (fileInfo.ERROR_MSG == null || fileInfo.equals(""))
                            fileInfo.ERROR_MSG = "?";
                        master.logWriter.updateLog(fileInfo);// host
                    } else {
                        break;
                    }
                }
            }
            if (force) {
                LOG.warn("?:" + taskId + " on " + hostName);
                synchronized (allTaskInfo) {
                    allTaskInfo.remove(hostName);
                }
                ZKUtil.deleteNodeRecursively(watcher,
                        watcher.dimportRunTaskNode + "/" + taskId + "/" + hostName);
            } else if (!isAllEnd) {
                break;
            }
        }
        if (isAllEnd) {
            List<String> waitHosts = new ArrayList<String>();
            if (taskInfo.hosts == null) {
                if (hosts.size() != master.getServerManager().getOnlineServers().size()) {
                    isAllEnd = false;
                } else {
                    for (String host : master.getServerManager().getOnlineServers().keySet()) {
                        if (!hosts.containsKey(host)) {
                            waitHosts.add(host);
                            isAllEnd = false;
                        }
                    }
                }
            } else {
                List<String> onLineHost = new ArrayList<String>(
                        master.getServerManager().getOnlineServers().keySet());
                List<String> taskHost = new ArrayList<String>(taskInfo.hosts);
                taskHost.removeAll(onLineHost);
                onLineHost.removeAll(hosts.keySet());
                if (onLineHost.size() > 0) {// 
                    isAllEnd = false; // ??
                    waitHosts.addAll(onLineHost);
                } else if (taskHost.size() > 0) {// ??
                    taskInfo.hosts.removeAll(taskHost);// ?
                }
            }
            if (waitHosts.size() > 0) {
                reWriteTaskOrder(taskInfo);
            }
        }
        if (isAllEnd && taskInfo.hosts == null) {
            taskInfo.hosts = new ArrayList<String>(hosts.keySet());
        }
        if (taskInfo.hosts != null && taskInfo.hosts.size() < taskInfo.HOST_SIZE) {
            taskInfo.HOST_SIZE = taskInfo.hosts.size();
        }
        if (force || isAllEnd) {
            taskInfo.IS_ALL_SUCCESS = isAllSuccess ? 1 : 0;
            taskInfo.END_TIME = new Date(System.currentTimeMillis());
            if (!force) {// ? 
                LOG.info("?:" + taskId + "  ");
                List<LogHostRunInfoPO> taskAllFile = new ArrayList<LogHostRunInfoPO>();
                for (String hostName : map.keySet()) {
                    for (LogHostRunInfoPO runInfo : map.get(hostName)) {
                        if (runInfo.START_TIME.getTime() < 100000) {
                            taskAllFile.add(runInfo);
                        }
                    }
                    // taskAllFile.addAll(map.get(hostName));
                }
                master.logWriter.updateLog(taskAllFile);// host
            }
            master.logWriter.updateLog(taskInfo);// task
            synchronized (allTask) {
                allTask.remove(taskId);
            }
            synchronized (allTaskInfo) {
                allTaskInfo.remove(taskId);
            }
            LOG.info("? " + taskId + " ?:" + watcher.dimportRunTaskNode + "/"
                    + taskId);
            ZKUtil.deleteNodeRecursively(watcher, watcher.dimportRunTaskNode + "/" + taskId);
        } else {
            String waitHost = "";
            for (String host : taskInfo.hosts) {
                if (!map.containsKey(host)) {
                    waitHost += host + ",";
                }
            }
        }

    }
}

From source file:com.teradata.benchto.driver.loader.BenchmarkLoader.java

public List<Benchmark> loadBenchmarks(String sequenceId) {
    try {//from   www.ja  va 2s.  c o m
        List<Path> benchmarkFiles = findBenchmarkFiles();

        benchmarkFiles = benchmarkFiles.stream().filter(activeBenchmarks()).collect(toList());

        benchmarkFiles.stream().forEach(path -> LOGGER.info("Benchmark file to be read: {}", path));

        List<Benchmark> allBenchmarks = loadBenchmarks(sequenceId, benchmarkFiles);
        LOGGER.debug("All benchmarks: {}", allBenchmarks);

        List<Benchmark> includedBenchmarks = allBenchmarks.stream()
                .filter(new BenchmarkByActiveVariablesFilter(properties)).collect(toList());

        Set<Benchmark> excludedBenchmarks = newLinkedHashSet(allBenchmarks);
        excludedBenchmarks.removeAll(includedBenchmarks);

        String formatString = createFormatString(allBenchmarks);
        LOGGER.info("Excluded Benchmarks:");
        printFormattedBenchmarksInfo(formatString, excludedBenchmarks);

        fillUniqueBenchmarkNames(includedBenchmarks);

        List<Benchmark> freshBenchmarks = ImmutableList.of();
        if (properties.isFrequencyCheckEnabled()) {
            freshBenchmarks = filterFreshBenchmarks(includedBenchmarks);
            LOGGER.info("Recently tested benchmarks:");
            printFormattedBenchmarksInfo(formatString, freshBenchmarks);
        }

        LOGGER.info("Selected Benchmarks:");
        includedBenchmarks.removeAll(freshBenchmarks);
        printFormattedBenchmarksInfo(formatString, includedBenchmarks);

        checkState(allBenchmarks.size() == includedBenchmarks.size() + excludedBenchmarks.size()
                + freshBenchmarks.size());

        return includedBenchmarks;
    } catch (IOException e) {
        throw new BenchmarkExecutionException("Could not load benchmarks", e);
    }
}

From source file:edu.stanford.cfuller.colocalization3d.Colocalization3DMain.java

private void checkAllRunningThreadsAndRemoveFinished(List<FittingThread> started,
        List<FittingThread> finished) {

    List<FittingThread> toMove = new java.util.ArrayList<FittingThread>();

    for (FittingThread ft : started) {
        try {//  w  w  w. j  a v a  2  s . co  m
            ft.join(DEFAULT_THREAD_WAIT_MS);
        } catch (InterruptedException e) {
            java.util.logging.Logger.getLogger(LOGGER_NAME)
                    .severe("Interrupted while waiting for completion of fitting thread: " + e.getMessage());

        }

        if (!ft.isAlive()) {
            toMove.add(ft);
        }
    }

    started.removeAll(toMove);
    finished.addAll(toMove);

}

From source file:org.eclipse.packagedrone.repo.channel.web.channel.ChannelController.java

protected List<DeployGroup> getGroupsForChannel(final Collection<DeployGroup> channelDeployGroups) {
    final List<DeployGroup> groups = new ArrayList<>(this.deployAuthService.listGroups(0, -1));
    groups.removeAll(channelDeployGroups);
    Collections.sort(groups, DeployGroup.NAME_COMPARATOR);
    return groups;
}

From source file:ca.sqlpower.wabit.AbstractWabitObjectTest.java

/**
 * Reflective test that the wabit object can be persisted as an object and all of
 * its properties are persisted with it.
 *//*from  w  w  w  .ja v  a2  s. com*/
public void testPersistsObjectAsChild() throws Exception {

    //This may need to actually have the wabit object as a child to itself.
    WabitObject parent = new StubWabitObject();

    CountingWabitPersister persister = new CountingWabitPersister();
    WorkspacePersisterListener listener = new WorkspacePersisterListener(
            new StubWabitSession(new StubWabitSessionContext()), persister, true);
    SPObject wo = getObjectUnderTest();
    if (wo.getParent() == null) {
        wo.setParent(parent);
    }

    listener.childAdded(new SPChildEvent(parent, wo.getClass(), wo, 0, EventType.ADDED));

    assertTrue(persister.getPersistObjectCount() > 0);
    PersistedSPObject persistedWabitObject = persister.getAllPersistedObjects().get(0);
    assertEquals(wo.getClass().getSimpleName(), persistedWabitObject.getType());
    assertEquals(wo.getUUID(), persistedWabitObject.getUUID());

    //confirm we get one persist property for each getter/setter pair
    //confirm we get one persist property for each value in one of the constructors in the object.

    List<PropertyDescriptor> settableProperties = new ArrayList<PropertyDescriptor>(
            Arrays.asList(PropertyUtils.getPropertyDescriptors(wo.getClass())));
    List<PersistedSPOProperty> allPropertyChanges = persister.getAllPropertyChanges();
    Set<String> ignorableProperties = getPropertiesToNotPersistOnObjectPersist();
    ignorableProperties.addAll(getPropertiesToIgnoreForEvents());

    List<PersistedSPOProperty> changesOnObject = new ArrayList<PersistedSPOProperty>();

    logger.debug("Looking through properties registered to persist...");
    for (int i = allPropertyChanges.size() - 1; i >= 0; i--) {
        if (allPropertyChanges.get(i).getUUID().equals(wo.getUUID())) {
            changesOnObject.add(allPropertyChanges.get(i));
            logger.debug(
                    "The property " + allPropertyChanges.get(i).getPropertyName() + " is ready to persist!");
        } else {
            logger.debug("The property " + allPropertyChanges.get(i).getPropertyName()
                    + " has not been set in WabitSessionPersister and"
                    + " WorkspacePersisterListener to persist properly!");
        }
    }

    List<String> settablePropertyNames = new ArrayList<String>();
    for (PropertyDescriptor pd : settableProperties) {
        settablePropertyNames.add(pd.getName());
    }

    settablePropertyNames.removeAll(ignorableProperties);

    if (settablePropertyNames.size() != changesOnObject.size()) {
        for (String descriptor : settablePropertyNames) {
            PersistedSPOProperty foundChange = null;
            for (PersistedSPOProperty propertyChange : changesOnObject) {
                if (propertyChange.getPropertyName().equals(descriptor)) {
                    foundChange = propertyChange;
                    break;
                }
            }
            assertNotNull("The property " + descriptor + " was not persisted", foundChange);
        }
    }
    logger.debug("Property names" + settablePropertyNames);
    assertTrue(settablePropertyNames.size() <= changesOnObject.size());

    WabitSessionPersisterSuperConverter factory = new WabitSessionPersisterSuperConverter(
            new StubWabitSession(new StubWabitSessionContext()), new WabitWorkspace(), true);

    for (String descriptor : settablePropertyNames) {
        PersistedSPOProperty foundChange = null;
        for (PersistedSPOProperty propertyChange : changesOnObject) {
            if (propertyChange.getPropertyName().equals(descriptor)) {
                foundChange = propertyChange;
                break;
            }
        }
        assertNotNull("The property " + descriptor + " was not persisted", foundChange);
        assertTrue(foundChange.isUnconditional());
        assertEquals(wo.getUUID(), foundChange.getUUID());
        Object value = PropertyUtils.getSimpleProperty(wo, descriptor);

        //XXX will replace this later
        List<Object> additionalVals = new ArrayList<Object>();
        if (wo instanceof OlapQuery && descriptor.equals("currentCube")) {
            additionalVals.add(((OlapQuery) wo).getOlapDataSource());
        }
        Object valueConvertedToBasic = factory.convertToBasicType(value, additionalVals.toArray());
        logger.debug("Property \"" + descriptor + "\": expected \"" + valueConvertedToBasic + "\" but was \""
                + foundChange.getNewValue() + "\" of type " + foundChange.getDataType());

        assertEquals(valueConvertedToBasic, foundChange.getNewValue());
    }
}

From source file:elaborate.editor.model.orm.service.ProjectService.java

public void setTextlayers(long project_id, List<String> textLayers, User user) {
    beginTransaction();/*ww  w.  j a  v a2  s .  com*/
    Set<Long> modifiedEntryIds = Sets.newHashSet();
    try {
        Project project = getProjectIfUserCanRead(project_id, user);
        List<String> previous = Lists.newArrayList(project.getTextLayers());
        List<String> deletedTextLayers = previous;
        deletedTextLayers.removeAll(textLayers);
        project.setTextLayers(textLayers);

        persist(project);
        persist(project.addLogEntry("project textlayers changed", user));
        setModifiedBy(project, user);

        if (!deletedTextLayers.isEmpty()) {
            persist(project.addLogEntry("removing textlayer(s) " + Joiner.on(", ").join(deletedTextLayers),
                    user));
            for (String textlayer : deletedTextLayers) {
                List<?> resultList = getEntityManager()//
                        .createQuery(
                                "select e.id, t.id from ProjectEntry e join e.transcriptions as t with t.text_layer=:textlayer where e.project=:project")//
                        .setParameter("project", project)//
                        .setParameter("textlayer", textlayer)//
                        .getResultList();
                for (Object object : resultList) {
                    Object[] ids = (Object[]) object;
                    Transcription transcription = getEntityManager().find(Transcription.class, ids[1]);
                    remove(transcription);
                    modifiedEntryIds.add((Long) ids[0]);
                }
            }
        }
    } finally {
        commitTransaction();
    }

    beginTransaction();
    try {
        for (Long id : modifiedEntryIds) {
            ProjectEntry entry = getEntityManager().find(ProjectEntry.class, id);
            setModifiedBy(entry, user);
        }
    } finally {
        commitTransaction();
    }

}