Example usage for java.util ArrayDeque ArrayDeque

List of usage examples for java.util ArrayDeque ArrayDeque

Introduction

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

Prototype

public ArrayDeque() 

Source Link

Document

Constructs an empty array deque with an initial capacity sufficient to hold 16 elements.

Usage

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

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

    ArrayDeque<Object> deque = new ArrayDeque<>();
    deque.addLast(o1);// w  w w .  j  a v  a2  s.  co  m
    checkDequeSizeAndContent(deque, o1);
    deque.addLast(o2);
    checkDequeSizeAndContent(deque, o1, o2);
    deque.addLast(o3);
    checkDequeSizeAndContent(deque, o1, o2, o3);

    try {
        deque.addLast(null);
        fail();
    } catch (NullPointerException expected) {
    }
}

From source file:com.grepcurl.random.ObjectGenerator.java

@SuppressWarnings("unused")
public <T> T generate(Class<T> klass, Object... constructorArgs) {
    Validate.notNull(klass);//from w  w w . j  a  va 2 s .c o  m
    Validate.notNull(constructorArgs);
    if (verbose) {
        log(String.format("generating object of type: %s, with args: %s", klass,
                Arrays.toString(constructorArgs)));
    }
    try {
        Deque<Object> objectStack = new ArrayDeque<>();
        Class[] constructorTypes = _toClasses(constructorArgs);
        T t;
        if (klass.isEnum()) {
            int randomOrdinal = randomInt(0, klass.getEnumConstants().length - 1);
            t = klass.getEnumConstants()[randomOrdinal];
        } else {
            t = klass.getConstructor(constructorTypes).newInstance(constructorArgs);
        }
        objectStack.push(t);
        Method[] methods = klass.getMethods();
        for (Method method : methods) {
            _processMethod(method, new SetterOverrides(), t, objectStack);
        }
        objectStack.pop();
        return t;
    } catch (Exception e) {
        throw new FailedRandomObjectGenerationException(e);
    }
}

From source file:net.sf.jasperreports.engine.json.expression.member.evaluation.ArrayIndexExpressionEvaluator.java

private List<JRJsonNode> goAnywhereDown(JRJsonNode jrJsonNode) {
    List<JRJsonNode> result = new ArrayList<>();
    Deque<JRJsonNode> stack = new ArrayDeque<>();
    JsonNode initialDataNode = jrJsonNode.getDataNode();

    if (log.isDebugEnabled()) {
        log.debug("initial stack population with: " + initialDataNode);
    }//from   ww  w  . jav  a 2 s. c  o  m

    // populate the stack initially
    stack.push(jrJsonNode);

    while (!stack.isEmpty()) {
        JRJsonNode stackNode = stack.pop();
        JsonNode stackDataNode = stackNode.getDataNode();

        addChildrenToStack(stackNode, stack);

        // process the current stack item
        if (stackDataNode.isArray()) {
            if (log.isDebugEnabled()) {
                log.debug("processing stack element: " + stackDataNode);
            }

            if (expression.getIndex() >= 0 && expression.getIndex() < stackDataNode.size()) {
                JsonNode nodeAtIndex = stackDataNode.get(expression.getIndex());
                JRJsonNode child = stackNode.createChild(nodeAtIndex);

                if (applyFilter(child)) {
                    result.add(child);
                }
            }
        }
    }

    return result;
}

From source file:com.ekeitho.sound.MainActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    Log.v("show up", "here!");
    setContentView(R.layout.activity_main);
    /* intiialize data structs */
    routes = new ArrayDeque<>();
    postponedCasts = new ArrayDeque<>();

    /* get reference to our fragment */
    soundCastFragment = (SoundCastFragment) getSupportFragmentManager().findFragmentById(R.id.castFragment);

    // Configure Cast device discovery
    mMediaRouter = MediaRouter.getInstance(getApplicationContext());
    mMediaRouteSelector = new MediaRouteSelector.Builder().addControlCategory(
            CastMediaControlIntent.categoryForCast(getResources().getString(R.string.app_id))).build();
    mMediaRouterCallback = new MyMediaRouterCallback();

    /* initialize our cast media player */
    mRemoteMediaPlayer = new RemoteMediaPlayer();

    shareMsgFromSoundcloud = handleIncomingIntentShareIfAny();
    /* this will happen when user wants to share from soundcloud & app is open */
    if (hasOpened > 0) {
        routes.add(mMediaRouter.getRoutes().get(1));
        postponedCasts.add(shareMsgFromSoundcloud);

        if (routes.peek().isSelected()) {
            mMediaRouter.unselect(1);/*from www  .  j a v  a 2 s .co m*/
        }
        routes.peek().select();
    }
    /* this will happen if share happens and the app isn't open yet */
    else if (shareMsgFromSoundcloud != null) {
        postponedCasts.add(shareMsgFromSoundcloud);
    }

    /* update to show change in phase */
    hasOpened++;
}

From source file:net.sf.jasperreports.engine.json.expression.member.evaluation.ArrayConstructionExpressionEvaluator.java

private List<JRJsonNode> goAnywhereDown(JRJsonNode jrJsonNode) {
    List<JRJsonNode> result = new ArrayList<>();
    Deque<JRJsonNode> stack = new ArrayDeque<>();
    JsonNode initialDataNode = jrJsonNode.getDataNode();

    if (log.isDebugEnabled()) {
        log.debug("initial stack population with: " + initialDataNode);
    }/*w w w  .  j  av  a2s. com*/

    // populate the stack initially
    stack.push(jrJsonNode);

    while (!stack.isEmpty()) {
        JRJsonNode stackNode = stack.pop();
        JsonNode stackDataNode = stackNode.getDataNode();

        addChildrenToStack(stackNode, stack);

        // process the current stack item
        if (stackDataNode.isArray()) {
            if (log.isDebugEnabled()) {
                log.debug("processing stack element: " + stackDataNode);
            }

            ArrayNode newNode = getEvaluationContext().getObjectMapper().createArrayNode();

            for (Integer idx : expression.getIndexes()) {
                if (idx >= 0 && idx < stackDataNode.size()) {
                    JRJsonNode nodeAtIndex = stackNode.createChild(stackDataNode.get(idx));

                    if (applyFilter(nodeAtIndex)) {
                        newNode.add(nodeAtIndex.getDataNode());
                    }
                }
            }

            if (newNode.size() > 0) {
                result.add(stackNode.createChild(newNode));
            }
        }
    }

    return result;
}

From source file:de.escalon.hypermedia.hydra.serialize.JacksonHydraSerializer.java

@Override
public void serialize(Object bean, JsonGenerator jgen, SerializerProvider serializerProvider)
        throws IOException {
    if (!isUnwrappingSerializer()) {
        jgen.writeStartObject();/*from   ww  w  . ja va  2  s . co  m*/
    }
    Deque<String> deque = (Deque<String>) serializerProvider.getAttribute(KEY_LD_CONTEXT);
    if (deque == null) {
        deque = new ArrayDeque<String>();
        serializerProvider.setAttribute(KEY_LD_CONTEXT, deque);
    }

    serializeContext(bean, jgen, serializerProvider, deque);
    serializeType(bean, jgen, serializerProvider);
    serializeFields(bean, jgen, serializerProvider);
    if (!isUnwrappingSerializer()) {
        jgen.writeEndObject();
    }
    deque = (Deque<String>) serializerProvider.getAttribute(KEY_LD_CONTEXT);
    if (!deque.isEmpty()) {
        deque.pop();
    }
}

From source file:io.fabric8.kubernetes.server.mock.MockServerExpectationImpl.java

private void enqueue(ServerRequest req, ServerResponse resp) {
    Queue<ServerResponse> queuedResponses = responses.get(req);
    if (queuedResponses == null) {
        queuedResponses = new ArrayDeque<>();
        responses.put(req, queuedResponses);
    }//  w w  w  . j av a2s . c o  m
    queuedResponses.add(resp);
}

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

public final Iterator<EventBean> iterator() {
    // The merge data view has multiple parent views which are AddPropertyValueView
    ArrayDeque<Iterable<EventBean>> iterables = new ArrayDeque<Iterable<EventBean>>();

    for (View dataView : parentViews) {
        iterables.add(dataView);//from w ww  .j  a  v  a 2 s  .  c o  m
    }

    return new IterablesListIterator(iterables);
}

From source file:org.azrul.langkuik.Langkuik.java

public void initLangkuik(final EntityManagerFactory emf, final UI ui,
        final RelationManagerFactory relationManagerFactory, List<Class<?>> customTypeInterfaces) {

    List<Class<?>> rootClasses = new ArrayList<>();
    for (ManagedType<?> entity : emf.getMetamodel().getManagedTypes()) {
        Class<?> clazz = entity.getJavaType();
        if (clazz.getAnnotation(WebEntity.class).isRoot() == true) {
            rootClasses.add(clazz);/*from   www  .ja va2  s  .  c om*/
        }
    }

    //Manage custom type
    if (customTypeInterfaces == null) {
        customTypeInterfaces = new ArrayList<>();
    }
    //add system level custom type
    customTypeInterfaces.add(AttachmentCustomType.class);
    //create DAOs for custom types
    final List<DataAccessObject<?>> customTypeDaos = new ArrayList<>();
    for (Class<?> clazz : customTypeInterfaces) {
        customTypeDaos.add(new HibernateGenericDAO(emf, clazz));
    }

    //Setup page
    VerticalLayout main = new VerticalLayout();
    VerticalLayout content = new VerticalLayout();
    final Navigator navigator = new Navigator(ui, content);
    final HorizontalLayout breadcrumb = new HorizontalLayout();

    MenuBar menubar = new MenuBar();
    menubar.setId("MENUBAR");
    main.addComponent(menubar);
    main.addComponent(breadcrumb);
    main.addComponent(content);

    final Deque<History> history = new ArrayDeque<>();
    final Configuration config = Configuration.getInstance();

    history.push(new History("START", "Start"));
    StartView startView = new StartView(history, breadcrumb);
    navigator.addView("START", startView);
    MenuBar.MenuItem create = menubar.addItem("Create", null);
    MenuBar.MenuItem view = menubar.addItem("View", null);

    final PageParameter pageParameter = new PageParameter(customTypeDaos, emf, relationManagerFactory, history,
            config, breadcrumb);

    for (final Class rootClass : rootClasses) {
        final WebEntity myObject = (WebEntity) rootClass.getAnnotation(WebEntity.class);
        final DataAccessObject<?> dao = new HibernateGenericDAO<>(emf, rootClass);
        create.addItem("New " + myObject.name(), new MenuBar.Command() {
            @Override
            public void menuSelected(MenuBar.MenuItem selectedItem) {
                Object object = dao.createNew(true);
                BeanView<Object, ?> createNewView = new BeanView<>(object, null, null, pageParameter);
                String targetView = "CREATE_NEW_APPLICATION_" + UUID.randomUUID().toString();
                navigator.addView(targetView, (View) createNewView);
                history.clear();
                history.push(new History("START", "Start"));
                History his = new History(targetView, "Create new " + myObject.name());
                history.push(his);
                navigator.navigateTo(targetView);
            }
        });
        view.addItem("View " + myObject.name(), new MenuBar.Command() {
            @Override
            public void menuSelected(MenuBar.MenuItem selectedItem) {
                PlainTableView<?> seeApplicationView = new PlainTableView<>(rootClass, pageParameter);
                String targetView = "VIEW_APPLICATION_" + UUID.randomUUID().toString();
                navigator.addView(targetView, (View) seeApplicationView);
                history.clear();
                history.push(new History("START", "Start"));
                History his = new History(targetView, "View " + myObject.name());
                history.push(his);
                navigator.navigateTo(targetView);
            }
        });
    }

    menubar.addItem("Logout", null).addItem("Logout", new MenuBar.Command() {
        @Override
        public void menuSelected(MenuBar.MenuItem selectedItem) {
            ConfirmDialog.show(ui, "Please Confirm:", "Are you really sure you want to log out?", "I am",
                    "Not quite", new ConfirmDialog.Listener() {
                        @Override
                        public void onClose(ConfirmDialog dialog) {
                            if (dialog.isConfirmed()) {
                                HttpServletRequest req = (HttpServletRequest) VaadinService.getCurrentRequest();
                                HttpServletResponse resp = (HttpServletResponse) VaadinService
                                        .getCurrentResponse();
                                Authentication auth = SecurityContextHolder.getContext().getAuthentication();
                                SecurityContextLogoutHandler ctxLogOut = new SecurityContextLogoutHandler();
                                ctxLogOut.logout(req, resp, auth);
                            }
                        }
                    });

        }
    });
    navigator.navigateTo("START");
    ui.setContent(main);
}

From source file:org.chromium.chrome.browser.media.router.cast.CastMessageHandler.java

/**
 * Initializes a new {@link CastMessageHandler} instance.
 * @param session  The {@link CastSession} for communicating with the Cast SDK.
 * @param provider The {@link CastMediaRouteProvider} for communicating with the page.
 *//*from ww  w.ja  va2s.  c o m*/
public CastMessageHandler(CastMediaRouteProvider provider) {
    mRouteProvider = provider;
    mRequests = new SparseArray<RequestRecord>();
    mStopRequests = new ArrayMap<String, Queue<Integer>>();
    mVolumeRequests = new ArrayDeque<RequestRecord>();
    mHandler = new Handler();

    synchronized (INIT_LOCK) {
        if (sMediaOverloadedMessageTypes == null) {
            sMediaOverloadedMessageTypes = new HashMap<String, String>();
            sMediaOverloadedMessageTypes.put("STOP_MEDIA", "STOP");
            sMediaOverloadedMessageTypes.put("MEDIA_SET_VOLUME", "SET_VOLUME");
            sMediaOverloadedMessageTypes.put("MEDIA_GET_STATUS", "GET_STATUS");
        }
    }
}