Example usage for java.util Queue add

List of usage examples for java.util Queue add

Introduction

In this page you can find the example usage for java.util Queue add.

Prototype

boolean add(E e);

Source Link

Document

Inserts the specified element into this queue if it is possible to do so immediately without violating capacity restrictions, returning true upon success and throwing an IllegalStateException if no space is currently available.

Usage

From source file:org.structr.core.entity.SchemaMethod.java

private void addType(final Queue<String> typeQueue, final AbstractSchemaNode schemaNode) {

    final String _extendsClass = schemaNode.getProperty(SchemaNode.extendsClass);
    if (_extendsClass != null) {

        typeQueue.add(StringUtils.substringBefore(_extendsClass, "<"));
    }/* w  w  w.  j  a v  a2 s  .com*/

    final String _interfaces = schemaNode.getProperty(SchemaNode.implementsInterfaces);
    if (_interfaces != null) {

        for (final String iface : _interfaces.split("[, ]+")) {

            typeQueue.add(iface);
        }
    }
}

From source file:com.github.pierods.ramltoapidocconverter.RAMLToApidocConverter.java

private List<Apidoc.Operation> walkSubresources(Resource rootResource) {

    List<Apidoc.Operation> operations = new ArrayList<>();

    class NameAndResource {

        public NameAndResource(String name, Resource resource) {
            this.name = name;
            this.resource = resource;
        }// www  .  java 2s .  co  m

        public String name;
        public Resource resource;
    }

    Queue<NameAndResource> bfsAccumulator = new LinkedList<>();

    // path is specified only once for the resource. Subpaths will be only specified if parameters (:xxx), see getOperations()
    bfsAccumulator.add(new NameAndResource("", rootResource));

    while (!bfsAccumulator.isEmpty()) {

        NameAndResource nr = bfsAccumulator.remove();

        operations.addAll(getOperations(nr.name, nr.resource));

        Map<String, Resource> subresources = nr.resource.getResources();

        for (String resourceName : subresources.keySet()) {
            bfsAccumulator.add(new NameAndResource(nr.name + resourceName, subresources.get(resourceName)));
        }

    }

    operations.sort((operation1, operation2) -> {
        if (operation1.path == null) {
            return 1;
        }
        if (operation2.path == null) {
            return -1;
        }

        return operation1.path.compareTo(operation2.path);
    });

    return operations;
}

From source file:com.connection.factory.FtpConnectionApacheLib.java

@Override
public List<RemoteFileObject> readAllFilesWalkinPath(String remotePath) {
    List<RemoteFileObject> willReturnObject = new ArrayList<>();
    Queue<RemoteFileObject> directorylist = new LinkedBlockingQueue<>();
    RemoteFileObject object = null;/* w  w  w .  j  a  v  a  2 s.c  o  m*/
    object = new FtpApacheFileObject(FileInfoEnum.DIRECTORY);
    object.setDirectPath(remotePath);
    directorylist.add(object);
    try {
        while (!directorylist.isEmpty()) {
            object = directorylist.poll();
            FTPFile[] fileListTemp = _ftpObj.listFiles(object.getPath());
            for (FTPFile each : fileListTemp) {
                RemoteFileObject objectTemp = null;
                if (each.isDirectory()) {
                    objectTemp = new FtpApacheFileObject(FileInfoEnum.DIRECTORY);
                    objectTemp.setFileName(each.getName());
                    objectTemp.setAbsolutePath(object.getPath());
                    directorylist.add(objectTemp);
                } else if (each.isFile()) {
                    objectTemp = new FtpApacheFileObject(FileInfoEnum.FILE);
                    objectTemp.setFileName(each.getName());
                    objectTemp.setAbsolutePath(object.getPath());
                    objectTemp.setFileSize(each.getSize());
                    objectTemp.setFileType();
                    objectTemp.setDate(each.getTimestamp().getTime());
                    willReturnObject.add(objectTemp);
                }
            }
            object = null;
            fileListTemp = null;
        }

    } catch (IOException ex) {
        return null;
    } catch (ConnectionException ex) {

    }
    return willReturnObject;
}

From source file:com.connection.factory.FtpConnectionApacheLib.java

@Override
public void readAllFilesWalkingPathWithListener(FileListener listener, String remotePath) {
    // List<RemoteFileObject> willReturnObject = new ArrayList<>();
    Queue<RemoteFileObject> directorylist = new LinkedBlockingQueue<>();
    RemoteFileObject object = null;// w  w  w  .  j  a v  a 2  s  .  co  m
    object = new FtpApacheFileObject(FileInfoEnum.DIRECTORY);
    object.setDirectPath(remotePath);
    directorylist.add(object);
    try {
        while (!directorylist.isEmpty()) {
            object = directorylist.poll();
            FTPFile[] fileListTemp = _ftpObj.listFiles(object.getPath());
            for (FTPFile each : fileListTemp) {
                RemoteFileObject objectTemp = null;
                if (each.isDirectory()) {
                    objectTemp = new FtpApacheFileObject(FileInfoEnum.DIRECTORY);
                    objectTemp.setFileName(each.getName());
                    objectTemp.setAbsolutePath(object.getPath());
                    directorylist.add(objectTemp);
                } else if (each.isFile()) {
                    objectTemp = new FtpApacheFileObject(FileInfoEnum.FILE);
                    objectTemp.setFileName(each.getName());
                    objectTemp.setAbsolutePath(object.getPath());
                    objectTemp.setFileSize(each.getSize());
                    objectTemp.setFileType();
                    objectTemp.setDate(each.getTimestamp().getTime());
                    listener.handleRemoteFile(object);
                }
            }
            object = null;
            fileListTemp = null;
        }

    } catch (IOException | ConnectionException ex) {
        //    return null;
    }
    //  return willReturnObject;

    //  return willReturnObject;
}

From source file:com.drunkendev.io.recurse.tests.RecursionTest.java

/**
 * Answer provided by benroth./*www.  j av a 2 s .  com*/
 *
 * Uses a {@link Queue} to hold directory references while traversing until
 * the queue becomes empty. Uses the {@link java.io.File} API.
 *
 * @see     <a href="http://stackoverflow.com/a/10814316/140037">Stack-Overflow answer by benroth</a>
 */
//    @Test
public void testQueue() {
    System.out.println("\nTEST: listFiles - Queue");
    time(() -> {
        Queue<File> dirsq = new LinkedList<>();
        dirsq.add(startPath.toFile());
        int files = 0;
        int dirs = 0;
        try {
            dirs++; // to count the initial dir.
            while (!dirsq.isEmpty()) {
                for (File f : dirsq.poll().listFiles()) {
                    if (isPlainDir(f)) {
                        dirsq.add(f);
                        dirs++;
                    } else if (f.isFile()) {
                        files++;
                    }
                }
            }
            System.out.format("Files: %d, dirs: %d. ", files, dirs);
        } catch (IOException ex) {
            fail(ex.getMessage());
        }
    });
}

From source file:org.hyperic.hq.product.JDBCMeasurementPlugin.java

protected void returnCachedConnection(String url, String user, String pass, Connection conn) {
    String cacheKey = calculateKey(url, user, pass);
    Queue<Connection> pool = connectionPools.get(cacheKey);
    if (pool != null) {
        pool.add(conn);
        log.debug("[retCC] Connection for '" + cacheKey + "' returned (pool.size=" + pool.size() + ")");
    } else {/* w w  w.  ja v a 2s . c  o  m*/
        DBUtil.closeJDBCObjects(log, conn, null, null);
        log.debug("[retCC] Pool for '" + cacheKey + "' not found, closing connection");
    }
}

From source file:com.baidu.rigel.biplatform.ac.util.DataModelUtils.java

/**
 * DataModel??/*from  w  ww  .  ja va2s .  c  om*/
 * 
 * @param dataModel DataModel
 * @throws IllegalAccessException 
 */
private static void buildSortSummary(DataModel dataModel) throws IllegalAccessException {
    List<HeadField> rowLeafs = getLeafNodeList(dataModel.getRowHeadFields());
    if (CollectionUtils.isNotEmpty(rowLeafs)) {
        if (dataModel.getOperateIndex() > rowLeafs.get(0).getCompareDatas().size()) {
            throw new IllegalAccessException("can not access operate index:" + dataModel.getOperateIndex());
        }
        for (HeadField rowHeadField : dataModel.getRowHeadFields()) {
            List<HeadField> leafFileds = rowHeadField.getLeafFileds(true);
            if (CollectionUtils.isNotEmpty(leafFileds)) {

                Queue<HeadField> queue = new LinkedList<HeadField>(leafFileds);
                while (!queue.isEmpty()) {
                    HeadField leafFiled = queue.remove();
                    if (CollectionUtils.isNotEmpty(leafFiled.getCompareDatas())) {
                        leafFiled
                                .setSummarizeData(leafFiled.getCompareDatas().get(dataModel.getOperateIndex()));
                    }
                    HeadField parent = null;
                    if (leafFiled.getParent() != null) {
                        parent = leafFiled.getParent();
                    } else if (leafFiled.getParentLevelField() != null) {
                        parent = leafFiled.getParentLevelField();
                        if (!queue.contains(parent)) {
                            queue.add(parent);
                        }
                    }

                    if (parent != null && CollectionUtils.isEmpty(parent.getCompareDatas())) {
                        parent.setSummarizeData(BigDecimalUtils.addBigDecimal(parent.getSummarizeData(),
                                leafFiled.getSummarizeData()));
                    }
                }
            }

        }
    }
}

From source file:com.connection.factory.SftpConnectionApacheLib.java

@Override
public void readAllFilesWalkingPathWithListener(FileListener listener, String remotePath) {
    //     List<RemoteFileObject> willReturnObject = new ArrayList<>();
    Queue<RemoteFileObject> directorylist = new LinkedBlockingQueue<>();
    RemoteFileObject object = null;/*from w  ww  .j a  v a2s.  c  o  m*/
    object = new FtpApacheFileObject(FileInfoEnum.DIRECTORY);
    object.setDirectPath(remotePath);
    directorylist.add(object);
    try {
        while (!directorylist.isEmpty()) {
            object = directorylist.poll();
            List<ChannelSftp.LsEntry> list = command.ls(object.getPath());
            for (ChannelSftp.LsEntry each : list) {
                if (each.getFilename().equals(".") || each.getFilename().equals("..")) {
                    continue;
                }
                RemoteFileObject objectTemp = null;
                SftpATTRS attributes = each.getAttrs();
                if (attributes.isDir()) {
                    objectTemp = new SftpApacheFileObject(FileInfoEnum.DIRECTORY);
                    objectTemp.setFileName(each.getFilename());
                    objectTemp.setAbsolutePath(object.getPath());
                    directorylist.add(objectTemp);
                } else if (attributes.isReg()) {
                    objectTemp = new SftpApacheFileObject(FileInfoEnum.FILE);
                    objectTemp.setFileName(each.getFilename());
                    objectTemp.setAbsolutePath(object.getPath());
                    objectTemp.setFileSize(attributes.getSize());
                    objectTemp.setDate(attributes.getMtimeString());
                    objectTemp.setFileType();
                    listener.handleRemoteFile(object);
                }
            }
            object = null;
            list = null;
        }

    } catch (ConnectionException | SftpException ex) {
        //  ex.printStackTrace();
    }
    //return willReturnObject;
}

From source file:com.connection.factory.SftpConnectionApacheLib.java

@Override
public List<RemoteFileObject> readAllFilesWalkinPath(String remotePath) {
    List<RemoteFileObject> willReturnObject = new ArrayList<>();
    Queue<RemoteFileObject> directorylist = new LinkedBlockingQueue<>();
    RemoteFileObject object = null;// w w w  . jav a2s .c om
    object = new FtpApacheFileObject(FileInfoEnum.DIRECTORY);
    object.setDirectPath(remotePath);
    directorylist.add(object);
    try {
        while (!directorylist.isEmpty()) {
            object = directorylist.poll();
            List<ChannelSftp.LsEntry> list = command.ls(object.getPath());
            for (ChannelSftp.LsEntry each : list) {
                if (each.getFilename().equals(".") || each.getFilename().equals("..")) {
                    continue;
                }
                RemoteFileObject objectTemp = null;
                SftpATTRS attributes = each.getAttrs();
                if (attributes.isDir()) {
                    objectTemp = new SftpApacheFileObject(FileInfoEnum.DIRECTORY);
                    objectTemp.setFileName(each.getFilename());
                    objectTemp.setAbsolutePath(object.getPath());
                    directorylist.add(objectTemp);
                } else if (attributes.isReg()) {
                    objectTemp = new SftpApacheFileObject(FileInfoEnum.FILE);
                    objectTemp.setFileName(each.getFilename());
                    objectTemp.setAbsolutePath(object.getPath());
                    objectTemp.setFileSize(attributes.getSize());
                    objectTemp.setDate(attributes.getMtimeString());
                    objectTemp.setFileType();
                    willReturnObject.add(objectTemp);
                }
            }
            object = null;
            list = null;
        }

    } catch (ConnectionException | SftpException ex) {
        ex.printStackTrace();
    }
    return willReturnObject;
}

From source file:edu.berkeley.compbio.sequtils.strings.RonPSTTest.java

/**
 * {@inheritDoc}/* w ww .  java2 s. c  o m*/
 */
@Override
public void addContractTestsToQueue(final Queue<ContractTest> theContractTests) {
    theContractTests.add(new SequenceSpectrumInterfaceTest(this));
}