Example usage for java.util Queue poll

List of usage examples for java.util Queue poll

Introduction

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

Prototype

E poll();

Source Link

Document

Retrieves and removes the head of this queue, or returns null if this queue is empty.

Usage

From source file:org.protempa.backend.ksb.SimpleKnowledgeSourceBackend.java

private Collection<PropositionDefinition> collectSubtreePropositionDefinitionsInt(String[] propIds,
        boolean narrower, boolean inDataSource) {
    ProtempaUtil.checkArray(propIds, "propDefs");
    Set<PropositionDefinition> propResult = new HashSet<>();
    Queue<String> queue = new LinkedList<>();
    for (String pd : propIds) {
        queue.add(pd);/*from   w w  w.  j av  a2  s.  com*/
    }
    while (!queue.isEmpty()) {
        String propId = queue.poll();
        PropositionDefinition pd = this.propDefsMap.get(propId);
        if (!inDataSource || pd.getInDataSource()) {
            propResult.add(pd);
        }
        if (narrower) {
            Arrays.addAll(queue, pd.getChildren());
        } else {
            Arrays.addAll(queue, pd.getInverseIsA());
        }
    }
    return propResult;
}

From source file:com.naver.wordladder.WordLadder.java

public void printTree() {
    Queue<Node<String>> queue = new LinkedList<Node<String>>();
    List<String> path = new ArrayList<String>();

    int shortestPathLength = dictionary.size();

    queue.offer(new Node<String>(startString));
    Node<String> currentNode;
    while ((currentNode = queue.poll()) != null) {
        String str = currentNode.getData();
        path.add(str);//from  w  ww  .j a  v a 2 s .  c  om
        Set<String> oneDistanceWords = getOneDistanceWords(str);
        for (String oneDistanceWord : oneDistanceWords) {
            if (path.contains(oneDistanceWord)) {
                continue;
            }
            Node<String> child = new Node<String>(oneDistanceWord);
            child.setParent(currentNode);
            child.setLevel(currentNode.getLevel() + 1);

            if (calculateEditDistance(oneDistanceWord, endString) == 1
                    && child.getLevel() <= shortestPathLength) {
                shortestPathLength = child.getLevel();
                System.out.println(shortestPathLength);
                Node<String> leaf = new Node<String>(endString);
                leaf.setParent(child);
                leaf.printTree();
            }
            queue.offer(child);
        }
    }
}

From source file:com.liferay.server.manager.internal.executor.PluginExecutor.java

@Override
public void executeRead(HttpServletRequest request, JSONObject responseJSONObject, Queue<String> arguments) {

    JSONObject pluginPackageJSONObject = JSONFactoryUtil.createJSONObject();

    String context = arguments.poll();

    PluginPackage pluginPackage = DeployManagerUtil.getInstalledPluginPackage(context);

    boolean installed = true;

    if (pluginPackage == null) {
        installed = false;//from   w w  w  . j a v  a 2s .c om
    }

    pluginPackageJSONObject.put("installed", installed);

    boolean started = true;

    if (pluginPackage == null) {
        started = false;
    }

    pluginPackageJSONObject.put("started", started);

    List<String> types = new ArrayList<>();

    if (pluginPackage != null) {
        types = pluginPackage.getTypes();
    }

    JSONArray typesJSONArray = JSONFactoryUtil.createJSONArray();

    for (String type : types) {
        typesJSONArray.put(type);
    }

    pluginPackageJSONObject.put("types", typesJSONArray);

    responseJSONObject.put(JSONKeys.OUTPUT, pluginPackageJSONObject);
}

From source file:it.geosolutions.geobatch.destination.action.DestinationBaseAction.java

public Queue<EventObject> execute(Queue<EventObject> events) throws ActionException {
    listenerForwarder.setTask("Check config");
    checkInit();//from   w w  w . ja v  a 2s .c  o m

    final LinkedList<EventObject> ret = new LinkedList<EventObject>();
    try {
        listenerForwarder.started();
        while (!events.isEmpty()) {
            EventObject event = events.poll();
            File file = null;
            if (event instanceof FileSystemEvent) {
                FileSystemEvent fse = (FileSystemEvent) event;
                file = fse.getSource();
            }
            FeatureConfiguration featureConfiguration = unwrapFeatureConfig(event);
            DataStore ds = FeatureConfigurationUtil.createDataStore(featureConfiguration);
            if (ds == null) {
                throw new ActionException(this, "Can't find datastore ");
            }
            try {
                if (!(ds instanceof JDBCDataStore)) {
                    throw new ActionException(this, "Bad Datastore type " + ds.getClass().getName());
                }
                JDBCDataStore dataStore = (JDBCDataStore) ds;
                dataStore.setExposePrimaryKeyColumns(true);
                MetadataIngestionHandler metadataHandler = new MetadataIngestionHandler(dataStore);
                doProcess((T) getConfiguration(), featureConfiguration, dataStore, metadataHandler, file);

                // pass the feature config to the next action
                ret.add(createOutputEvent(event));
            } finally {
                ds.dispose();
            }
        }
        listenerForwarder.completed();
        return ret;
    } catch (Exception t) {
        listenerForwarder.failed(t);
        throw new ActionException(this, t.getMessage(), t);
    }
}

From source file:playground.johannes.socialnets.NetworkGenerator2.java

private TObjectIntHashMap<Ego> initDegreeDistribution(Collection<? extends Ego> egos) {
    TObjectIntHashMap<Ego> stubsMap = new TObjectIntHashMap<Ego>();
    /*//from  www .  j a va 2 s  . co  m
     * For now, uniform degree distribution
     */
    Queue<Ego> egos2 = new LinkedList<Ego>(egos);
    while (!egos2.isEmpty()) {
        Ego e1 = egos2.poll();
        for (Ego e2 : egos) {
            if (random.nextDouble() <= 1 / alpha * getDyadProba(e1, e2, scale)) {
                stubsMap.adjustOrPutValue(e1, 1, 1);
                stubsMap.adjustOrPutValue(e2, 1, 1);
            }
        }
    }

    return stubsMap;
}

From source file:objects.PatternEntry.java

public PatternEntry[] segment(Ruleset rule) {
    if (cells.getW() == 0 || cells.getH() == 0) {
        PatternEntry[] returnArray = {};
        return returnArray;
    }/*  w  ww  .j  av  a 2s .  co m*/
    int startX = 0;
    int startY = 0;
    for (int x = 0; x < cells.getW(); x++)
        for (int y = 0; y < cells.getH(); y++)
            if (cells.pattern[x][y] != 0) {
                startX = x;
                startY = y;
                break;
            }
    boolean[][] isPart = new boolean[cells.getW()][cells.getH()];
    Queue<int[]> knownPoints = new LinkedList<int[]>();
    int[] starterPoint = { startX, startY };
    knownPoints.add(starterPoint);
    isPart[startX][startY] = true;
    while (!knownPoints.isEmpty()) {
        int[] pt = knownPoints.poll();
        for (int[] dP : rule.getNeighborField()) {
            int[] thispt = { pt[0] + dP[0], pt[1] + dP[1] };
            if (Engine.getByte(cells.pattern, thispt[0], thispt[1]) != 0
                    && !Engine.isActive(isPart, thispt[0], thispt[1])) {
                knownPoints.add(thispt);
                isPart[thispt[0]][thispt[1]] = true;
            }
        }
    }

    boolean canSplit = false;
    for (int x = 0; x < cells.getW(); x++)
        for (int y = 0; y < cells.getH(); y++)
            if (cells.pattern[x][y] != 0 && !isPart[x][y])
                canSplit = true;

    if (canSplit) {
        byte[][] cellsOne = new byte[cells.getW()][cells.getH()];
        byte[][] cellsTwo = new byte[cells.getW()][cells.getH()];
        for (int x = 0; x < cells.getW(); x++)
            for (int y = 0; y < cells.getH(); y++) {
                if (isPart[x][y])
                    cellsOne[x][y] = cells.pattern[x][y];
                else
                    cellsTwo[x][y] = cells.pattern[x][y];
            }
        PatternEntry componentPatternOne = new PatternEntry(cellsOne);
        PatternEntry[] getOtherParts = new PatternEntry(cellsTwo).segment(rule);
        return ArrayUtils.addAll(getOtherParts, componentPatternOne);
    }

    PatternEntry[] returnArray = { this };
    return returnArray;

}

From source file:org.apache.hadoop.yarn.server.resourcemanager.recovery.TestFSRMStateStore.java

private void verifyFilesUnreadablebyHDFS(MiniDFSCluster cluster, Path root) throws Exception {
    DistributedFileSystem fs = cluster.getFileSystem();
    Queue<Path> paths = new LinkedList<>();
    paths.add(root);/*  w  w  w.j  a  v  a  2 s  .co m*/
    while (!paths.isEmpty()) {
        Path p = paths.poll();
        FileStatus stat = fs.getFileStatus(p);
        if (!stat.isDirectory()) {
            try {
                LOG.warn("\n\n ##Testing path [" + p + "]\n\n");
                fs.open(p);
                Assert.fail("Super user should not be able to read [" + UserGroupInformation.getCurrentUser()
                        + "] [" + p.getName() + "]");
            } catch (AccessControlException e) {
                Assert.assertTrue(
                        e.getMessage().contains("superuser is not allowed to perform this operation"));
            } catch (Exception e) {
                Assert.fail("Should get an AccessControlException here");
            }
        }
        if (stat.isDirectory()) {
            FileStatus[] ls = fs.listStatus(p);
            for (FileStatus f : ls) {
                paths.add(f.getPath());
            }
        }
    }

}

From source file:org.polymap.model2.engine.EntityRepositoryImpl.java

public EntityRepositoryImpl(final Configuration config) {
    this.config = config;

    // init store
    getStore().init(new StoreRuntimeContextImpl());

    // init infos
    log.debug("Initialializing Composite types:");
    Queue<Class<? extends Composite>> queue = new LinkedList();
    queue.addAll(Arrays.asList(config.entities.get()));

    while (!queue.isEmpty()) {
        Class<? extends Composite> type = queue.poll();
        if (!infos.containsKey(type)) {
            log.debug("    Composite type: " + type);
            CompositeInfoImpl info = new CompositeInfoImpl(type);
            infos.put(type, info);/*from w ww.j  a  va 2 s .  co m*/

            // init static TYPE variable
            try {
                Field field = type.getDeclaredField("TYPE");
                field.setAccessible(true);
                field.set(null, Expressions.template(type, this));
            } catch (NoSuchFieldException e) {
            } catch (SecurityException | IllegalAccessException e) {
                throw new ModelRuntimeException(e);
            }

            // mixins
            queue.addAll(info.getMixins());

            // Composite properties
            for (PropertyInfo propInfo : info.getProperties()) {
                if (Composite.class.isAssignableFrom(propInfo.getType())) {
                    queue.offer(propInfo.getType());
                }
            }
        }
    }
}

From source file:hudson.plugins.plot.XMLSeries.java

/***
 * This is a fallback strategy for nodesets that include non numeric content
 * enabling users to create lists by selecting them such that names and
 * values share a common parent. If a node has attributes and is empty that
 * node will be re-enqueued as a parent to its attributes.
 * /*from   w ww  .  j a  v  a 2 s .c  o m*/
 * @param buildNumber
 *            the build number
 * 
 * @returns a list of PlotPoints where the label is the last non numeric
 *          text content and the value is the last numeric text content for
 *          each set of nodes under a given parent.
 ***/
private List<PlotPoint> coalesceTextnodesAsLabelsStrategy(NodeList nodeList, int buildNumber) {
    Map<Node, List<Node>> parentNodeMap = new HashMap<Node, List<Node>>();

    for (int i = 0; i < nodeList.getLength(); i++) {
        Node node = nodeList.item(i);
        if (!parentNodeMap.containsKey(node.getParentNode())) {
            parentNodeMap.put(node.getParentNode(), new ArrayList<Node>());
        }
        parentNodeMap.get(node.getParentNode()).add(node);
    }

    List<PlotPoint> retval = new ArrayList<PlotPoint>();
    Queue<Node> parents = new ArrayDeque<Node>(parentNodeMap.keySet());
    while (!parents.isEmpty()) {
        Node parent = parents.poll();
        Double value = null;
        String label = null;

        for (Node child : parentNodeMap.get(parent)) {
            if (null == child.getTextContent() || child.getTextContent().trim().isEmpty()) {
                NamedNodeMap attrmap = child.getAttributes();
                List<Node> attrs = new ArrayList<Node>();
                for (int i = 0; i < attrmap.getLength(); i++) {
                    attrs.add(attrmap.item(i));
                }
                parentNodeMap.put(child, attrs);
                parents.add(child);
            } else if (new Scanner(child.getTextContent().trim()).hasNextDouble()) {
                value = new Scanner(child.getTextContent().trim()).nextDouble();
            } else {
                label = child.getTextContent().trim();
            }
        }
        if ((label != null) && (value != null)) {
            addValueToList(retval, new String(label), String.valueOf(value), buildNumber);
        }
    }
    return retval;
}

From source file:org.polymap.core.model2.engine.EntityRepositoryImpl.java

public EntityRepositoryImpl(final EntityRepositoryConfiguration config) {
    this.config = config;

    // init store
    getStore().init(new StoreRuntimeContextImpl());

    // init infos
    log.info("Initialializing Composite types:");
    Queue<Class<? extends Composite>> queue = new LinkedList();
    queue.addAll(Arrays.asList(config.getEntities()));

    while (!queue.isEmpty()) {
        log.info("    Composite type: " + queue.peek());
        CompositeInfoImpl info = new CompositeInfoImpl(queue.poll());
        infos.put(info.getType(), info);

        // mixins
        queue.addAll(info.getMixins());/*from w  w  w  . j  a v a2 s.  c om*/

        // Composite properties
        for (PropertyInfo propInfo : info.getProperties()) {
            if (Composite.class.isAssignableFrom(propInfo.getType())) {
                queue.offer(propInfo.getType());
            }
        }
    }
}