Example usage for java.util LinkedList addAll

List of usage examples for java.util LinkedList addAll

Introduction

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

Prototype

public 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.

Usage

From source file:de.quadrillenschule.azocamsyncd.ftpservice.FTPConnection.java

public LinkedList<AZoFTPFile> discoverRemoteFiles(String root, boolean includeDirs) throws IOException {
    LinkedList<AZoFTPFile> retval = new LinkedList();
    for (FTPFile f : ftpclient.listFiles(root)) {

        AZoFTPFile af = new AZoFTPFile(f, root);
        if (f.isFile() && isPicture(af) && !retval.contains(af)) {
            retval.add(af);/*  www . j  a v a 2 s . co m*/
        }
        if (f.isDirectory()) {
            if (includeDirs) {
                retval.add(af);
            }

            retval.addAll(discoverRemoteFiles(root + f.getName() + "/", includeDirs));
        }
    }
    return retval;

}

From source file:org.dataconservancy.ui.services.MockDcsConnector.java

/**
 * Performs an search.  The caller indicates the maximum number of results to return, and the offset within
 * the total number of results./*from   w  ww  .  ja  va2s. c o  m*/
 * <p/>
 * Because there is no concrete search implementation backing the mock connector, the query semantics are
 * determined by parsing the query string, and the query itself is emulated. Currently, the following kinds
 * of searches are supported:
 * <ul>
 * <li>ancestry search - find entities that share a common ancestor</li>
 * <li>identity search - find an entity with a specific id</li>
 * <li>parent search - find child Deliverable Units of a parent DU</li>
 * </ul>
 *
 * @param query the query string
 * @return an iterator over the search results
 * @throws DcsConnectorFault
 */
public CountableIterator<DcsEntity> search(String query, int maxResults, int offset) throws DcsConnectorFault {

    LinkedList<DcsEntity> result = new LinkedList<DcsEntity>();

    // Grab id
    String archive_id = null;
    if (query.contains("parent:")) {
        archive_id = query.substring(query.indexOf("parent:") + "parent:".length() + 1, query.length() - 2);
    } else {
        int i = query.indexOf('\"');
        archive_id = query.substring(i + 1, query.indexOf('\"', i + 1));
    }

    // TODO unescape solr syntax correctly
    archive_id = archive_id.replace("\\", "");

    if (query.contains(" OR ") && !query.contains("former:")) {
        // Assume sip recreation search

        // Find all the ancestors of archive_id
        performAncestrySearch(result, archive_id);

        // Add the common ancestor itself.
        DcsEntity e = archiveUtil.getEntity(archive_id);
        if (!result.contains(e)) {
            result.add(e);
        }

    } else if (query.startsWith("id:")) {
        // Assume id search
        if (archiveUtil.getEntity(archive_id) != null) {
            result.add(archiveUtil.getEntity(archive_id));
        }
    } else if (query.startsWith("ancestry:")) {
        // Assume ancestry search
        performAncestrySearch(result, archive_id);
    } else if (query.contains("parent")) {
        performParentSearch(result, archive_id);
    } else if (query.contains("former:")) {
        // example query we're handling:
        // ((entityType:"DeliverableUnit" AND former:"ed64f0fc\-8201\-47c0\-bdc9\-024078aaefbc" AND type:"root"))
        // OR ((entityType:"DeliverableUnit" AND former:"ed64f0fc\-8201\-47c0\-bdc9\-024078aaefbc" AND type:"state"))
        // another example query:
        // ((entityType:"DeliverableUnit" AND former:"id\://mooo" AND type:"root")) OR ((entityType:"DeliverableUnit" AND former:"id\://mooo" AND type:"state"))
        // another example:
        // (entityType:"DeliverableUnit" AND former:"http\://localhost\:8080/item/8" AND type:"org.dataconservancy\:types\:DataItem")

        Pattern p = Pattern.compile("^.*former:(\\S*)\\s.*$");
        Matcher m = p.matcher(query);
        if (m.find()) {
            String former_ref = m.group(1);
            former_ref = stripQuotes(former_ref);
            performFormerSearch(result, former_ref);
        } else {
            throw new RuntimeException(
                    "Unable to parse value for the 'former:' parameter from query string '" + query + "'");
        }

        LinkedList<DcsEntity> culledResults = new LinkedList<DcsEntity>();

        p = Pattern.compile("type:(\\S*)");
        m = p.matcher(query);
        if (!m.find()) {
            culledResults.addAll(result);
        }

        m = p.matcher(query);

        while (m.find()) {
            String type = stripQuotes(m.group(1));

            Iterator<DcsEntity> itr = result.iterator();
            while (itr.hasNext()) {
                DcsEntity entity = itr.next();
                if (!(entity instanceof DcsDeliverableUnit)) {
                    culledResults.add(entity);
                }

                if (type.equals(((DcsDeliverableUnit) entity).getType())) {
                    culledResults.add(entity);
                }
            }
        }

        result = culledResults;
    } else {
        throw new UnsupportedOperationException("Search not handled: " + query);
    }

    if (offset > 0 && result.size() > 0) {
        result.subList(0, offset).clear();
    }

    if (maxResults > 0 && result.size() > maxResults) {
        result.subList(maxResults, result.size()).clear();
    }

    return new MockSearchIterator(result);
}

From source file:org.apache.zeppelin.interpreter.InterpreterFactory.java

public List<String> getNoteInterpreterSettingBinding(String noteId) {
    LinkedList<String> bindings = new LinkedList<String>();
    synchronized (interpreterSettings) {
        List<String> settingIds = interpreterBindings.get(noteId);
        if (settingIds != null) {
            bindings.addAll(settingIds);
        }/*from   w  w w  .  j  a va2 s.  c om*/
    }
    return bindings;
}

From source file:ca.uvic.cs.tagsea.statistics.svn.jobs.SVNCommentScanningJob.java

List findJavaFiles(File dir) {
    LinkedList files = new LinkedList();
    if (!dir.isDirectory()) {
        return files;
    }//from  www.  j  a va2 s.c  o m
    String[] subs = dir.list();
    for (int i = 0; i < subs.length; i++) {
        String next = subs[i];
        File nextFile = new File(dir, next);
        if (nextFile.isDirectory()) {
            files.addAll(findJavaFiles(nextFile));
        } else {
            if (next.endsWith(".java")) {
                files.add(nextFile);
            }
        }
    }
    return files;
}

From source file:fr.ericlab.sondy.core.DataManipulation.java

public LinkedList<String> getDatasetList(String repositoryPath) {
    LinkedList<String> datasetList = new LinkedList<>();
    File dir = new File(repositoryPath + "/");
    if (dir.exists()) {
        String[] files = dir.list(DirectoryFileFilter.INSTANCE);
        datasetList.addAll(Arrays.asList(files));
    } else {//from w w  w .  j a v  a  2 s  .  c  o  m
        dir.mkdir();
    }
    return datasetList;
}

From source file:controllers.SnLocationsController.java

public static void discoverFsqLocations(String lat, String lng) {

    String appid = params._contains(PARAM_APPID) ? params.get(PARAM_APPID) : "";
    String limit = params._contains(PARAM_LIMIT) ? params.get(PARAM_LIMIT) : "";
    limit = verifyRecordLimit(limit);//from   w w  w  .  j  ava2  s. com
    String radius = params._contains(PARAM_RADIUS) ? params.get(PARAM_RADIUS) : "";
    radius = verifyRadius(radius);
    String herenow = params._contains(PARAM_HERENOW) ? params.get(PARAM_HERENOW) : "true";// by default : true
    String query = params._contains(PARAM_QUERY) ? params.get(PARAM_QUERY) : "";

    Logger.info("PARAMS -> appid:%s ; lat,lng:%s,%s ; radius:%s ; limit:%s ; herenow:%s ; query:%s", appid, lat,
            lng, radius, limit, herenow, query);

    ResponseModel responseModel = new ResponseModel();
    ResponseMeta responseMeta = new ResponseMeta();
    LinkedList<Object> dataList = new LinkedList<Object>();

    HashMap params = new HashMap();
    String cacheKey = CACHE_KEYPREFIX_NEARBY + "geo:" + lat + "," + lng;
    if (!StringUtils.isEmpty(limit))
        cacheKey += "|" + limit;
    if (!StringUtils.isEmpty(query))
        cacheKey += "|" + query;

    try {

        //dataList = (LinkedList<Object>) Cache.get(cacheKey);
        dataList = Cache.get(cacheKey, LinkedList.class);
        if (dataList == null) {

            dataList = new LinkedList<Object>();

            params.clear();
            if (!StringUtils.isEmpty(lat) && !StringUtils.isEmpty(lng))
                params.put("ll", lat + "," + lng);
            if (!StringUtils.isEmpty(limit))
                params.put(PARAM_LIMIT, limit);

            if (!StringUtils.isEmpty(radius))
                params.put(PARAM_RADIUS, radius);
            /*params.put(PARAM_RADIUS,
                  !StringUtils.isEmpty(radius)?
                radius
                :Play.configuration.getProperty("fsqdiscovery.discovery.API_LOCO_SEARCHDISTANCE")
                  );*/
            if (!StringUtils.isEmpty(query))
                params.put(PARAM_QUERY, query);

            FoursquareDiscoverPoiJob mFoursquarePoiJob = new FoursquareDiscoverPoiJob();
            mFoursquarePoiJob.setReqParams(params);
            dataList.addAll((LinkedList<Object>) mFoursquarePoiJob.doJobWithResult());

            if (dataList.size() > 0) {
                Logger.info("adding to cache!!! %s", dataList.size());
                Cache.set(cacheKey, dataList, CACHE_TTL_NEARBY);
            } else {
                Logger.info("NO NEED to cache, dataList.size(): 0");

                response.status = Http.StatusCode.OK;
                responseMeta.code = response.status;
                responseModel.meta = responseMeta;
                responseModel.data = dataList;

                renderJSON(LocoUtils.getGson().toJson(responseModel));
            }
        } else {
            Logger.info("Found in CACHE!!! %s", dataList.size());
        }

        if ("true".equalsIgnoreCase(herenow)) {
            // HereNow part
            params.clear();
            FoursquareDiscoverHereNowJob mFoursquareDiscoverHereNowJob = new FoursquareDiscoverHereNowJob();
            mFoursquareDiscoverHereNowJob.setReqParams(params);
            mFoursquareDiscoverHereNowJob.setPoiList(dataList);
            dataList = new LinkedList<Object>();//dataList.clear();
            dataList.addAll((LinkedList<Object>) mFoursquareDiscoverHereNowJob.doJobWithResult());

            // remove items which doesn't have any hereNow in it!!!
            try {
                PoiModelFoursquare fsqPoi = null;
                LinkedList<Object> dataListFiltered = new LinkedList<Object>();
                for (Object obj : dataList) {
                    fsqPoi = (PoiModelFoursquare) obj;

                    //if (fsqPoi.herenow==null || fsqPoi.herenow.size()==0) dataList.remove(obj);
                    if (fsqPoi.herenow != null && fsqPoi.herenow.size() > 0)
                        dataListFiltered.add(obj);
                }
                Logger.info("dataList.size(): %s | dataListFiltered.size(): %s", dataList.size(),
                        dataListFiltered.size());
                dataList = new LinkedList<Object>();//dataList.clear();
                dataList.addAll(dataListFiltered);
            } catch (Exception ex) {
                Logger.warn("exception while filtering out hereNow : %s", ex.toString());
            }
        } else {
            Logger.info("herenow param is NOT set true, skip loading hereNow!!! herenow: %s", herenow);
        }

        response.status = Http.StatusCode.OK;
        responseMeta.code = response.status;
        responseModel.meta = responseMeta;
        responseModel.data = dataList;

        renderJSON(LocoUtils.getGson().toJson(responseModel));
    } catch (Exception ex) {

        responseMeta.code = Http.StatusCode.INTERNAL_ERROR;
        gotError(responseMeta, ex);
        //renderJSON(responseModel);
    }
}

From source file:org.j2free.invoker.InvokerFilter.java

/**
 * Locks to prevent request processing while mapping is added.
 *
 * Finds all classes annotated with ServletConfig and maps the class to
 * the url specified in the annotation.  Wildcard mapping are allowed in
 * the form of *.extension or /some/path/*
 *
 * @param context an active ServletContext
 *///from  w w w .  j  a  v  a 2  s.  c  om
public void load(final ServletContext context) {
    try {
        write.lock();

        LinkedList<URL> urlList = new LinkedList<URL>();
        urlList.addAll(Arrays.asList(ClasspathUrlFinder.findResourceBases(EMPTY)));
        urlList.addAll(Arrays.asList(WarUrlFinder.findWebInfLibClasspaths(context)));

        URL[] urls = new URL[urlList.size()];
        urls = urlList.toArray(urls);

        AnnotationDB annoDB = new AnnotationDB();
        annoDB.setScanClassAnnotations(true);
        annoDB.setScanFieldAnnotations(false);
        annoDB.setScanMethodAnnotations(false);
        annoDB.setScanParameterAnnotations(false);
        annoDB.scanArchives(urls);

        HashMap<String, Set<String>> annotationIndex = (HashMap<String, Set<String>>) annoDB
                .getAnnotationIndex();
        if (annotationIndex != null && !annotationIndex.isEmpty()) {
            //-----------------------------------------------------------
            // Look for any classes annotated with @ServletConfig
            Set<String> classNames = annotationIndex.get(ServletConfig.class.getName());

            if (classNames != null) {
                for (String c : classNames) {
                    try {
                        final Class<? extends HttpServlet> klass = (Class<? extends HttpServlet>) Class
                                .forName(c);

                        if (klass.isAnnotationPresent(ServletConfig.class)) {
                            final ServletConfig config = (ServletConfig) klass
                                    .getAnnotation(ServletConfig.class);

                            // If the config specifies String mapppings...
                            if (config.mappings() != null) {
                                for (String url : config.mappings()) {
                                    // Leave the asterisk, we'll add it when matching...
                                    //if (url.matches("(^\\*[^*]*?)|([^*]*?/\\*$)"))
                                    //    url = url.replace("*", EMPTY);

                                    url = url.toLowerCase(); // all comparisons are lower-case

                                    if (urlMap.putIfAbsent(url, klass) == null) {
                                        if (log.isDebugEnabled())
                                            log.debug("Mapping servlet " + klass.getName() + " to path " + url);
                                    } else
                                        log.error("Unable to map servlet  " + klass.getName() + " to path "
                                                + url + ", path already mapped to "
                                                + urlMap.get(url).getName());
                                }
                            }

                            // If the config specifies a regex mapping...
                            if (!empty(config.regex())) {
                                regexMap.putIfAbsent(config.regex(), klass);
                                if (log.isDebugEnabled())
                                    log.debug("Mapping servlet " + klass.getName() + " to regex path "
                                            + config.regex());
                            }

                            // Create an instance of the servlet and init it
                            HttpServlet servlet = klass.newInstance();
                            servlet.init(new ServletConfigImpl(klass.getName(), context));

                            // Store a reference
                            servletMap.put(klass, new ServletMapping(servlet, config));
                        }

                    } catch (Exception e) {
                        log.error("Error registering servlet [name=" + c + "]", e);
                    }
                }
            }

            //-----------------------------------------------------------
            // Look for any classes annotated with @FiltersConfig
            classNames = annotationIndex.get(FilterConfig.class.getName());
            if (classNames != null) {
                for (String c : classNames) {
                    try {
                        final Class<? extends Filter> klass = (Class<? extends Filter>) Class.forName(c);

                        if (klass.isAnnotationPresent(FilterConfig.class)) {
                            final FilterConfig config = (FilterConfig) klass.getAnnotation(FilterConfig.class);

                            // Create an instance of the servlet and init it
                            Filter filter = klass.newInstance();
                            filter.init(new FilterConfigImpl(klass.getName(), context));

                            if (log.isDebugEnabled())
                                log.debug("Mapping filter " + klass.getName() + " to path " + config.match());

                            // Store a reference
                            filters.add(new FilterMapping(filter, config));
                        }
                    } catch (Exception e) {
                        log.error("Error registering servlet [name=" + c + "]", e);
                    }
                }
            }
        }
    } catch (IOException e) {
        log.error("Error loading urlMappings", e);
    } finally {
        write.unlock(); // ALWAYS Release the configure lock
    }
}

From source file:controllers.SnLocationsController.java

public static void trendingFsqLocations(String lat, String lng) {

    String appid = params._contains(PARAM_APPID) ? params.get(PARAM_APPID) : "";
    String limit = params._contains(PARAM_LIMIT) ? params.get(PARAM_LIMIT) : "";
    limit = verifyRecordLimit(limit);//from w  w w .  j  a  va 2s.  c o m
    String radius = params._contains(PARAM_RADIUS) ? params.get(PARAM_RADIUS) : "";
    radius = verifyRadius(radius);
    String herenow = params._contains(PARAM_HERENOW) ? params.get(PARAM_HERENOW) : "true";// by default, thats true!
    String query = params._contains(PARAM_QUERY) ? params.get(PARAM_QUERY) : "";

    Logger.info("PARAMS -> appid:%s ; lat,lng:%s,%s ; radius:%s ; limit:%s ; herenow:%s ; query:%s", appid, lat,
            lng, radius, limit, herenow, query);

    // using Async jobs
    ResponseModel responseModel = new ResponseModel();
    ResponseMeta responseMeta = new ResponseMeta();
    LinkedList<Object> dataList = new LinkedList<Object>();

    HashMap params = new HashMap();
    String cacheKey = CACHE_KEYPREFIX_TRENDING + "geo:" + lat + "," + lng;
    if (!StringUtils.isEmpty(limit))
        cacheKey += "|" + limit;
    if (!StringUtils.isEmpty(query))
        cacheKey += "|" + query;

    try {

        //dataList = (LinkedList<Object>) Cache.get(cacheKey);
        dataList = Cache.get(cacheKey, LinkedList.class);
        if (dataList == null) {

            dataList = new LinkedList<Object>();

            params.clear();
            if (!StringUtils.isEmpty(lat) && !StringUtils.isEmpty(lng))
                params.put("ll", lat + "," + lng);
            if (!StringUtils.isEmpty(limit))
                params.put(PARAM_LIMIT, limit);

            if (!StringUtils.isEmpty(radius))
                params.put(PARAM_RADIUS, radius);
            /*params.put(PARAM_RADIUS,
                  !StringUtils.isEmpty(radius)?
                radius
                :Play.configuration.getProperty("fsqdiscovery.trending.API_LOCO_SEARCHDISTANCE")
                  );*/
            if (!StringUtils.isEmpty(query))
                params.put(PARAM_QUERY, query);

            FoursquareTrendingPoiJob mFoursquareTrendingPoiJob = new FoursquareTrendingPoiJob();
            mFoursquareTrendingPoiJob.setReqParams(params);
            dataList.addAll((LinkedList<Object>) mFoursquareTrendingPoiJob.doJobWithResult());

            //Logger.info("adding to cache!!! %s", dataList.size());
            //Cache.set(cacheKey, dataList, CACHE_TTL_TRENDING);
            if (dataList.size() > 0) {
                Logger.info("adding to cache!!! %s", dataList.size());
                Cache.set(cacheKey, dataList, CACHE_TTL_TRENDING);
            } else {
                Logger.info("NO NEED to cache, dataList.size(): 0");

                response.status = Http.StatusCode.OK;
                responseMeta.code = response.status;
                responseModel.meta = responseMeta;
                responseModel.data = dataList;

                renderJSON(LocoUtils.getGson().toJson(responseModel));
            }
        } else {
            Logger.info("Found in CACHE!!! %s", dataList.size());
        }

        if ("true".equalsIgnoreCase(herenow)) {
            // HereNow part
            params.clear();
            FoursquareDiscoverHereNowJob mFoursquareDiscoverHereNowJob = new FoursquareDiscoverHereNowJob();
            mFoursquareDiscoverHereNowJob.setReqParams(params);
            mFoursquareDiscoverHereNowJob.setPoiList(dataList);
            dataList = new LinkedList<Object>();//dataList.clear();
            dataList.addAll((LinkedList<Object>) mFoursquareDiscoverHereNowJob.doJobWithResult());
        } else {
            Logger.info("herenow param is NOT set true, skip loading hereNow!!! herenow: %s", herenow);
        }

        response.status = Http.StatusCode.OK;
        responseMeta.code = response.status;
        responseModel.meta = responseMeta;
        responseModel.data = dataList;

        renderJSON(LocoUtils.getGson().toJson(responseModel));
    } catch (Exception ex) {

        responseMeta.code = Http.StatusCode.INTERNAL_ERROR;
        gotError(responseMeta, ex);
        //renderJSON(responseModel);
    }
}

From source file:org.trnltk.apps.morphology.contextless.parser.CachingMorphologicParserApp.java

@App("Parse all sample corpus. Does not do an offline analysis to add most frequent words to cache in advance.")
public void parse8MWords() throws Exception {
    /*/*from   www.j a v a 2s . co  m*/
     Total time :0:07:29.799
     Nr of tokens : 18362187
     Avg time : 0.024495938310616267 ms
    */
    final Set<File> files = SampleFiles.oneMillionSentencesTokenizedFiles();

    final LinkedList<String> words = new LinkedList<String>();
    final HashSet<String> uniqueWords = new HashSet<String>();

    for (File tokenizedFile : files) {
        final List<String> lines = Files.readLines(tokenizedFile, Charsets.UTF_8);
        for (String line : lines) {
            final ArrayList<String> strings = Lists
                    .newArrayList(Splitter.on(" ").trimResults().omitEmptyStrings().split(line));
            words.addAll(strings);
            uniqueWords.addAll(strings);
        }
    }

    System.out.println("Number of words : " + words.size());
    System.out.println("Number of unique words : " + uniqueWords.size());
    System.out.println("======================");

    final MorphologicParserCache l1Cache = new LRUMorphologicParserCache(NUMBER_OF_THREADS,
            INITIAL_L1_CACHE_SIZE, MAX_L1_CACHE_SIZE);

    final ThreadPoolExecutor pool = (ThreadPoolExecutor) Executors.newFixedThreadPool(NUMBER_OF_THREADS);

    final MorphologicParser[] parsers = new MorphologicParser[NUMBER_OF_THREADS];
    for (int i = 0; i < parsers.length; i++) {
        parsers[i] = new CachingMorphologicParser(new TwoLevelMorphologicParserCache(BULK_SIZE, l1Cache),
                contextlessMorphologicParser, true);
    }

    final StopWatch stopWatch = new StopWatch();
    stopWatch.start();

    for (int i = 0; i < words.size(); i = i + BULK_SIZE) {
        final MorphologicParser parser = parsers[(i / BULK_SIZE) % NUMBER_OF_THREADS];
        int start = i;
        int end = i + BULK_SIZE < words.size() ? i + BULK_SIZE : words.size();
        final List<String> subWordList = words.subList(start, end);
        final int wordIndex = i;
        pool.execute(new BulkParseCommand(parser, subWordList, wordIndex, false));
    }

    pool.shutdown();
    while (!pool.isTerminated()) {
        System.out.println("Waiting pool to be terminated!");
        pool.awaitTermination(1000, TimeUnit.MILLISECONDS);
    }

    stopWatch.stop();

    System.out.println("Total time :" + stopWatch.toString());
    System.out.println("Nr of tokens : " + words.size());
    System.out.println("Avg time : " + (stopWatch.getTime() * 1.0d) / (words.size() * 1.0d) + " ms");
}

From source file:uk.ac.horizon.ug.exploding.client.Client.java

public List<Object> getFacts(String typeName) {

    synchronized (facts) {
        LinkedList<Object> fs = new LinkedList<Object>();
        HashMap<Object, Object> typeFacts = facts.get(typeName);
        if (typeFacts != null) {
            fs.addAll(typeFacts.values());
        }/*w w  w .jav a  2 s. c om*/
        return fs;
    }
}