Example usage for java.util ArrayDeque isEmpty

List of usage examples for java.util ArrayDeque isEmpty

Introduction

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

Prototype

public boolean isEmpty() 

Source Link

Document

Returns true if this deque contains no elements.

Usage

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

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

    ArrayDeque<Object> deque = new ArrayDeque<>();
    try {/*  w  ww  . jav a 2 s .com*/
        deque.getFirst();
        fail();
    } catch (NoSuchElementException expected) {
    }

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

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

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

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

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

    ArrayDeque<Object> deque = new ArrayDeque<>();
    assertNull(deque.peek());//w w w. ja  v a2 s.  co m

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

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

    deque.addFirst(o3);
    assertEquals(o3, deque.peek());
    checkDequeSizeAndContent(deque, o3, o1, o2);

    deque.clear();
    assertTrue(deque.isEmpty());
    assertNull(deque.peek());
}

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));// w ww. j  a v  a  2 s  . c  om
    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.google.gwt.emultest.java.util.ArrayDequeTest.java

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

    ArrayDeque<Object> deque = new ArrayDeque<>();
    assertNull(deque.peekLast());//from   w ww  . j  av  a2  s.  c  om

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

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

    deque.addFirst(o3);
    assertEquals(o2, deque.peekLast());
    checkDequeSizeAndContent(deque, o3, o1, o2);

    deque.clear();
    assertTrue(deque.isEmpty());
    assertNull(deque.peekLast());
}

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

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

    ArrayDeque<Object> deque = new ArrayDeque<>();
    assertNull(deque.peekFirst());/* w  w w  .ja  v a 2s . com*/

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

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

    deque.addFirst(o3);
    assertEquals(o3, deque.peekFirst());
    checkDequeSizeAndContent(deque, o3, o1, o2);

    deque.clear();
    assertTrue(deque.isEmpty());
    assertNull(deque.peekFirst());
}

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

/**
 * Processing multiple filter matches for a statement.
 * @param handle statement handle/*from  w w  w  .j a va2 s .c o m*/
 * @param callbackList object containing callbacks
 * @param theEvent to process
 * @param version filter version
 */
public void processStatementFilterMultiple(EPStatementAgentInstanceHandle handle, Object callbackList,
        EventBean theEvent, long version) {
    handle.getStatementAgentInstanceLock().acquireWriteLock(services.getStatementLockFactory());
    try {
        if (handle.isHasVariables()) {
            services.getVariableService().setLocalVersion();
        }
        if (!handle.isCurrentFilter(version)) {
            if (handle.getFilterFaultHandler() != null) {
                handle.getFilterFaultHandler().handleFilterFault(theEvent, version);
            }

            ArrayDeque<FilterHandle> callbackListNew = getCallbackList(theEvent, handle.getStatementId());
            if (callbackListNew.isEmpty()) {
                callbackList = Collections.emptyList();
            } else if (callbackListNew.size() == 1) {
                callbackList = ((EPStatementHandleCallback) callbackListNew.getFirst()).getFilterCallback();
            } else {
                ArrayDeque<FilterHandleCallback> q = new ArrayDeque<FilterHandleCallback>(
                        callbackListNew.size());
                callbackList = q;
                for (FilterHandle callback : callbackListNew) {
                    EPStatementHandleCallback handleCallbackFilter = (EPStatementHandleCallback) callback;
                    q.add(handleCallbackFilter.getFilterCallback());
                }
            }
        }

        if (callbackList instanceof Collection) {
            Collection<FilterHandleCallback> callbackColl = (Collection<FilterHandleCallback>) callbackList;
            if (isSubselectPreeval) {
                // sub-selects always go first
                for (FilterHandleCallback callback : callbackColl) {
                    if (callback.isSubSelect()) {
                        callback.matchFound(theEvent, callbackColl);
                    }
                }

                for (FilterHandleCallback callback : callbackColl) {
                    if (!callback.isSubSelect()) {
                        callback.matchFound(theEvent, callbackColl);
                    }
                }
            } else {
                // sub-selects always go last
                for (FilterHandleCallback callback : callbackColl) {
                    if (!callback.isSubSelect()) {
                        callback.matchFound(theEvent, callbackColl);
                    }
                }

                for (FilterHandleCallback callback : callbackColl) {
                    if (callback.isSubSelect()) {
                        callback.matchFound(theEvent, callbackColl);
                    }
                }
            }
        } else {
            FilterHandleCallback single = (FilterHandleCallback) callbackList;
            single.matchFound(theEvent, null);
        }

        // internal join processing, if applicable
        handle.internalDispatch(this.engineFilterAndDispatchTimeContext);
    } catch (RuntimeException ex) {
        services.getExceptionHandlingService().handleException(ex, handle);
    } finally {
        handle.getStatementAgentInstanceLock().releaseWriteLock(services.getStatementLockFactory());
    }
}

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   www  .  j a va 2s .  c  o m*/
    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, ',')));
    }
}