Example usage for java.util List addAll

List of usage examples for java.util List addAll

Introduction

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

Prototype

boolean addAll(Collection<? extends E> c);

Source Link

Document

Appends all of the elements in the specified collection to the end of this list, in the order that they are returned by the specified collection's iterator (optional operation).

Usage

From source file:com.googlecode.dex2jar.test.TestUtils.java

public static Collection<File> listTestDexFiles(boolean withOdex) {
    File file = new File("target/test-classes/dexes");
    List<File> list = new ArrayList<File>();
    if (file.exists()) {
        list.addAll(FileUtils.listFiles(file, new String[] { "dex", "zip", "apk", "odex" }, false));
    }//from   w  ww  . jav a  2s  .co m
    if (withOdex) {
        list = new ArrayList<File>();
        file = new File("target/test-classes/odexes");
        if (file.exists()) {
            list.addAll(FileUtils.listFiles(file, new String[] { "odex" }, true));
        }
    }
    return list;
}

From source file:org.eclipse.virgo.ide.jdt.internal.core.classpath.ServerClasspathUtils.java

/**
 * Reads the persisted classpath entries for the given <code>project</code> and returns the
 * {@link IClasspathEntry}s.// www. j  a v a 2 s .c o m
 * <p>
 * This method returns <code>null</code> to indicate that the file could not be read.
 */
@SuppressWarnings({ "unchecked", "rawtypes" })
protected static IClasspathEntry[] readPersistedClasspathEntries(IJavaProject project) {
    File file = new File(ServerCorePlugin.getDefault().getStateLocation().toFile(),
            project.getProject().getName() + CLASSPATH_FILE);

    String xmlClasspath = null;
    if (file.exists()) {
        try {
            byte[] bytes = FileCopyUtils.copyToByteArray(file);
            xmlClasspath = new String(bytes, org.eclipse.jdt.internal.compiler.util.Util.UTF_8);
        } catch (UnsupportedEncodingException e) {
            // can't happen as default UTF-8 is used
        } catch (IOException e) {
        }
    }

    if (xmlClasspath == null) {
        return null;
    }

    if (project instanceof JavaProject) {
        JavaProject javaProject = (JavaProject) project;
        try {
            Object decodedClassPath;

            try {
                // needs reflection since return type of decodeClasspath has changed in Eclipse 3.6
                Method method = javaProject.getClass().getMethod("decodeClasspath", String.class, Map.class);
                decodedClassPath = method.invoke(javaProject, xmlClasspath, new HashMap());
                if (decodedClassPath instanceof IClasspathEntry[][]) {
                    List<IClasspathEntry> decodedEntries = new ArrayList<IClasspathEntry>();
                    for (IClasspathEntry[] entry : (IClasspathEntry[][]) decodedClassPath) {
                        decodedEntries.addAll(Arrays.asList(entry));
                    }
                    return decodedEntries.toArray(new IClasspathEntry[decodedEntries.size()]);
                } else if (decodedClassPath instanceof IClasspathEntry[]) {
                    return (IClasspathEntry[]) decodedClassPath;
                }
            } catch (Exception e) {
                JdtCorePlugin.log(e);
            }

        } catch (AssertionFailedException e) {
            JdtCorePlugin.log(e);
        }
    }

    return null;
}

From source file:com.meltmedia.cadmium.blackbox.test.CadmiumAssertions.java

/**
 * <p>Gets an array of file objects representing the directory contents recursively listed. (<em>Not including directories named in the excludes.</em>)</p>
 * @param directory The directory to list.
 * @param excludes The directory and/or filenames to exclude.
 * @return The list of files./*from  w  w  w . j  a  v a  2s .  c om*/
 */
private static File[] getAllDirectoryContents(File directory, String... excludes)
        throws IllegalArgumentException {
    if (directory == null || !directory.exists() || !directory.isDirectory()) {
        throw new IllegalArgumentException(
                "Path \"" + directory + "\" either does not exist or is not a directory.");
    }
    FilenameFilter filter = new FilenameExclusionFilter(excludes);
    List<File> files = new ArrayList<File>();
    File listedFiles[] = directory.listFiles(filter);
    if (listedFiles != null) {
        files.addAll(Arrays.asList(listedFiles));
    }
    for (int i = 0; i < files.size(); i++) {
        File aFile = files.get(i);
        if (aFile.isDirectory()) {
            listedFiles = aFile.listFiles(filter);
            if (listedFiles != null && listedFiles.length > 0) {
                files.addAll(i + 1, Arrays.asList(listedFiles));
            }
        }
    }

    return files.toArray(new File[] {});
}

From source file:com.alibaba.jstorm.cache.rocksdb.RocksDbFactory.java

private static List<ColumnFamilyDescriptor> getExistingColumnFamilyDesc(Map conf, String dbPath)
        throws IOException {
    try {// w  w  w . ja  v  a 2  s  .  c  o  m
        List<byte[]> families = Lists.newArrayList();
        List<byte[]> existingFamilies = RocksDB.listColumnFamilies(getOptions(conf), dbPath);
        if (existingFamilies != null) {
            families.addAll(existingFamilies);
        } else {
            families.add(RocksDB.DEFAULT_COLUMN_FAMILY);
        }

        List<ColumnFamilyDescriptor> columnFamilyDescriptors = new ArrayList<>();
        for (byte[] bytes : families) {
            columnFamilyDescriptors.add(new ColumnFamilyDescriptor(bytes, getColumnFamilyOptions(conf)));
            LOG.info("Load column family of {}", new String(bytes));
        }
        return columnFamilyDescriptors;
    } catch (RocksDBException e) {
        throw new IOException("Failed to retrieve existing column families.", e);
    }
}

From source file:com.microsoft.tfs.client.eclipse.resource.PluginResourceHelpers.java

public static ResourceRepositoryMap mapResources(final IResource[] resources) {
    final Map<IProject, List<IResource>> projectsToResources = new HashMap<IProject, List<IResource>>();

    for (int i = 0; i < resources.length; i++) {
        final IProject project = resources[i].getProject();

        List<IResource> list = projectsToResources.get(project);
        if (list == null) {
            list = new ArrayList<IResource>();
            projectsToResources.put(project, list);
        }/*from w  ww  .  j a  v  a  2 s .  c  om*/
        list.add(resources[i]);
    }

    final IProject[] projects = projectsToResources.keySet()
            .toArray(new IProject[projectsToResources.keySet().size()]);

    final Map<TFSRepository, List<IProject>> repositoriesToProjects = new HashMap<TFSRepository, List<IProject>>();

    for (int i = 0; i < projects.length; i++) {
        final TFSRepository repository = TFSEclipseClientPlugin.getDefault().getProjectManager()
                .getRepository(projects[i]);

        if (repository == null) {
            PluginResourceHelpers.log
                    .warn(MessageFormat.format("No TFS Repository for project {0}", projects[i].getName())); //$NON-NLS-1$
            continue;
        }

        List<IProject> list = repositoriesToProjects.get(repository);
        if (list == null) {
            list = new ArrayList<IProject>();
            repositoriesToProjects.put(repository, list);
        }
        list.add(projects[i]);
    }

    final TFSRepository[] repositories = repositoriesToProjects.keySet()
            .toArray(new TFSRepository[repositoriesToProjects.keySet().size()]);

    final ResourceRepositoryMap resultMap = new ResourceRepositoryMap();

    for (int i = 0; i < repositories.length; i++) {
        final IProject[] projectsForRepository = repositoriesToProjects.get(repositories[i])
                .toArray(new IProject[] {});

        final List<IResource> resourcesForRepositoryList = new ArrayList<IResource>();
        for (int j = 0; j < projectsForRepository.length; j++) {
            resourcesForRepositoryList.addAll(projectsToResources.get(projectsForRepository[j]));
        }
        final IResource[] resourcesForRepository = resourcesForRepositoryList
                .toArray(new IResource[resourcesForRepositoryList.size()]);

        resultMap.addMappings(repositories[i], resourcesForRepository);
    }

    return resultMap;
}

From source file:com.dianping.phoenix.dev.core.tools.generator.stable.GitRepositoryListGenerator.java

private static List<ProjectRepositoryPair> parse() throws Exception {
    List<ProjectRepositoryPair> pairs = new ArrayList<ProjectRepositoryPair>();

    List<ProjectRepositoryPair> temp = null;
    int pageNo = 1;

    while (true) {
        temp = parsePage(pageNo++);/*from ww  w  .j  a va  2 s .  c  o m*/
        if (temp == null) {
            break;
        } else {
            pairs.addAll(temp);
        }
    }

    return pairs;
}

From source file:io.github.retz.web.ClientHelper.java

public static List<Job> running(Client c) throws IOException {
    List<Job> jobs = new LinkedList<>();
    Response res = c.list(Job.JobState.STARTING, Optional.empty());
    jobs.addAll(((ListJobResponse) res).jobs());
    res = c.list(Job.JobState.STARTED, Optional.empty());
    jobs.addAll(((ListJobResponse) res).jobs());
    return jobs;/*from  ww w.  j  a v a  2 s.  com*/
}

From source file:io.github.retz.web.ClientHelper.java

public static List<Job> finished(Client c) throws IOException {
    List<Job> jobs = new LinkedList<>();
    Response res = c.list(Job.JobState.FINISHED, Optional.empty());
    jobs.addAll(((ListJobResponse) res).jobs());
    res = c.list(Job.JobState.KILLED, Optional.empty());
    jobs.addAll(((ListJobResponse) res).jobs());
    return jobs;/* ww  w.  j  a va 2s. c  o  m*/
}

From source file:ninja.eivind.hotsreplayuploader.models.ReplayFile.java

public static List<ReplayFile> fromDirectory(File file) {
    final List<ReplayFile> replayFiles = new ArrayList<>();
    final File[] children = file.listFiles((dir, name) -> name.endsWith(".StormReplay"));
    for (final File child : children) {
        if (child.isDirectory()) {
            replayFiles.addAll(fromDirectory(child));
        } else {/*from   w  w  w  . jav a2  s  .c o m*/
            replayFiles.add(new ReplayFile(child));
        }
    }

    return replayFiles;
}

From source file:ch.systemsx.cisd.openbis.plugin.generic.client.web.server.parser.SampleUploadSectionsParser.java

private static List<BatchRegistrationResult> loadSamplesFromFiles(UploadedFilesBean uploadedFiles,
        SampleType sampleType, boolean isAutoGenerateCodes, final List<NewSamplesWithTypes> newSamples,
        boolean allowExperiments) {

    final List<BatchRegistrationResult> results = new ArrayList<BatchRegistrationResult>(uploadedFiles.size());

    for (final IUncheckedMultipartFile multipartFile : uploadedFiles.iterable()) {
        List<FileSection> sampleSections = new ArrayList<FileSection>();
        if (sampleType.isDefinedInFileSampleTypeCode()) {
            sampleSections.addAll(extractSections(multipartFile));
        } else {/*from   ww w . j av a 2  s. c om*/
            sampleSections.add(new FileSection(new String(multipartFile.getBytes()), sampleType.getCode()));
        }
        int sampleCounter = 0;
        for (FileSection fs : sampleSections) {
            final StringReader stringReader = new StringReader(fs.getContent());
            SampleType typeFromSection = new SampleType();
            typeFromSection.setCode(fs.getSectionName());
            final BisTabFileLoader<NewSample> tabFileLoader = createSampleLoader(typeFromSection,
                    isAutoGenerateCodes, allowExperiments);
            String sectionInFile = sampleSections.size() == 1 ? "" : " (section:" + fs.getSectionName() + ")";
            final List<NewSample> loadedSamples = tabFileLoader.load(
                    new DelegatedReader(stringReader, multipartFile.getOriginalFilename() + sectionInFile));
            if (loadedSamples.size() > 0) {
                newSamples.add(new NewSamplesWithTypes(typeFromSection, loadedSamples));
                sampleCounter += loadedSamples.size();
            }
        }
        results.add(new BatchRegistrationResult(multipartFile.getOriginalFilename(),
                String.format("%d sample(s) found and registered.", sampleCounter)));
    }
    return results;
}