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:edu.oregonstate.eecs.mcplan.domains.tamarisk.TamariskParameters.java

public static void main(final String[] argv) {
    //      for( int i = 0; i < 1000; ++i ) {
    //         final int Nreaches = 4;
    //         final int Nhabitats = 4;
    //         final RandomGenerator rng = new MersenneTwister( 42 );
    //         final ListenableDirectedWeightedGraph<Integer, DefaultEdge> g
    //            = new TamariskParameters( rng, Nreaches, Nhabitats ).createRandomGraph( 42 + i, true );
    //      }/*from  w  w w .j  a  v  a  2  s .c o  m*/

    final int Nreaches = 10;
    final int Nhabitats = 4;
    final RandomGenerator rng = new MersenneTwister(42);
    final TamariskParameters params = new TamariskParameters(rng, Nreaches, Nhabitats);

    //      final ListenableDirectedWeightedGraph<Integer, DefaultEdge> g = params.createRandomGraph( 42, true );
    final ListenableDirectedWeightedGraph<Integer, DefaultEdge> g = params.createBalancedGraph(3);
    final double[][] K = params.calculateDispersionKernel(g);
    for (int i = 0; i < K.length; ++i) {
        System.out.println(Arrays.toString(K[i]));
    }

    final JGraphModelAdapter adapter = new JGraphModelAdapter(g);
    final JGraph jgraph = new JGraph(adapter);
    //      final JGraphLayoutAlgorithm layout = new SugiyamaLayoutAlgorithm();

    final JFrame frame = new JFrame();
    frame.setSize(480, 360);
    frame.getContentPane().add(new JGraph(new JGraphModelAdapter(g)));
    frame.setVisible(true);

    final TamariskState state = new TamariskState(rng, params, g);
    final TamariskSimulator sim = new TamariskSimulator(state);

    System.out.println(state);
    System.out.println();

    final int T = 30;
    final ArrayDeque<String> hist = new ArrayDeque<String>();
    for (int t = 0; t < T; ++t) {
        sim.takeAction(new JointAction<TamariskAction>(new NothingAction()));
        System.out.println(state);
        System.out.println();
        hist.push(state.toString());
    }

    for (int t = 0; t < T; ++t) {
        final String forward = hist.pop();
        final String backward = sim.state().toString();
        assert (forward.equals(backward));
        sim.untakeLastAction();
    }
}

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

public V3Migrator(ImageOnMap plugin) {
    this.plugin = plugin;

    File dataFolder = plugin.getDataFolder();

    oldPostersFile = new File(dataFolder, OLD_POSTERS_FILE_NAME);
    oldMapsFile = new File(dataFolder, OLD_MAPS_FILE_NAME);

    backupsPrev3Directory = new File(dataFolder, BACKUPS_PREV3_DIRECTORY_NAME);
    backupsPostv3Directory = new File(dataFolder, BACKUPS_POSTV3_DIRECTORY_NAME);

    postersToMigrate = new ArrayDeque<>();
    mapsToMigrate = new ArrayDeque<>();
    userNamesToFetch = new HashSet<>();
}

From source file:com.core.controller.AlgoritmoController.java

public static Solucion busquedaProfundidadConSolucion(Grafo g, String inicio, String fin) {
    Deque<String> pila = new ArrayDeque<>();
    Deque<String> padresPila = new ArrayDeque<>();
    List<String> explorados = new ArrayList<>();
    List<String> padresExplorados = new ArrayList<>();
    String nodoActual, nodoPadre;
    Solucion result = new Solucion("Algoritmo de Busqueda Primero en Profundidad");
    result.agregarPaso("Cantidad de nodos: " + g.getNodos().size());
    result.agregarPaso("Cantidad de aristas: " + g.getAristas().size());
    pila.push(inicio);//from  w  w  w  . j av a 2 s  .  c  om
    padresPila.push("#");
    while (true) {
        result.agregarPaso("Pila: " + Arrays.toString(pila.toArray()));
        if (pila.isEmpty()) {
            result.agregarPaso("No se encontro el nodo destino");
            break;
        }
        nodoActual = pila.pop();
        nodoPadre = padresPila.pop();
        explorados.add(nodoActual);
        padresExplorados.add(nodoPadre);
        if (nodoActual.equals(fin)) {
            result.agregarPaso("Nodo fin alcanzado"); //Mostrar camino
            String nodo = nodoActual;
            String secuenciaResultado = "";
            while (nodo != "#") {
                secuenciaResultado = nodo + " " + secuenciaResultado;
                nodo = padresExplorados.get(explorados.indexOf(nodo));
            }
            result.agregarPaso("Camino solucion: " + secuenciaResultado);
            break;
        }
        List<String> vecinos = g.nodosVecinos(nodoActual);
        for (int i = vecinos.size() - 1; i >= 0; i--) {
            String a = vecinos.get(i);
            if (!explorados.contains(a)) {
                if (pila.contains(a)) {
                    pila.remove(a);
                    padresPila.remove(nodoActual);
                }
                pila.push(a);
                padresPila.push(nodoActual);
            }
        }
    }
    //Verifico la solucion y la guardo en Solucion
    if (result.getPasos().contains("Nodo fin alcanzado")) {
        String solucion = result.getPasos().split("Nodo fin alcanzado\n")[1];
        System.out.println("Solucion: " + solucion);
        String[] array = solucion.split(" ");
        //            ArrayUtils.reverse(array);
        for (String nombreNodo : array) {
            System.out.println("--------------------------------------");
            for (Map.Entry<String, Nodo> n : g.getNodos().entrySet()) {
                System.out.println("Comparando " + n.getKey() + " con " + nombreNodo);
                if (n.getKey().equals(nombreNodo)) {
                    System.out.println("Son iguales! Agregando " + nombreNodo + " a la lista");
                    result.getNodos().add(n.getValue());
                }
            }
        }

        System.out.println(
                "Nodos del resultado final en la lista: " + Arrays.toString(result.getNodos().toArray()));
    }
    return result;
}

From source file:com.espertech.esper.epl.expression.ExprTimePeriodImpl.java

public void validate(ExprValidationContext validationContext) throws ExprValidationException {
    evaluators = ExprNodeUtility.getEvaluators(this.getChildNodes());
    for (ExprNode childNode : this.getChildNodes()) {
        validate(childNode);//ww w . j a v  a 2 s  .com
    }

    ArrayDeque<TimePeriodAdder> list = new ArrayDeque<TimePeriodAdder>();
    if (hasYear) {
        list.add(new TimePeriodAdderYear());
    }
    if (hasMonth) {
        list.add(new TimePeriodAdderMonth());
    }
    if (hasWeek) {
        list.add(new TimePeriodAdderWeek());
    }
    if (hasDay) {
        list.add(new TimePeriodAdderDay());
    }
    if (hasHour) {
        list.add(new TimePeriodAdderHour());
    }
    if (hasMinute) {
        list.add(new TimePeriodAdderMinute());
    }
    if (hasSecond) {
        list.add(new TimePeriodAdderSecond());
    }
    if (hasMillisecond) {
        list.add(new TimePeriodAdderMSec());
    }
    adders = list.toArray(new TimePeriodAdder[list.size()]);
}

From source file:com.espertech.esper.view.window.LengthBatchView.java

/**
 * This method updates child views and clears the batch of events.
 *//*from ww  w . j av a  2 s .  c  om*/
protected void sendBatch() {
    // If there are child views and the batch was filled, fireStatementStopped update method
    if (this.hasViews()) {
        // Convert to object arrays
        EventBean[] newData = null;
        EventBean[] oldData = null;
        if (!currentBatch.isEmpty()) {
            newData = currentBatch.toArray(new EventBean[currentBatch.size()]);
        }
        if ((lastBatch != null) && (!lastBatch.isEmpty())) {
            oldData = lastBatch.toArray(new EventBean[lastBatch.size()]);
        }

        // update view buffer to serve expressions require access to events held
        if (viewUpdatedCollection != null) {
            viewUpdatedCollection.update(newData, oldData);
        }

        // Post new data (current batch) and old data (prior batch)
        if ((newData != null) || (oldData != null)) {
            updateChildren(newData, oldData);
        }
    }

    lastBatch = currentBatch;
    currentBatch = new ArrayDeque<EventBean>();
}

From source file:edu.odu.cs.cs350.yellow1.jar.JarExecutor.java

/**
 * Set up the executor by looking for and getting the jars and then check to
 * see if the log directory <br>//from  w  w w .  ja  va2  s . c  om
 * exists if not create it
 * 
 * @return if set up was successful
 */
public boolean setUp() {
    if (executionState.equals(ExecutionState.multiFile)) {
        jarsToExecute = new ArrayDeque<File>();
        jarsToExecute.addAll(Arrays.asList(jarDir.listFiles(jarFilter)));
        if (jarsToExecute.isEmpty()) {
            logger.error("JarExecutor no jars were found in jar directory");
            return false;
        }

    } else {
        if (jarDir.listFiles(jarFilter).length <= 0) {
            logger.error("JarExecutor executing in singleFile mode found no jar");
            return false;
        }

    }

    if (!logDir.exists()) {
        return logDir.mkdir();
    }

    return true;
}

From source file:org.ambraproject.rhino.content.xml.AbstractXpathReader.java

private static List<String> getParentChain(Node node) {
    Deque<String> stack = new ArrayDeque<>();
    while (node != null) {
        stack.push(node.getNodeName());/*from  w ww.j  a va  2  s  .  com*/
        node = node.getParentNode();
    }
    return ImmutableList.copyOf(stack);
}

From source file:org.pdfsam.guiclient.configuration.services.xml.XmlGuiConfigurationService.java

/**
 * Initialization of recent environments
 *///  w w w. j  a  va2  s  .  co  m
private void initRecentEnvs() {
    recentEnvironments = new ArrayDeque<String>();
    for (String env : XmlUtility.getXmlValues(document,
            ROOT_NODE + RECENT_ENVS_PARENT_XPATH + RECENT_ENVS_NODE_XPATH)) {
        recentEnvironments.addLast(env);
    }
}

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

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

    ArrayDeque<Object> deque = new ArrayDeque<>();
    Iterator<Object> it = deque.descendingIterator();
    assertFalse(it.hasNext());/*  w  ww  .jav a 2 s  . c om*/
    try {
        it.next();
        fail();
    } catch (NoSuchElementException expected) {
    }

    deque.add(o1);
    deque.add(o2);
    deque.add(o3);
    it = deque.descendingIterator();
    assertTrue(it.hasNext());
    assertEquals(o3, it.next());
    assertTrue(it.hasNext());
    assertEquals(o2, it.next());
    assertTrue(it.hasNext());
    assertEquals(o1, it.next());
    assertFalse(it.hasNext());
    try {
        it.next();
        fail();
    } catch (NoSuchElementException expected) {
    }
    checkDequeSizeAndContent(deque, o1, o2, o3);

    deque = new ArrayDeque<>();
    deque.add(o1);
    deque.add(o2);
    deque.add(o3);
    it = deque.descendingIterator();
    assertTrue(it.hasNext());
    assertEquals(o3, it.next());
    it.remove();
    assertEquals(2, deque.size());
    assertTrue(it.hasNext());
    assertEquals(o2, it.next());
    assertTrue(it.hasNext());
    assertEquals(o1, it.next());
    it.remove();
    checkDequeSizeAndContent(deque, o2);
}

From source file:onl.area51.httpd.action.Response.java

static Response create(Request request) {
    class State {

        private final String tag;
        private final boolean disableMini;
        private boolean body;

        public State(String tag, boolean disableMini) {
            this.tag = tag;
            this.disableMini = disableMini;
        }/* w  w w  .j  a  v  a  2  s.c  o  m*/

        @Override
        public String toString() {
            return tag;
        }

    }

    CharArrayWriter writer = new CharArrayWriter();

    return new Response() {
        private ContentType contentType = ContentType.TEXT_HTML;

        private Deque<State> deque = new ArrayDeque<>();
        private State state;

        @Override
        public Response exec(Action a) throws IOException, HttpException {
            if (a != null) {
                // Ensure we have finished the current tag
                startBody();

                // Now preserve the stack & start a new one.
                // This means one action cannot affect the state of this one
                final Deque<State> orig = deque;
                deque = new ArrayDeque<>();
                try {
                    a.apply(request);
                } finally {
                    endAll();
                    deque = orig;
                }
            }
            return this;
        }

        @Override
        public Response setContentType(ContentType contentType) {
            this.contentType = contentType;
            return this;
        }

        @Override
        public HttpEntity getEntity() throws IOException {
            while (!deque.isEmpty()) {
                end();
            }
            return new StringEntity(writer.toString(), contentType);
        }

        private void startBody() {
            if (state != null && !state.body) {
                state.body = true;
                writer.append('>');
            }
        }

        private void tagOnly() {
            if (state == null || state.body) {
                throw new IllegalStateException("Not in tag");
            }
        }

        @Override
        public Response write(CharSequence seq, int s, int e) throws IOException {
            startBody();
            writer.append(seq, s, e);
            return this;
        }

        @Override
        public Response write(char[] v, int s, int l) throws IOException {
            startBody();
            writer.write(v, s, l);
            return this;
        }

        @Override
        public Response write(char v) throws IOException {
            startBody();
            writer.write(v);
            return this;
        }

        @Override
        public Response begin(String t, boolean disableMini) throws IOException {
            startBody();

            if (state != null) {
                deque.addLast(state);
            }

            state = new State(t, disableMini);

            writer.append('<');
            writer.write(state.tag);
            return this;
        }

        @Override
        public Response end() throws IOException {
            if (state == null) {
                throw new IllegalStateException("end() called outside of tag");
            }

            // elements like script mustn't be minified, i.e. <script/> is invalid must be <script></script>
            if (state.disableMini) {
                startBody();
            }

            if (state.body) {
                writer.append('<');
                writer.append('/');
                writer.append(state.tag);
                writer.append('>');
            } else {
                writer.append('/');
                writer.append('>');
            }

            state = deque.pollLast();

            return this;
        }

        @Override
        public Response endAll() throws IOException {
            while (!deque.isEmpty()) {
                end();
            }
            return this;
        }

        @Override
        public Response attr(String n, CharSequence seq) throws IOException {
            tagOnly();
            writer.append(' ');
            writer.append(n);
            writer.append('=');
            writer.append('"');
            writer.append(seq);
            writer.append('"');
            return this;
        }

        @Override
        public Response attr(String n, CharSequence seq, int s, int e) throws IOException {
            tagOnly();
            writer.append(' ');
            writer.append(n);
            writer.append('=');
            writer.append('"');
            writer.append(seq, s, e);
            writer.append('"');
            return this;
        }

        @Override
        public Response attr(String n, char[] v) throws IOException {
            tagOnly();
            writer.append(' ');
            writer.append(n);
            writer.append('=');
            writer.append('"');
            writer.write(v);
            writer.append('"');
            return this;
        }

        @Override
        public Response attr(String n, char[] v, int s, int l) throws IOException {
            tagOnly();
            writer.append(' ');
            writer.append(n);
            writer.append('=');
            writer.append('"');
            writer.write(v, s, l);
            writer.append('"');
            return this;
        }

    };
}