Example usage for java.util ArrayDeque add

List of usage examples for java.util ArrayDeque add

Introduction

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

Prototype

public boolean add(E e) 

Source Link

Document

Inserts the specified element at the end of this deque.

Usage

From source file:com.google.gwt.emultest.java.util.ArrayDequeTest.java

public void testRemoveLastOccurrence() {
    Object o1 = new Object();
    Object o2 = new Object();
    Object o3 = new Object();

    ArrayDeque<Object> deque = new ArrayDeque<>();
    assertFalse(deque.removeLastOccurrence(o1));

    deque.add(o1);
    assertTrue(deque.removeLastOccurrence(o1));
    assertTrue(deque.isEmpty());//from  w  ww . j a v a  2  s  .com

    deque = new ArrayDeque<>();
    deque.add(o1);
    deque.add(o2);
    deque.add(o3);
    assertTrue(deque.removeLastOccurrence(o2));
    checkDequeSizeAndContent(deque, o1, o3);

    deque = new ArrayDeque<>();
    deque.add(o1);
    deque.add(o2);
    deque.add(o3);
    deque.add(o1);
    deque.add(o2);
    deque.add(o3);
    assertTrue(deque.removeLastOccurrence(o2));
    checkDequeSizeAndContent(deque, o1, o2, o3, o1, o3);
    assertTrue(deque.removeLastOccurrence(o2));
    checkDequeSizeAndContent(deque, o1, o3, o1, o3);
    assertTrue(deque.removeLastOccurrence(o3));
    checkDequeSizeAndContent(deque, o1, o3, o1);
    assertTrue(deque.removeLastOccurrence(o3));
    checkDequeSizeAndContent(deque, o1, o1);
    assertFalse(deque.removeLastOccurrence(o3));

    assertFalse(deque.removeLastOccurrence(null));
}

From source file:com.google.gwt.emultest.java.util.ArrayDequeTest.java

public void testRemoveFirstOccurrence() {
    Object o1 = new Object();
    Object o2 = new Object();
    Object o3 = new Object();

    ArrayDeque<Object> deque = new ArrayDeque<>();
    assertFalse(deque.removeFirstOccurrence(o1));

    deque.add(o1);
    assertTrue(deque.removeFirstOccurrence(o1));
    assertTrue(deque.isEmpty());//w w w  .  j  a  v  a2s .c  o m

    deque = new ArrayDeque<>();
    deque.add(o1);
    deque.add(o2);
    deque.add(o3);
    assertTrue(deque.removeFirstOccurrence(o2));
    checkDequeSizeAndContent(deque, o1, o3);

    deque = new ArrayDeque<>();
    deque.add(o1);
    deque.add(o2);
    deque.add(o3);
    deque.add(o1);
    deque.add(o2);
    deque.add(o3);
    assertTrue(deque.removeFirstOccurrence(o2));
    checkDequeSizeAndContent(deque, o1, o3, o1, o2, o3);
    assertTrue(deque.removeFirstOccurrence(o2));
    checkDequeSizeAndContent(deque, o1, o3, o1, o3);
    assertTrue(deque.removeFirstOccurrence(o1));
    checkDequeSizeAndContent(deque, o3, o1, o3);
    assertTrue(deque.removeFirstOccurrence(o1));
    checkDequeSizeAndContent(deque, o3, o3);
    assertFalse(deque.removeFirstOccurrence(o1));

    assertFalse(deque.removeFirstOccurrence(null));
}

From source file:com.espertech.esper.core.EPRuntimeIsolatedImpl.java

private void processMatches(EventBean event) {
    // get matching filters
    ArrayBackedCollection<FilterHandle> matches = matchesArrayThreadLocal.get();
    services.getFilterService().evaluate(event, matches, isolatedTimeEvalContext);

    if (ThreadLogUtil.ENABLED_TRACE) {
        ThreadLogUtil.trace("Found matches for underlying ", matches.size(), event.getUnderlying());
    }//from   ww w  .  j a va 2 s  .co  m

    if (matches.size() == 0) {
        return;
    }

    Map<EPStatementHandle, ArrayDeque<FilterHandleCallback>> stmtCallbacks = matchesPerStmtThreadLocal.get();
    Object[] matchArray = matches.getArray();
    int entryCount = matches.size();

    for (int i = 0; i < entryCount; i++) {
        EPStatementHandleCallback handleCallback = (EPStatementHandleCallback) matchArray[i];
        EPStatementHandle handle = handleCallback.getEpStatementHandle();

        // Self-joins require that the internal dispatch happens after all streams are evaluated.
        // Priority or preemptive settings also require special ordering.
        if (handle.isCanSelfJoin() || isPrioritized) {
            ArrayDeque<FilterHandleCallback> callbacks = stmtCallbacks.get(handle);
            if (callbacks == null) {
                callbacks = new ArrayDeque<FilterHandleCallback>();
                stmtCallbacks.put(handle, callbacks);
            }
            callbacks.add(handleCallback.getFilterCallback());
            continue;
        }

        processStatementFilterSingle(handle, handleCallback, event);
    }
    matches.clear();
    if (stmtCallbacks.isEmpty()) {
        return;
    }

    for (Map.Entry<EPStatementHandle, ArrayDeque<FilterHandleCallback>> entry : stmtCallbacks.entrySet()) {
        EPStatementHandle handle = entry.getKey();
        ArrayDeque<FilterHandleCallback> callbackList = entry.getValue();

        processStatementFilterMultiple(handle, callbackList, event);

        if ((isPrioritized) && (handle.isPreemptive())) {
            break;
        }
    }
    stmtCallbacks.clear();
}

From source file:com.google.gwt.emultest.java.util.ArrayDequeTest.java

public void testPollLast() {
    Object o1 = new Object();
    Object o2 = new Object();

    ArrayDeque<Object> deque = new ArrayDeque<>();
    assertNull(deque.pollLast());/*from  w w w.  ja  va 2s  . co  m*/
    assertTrue(deque.isEmpty());

    deque.add(o1);
    assertEquals(o1, deque.pollLast());
    assertTrue(deque.isEmpty());
    assertNull(deque.pollFirst());

    deque.add(o1);
    deque.add(o2);
    assertEquals(o2, deque.pollLast());
    checkDequeSizeAndContent(deque, o1);
    assertEquals(o1, deque.pollLast());
    assertTrue(deque.isEmpty());
    assertNull(deque.pollLast());
}

From source file:com.google.gwt.emultest.java.util.ArrayDequeTest.java

public void testPollFirst() {
    Object o1 = new Object();
    Object o2 = new Object();

    ArrayDeque<Object> deque = new ArrayDeque<>();
    assertNull(deque.pollFirst());//from  w ww .  ja  v  a 2s  . c om
    assertTrue(deque.isEmpty());

    deque.add(o1);
    assertEquals(o1, deque.pollFirst());
    assertTrue(deque.isEmpty());
    assertNull(deque.pollFirst());

    deque.add(o1);
    deque.add(o2);
    assertEquals(o1, deque.pollFirst());
    checkDequeSizeAndContent(deque, o2);
    assertEquals(o2, deque.pollFirst());
    assertTrue(deque.isEmpty());
    assertNull(deque.pollFirst());
}

From source file:fr.moribus.imageonmap.migration.V3Migrator.java

private void mergeMapData() {
    PluginLogger.info(I.t("Merging map data..."));

    ArrayDeque<OldSavedMap> remainingMaps = new ArrayDeque<>();
    ArrayDeque<OldSavedPoster> remainingPosters = new ArrayDeque<>();

    ArrayDeque<Short> missingMapIds = new ArrayDeque<>();

    UUID playerUUID;/*from   w  w w  . jav  a2s. c  om*/
    OldSavedMap map;
    while (!mapsToMigrate.isEmpty()) {
        map = mapsToMigrate.pop();
        playerUUID = usersUUIDs.get(map.getUserName());
        if (playerUUID == null) {
            remainingMaps.add(map);
        } else if (!map.isMapValid()) {
            missingMapIds.add(map.getMapId());
        } else {
            MapManager.insertMap(map.toImageMap(playerUUID));
        }
    }
    mapsToMigrate.addAll(remainingMaps);

    OldSavedPoster poster;
    while (!postersToMigrate.isEmpty()) {
        poster = postersToMigrate.pop();
        playerUUID = usersUUIDs.get(poster.getUserName());
        if (playerUUID == null) {
            remainingPosters.add(poster);
        } else if (!poster.isMapValid()) {
            missingMapIds.addAll(Arrays.asList(ArrayUtils.toObject(poster.getMapsIds())));
        } else {
            MapManager.insertMap(poster.toImageMap(playerUUID));
        }
    }
    postersToMigrate.addAll(remainingPosters);

    if (!missingMapIds.isEmpty()) {
        PluginLogger.warning(I.tn("{0} registered minecraft map is missing from the save.",
                "{0} registered minecraft maps are missing from the save.", missingMapIds.size()));
        PluginLogger.warning(I.t(
                "These maps will not be migrated, but this could mean the save has been altered or corrupted."));
        PluginLogger
                .warning(I.t("The following maps are missing : {0} ", StringUtils.join(missingMapIds, ',')));
    }
}

From source file:com.google.gwt.emultest.java.util.ArrayDequeTest.java

public void testContains() {
    Object o1 = new Object();
    Object o2 = new Object();
    Object o3 = new Object();

    ArrayDeque<Object> deque = new ArrayDeque<>();
    assertFalse(deque.contains(o3));//from w  ww  .  j  a  va  2 s.  c o m
    assertFalse(deque.contains(null));
    assertTrue(deque.add(o1));
    assertTrue(deque.add(o2));
    assertTrue(deque.add(o1));
    assertTrue(deque.add(o3));
    assertTrue(deque.contains(o1));
    assertTrue(deque.contains(o2));
    assertTrue(deque.contains(o3));
    assertFalse(deque.contains(null));

    deque.clear();
    assertTrue(deque.isEmpty());
    assertFalse(deque.contains(o1));
    assertFalse(deque.contains(o2));
    assertFalse(deque.contains(o3));
}

From source file:com.espertech.esper.core.service.EPRuntimeIsolatedImpl.java

private void processMatches(EventBean theEvent) {
    // get matching filters
    ArrayBackedCollection<FilterHandle> matches = matchesArrayThreadLocal.get();
    services.getFilterService().evaluate(theEvent, matches);

    if (ThreadLogUtil.ENABLED_TRACE) {
        ThreadLogUtil.trace("Found matches for underlying ", matches.size(), theEvent.getUnderlying());
    }//from w  w  w. java  2  s  . c  om

    if (matches.size() == 0) {
        return;
    }

    Map<EPStatementAgentInstanceHandle, ArrayDeque<FilterHandleCallback>> stmtCallbacks = matchesPerStmtThreadLocal
            .get();
    Object[] matchArray = matches.getArray();
    int entryCount = matches.size();

    for (int i = 0; i < entryCount; i++) {
        EPStatementHandleCallback handleCallback = (EPStatementHandleCallback) matchArray[i];
        EPStatementAgentInstanceHandle handle = handleCallback.getAgentInstanceHandle();

        // Self-joins require that the internal dispatch happens after all streams are evaluated.
        // Priority or preemptive settings also require special ordering.
        if (handle.isCanSelfJoin() || isPrioritized) {
            ArrayDeque<FilterHandleCallback> callbacks = stmtCallbacks.get(handle);
            if (callbacks == null) {
                callbacks = new ArrayDeque<FilterHandleCallback>();
                stmtCallbacks.put(handle, callbacks);
            }
            callbacks.add(handleCallback.getFilterCallback());
            continue;
        }

        processStatementFilterSingle(handle, handleCallback, theEvent);
    }
    matches.clear();
    if (stmtCallbacks.isEmpty()) {
        return;
    }

    for (Map.Entry<EPStatementAgentInstanceHandle, ArrayDeque<FilterHandleCallback>> entry : stmtCallbacks
            .entrySet()) {
        EPStatementAgentInstanceHandle handle = entry.getKey();
        ArrayDeque<FilterHandleCallback> callbackList = entry.getValue();

        processStatementFilterMultiple(handle, callbackList, theEvent);

        if ((isPrioritized) && (handle.isPreemptive())) {
            break;
        }
    }
    stmtCallbacks.clear();
}

From source file:com.google.gwt.emultest.java.util.ArrayDequeTest.java

public void testPop() {
    Object o1 = new Object();
    Object o2 = new Object();

    ArrayDeque<Object> deque = new ArrayDeque<>();
    try {//from  w ww. j  ava2 s.  c om
        deque.pop();
        fail();
    } catch (NoSuchElementException expected) {
    }

    deque.add(o1);
    assertEquals(o1, deque.pop());
    assertTrue(deque.isEmpty());

    deque.add(o1);
    deque.add(o2);
    assertEquals(o1, deque.pop());
    checkDequeSizeAndContent(deque, o2);
    assertEquals(o2, deque.pop());
    assertTrue(deque.isEmpty());
    try {
        deque.pop();
        fail();
    } catch (NoSuchElementException expected) {
    }
}

From source file:com.google.gwt.emultest.java.util.ArrayDequeTest.java

public void testElement() {
    Object o1 = new Object();
    Object o2 = new Object();

    ArrayDeque<Object> deque = new ArrayDeque<>();
    try {/*from   w  ww .  j a  v  a 2s.c  om*/
        deque.element();
        fail();
    } catch (NoSuchElementException expected) {
    }

    deque.add(o1);
    assertEquals(o1, deque.element());
    checkDequeSizeAndContent(deque, o1);

    deque.add(o2);
    assertEquals(o1, deque.element());
    checkDequeSizeAndContent(deque, o1, o2);

    deque.clear();
    assertTrue(deque.isEmpty());
    try {
        deque.element();
        fail();
    } catch (NoSuchElementException expected) {
    }
}