Example usage for java.util LinkedList poll

List of usage examples for java.util LinkedList poll

Introduction

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

Prototype

public E poll() 

Source Link

Document

Retrieves and removes the head (first element) of this list.

Usage

From source file:org.jahia.services.content.PublicationInfo.java

public List<String> getAllUuids(boolean includeDeleted, boolean includePublished,
        boolean includeWorkInProgress) {
    String cacheKey = getKey(includeDeleted, includePublished);
    List<String> allUuids = allUuidsCache.get(cacheKey);
    if (allUuids != null) {
        return allUuids;
    }/*www.j  av  a2s  .co  m*/
    allUuids = new ArrayList<String>();
    LinkedList<PublicationInfoNode> nodes = new LinkedList<PublicationInfoNode>();
    Set<PublicationInfoNode> processed = new HashSet<PublicationInfoNode>();
    nodes.add(root);
    processed.add(root);
    PublicationInfoNode node = nodes.poll();
    while (node != null) {
        for (PublicationInfoNode infoNode : node.getChildren()) {
            if (!processed.contains(infoNode)) {
                nodes.add(infoNode);
                processed.add(infoNode);
            }
        }
        if ((includeDeleted || node.getStatus() != DELETED)
                && (includePublished || node.getStatus() != PUBLISHED)
                && (includeWorkInProgress || !node.isWorkInProgress())) {
            allUuids.add(node.getUuid());
        }
        node = nodes.poll();
    }
    allUuidsCache.put(cacheKey, allUuids);
    return allUuids;
}

From source file:org.gbif.namefinder.analysis.sciname.SciNameAnalyzerTest.java

@Test
public void testAbbreviatedNames() throws Exception {
    String text = "A survey of the Abies conifers found in Europe. A. is not a abbreviated genus. A. alba, A. betula, A.picea and Picea picea is something else.";
    Reader input = new StringReader(text);
    LinkedList<String> expected = new LinkedList<String>();
    expected.add("Abies");
    expected.add("Abies alba");
    expected.add("Abies betula");
    expected.add("Abies picea");
    expected.add("Picea picea");

    TokenStream tokens = getTokens(input);
    SciNameIterator iter = new SciNameIterator(tokens);
    for (SciName sn : iter) {
        //      System.out.println(sn);
        assertEquals(expected.poll(), sn.scientificName);
    }//from  www . ja  v  a 2 s  .  c  om
    tokens.end();
    tokens.close();
}

From source file:org.gbif.namefinder.analysis.sciname.SciNameAnalyzerTest.java

@Test
public void testSimpleText() throws Exception {
    System.out.println(StringUtils.isAllUpperCase("G"));
    System.out.println(StringUtils.isAllUpperCase("G"));
    String text = "Help, Asteraceae or is (Felinia) or Felis (Felinia) foordi found. I can't see any of these famous Abies alba anywhere around here, can you? Maybe this is Potentilla vulgaris L. ? You can't be sure, my dear. Paris is a pretty town too, isn't it? They have big numbers of Passer domesticus subsp. domesticus, the most frequent subspecies of Passer domesticus (Linnaeus, 1758)";
    Reader input = new StringReader(text);
    LinkedList<String> expected = new LinkedList<String>();
    expected.add("Asteraceae");
    expected.add("Felis (Felinia) foordi");
    expected.add("Abies alba");
    expected.add("Potentilla vulgaris");
    expected.add("Passer domesticus subsp. domesticus");
    expected.add("Passer domesticus");
    TokenStream tokens = getTokens(input);
    SciNameIterator iter = new SciNameIterator(tokens);
    for (SciName sn : iter) {
        //      System.out.println(sn);
        assertEquals(expected.poll(), sn.scientificName);
    }//from w ww . j a v a  2s .c  o  m
    tokens.end();
    tokens.close();
}

From source file:org.geoserver.importer.Directory.java

@Override
public void prepare(ProgressMonitor m) throws IOException {
    files = new ArrayList<FileData>();

    //recursively search for spatial files, maintain a queue of directories to recurse into
    LinkedList<File> q = new LinkedList<File>();
    q.add(file);/*from   w  w  w.java 2 s . c om*/

    while (!q.isEmpty()) {
        File dir = q.poll();

        if (m.isCanceled()) {
            return;
        }
        m.setTask("Scanning " + dir.getPath());

        //get all the regular (non directory) files
        Set<File> all = new LinkedHashSet<File>(Arrays.asList(dir.listFiles(new FilenameFilter() {
            public boolean accept(File dir, String name) {
                return !new File(dir, name).isDirectory();
            }
        })));

        //scan all the files looking for spatial ones
        for (File f : dir.listFiles()) {
            if (f.isHidden()) {
                all.remove(f);
                continue;
            }
            if (f.isDirectory()) {
                if (!recursive && !f.equals(file)) {
                    //skip it
                    continue;
                }
                // @hacky - ignore __MACOSX
                // this could probably be dealt with in a better way elsewhere
                // like by having Directory ignore the contents since they
                // are all hidden files anyway
                if (!"__MACOSX".equals(f.getName())) {
                    Directory d = new Directory(f);
                    d.prepare(m);

                    files.add(d);
                }
                //q.push(f);
                continue;
            }

            //special case for .aux files, they are metadata but get picked up as readable 
            // by the erdas imagine reader...just ignore them for now 
            if ("aux".equalsIgnoreCase(FilenameUtils.getExtension(f.getName()))) {
                continue;
            }

            //determine if this is a spatial format or not
            DataFormat format = DataFormat.lookup(f);

            if (format != null) {
                SpatialFile sf = newSpatialFile(f, format);

                //gather up the related files
                sf.prepare(m);

                files.add(sf);

                all.removeAll(sf.allFiles());
            }
        }

        //take any left overs and add them as unspatial/unrecognized
        for (File f : all) {
            files.add(new ASpatialFile(f));
        }
    }

    format = format();
    //        //process ignored for files that should be grouped with the spatial files
    //        for (DataFile df : files) {
    //            SpatialFile sf = (SpatialFile) df;
    //            String base = FilenameUtils.getBaseName(sf.getFile().getName());
    //            for (Iterator<File> i = ignored.iterator(); i.hasNext(); ) {
    //                File f = i.next();
    //                if (base.equals(FilenameUtils.getBaseName(f.getName()))) {
    //                    //.prj file?
    //                    if ("prj".equalsIgnoreCase(FilenameUtils.getExtension(f.getName()))) {
    //                        sf.setPrjFile(f);
    //                    }
    //                    else {
    //                        sf.getSuppFiles().add(f);
    //                    }
    //                    i.remove();
    //                }
    //            }
    //        }
    //        
    //        //take any left overs and add them as unspatial/unrecognized
    //        for (File f : ignored) {
    //            files.add(new ASpatialFile(f));
    //        }
    //        
    //        return files;
    //        
    //        for (DataFile f : files()) {
    //            f.prepare();
    //        }
}

From source file:org.silverpeas.core.process.io.file.AbstractFileHandler.java

/**
 * Recursive file copying/*from  ww  w  .ja  va2s  .c o m*/
 * @param basePath
 * @param file
 * @throws IOException
 */
private void copyFiles(final FileBasePath basePath, final File file) throws IOException {
    if (file.exists()) {
        final LinkedList<File> fifo = new LinkedList<>();
        fifo.add(file);
        File currentFile;
        while ((currentFile = fifo.poll()) != null) {
            if (currentFile.isDirectory()) {
                File[] files = currentFile.listFiles();
                if (files != null) {
                    Collections.addAll(fifo, files);
                }
            } else {
                FileUtils.copyFile(currentFile, translateToRealPath(basePath, currentFile));
            }
        }
    }
}

From source file:org.silverpeas.process.io.file.AbstractFileHandler.java

/**
 * Recursive file copying/*from w w  w.j ava2 s .  co  m*/
 * @param basePath
 * @param file
 * @throws IOException
 */
private void copyFiles(final FileBasePath basePath, final File file) throws IOException {
    if (file.exists()) {
        final LinkedList<File> fifo = new LinkedList<File>();
        fifo.add(file);
        File currentFile;
        while ((currentFile = fifo.poll()) != null) {
            if (currentFile.isDirectory()) {
                File[] files = currentFile.listFiles();
                if (files != null) {
                    Collections.addAll(fifo, files);
                }
            } else {
                FileUtils.copyFile(currentFile, translateToRealPath(basePath, currentFile));
            }
        }
    }
}

From source file:org.deegree.style.se.parser.GraphicSymbologyParser.java

Pair<Graphic, Continuation<Graphic>> parseGraphic(XMLStreamReader in) throws XMLStreamException {
    in.require(START_ELEMENT, null, "Graphic");

    Graphic base = new Graphic();
    Continuation<Graphic> contn = null;

    while (!(in.isEndElement() && in.getLocalName().equals("Graphic"))) {
        in.nextTag();/*  ww  w. j  a v a 2s . c  o m*/

        if (in.getLocalName().equals("Mark")) {
            final Pair<Mark, Continuation<Mark>> pair = parseMark(in);

            if (pair != null) {
                base.mark = pair.first;
                if (pair.second != null) {
                    contn = new Continuation<Graphic>(contn) {
                        @Override
                        public void updateStep(Graphic base, Feature f, XPathEvaluator<Feature> evaluator) {
                            pair.second.evaluate(base.mark, f, evaluator);
                        }
                    };
                }
            }
        } else if (in.getLocalName().equals("ExternalGraphic")) {
            try {
                final Triple<BufferedImage, String, Continuation<List<BufferedImage>>> p = parseExternalGraphic(
                        in);
                if (p.third != null) {
                    contn = new Continuation<Graphic>(contn) {
                        @Override
                        public void updateStep(Graphic base, Feature f, XPathEvaluator<Feature> evaluator) {
                            LinkedList<BufferedImage> list = new LinkedList<BufferedImage>();
                            p.third.evaluate(list, f, evaluator);
                            base.image = list.poll();
                        }
                    };
                } else {
                    base.image = p.first;
                    base.imageURL = p.second;
                }
            } catch (IOException e) {
                LOG.debug("Stack trace", e);
                LOG.warn("External graphic could not be loaded. Location: line '{}' column '{}' of file '{}'.",
                        new Object[] { in.getLocation().getLineNumber(), in.getLocation().getColumnNumber(),
                                in.getLocation().getSystemId() });
            }
        } else if (in.getLocalName().equals("Opacity")) {
            contn = context.parser.updateOrContinue(in, "Opacity", base, new Updater<Graphic>() {
                public void update(Graphic obj, String val) {
                    obj.opacity = Double.parseDouble(val);
                }
            }, contn).second;
        } else if (in.getLocalName().equals("Size")) {
            contn = context.parser.updateOrContinue(in, "Size", base, new Updater<Graphic>() {
                public void update(Graphic obj, String val) {
                    obj.size = Double.parseDouble(val);
                }
            }, contn).second;
        } else if (in.getLocalName().equals("Rotation")) {
            contn = context.parser.updateOrContinue(in, "Rotation", base, new Updater<Graphic>() {
                public void update(Graphic obj, String val) {
                    obj.rotation = Double.parseDouble(val);
                }
            }, contn).second;
        } else if (in.getLocalName().equals("AnchorPoint")) {
            while (!(in.isEndElement() && in.getLocalName().equals("AnchorPoint"))) {
                in.nextTag();

                if (in.getLocalName().equals("AnchorPointX")) {
                    contn = context.parser.updateOrContinue(in, "AnchorPointX", base, new Updater<Graphic>() {
                        public void update(Graphic obj, String val) {
                            obj.anchorPointX = Double.parseDouble(val);
                        }
                    }, contn).second;
                } else if (in.getLocalName().equals("AnchorPointY")) {
                    contn = context.parser.updateOrContinue(in, "AnchorPointY", base, new Updater<Graphic>() {
                        public void update(Graphic obj, String val) {
                            obj.anchorPointY = Double.parseDouble(val);
                        }
                    }, contn).second;
                } else if (in.isStartElement()) {
                    Location loc = in.getLocation();
                    LOG.error("Found unknown element '{}' at line {}, column {}, skipping.",
                            new Object[] { in.getLocalName(), loc.getLineNumber(), loc.getColumnNumber() });
                    skipElement(in);
                }
            }
        } else if (in.getLocalName().equals("Displacement")) {
            while (!(in.isEndElement() && in.getLocalName().equals("Displacement"))) {
                in.nextTag();

                if (in.getLocalName().equals("DisplacementX")) {
                    contn = context.parser.updateOrContinue(in, "DisplacementX", base, new Updater<Graphic>() {
                        public void update(Graphic obj, String val) {
                            obj.displacementX = Double.parseDouble(val);
                        }
                    }, contn).second;
                } else if (in.getLocalName().equals("DisplacementY")) {
                    contn = context.parser.updateOrContinue(in, "DisplacementY", base, new Updater<Graphic>() {
                        public void update(Graphic obj, String val) {
                            obj.displacementY = Double.parseDouble(val);
                        }
                    }, contn).second;
                } else if (in.isStartElement()) {
                    Location loc = in.getLocation();
                    LOG.error("Found unknown element '{}' at line {}, column {}, skipping.",
                            new Object[] { in.getLocalName(), loc.getLineNumber(), loc.getColumnNumber() });
                    skipElement(in);
                }
            }
        } else if (in.isStartElement()) {
            Location loc = in.getLocation();
            LOG.error("Found unknown element '{}' at line {}, column {}, skipping.",
                    new Object[] { in.getLocalName(), loc.getLineNumber(), loc.getColumnNumber() });
            skipElement(in);
        }
    }
    in.require(END_ELEMENT, null, "Graphic");

    return new Pair<Graphic, Continuation<Graphic>>(base, contn);
}

From source file:com.google.enterprise.connector.filesystem.FileConnectorTypeTest.java

/**
 * Make sure HTML tags in {@code s} are balanced.
 *
 * @param s//  www. j ava 2 s . c  o m
 */
private void assertBalancedTags(String s) {
    LinkedList<String> stack = Lists.newLinkedList();
    Matcher m = TAG.matcher(s);
    int start = 0;
    while (m.find(start)) {
        String tag = s.substring(m.start(), m.end());

        if (isOpenTag(tag)) {
            stack.addFirst(tag);
        } else if (isCloseTag(tag)) {
            String open = stack.poll();
            assertNotNull(String.format("extra tag: %s", tag), open);
            assertEquals(String.format("mismatched tags: %s vs %s", open, tag), getName(open), getName(tag));
        } else {
            // Ignore open-closed tags (<tag/>).
        }
        start = m.end();
    }
    assertEquals("Open tags at end of input", 0, stack.size());
}

From source file:org.apache.flink.table.codegen.SortCodeGeneratorTest.java

private void randomKeysAndOrders() {
    Random rnd = new Random();
    fields = new int[rnd.nextInt(9) + 1];
    for (int i = 0; i < fields.length; i++) {
        fields[i] = rnd.nextInt(types.length);
    }/*from   w w  w . j ava 2s  .  c  om*/

    keys = new int[rnd.nextInt(fields.length) + 1];
    LinkedList<Integer> indexQueue = new LinkedList<>();
    for (int i = 0; i < fields.length; i++) {
        indexQueue.add(i);
    }
    Collections.shuffle(indexQueue);
    orders = new boolean[keys.length];
    for (int i = 0; i < keys.length; i++) {
        keys[i] = indexQueue.poll();
        orders[i] = rnd.nextBoolean();
    }
    nullsIsLast = SortUtil.getNullDefaultOrders(orders);
}

From source file:org.unitime.timetable.onlinesectioning.server.AbstractServer.java

protected void releaseCurrentHelper() {
    LinkedList<OnlineSectioningHelper> h = sHelper.get();
    h.poll();
    if (h.isEmpty())
        sHelper.remove();/*from   ww  w .jav  a  2 s. co  m*/
}