Example usage for java.util Deque add

List of usage examples for java.util Deque add

Introduction

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

Prototype

boolean add(E e);

Source Link

Document

Inserts the specified element into the queue represented by this deque (in other words, at the tail of this deque) 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:Main.java

public static void main(String[] args) {

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

    deque.add(20);
    deque.add(30);//from   w ww  . j  a  v  a2  s.com
    deque.add(20);
    deque.add(18);
    deque.add(22);
    deque.add(24);

    deque.addLast(10);
    deque.addLast(12);

    System.out.println(deque);
}

From source file:Main.java

public static void main(String[] args) {

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

    deque.add(25);
    deque.add(30);//from ww w . j a  v  a 2 s.c o  m
    deque.add(35);

    deque.addFirst(10);
    deque.addFirst(15);
    deque.addFirst(20);

    deque.add(45);
    deque.add(40);

    System.out.println(deque);
}

From source file:Main.java

public static void main(String[] args) {

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

    deque.add(15);
    deque.add(30);/*w  w  w.  j  a va  2 s .c  o m*/
    deque.add(25);
    deque.add(40);

    System.out.println(deque);

    // this will remove element at last position
    int retval = deque.removeLast();
    System.out.println("Element removed is: " + retval);

    System.out.println(deque);
}

From source file:Main.java

public static void main(String[] args) {

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

    deque.add(1);
    deque.add(2);//from w  ww  .ja va  2 s. c  om
    deque.add(3);
    deque.add(4);

    for (Iterator itr = deque.iterator(); itr.hasNext();) {
        System.out.println(itr.next());
    }

    for (Iterator descItr = deque.descendingIterator(); descItr.hasNext();) {
        System.out.println(descItr.next());
    }
}

From source file:Main.java

public static void main(String[] args) {

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

    deque.add(20);
    deque.add(30);//from   w w  w. j a v  a  2s  .  c om
    deque.add(10);
    deque.add(18);

    System.out.println(deque);

    // deque contains element 10
    boolean retval = deque.contains(10);

    if (retval == true) {
        System.out.println("element 10 is contained in the deque");
    } else {
        System.out.println("element 10 is not contained in the deque");
    }
}

From source file:Main.java

public static void main(String[] args) {

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

    deque.add(25);
    deque.add(30);//from ww w . j a  v a  2 s  .co  m
    deque.add(20);
    deque.add(40);

    System.out.println(deque);

    boolean retval = deque.remove(30);
    if (retval == true) {
        System.out.println("element 30 is removed from the deque");
    } else {
        System.out.println("element 30 is not contained in the deque");
    }

    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:Main.java

private static <T> Iterator<T> reverse(Iterable<T> values) {
    Deque<T> reversed = new LinkedList<>();
    for (T value : values) {
        reversed.add(value);
    }/*from   ww w . j  a v  a 2  s. com*/
    return reversed.descendingIterator();
}

From source file:org.openhab.io.transport.modbus.json.WriteRequestJsonUtilities.java

/**
 * Parse JSON string to collection of {@link ModbusWriteRequestBlueprint}
 *
 * JSON string should represent a JSON array, with JSON objects. Each JSON object represents a write request. The
 * JSON object must have the following keys
 * - functionCode: numeric function code
 * - address: reference or start address of the write
 * - value: array of data to be written. Use zero and one when writing coils. With registers, each number
 * corresponds to register's 16 bit data.
 * - maxTries: number of tries with the write in case of errors
 *
 *
 * @param unitId unit id for the constructed {@link ModbusWriteRequestBlueprint}
 * @param jsonString json to be parsed in string format
 * @return collection of {@link ModbusWriteRequestBlueprint} representing the json
 * @throws IllegalArgumentException in case of unexpected function codes
 * @throws IllegalStateException in case of parsing errors and unexpected json structure
 *
 * @see WriteRequestJsonUtilities.JSON_FUNCTION_CODE
 * @see WriteRequestJsonUtilities.JSON_ADDRESS
 * @see WriteRequestJsonUtilities.JSON_VALUE
 * @see WriteRequestJsonUtilities.JSON_MAX_TRIES
 *//*from ww w.j a v  a2  s.c  om*/
public static Collection<ModbusWriteRequestBlueprint> fromJson(int unitId, String jsonString) {
    JsonArray jsonArray = PARSER.parse(jsonString).getAsJsonArray();
    if (jsonArray.size() == 0) {
        return new LinkedList<>();
    }
    Deque<ModbusWriteRequestBlueprint> writes = new LinkedList<>();
    jsonArray.forEach(writeElem -> {
        writes.add(constructBluerint(unitId, writeElem));
    });
    return writes;
}

From source file:com.espertech.esper.view.std.GroupByViewImpl.java

protected static Object addUpgradeToDequeIfPopulated(Object holder, EventBean theEvent) {
    if (holder == null) {
        return theEvent;
    } else if (holder instanceof Deque) {
        Deque<EventBean> deque = (Deque<EventBean>) holder;
        deque.add(theEvent);
        return deque;
    } else {/*from  w ww  .j  a va 2  s .  co m*/
        ArrayDeque<EventBean> deque = new ArrayDeque<EventBean>(4);
        deque.add((EventBean) holder);
        deque.add(theEvent);
        return deque;
    }
}