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.sipfoundry.commons.userdb.ValidUsers.java

/**
 * Parse the Display name into a list of DTMF sequences
 *
 * Do one for Last name first And one for First name first
 *
 * @param u//from w  w w .j  a  va 2s.c o m
 */
protected static void buildDialPatterns(User u) {
    u.setDialPatterns(new Vector<String>());

    if (u.getDisplayName() == null) {
        return;
    }

    String[] names = u.getDisplayName().split("\\W");
    // Remove all non-character data, convert to upper case, convert to DTMF

    LinkedList<String> queue = new LinkedList<String>();
    for (String name : names) {
        String dtmf = mapDTMF(compress(name));
        if (dtmf.length() > 0) {
            queue.add(mapDTMF(compress(name)));
        }
    }

    // Given a b c d, generate:
    // a b c d
    // b c d a
    // c d a b
    // d a b c
    for (int i = 0; i < queue.size(); i++) {
        String mashup;
        String first = queue.poll(); // Pull first
        mashup = first;
        for (int j = 0; j < queue.size(); j++) {
            String next = queue.poll();
            mashup += next;
            queue.add(next);
        }
        queue.add(first); // Put first back (its now last)
        u.getDialPatterns().add(mashup);
    }
}

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

private void getAllReferences(LinkedHashSet<PublicationInfo> uuids, LinkedList<PublicationInfoNode> nodes,
        Set<PublicationInfoNode> processedNodes) {
    nodes.add(root);/*from w w w.  j a v  a  2 s .  c om*/
    processedNodes.add(root);

    PublicationInfoNode node = nodes.poll();
    while (node != null) {
        for (PublicationInfoNode infoNode : node.getChildren()) {
            if (!processedNodes.contains(infoNode)) {
                nodes.add(infoNode);
                processedNodes.add(infoNode);
            }
        }
        for (PublicationInfo refInfo : node.getReferences()) {
            if (!processedNodes.contains(refInfo.getRoot())) {
                refInfo.getAllReferences(uuids, nodes, processedNodes);
            }
        }
        uuids.addAll(node.getReferences());
        node = nodes.poll();
    }
}

From source file:io.druid.firehose.google.StaticGoogleBlobStoreFirehoseFactory.java

@Override
public Firehose connect(StringInputRowParser stringInputRowParser) throws IOException {
    Preconditions.checkNotNull(storage, "null storage");

    final LinkedList<GoogleBlob> objectQueue = Lists.newLinkedList(blobs);

    return new FileIteratingFirehose(new Iterator<LineIterator>() {
        @Override/*  w  w  w.jav a2s .c  om*/
        public boolean hasNext() {
            return !objectQueue.isEmpty();
        }

        @Override
        public LineIterator next() {
            final GoogleBlob nextURI = objectQueue.poll();

            final String bucket = nextURI.getBucket();
            final String path = nextURI.getPath().startsWith("/") ? nextURI.getPath().substring(1)
                    : nextURI.getPath();

            try {
                final InputStream innerInputStream = new GoogleByteSource(storage, bucket, path).openStream();

                final InputStream outerInputStream = path.endsWith(".gz")
                        ? CompressionUtils.gzipInputStream(innerInputStream)
                        : innerInputStream;

                return IOUtils.lineIterator(
                        new BufferedReader(new InputStreamReader(outerInputStream, Charsets.UTF_8)));
            } catch (Exception e) {
                LOG.error(e, "Exception opening bucket[%s] blob[%s]", bucket, path);

                throw Throwables.propagate(e);
            }
        }

        @Override
        public void remove() {
            throw new UnsupportedOperationException();
        }
    }, stringInputRowParser);
}

From source file:io.druid.firehose.azure.StaticAzureBlobStoreFirehoseFactory.java

@Override
public Firehose connect(StringInputRowParser stringInputRowParser) throws IOException {
    Preconditions.checkNotNull(azureStorage, "null azureStorage");

    final LinkedList<AzureBlob> objectQueue = Lists.newLinkedList(blobs);

    return new FileIteratingFirehose(new Iterator<LineIterator>() {
        @Override//from www .j  a  v  a2  s . com
        public boolean hasNext() {
            return !objectQueue.isEmpty();
        }

        @Override
        public LineIterator next() {
            final AzureBlob nextURI = objectQueue.poll();

            final String container = nextURI.getContainer();
            final String path = nextURI.getPath().startsWith("/") ? nextURI.getPath().substring(1)
                    : nextURI.getPath();

            try {
                final InputStream innerInputStream = new AzureByteSource(azureStorage, container, path)
                        .openStream();

                final InputStream outerInputStream = path.endsWith(".gz")
                        ? CompressionUtils.gzipInputStream(innerInputStream)
                        : innerInputStream;

                return IOUtils.lineIterator(
                        new BufferedReader(new InputStreamReader(outerInputStream, Charsets.UTF_8)));
            } catch (Exception e) {
                log.error(e, "Exception opening container[%s] blob[%s]", container, path);

                throw Throwables.propagate(e);
            }
        }

        @Override
        public void remove() {
            throw new UnsupportedOperationException();
        }
    }, stringInputRowParser);
}

From source file:io.druid.segment.realtime.firehose.LocalFirehoseFactory.java

@Override
public Firehose connect(StringInputRowParser firehoseParser) throws IOException {
    log.info("Searching for all [%s] in and beneath [%s]", filter, baseDir.getAbsoluteFile());

    Collection<File> foundFiles = FileUtils.listFiles(baseDir.getAbsoluteFile(), new WildcardFileFilter(filter),
            TrueFileFilter.INSTANCE);/*  w  w  w . j  a  v  a 2s.co m*/

    if (foundFiles == null || foundFiles.isEmpty()) {
        throw new ISE("Found no files to ingest! Check your schema.");
    }
    log.info("Found files: " + foundFiles);

    final LinkedList<File> files = Lists.newLinkedList(foundFiles);

    return new FileIteratingFirehose(new Iterator<LineIterator>() {
        @Override
        public boolean hasNext() {
            return !files.isEmpty();
        }

        @Override
        public LineIterator next() {
            try {
                return FileUtils.lineIterator(files.poll());
            } catch (Exception e) {
                throw Throwables.propagate(e);
            }
        }

        @Override
        public void remove() {
            throw new UnsupportedOperationException();
        }
    }, firehoseParser);
}

From source file:io.druid.firehose.s3.StaticS3FirehoseFactory.java

@Override
public Firehose connect(StringInputRowParser firehoseParser) throws IOException {
    Preconditions.checkNotNull(s3Client, "null s3Client");

    final LinkedList<URI> objectQueue = Lists.newLinkedList(uris);

    return new FileIteratingFirehose(new Iterator<LineIterator>() {
        @Override// w w  w  . j a v  a 2  s . c  o  m
        public boolean hasNext() {
            return !objectQueue.isEmpty();
        }

        @Override
        public LineIterator next() {
            final URI nextURI = objectQueue.poll();

            final String s3Bucket = nextURI.getAuthority();
            final S3Object s3Object = new S3Object(
                    nextURI.getPath().startsWith("/") ? nextURI.getPath().substring(1) : nextURI.getPath());

            log.info("Reading from bucket[%s] object[%s] (%s)", s3Bucket, s3Object.getKey(), nextURI);

            try {
                final InputStream innerInputStream = s3Client
                        .getObject(new S3Bucket(s3Bucket), s3Object.getKey()).getDataInputStream();

                final InputStream outerInputStream = s3Object.getKey().endsWith(".gz")
                        ? CompressionUtils.gzipInputStream(innerInputStream)
                        : innerInputStream;

                return IOUtils.lineIterator(
                        new BufferedReader(new InputStreamReader(outerInputStream, Charsets.UTF_8)));
            } catch (Exception e) {
                log.error(e, "Exception reading from bucket[%s] object[%s]", s3Bucket, s3Object.getKey());

                throw Throwables.propagate(e);
            }
        }

        @Override
        public void remove() {
            throw new UnsupportedOperationException();
        }
    }, firehoseParser);
}

From source file:io.druid.firehose.oss.StaticOSSFirehoseFactory.java

@Override
public Firehose connect(StringInputRowParser firehoseParser) throws IOException {

    Preconditions.checkNotNull(ossClient, "null ossClient");

    final LinkedList<URI> objectQueue = Lists.newLinkedList(uris);

    return new FileIteratingFirehose(new Iterator<LineIterator>() {
        @Override/*www  .  j  ava  2s  .  c  o  m*/
        public boolean hasNext() {
            return !objectQueue.isEmpty();
        }

        @Override
        public LineIterator next() {
            final URI nextURI = objectQueue.poll();

            final String bucket = nextURI.getAuthority();
            final String key = nextURI.getPath().startsWith("/") ? nextURI.getPath().substring(1)
                    : nextURI.getPath();

            log.info("reading from bucket[%s] object[%s] (%s)", bucket, key, nextURI);

            try {
                final InputStream innerInputStream = ossClient.getObject(bucket, key).getObjectContent();

                final InputStream outerInputStream = key.endsWith(".gz")
                        ? CompressionUtils.gzipInputStream(innerInputStream)
                        : innerInputStream;

                return IOUtils.lineIterator(
                        new BufferedReader(new InputStreamReader(outerInputStream, Charsets.UTF_8)));
            } catch (Exception e) {
                log.error(e, "exception reading from bucket[%s] object[%s]", bucket, key);

                throw Throwables.propagate(e);
            }
        }

        @Override
        public void remove() {
            throw new UnsupportedOperationException();
        }
    }, firehoseParser);
}

From source file:io.druid.firehose.cloudfiles.StaticCloudFilesFirehoseFactory.java

@Override
public Firehose connect(StringInputRowParser stringInputRowParser) throws IOException, ParseException {
    Preconditions.checkNotNull(cloudFilesApi, "null cloudFilesApi");

    final LinkedList<CloudFilesBlob> objectQueue = Lists.newLinkedList(blobs);

    return new FileIteratingFirehose(new Iterator<LineIterator>() {

        @Override/*from w ww  .j a  v  a 2s  . c o  m*/
        public boolean hasNext() {
            return !objectQueue.isEmpty();
        }

        @Override
        public LineIterator next() {
            final CloudFilesBlob nextURI = objectQueue.poll();

            final String region = nextURI.getRegion();
            final String container = nextURI.getContainer();
            final String path = nextURI.getPath();

            log.info("Retrieving file from region[%s], container[%s] and path [%s]", region, container, path);
            CloudFilesObjectApiProxy objectApi = new CloudFilesObjectApiProxy(cloudFilesApi, region, container);
            final CloudFilesByteSource byteSource = new CloudFilesByteSource(objectApi, path);

            try {
                final InputStream innerInputStream = byteSource.openStream();
                final InputStream outerInputStream = path.endsWith(".gz")
                        ? CompressionUtils.gzipInputStream(innerInputStream)
                        : innerInputStream;

                return IOUtils.lineIterator(
                        new BufferedReader(new InputStreamReader(outerInputStream, Charsets.UTF_8)));
            } catch (IOException e) {
                log.error(e, "Exception opening container[%s] blob[%s] from region[%s]", container, path,
                        region);

                throw Throwables.propagate(e);
            }
        }

        @Override
        public void remove() {
            throw new UnsupportedOperationException();
        }

    }, stringInputRowParser);
}

From source file:org.nanocom.console.input.ArgsInput.java

/**
 * {@inheritDoc}//from w w  w  .j  a v  a2s  . c  om
 */
@Override
public Object getParameterOption(List<String> values, Object defaultValue) {
    LinkedList<String> locTokens = new LinkedList<String>();
    locTokens.addAll(tokens);

    while (!locTokens.isEmpty()) {
        String token = locTokens.poll();

        for (String value : values) {
            if (value.startsWith(token)) {
                int pos = token.indexOf("=");
                if (pos > -1) {
                    return token.substring(pos + 1);
                }

                return locTokens.poll();
            }
        }
    }

    return defaultValue;
}

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

/**
 * Retrieves a set of all various statuses for the tree.
 * //w ww .j  av  a2 s .  c o  m
 * @param language
 *            the language we are checking
 * @return a set of all various statuses for the tree
 */
public Set<Integer> getTreeStatus(String language) {
    Set<Integer> status = new HashSet<Integer>();
    LinkedList<PublicationInfoNode> nodes = new LinkedList<PublicationInfoNode>();
    Set<PublicationInfoNode> processed = new HashSet<PublicationInfoNode>();
    nodes.add(root);
    processed.add(root);
    PublicationInfoNode node = nodes.poll();
    String translationNodePath = language != null && node.getChildren().size() > 0
            ? "/j:translation_" + language
            : null;
    while (node != null) {
        for (PublicationInfoNode infoNode : node.getChildren()) {
            if (!processed.contains(infoNode)
                    && (language == null || !infoNode.getPath().contains("/j:translation_")
                            || infoNode.getPath().contains(translationNodePath))) {
                nodes.add(infoNode);
            }
        }
        status.add(node.getStatus());

        node = nodes.poll();
    }
    return status;

}