Example usage for java.util ArrayDeque push

List of usage examples for java.util ArrayDeque push

Introduction

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

Prototype

public void push(E e) 

Source Link

Document

Pushes an element onto the stack represented by this deque.

Usage

From source file:Main.java

public static void main(String[] args) {

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

    deque.add(25);//from www .ja va2s .c o  m
    deque.add(2);
    deque.add(35);

    // adding elements using push() method
    deque.push(10);
    deque.push(3);

    System.out.println(deque);
}

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   www .j  a  v a  2 s .  co 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:org.datagator.tools.importer.Main.java

public static void main(String[] args) throws IOException {

    int columnHeaders = 0; // cli input
    int rowHeaders = 0; // cli input

    try {// ww  w  .  j a  v  a 2  s. c o  m
        CommandLine cmds = parser.parse(opts, args);
        if (cmds.hasOption("filter")) {
            throw new UnsupportedOperationException("Not supported yet.");
        }
        if (cmds.hasOption("layout")) {
            String[] layout = cmds.getOptionValues("layout");
            if ((layout == null) || (layout.length != 2)) {
                throw new IllegalArgumentException("Bad layout.");
            }
            try {
                columnHeaders = Integer.valueOf(layout[0]);
                rowHeaders = Integer.valueOf(layout[1]);
                if ((columnHeaders < 0) || (rowHeaders < 0)) {
                    throw new IllegalArgumentException("Bad layout.");
                }
            } catch (NumberFormatException ex) {
                throw new IllegalArgumentException(ex);
            }
        }
        if (cmds.hasOption("help")) {
            help.printHelp("importer", opts, true);
            System.exit(EX_OK);
        }
        // positional arguments, i.e., input file name(s)
        args = cmds.getArgs();
    } catch (ParseException ex) {
        throw new IllegalArgumentException(ex);
    } catch (IllegalArgumentException ex) {
        help.printHelp("importer", opts, true);
        throw ex;
    }

    JsonGenerator jg = json.createGenerator(System.out, JsonEncoding.UTF8);
    jg.setPrettyPrinter(new StandardPrinter());

    final Extractor extractor;

    if (args.length == 1) {
        extractor = new FileExtractor(new File(args[0]));
    } else if (args.length > 1) {
        throw new UnsupportedOperationException("Not supported yet.");
    } else {
        throw new IllegalArgumentException("Missing input.");
    }

    int columnsCount = -1;
    int matrixCount = 0;

    ArrayDeque<String> stack = new ArrayDeque<String>();

    AtomType token = extractor.nextAtom();
    while (token != null) {
        switch (token) {
        case FLOAT:
        case INTEGER:
        case STRING:
        case NULL:
            jg.writeObject(extractor.getCurrentAtomData());
            break;
        case START_RECORD:
            jg.writeStartArray();
            break;
        case END_RECORD:
            int _numFields = (Integer) extractor.getCurrentAtomData();
            if (columnsCount < 0) {
                columnsCount = _numFields;
            } else if (columnsCount != _numFields) {
                throw new RuntimeException(String.format("row %s has different length than previous rows",
                        String.valueOf(_numFields - 1)));
            }
            jg.writeEndArray();
            break;
        case START_GROUP:
            stack.push(String.valueOf(extractor.getCurrentAtomData()));
            jg.writeStartObject();
            jg.writeStringField("kind", "datagator#Matrix");
            jg.writeNumberField("columnHeaders", columnHeaders);
            jg.writeNumberField("rowHeaders", rowHeaders);
            jg.writeFieldName("rows");
            jg.writeStartArray();
            break;
        case END_GROUP:
            int rowsCount = (Integer) extractor.getCurrentAtomData();
            if (rowsCount == 0) {
                jg.writeStartArray();
                jg.writeEndArray();
                rowsCount = 1;
                columnsCount = 0;
            }
            jg.writeEndArray();
            jg.writeNumberField("rowsCount", rowsCount);
            jg.writeNumberField("columnsCount", columnsCount);
            jg.writeEndObject();
            matrixCount += 1;
            stack.pop();
            break;
        default:
            break;
        }
        token = extractor.nextAtom();
    }

    jg.close();

    System.exit(EX_OK);
}

From source file:com.tussle.script.StackedBindings.java

public StackedBindings(Map<String, Object> startValues) {
    bindingStack = new ArrayDeque<>();
    bindingMap = new HashMap<>();
    bindingStack.push(new SimpleBindings(startValues));
    for (Map.Entry<String, Object> entry : startValues.entrySet()) {
        ArrayDeque<Object> toPut = new ArrayDeque<>();
        toPut.push(entry.getValue());
        bindingMap.put(entry.getKey(), toPut);
    }/*w  w w  .  j av a  2s . c  om*/
}

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

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

    ArrayDeque<Object> deque = new ArrayDeque<>();
    deque.push(o1);
    checkDequeSizeAndContent(deque, o1);
    deque.push(o2);//from w  w w  . j a v  a 2s  . c o m
    checkDequeSizeAndContent(deque, o2, o1);
    deque.push(o3);
    checkDequeSizeAndContent(deque, o3, o2, o1);

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

From source file:org.apache.asterix.optimizer.rules.IntroduceAutogenerateIDRule.java

@Override
public boolean rewritePost(Mutable<ILogicalOperator> opRef, IOptimizationContext context)
        throws AlgebricksException {

    // match: commit OR distribute-result OR SINK - ... followed by:
    // [insert to internal dataset with autogenerated id] - assign - project
    // produce: insert - assign - assign* - project
    // **//w w w .  j a  v a  2 s .  c o m
    // OR [insert to internal dataset with autogenerated id] - assign - [datasource scan]
    // produce insert - assign - assign* - datasource scan

    AbstractLogicalOperator currentOp = (AbstractLogicalOperator) opRef.getValue();
    if (currentOp.getOperatorTag() == LogicalOperatorTag.DELEGATE_OPERATOR) {
        DelegateOperator dOp = (DelegateOperator) currentOp;
        if (!(dOp.getDelegate() instanceof CommitOperator)) {
            return false;
        } else if (!((CommitOperator) dOp.getDelegate()).isSink()) {
            return false;
        }

    } else if (currentOp.getOperatorTag() != LogicalOperatorTag.DISTRIBUTE_RESULT
            && currentOp.getOperatorTag() != LogicalOperatorTag.SINK) {
        return false;
    }
    ArrayDeque<AbstractLogicalOperator> opStack = new ArrayDeque<>();
    opStack.push(currentOp);
    while (currentOp.getInputs().size() == 1) {
        currentOp = (AbstractLogicalOperator) currentOp.getInputs().get(0).getValue();
        if (currentOp.getOperatorTag() == LogicalOperatorTag.INSERT_DELETE_UPSERT) {
            break;
        }
        opStack.push(currentOp);
    }
    if (currentOp.getOperatorTag() != LogicalOperatorTag.INSERT_DELETE_UPSERT) {
        return false;
    }

    InsertDeleteUpsertOperator insertOp = (InsertDeleteUpsertOperator) currentOp;
    if (insertOp.getOperation() != Kind.INSERT) {
        return false;
    }

    DatasetDataSource dds = (DatasetDataSource) insertOp.getDataSource();
    boolean autogenerated = ((InternalDatasetDetails) dds.getDataset().getDatasetDetails()).isAutogenerated();
    if (!autogenerated) {
        return false;
    }

    if (((AqlDataSource) insertOp.getDataSource()).getDatasourceType() != AqlDataSourceType.INTERNAL_DATASET) {
        return false;
    }

    AbstractLogicalOperator parentOp = (AbstractLogicalOperator) currentOp.getInputs().get(0).getValue();
    if (parentOp.getOperatorTag() != LogicalOperatorTag.ASSIGN) {
        return false;
    }
    AssignOperator assignOp = (AssignOperator) parentOp;
    LogicalVariable inputRecord;

    //TODO: bug here. will not work for internal datasets with filters since the pattern becomes 
    //[project-assign-assign-insert]
    AbstractLogicalOperator grandparentOp = (AbstractLogicalOperator) parentOp.getInputs().get(0).getValue();
    if (grandparentOp.getOperatorTag() == LogicalOperatorTag.PROJECT) {
        ProjectOperator projectOp = (ProjectOperator) grandparentOp;
        inputRecord = projectOp.getVariables().get(0);
    } else if (grandparentOp.getOperatorTag() == LogicalOperatorTag.DATASOURCESCAN) {
        DataSourceScanOperator dssOp = (DataSourceScanOperator) grandparentOp;
        inputRecord = dssOp.getVariables().get(0);
    } else {
        return false;
    }

    List<String> pkFieldName = ((InternalDatasetDetails) dds.getDataset().getDatasetDetails()).getPrimaryKey()
            .get(0);
    ILogicalExpression rec0 = new VariableReferenceExpression(inputRecord);
    ILogicalExpression rec1 = createPrimaryKeyRecordExpression(pkFieldName);
    ILogicalExpression mergedRec = createRecordMergeFunction(rec0, rec1);
    ILogicalExpression nonNullMergedRec = createNotNullFunction(mergedRec);

    LogicalVariable v = context.newVar();
    AssignOperator newAssign = new AssignOperator(v, new MutableObject<ILogicalExpression>(nonNullMergedRec));
    newAssign.getInputs().add(new MutableObject<ILogicalOperator>(grandparentOp));
    assignOp.getInputs().set(0, new MutableObject<ILogicalOperator>(newAssign));
    VariableUtilities.substituteVariables(assignOp, inputRecord, v, context);
    VariableUtilities.substituteVariables(insertOp, inputRecord, v, context);
    context.computeAndSetTypeEnvironmentForOperator(newAssign);
    context.computeAndSetTypeEnvironmentForOperator(assignOp);
    context.computeAndSetTypeEnvironmentForOperator(insertOp);
    ;
    for (AbstractLogicalOperator op : opStack) {
        VariableUtilities.substituteVariables(op, inputRecord, v, context);
        context.computeAndSetTypeEnvironmentForOperator(op);
    }

    return true;
}