Example usage for java.util Deque remove

List of usage examples for java.util Deque remove

Introduction

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

Prototype

E remove();

Source Link

Document

Retrieves and removes the head of the queue represented by this deque (in other words, the first element of this deque).

Usage

From source file:Main.java

public static void main(String[] args) {

    Deque<Integer> deque = new ArrayDeque<Integer>(8);

    deque.add(1);//from w  ww  . j a va 2 s . c o  m
    deque.add(2);
    deque.add(3);
    deque.add(4);

    // this will remove element at the first(head) postion
    int retval = deque.remove();
    System.out.println("Element removed is: " + retval);

    System.out.println(deque);
}

From source file:Main.java

public static void main(String args[]) {
    Deque<String> stack = new ArrayDeque<String>();
    Deque<String> queue = new ArrayDeque<String>();

    stack.push("A");
    stack.push("B");
    stack.push("C");
    stack.push("D");

    while (!stack.isEmpty())
        System.out.print(stack.pop() + " ");

    queue.add("A");
    queue.add("B");
    queue.add("C");
    queue.add("D");
    while (!queue.isEmpty())
        System.out.print(queue.remove() + " ");
}

From source file:com.reprezen.swaggerparser.test.ExamplesTest.java

@Parameters
public static Collection<URL> findExamples() throws IOException {
    Collection<URL> examples = Lists.newArrayList();
    Deque<URL> dirs = Queues.newArrayDeque();
    String auth = System.getenv("GITHUB_AUTH") != null ? System.getenv("GITHUB_AUTH") + "@" : "";
    String request = String.format("https://%sapi.github.com/repos/%s/contents/%s?ref=%s", auth, SPEC_REPO,
            EXAMPLES_ROOT, EXAMPLES_BRANCH);
    dirs.add(new URL(request));
    while (!dirs.isEmpty()) {
        URL url = dirs.remove();
        String json = IOUtils.toString(url, Charsets.UTF_8);
        JsonNode tree = mapper.readTree(json);
        for (JsonNode result : iterable(tree.elements())) {
            String type = result.get("type").asText();
            String path = result.get("path").asText();
            String resultUrl = result.get("url").asText();
            if (type.equals("dir")) {
                dirs.add(new URL(resultUrl));
            } else if (type.equals("file") && (path.endsWith(".yaml") || path.endsWith(".json"))) {
                String downloadUrl = result.get("download_url").asText();
                examples.add(new URL(downloadUrl));
            }/*from  w ww.j  av a  2 s . c  o  m*/
        }
    }
    return examples;
}

From source file:com.fizzed.blaze.system.TailTest.java

@Test
public void works() throws Exception {
    Tail tail = new Tail(null);

    String s = "a\nb\nc\n";

    StringReader sr = new StringReader(s);

    tail.pipeInput(new ReaderInputStream(sr));

    Deque<String> output = tail.run();

    assertThat(output.size(), is(3));//w w w  .  j  a  v a  2 s.c  o m
    assertThat(output.remove(), is("a"));
    assertThat(output.remove(), is("b"));
    assertThat(output.remove(), is("c"));
}

From source file:logicProteinHypernetwork.analysis.reactions.ComplexMultigraph.java

public Set<Integer> bfs() {
    Set<Integer> visited = new HashSet<Integer>();
    Deque<Integer> todo = new ArrayDeque<Integer>();

    todo.add(0);//from  w  w w . j  a  v  a2 s  .  c o m
    while (!todo.isEmpty()) {
        int u = todo.remove();
        visited.add(u);

        for (int v : getNeighbors(u)) {
            todo.add(v);
        }
    }
    return visited;
}

From source file:logicProteinHypernetwork.analysis.reactions.ComplexMultigraph.java

private void subtract(Set<Interaction> impossible, int vertex) throws NotConnectedException {
    Set<Integer> visited = new HashSet<Integer>();
    Deque<Integer> todo = new ArrayDeque<Integer>();

    todo.add(vertex);/*from   ww  w  .  ja  va 2s  . c  o  m*/
    while (!todo.isEmpty()) {
        int u = todo.remove();
        visited.add(u);

        for (int e : getIncidentEdges(u)) {
            Interaction i = edgesToInteractions.get(e);
            if (impossible.contains(i)) {
                removeEdge(e);
                edgesToInteractions.remove(e);
                interactionToEdges.remove(i, e);
                impossible.remove(i);
            }
        }

        for (int v : getNeighbors(u)) {
            todo.add(v);
        }
    }

    if (visited.size() < getVertexCount()) {
        throw new NotConnectedException();
    }
}

From source file:com.reprezen.swaggerparser.test.BigParseTest.java

private Object getFromModelObject(JsonOverlay<?> modelObj, Deque<PathKey> path) {
    if (modelObj == null) {
        throw new NullPointerException("Attempt to get value of a null overlay");
    } else if (path.isEmpty()) {
        return modelObj.get();
    } else {//from   w  ww .  j a  v  a  2  s  .c o  m
        PathKey key = path.remove();
        if (modelObj instanceof CollectionOverlay<?>) {
            JsonOverlay<?> item = getFromCollectionOverlay((CollectionOverlay<?>) modelObj, key);
            return getFromModelObject(item, path);
        } else if (modelObj instanceof ObjectOverlay<?>) {
            path.addFirst(key);
            ArrayDeque<PathKey> origPath = Queues.newArrayDeque(path);
            Optional<? extends JsonOverlay<?>> field;
            try {
                field = getField((ObjectOverlay<?>) modelObj, path);
            } catch (IllegalArgumentException | IllegalAccessException e) {
                throw new IllegalStateException("Cannot access object overlay field value", e);
            }
            if (field.isPresent()) {
                return getFromModelObject(field.get(), path);
            } else {
                throw new IllegalArgumentException(
                        "Path does not identify an object overlay field: " + origPath);
            }

        } else {
            throw new UnsupportedOperationException("Attempt to get a component from a primitive overlay");
        }
    }
}

From source file:com.spotify.helios.agent.QueueingHistoryWriter.java

private void add(TaskStatusEvent item) throws InterruptedException {
    // If too many "globally", toss them
    while (count.get() >= MAX_TOTAL_SIZE) {
        getNext();//from w  ww .  ja  v a 2s . c  om
    }

    final JobId key = item.getStatus().getJob().getId();
    final Deque<TaskStatusEvent> deque = getDeque(key);

    synchronized (deque) {
        // if too many in the particular deque, toss them
        while (deque.size() >= MAX_QUEUE_SIZE) {
            deque.remove();
            count.decrementAndGet();
        }
        deque.add(item);
        count.incrementAndGet();
    }

    try {
        backingStore.set(items);
    } catch (ClosedByInterruptException e) {
        log.debug("Writing task status event to backing store was interrupted");
    } catch (IOException e) { // We are best effort after all...
        log.warn("Failed to write task status event to backing store", e);
    }
}

From source file:ict.ocrabase.main.java.client.bulkload.LoadHFiles.java

/**
 * Perform a bulk load of the given directory into the given
 * pre-existing table./*from  w w w .j av a 2  s . c  o  m*/
 * @param hfofDir the directory that was provided as the output path
 * of a job using HFileOutputFormat
 * @param table the table to load into
 * @throws TableNotFoundException if table does not yet exist
 */
public void doBulkLoad(Path outDir, String[] tableNames) throws TableNotFoundException, IOException {
    Configuration config = getConf();
    int num = 0;
    int tableNum = tableNames.length;
    for (String tableName : tableNames) {
        HTable table = new HTable(config, tableName);
        Path hfofDir = new Path(outDir, tableName);
        HConnection conn = table.getConnection();

        if (!conn.isTableAvailable(table.getTableName())) {
            throw new TableNotFoundException(
                    "Table " + Bytes.toStringBinary(table.getTableName()) + "is not currently available.");
        }

        Deque<LoadQueueItem> queue = null;
        try {
            queue = discoverLoadQueue(hfofDir);
            int total = queue.size();
            while (!queue.isEmpty()) {
                LoadQueueItem item = queue.remove();
                tryLoad(item, conn, table.getTableName(), queue, config);
                progress = (num + 1 - (float) queue.size() / total) / tableNum;
            }
        } finally {
            if (queue != null && !queue.isEmpty()) {
                StringBuilder err = new StringBuilder();
                err.append("-------------------------------------------------\n");
                err.append("Bulk load aborted with some files not yet loaded:\n");
                err.append("-------------------------------------------------\n");
                for (LoadQueueItem q : queue) {
                    err.append("  ").append(q.hfilePath).append('\n');
                }
                LOG.error(err);
                throw new IOException();
            }
        }
        num++;
    }
    progress = 1;
}

From source file:com.reprezen.swaggerparser.test.BigParseTest.java

private Optional<? extends JsonOverlay<?>> getField(ObjectOverlay<?> modelObj, Deque<PathKey> path)
        throws IllegalArgumentException, IllegalAccessException {
    String key = "";
    boolean first = true;
    Optional<? extends JsonOverlay<?>> value = Optional.absent();
    if (path.peek() != null && path.peek().isIndex()) {
        // next path item is an index, so our only shot is to get a list overlay bound directly to this object's
        // json node
        value = modelObj.getFieldValue("");
        if (value.isPresent()
                && (value.get() instanceof ListOverlay || value.get() instanceof ValListOverlay)) {
            return value;
        }/* ww  w . j  a  va  2 s .  c o  m*/
    }
    while (!value.isPresent()) {
        if (path.peek() == null || path.peek().isIndex()) {
            break;
        }
        String next = path.remove().getString();
        key = first ? next : key + ":" + next;
        value = modelObj.getFieldValue(key);
        first = false;
    }
    return value;
}