Example usage for java.util Deque isEmpty

List of usage examples for java.util Deque isEmpty

Introduction

In this page you can find the example usage for java.util Deque isEmpty.

Prototype

boolean isEmpty();

Source Link

Document

Returns true if this collection contains no elements.

Usage

From source file:org.apache.hadoop.hbase.replication.regionserver.HFileReplicator.java

private void doBulkLoad(LoadIncrementalHFiles loadHFiles, Table table, Deque<LoadQueueItem> queue,
        RegionLocator locator, int maxRetries) throws IOException {
    int count = 0;
    Pair<byte[][], byte[][]> startEndKeys;
    while (!queue.isEmpty()) {
        // need to reload split keys each iteration.
        startEndKeys = locator.getStartEndKeys();
        if (count != 0) {
            LOG.warn("Error occured while replicating HFiles, retry attempt " + count + " with " + queue.size()
                    + " files still remaining to replicate.");
        }/*from  w  w  w.j a v  a2 s  .c om*/

        if (maxRetries != 0 && count >= maxRetries) {
            throw new IOException("Retry attempted " + count + " times without completing, bailing out.");
        }
        count++;

        // Try bulk load
        loadHFiles.loadHFileQueue(table, connection, queue, startEndKeys);
    }
}

From source file:com.spotify.helios.servicescommon.coordination.DefaultZooKeeperClient.java

@Override
public List<String> listRecursive(final String path) throws KeeperException {
    assertClusterIdFlagTrue();//w w  w  .  j ava  2s .  c o m
    final Deque<String> queue = newLinkedList();
    final List<String> tree = newArrayList();

    queue.add(path);
    tree.add(path);

    while (!queue.isEmpty()) {
        final String node = queue.pollFirst();
        final List<String> children = getChildren(node);

        for (final String child : children) {
            final String childPath = node.replaceAll("/$", "") + "/" + child;
            queue.add(childPath);
            tree.add(childPath);
        }
    }

    return tree;
}

From source file:uniol.apt.adt.automaton.FiniteAutomatonUtility.java

static private List<String> findAcceptedWord(DeterministicFiniteAutomaton dfa) {
    Set<DFAState> statesSeen = new HashSet<>();
    LinkedList<String> word = new LinkedList<>();
    Deque<Pair<DFAState, Iterator<Symbol>>> trace = new LinkedList<>();
    DFAState initial = dfa.getInitialState();
    trace.add(new Pair<>(initial, initial.getDefinedSymbols().iterator()));

    while (!trace.isEmpty()) {
        InterrupterRegistry.throwIfInterruptRequestedForCurrentThread();
        Pair<DFAState, Iterator<Symbol>> pair = trace.peekLast();
        if (!pair.getSecond().hasNext()) {
            trace.removeLast();/*from  w  w w  . j av a2 s. c  om*/
            word.pollLast();
        } else {
            Symbol symbol = pair.getSecond().next();
            DFAState nextState = pair.getFirst().getFollowingState(symbol);

            // Only follow this state if we haven't followed it yet before
            if (statesSeen.add(nextState)) {
                trace.add(new Pair<>(nextState, nextState.getDefinedSymbols().iterator()));
                word.add(symbol.getEvent());

                if (nextState.isFinalState())
                    return word;
            }
        }
    }

    return null;
}

From source file:edu.stanford.cfuller.imageanalysistools.filter.VariableSizeMeanFilter.java

@Override
public void apply(WritableImage im) {

    //calculate Laplacian of Image, calculate pseudo-residual (as in Boulanger, 2010)

    WritableImage residual = ImageFactory.createWritable(im);

    LaplacianFilterND LF = new LaplacianFilterND();

    LF.apply(residual);/*from   w w  w.j  av  a 2  s.c  o  m*/

    //for 3D, residual is Laplacian divided by sqrt(56)

    float norm = (float) Math.sqrt(56);

    //for 2D, residual is sqrt(30)

    //norm = Math.sqrt(30);

    for (ImageCoordinate ic : residual) {

        residual.setValue(ic, residual.getValue(ic) / norm);

    }

    //perform an octtree segmentation of the Image, using a criterion based on relative variance of image and noise (as in Boulanger, 2010)

    OcttreeNode root = new OcttreeNode(ImageCoordinate.createCoordXYZCT(0, 0, 0, 0, 0),
            ImageCoordinate.cloneCoord(im.getDimensionSizes()));

    if (this.shouldSubDivide(root, im, residual)) {
        root.subDivide();
    }

    Deque<OcttreeNode> queue = new java.util.ArrayDeque<OcttreeNode>();

    queue.addAll(root.getChildren());

    List<OcttreeNode> leaves = new java.util.ArrayList<OcttreeNode>();

    while (!queue.isEmpty()) {

        OcttreeNode current = queue.pop();

        if (this.shouldSubDivide(current, im, residual) && current.subDivide()) {

            queue.addAll(current.getChildren());

        } else {

            leaves.add(current);

        }

    }

    for (OcttreeNode node : leaves) {

        double count = 0;
        float mean = 0;

        im.setBoxOfInterest(node.getBoxMin(), node.getBoxMax());

        for (ImageCoordinate ic : im) {

            mean += im.getValue(ic);
            count++;

        }

        mean /= count;

        for (ImageCoordinate ic : im) {

            im.setValue(ic, mean);

        }

        im.clearBoxOfInterest();

    }

}

From source file:org.apache.hadoop.hive.ql.parse.mr3.GenMR3Utils.java

public void removeUnionOperators(Configuration conf, GenMR3ProcContext context, BaseWork work)
        throws SemanticException {

    List<Operator<?>> roots = new ArrayList<Operator<?>>();
    roots.addAll(work.getAllRootOperators());
    if (work.getDummyOps() != null) {
        roots.addAll(work.getDummyOps());
    }//www  . j  av a2  s  . c om
    roots.addAll(context.eventOperatorSet);

    // need to clone the plan.
    List<Operator<?>> newRoots = Utilities.cloneOperatorTree(conf, roots);

    // we're cloning the operator plan but we're retaining the original work. That means
    // that root operators have to be replaced with the cloned ops. The replacement map
    // tells you what that mapping is.
    BiMap<Operator<?>, Operator<?>> replacementMap = HashBiMap.create();

    // there's some special handling for dummyOps required. Mapjoins won't be properly
    // initialized if their dummy parents aren't initialized. Since we cloned the plan
    // we need to replace the dummy operators in the work with the cloned ones.
    List<HashTableDummyOperator> dummyOps = new LinkedList<HashTableDummyOperator>();

    Iterator<Operator<?>> it = newRoots.iterator();
    for (Operator<?> orig : roots) {
        Operator<?> newRoot = it.next();

        replacementMap.put(orig, newRoot);

        if (newRoot instanceof HashTableDummyOperator) {
            // dummy ops need to be updated to the cloned ones.
            dummyOps.add((HashTableDummyOperator) newRoot);
            it.remove();
        } else if (newRoot instanceof AppMasterEventOperator) {
            // event operators point to table scan operators. When cloning these we
            // need to restore the original scan.
            if (newRoot.getConf() instanceof DynamicPruningEventDesc) {
                TableScanOperator ts = ((DynamicPruningEventDesc) orig.getConf()).getTableScan();
                if (ts == null) {
                    throw new AssertionError("No table scan associated with dynamic event pruning. " + orig);
                }
                ((DynamicPruningEventDesc) newRoot.getConf()).setTableScan(ts);
            }
            it.remove();
        } else {
            if (newRoot instanceof TableScanOperator) {
                if (context.tsToEventMap.containsKey(orig)) {
                    // we need to update event operators with the cloned table scan
                    for (AppMasterEventOperator event : context.tsToEventMap.get(orig)) {
                        ((DynamicPruningEventDesc) event.getConf()).setTableScan((TableScanOperator) newRoot);
                    }
                }
            }
            context.rootToWorkMap.remove(orig);
            context.rootToWorkMap.put(newRoot, work);
        }
    }

    // now we remove all the unions. we throw away any branch that's not reachable from
    // the current set of roots. The reason is that those branches will be handled in
    // different tasks.
    Deque<Operator<?>> operators = new LinkedList<Operator<?>>();
    operators.addAll(newRoots);

    Set<Operator<?>> seen = new HashSet<Operator<?>>();

    while (!operators.isEmpty()) {
        Operator<?> current = operators.pop();
        seen.add(current);

        if (current instanceof FileSinkOperator) {
            FileSinkOperator fileSink = (FileSinkOperator) current;

            // remember it for additional processing later
            context.fileSinkSet.add(fileSink);

            FileSinkDesc desc = fileSink.getConf();
            Path path = desc.getDirName();
            List<FileSinkDesc> linked;

            if (!context.linkedFileSinks.containsKey(path)) {
                linked = new ArrayList<FileSinkDesc>();
                context.linkedFileSinks.put(path, linked);
            }
            linked = context.linkedFileSinks.get(path);
            linked.add(desc);

            desc.setDirName(new Path(path, "" + linked.size()));
            desc.setLinkedFileSinkDesc(linked);
        }

        if (current instanceof AppMasterEventOperator) {
            // remember for additional processing later
            context.eventOperatorSet.add((AppMasterEventOperator) current);

            // mark the original as abandoned. Don't need it anymore.
            context.abandonedEventOperatorSet
                    .add((AppMasterEventOperator) replacementMap.inverse().get(current));
        }

        if (current instanceof UnionOperator) {
            Operator<?> parent = null;
            int count = 0;

            for (Operator<?> op : current.getParentOperators()) {
                if (seen.contains(op)) {
                    ++count;
                    parent = op;
                }
            }

            // we should have been able to reach the union from only one side.
            assert count <= 1;

            if (parent == null) {
                // root operator is union (can happen in reducers)
                replacementMap.put(current, current.getChildOperators().get(0));
            } else {
                parent.removeChildAndAdoptItsChildren(current);
            }
        }

        if (current instanceof FileSinkOperator || current instanceof ReduceSinkOperator) {
            current.setChildOperators(null);
        } else {
            operators.addAll(current.getChildOperators());
        }
    }
    work.setDummyOps(dummyOps);
    work.replaceRoots(replacementMap);
}

From source file:org.talend.dataquality.semantic.statistics.SemanticQualityAnalyzer.java

/**
 * For the validation of a COMPOUND category, we only have to valid the leaves children categories.
 * This methods find the DICT children categories and the REGEX children categories.
 * //  www. j  a v a  2 s . c  om
 * @param id, the category from we search the children
 * @return the DICT children categories and the REGEX children categories with a map.
 */
private Map<CategoryType, Set<DQCategory>> getChildrenCategories(String id) {
    Deque<String> catToSee = new ArrayDeque<>();
    Set<String> catAlreadySeen = new HashSet<>();
    Map<CategoryType, Set<DQCategory>> children = new HashMap<>();
    children.put(CategoryType.REGEX, new HashSet<DQCategory>());
    children.put(CategoryType.DICT, new HashSet<DQCategory>());
    catToSee.add(id);
    String currentCategory;
    while (!catToSee.isEmpty()) {
        currentCategory = catToSee.pop();
        DQCategory dqCategory = crm.getCategoryMetadataById(currentCategory);
        if (dqCategory != null)
            if (!CollectionUtils.isEmpty(dqCategory.getChildren())) {
                for (DQCategory child : dqCategory.getChildren()) {
                    if (!catAlreadySeen.contains(child.getId())) {
                        catAlreadySeen.add(child.getId());
                        catToSee.add(child.getId());
                    }
                }
            } else if (!currentCategory.equals(id)) {
                children.get(dqCategory.getType()).add(dqCategory);
            }
    }
    return children;
}

From source file:ninja.undertow.NinjaUndertowContext.java

@Override
public String getParameter(String name) {
    // Returns the value of a request parameter as a String, or null if the
    // parameter does not exist. Request parameters are extra information sent
    // with the request. For ninja (following servlet rule), parameters are contained in the
    // query string or posted form data.
    Deque<String> queryParameterValues = exchange.getQueryParameters().get(name);

    if (queryParameterValues != null && !queryParameterValues.isEmpty()) {
        return queryParameterValues.getFirst();
    } else {//w  w  w .  ja v a 2s.c  om
        // fallback to form data
        if (this.formData != null) {
            FormData.FormValue value = this.formData.getFirst(name);
            if (value != null) {
                return value.getValue();
            }
        }
    }

    return null;
}

From source file:specminers.evaluation.MinedSpecsFilter.java

private boolean checkIfCatchSectionSwallowsException(String catchBlockStartLine) {
    int startIndex = this.lines.indexOf(catchBlockStartLine);

    // contains return, continue or does not throw.
    Deque<String> blocks = new LinkedList<>();
    blocks.add(catchBlockStartLine);// w  w w.  ja  v a  2  s  . c  om

    Deque<Integer> blockStartPositions = new LinkedList<>();
    blockStartPositions.add(sourceCode.indexOf(catchBlockStartLine) + catchBlockStartLine.indexOf("{"));

    boolean throwFound = false;

    int currentBlockStart = blockStartPositions.peekFirst();
    int currentIndexInFile = currentBlockStart;
    for (int i = startIndex; i < lines.size(); i++) {
        String line = lines.get(i);
        if (!blocks.isEmpty()) {
            if (line.contains("{") && i != startIndex) {
                blocks.add(line);
                blockStartPositions.add(sourceCode.indexOf(line.trim()));
            }

            if (line.contains("}") && line.indexOf("}") + currentIndexInFile > currentBlockStart) {
                blocks.pop();
                currentBlockStart = blockStartPositions.pop();
            }
            if (line.contains("return ") || line.contains("return;") || line.contains("continue;")) {
                return true;
            }

            if (line.contains("throw ")) {
                throwFound = true;
            }
        }
        currentIndexInFile += line.length();
    }

    return !throwFound;
}

From source file:de.nrw.hbz.regal.sync.ingest.Downloader.java

/**
 * @param directory//ww  w.  j  a  v  a  2  s. c  om
 *            the directory will be zipped
 * @param zipfile
 *            the Outputfile
 */
@SuppressWarnings("resource")
protected void zip(File directory, File zipfile) {

    try (ZipOutputStream zout = new ZipOutputStream(new FileOutputStream(zipfile))) {
        URI base = directory.toURI();
        Deque<File> queue = new LinkedList<File>();
        queue.push(directory);

        while (!queue.isEmpty()) {
            directory = queue.pop();
            for (File kid : directory.listFiles()) {
                String name = base.relativize(kid.toURI()).getPath();
                if (kid.isDirectory()) {
                    queue.push(kid);
                    name = name.endsWith("/") ? name : name + "/";
                    zout.putNextEntry(new ZipEntry(name));
                } else {
                    zout.putNextEntry(new ZipEntry(name));
                    copy(kid, zout);
                    zout.closeEntry();
                }
            }
        }
    } catch (IOException e) {
        throw new ZipDownloaderException(e);
    }
}

From source file:org.apache.pig.newplan.BaseOperatorPlan.java

/**
 * Move everything below a given operator to the new operator plan.  The specified operator will
 * be moved and will be the root of the new operator plan
 * @param root Operator to move everything after
 * @param newPlan new operator plan to move things into
 * @throws PlanException /*www .  j  a v  a  2s . c  om*/
 */
public void moveTree(Operator root, BaseOperatorPlan newPlan) throws FrontendException {
    Deque<Operator> queue = new ArrayDeque<Operator>();
    newPlan.add(root);
    root.setPlan(newPlan);
    queue.addLast(root);
    while (!queue.isEmpty()) {
        Operator node = queue.poll();
        if (getSuccessors(node) != null) {
            for (Operator succ : getSuccessors(node)) {
                if (!queue.contains(succ)) {
                    queue.addLast(succ);
                    newPlan.add(succ);
                    succ.setPlan(newPlan);
                    newPlan.connect(node, succ);
                }
            }
        }
    }

    trimBelow(root);
}