List of usage examples for java.util ArrayDeque ArrayDeque
public ArrayDeque()
From source file:Main.java
public static void main(String[] args) { ArrayDeque<Integer> deque = new ArrayDeque<Integer>(); deque.add(3);//from ww w . j av a 2s . co m deque.add(18); deque.add(25); deque.add(18); System.out.println(deque); }
From source file:Main.java
public static void main(String args[]) { Deque<String> stack = new ArrayDeque<String>(); Deque<String> queue = new ArrayDeque<String>(); stack.push("A"); stack.push("B"); stack.push("C"); stack.push("D"); while (!stack.isEmpty()) System.out.print(stack.pop() + " "); queue.add("A"); queue.add("B"); queue.add("C"); queue.add("D"); while (!queue.isEmpty()) System.out.print(queue.remove() + " "); }
From source file:Main.java
public static void main(String[] args) { // Create a Deque and use it as stack Deque<String> deque = new ArrayDeque<>(); deque.push("Oracle"); deque.push("HTML"); deque.push("CSS"); deque.push("XML"); System.out.println("Stack: " + deque); // remove all elements from the Deque while (deque.peek() != null) { System.out.println("Element at top: " + deque.peek()); System.out.println("Popped: " + deque.pop()); System.out.println("Stack: " + deque); }//from www.java 2 s.c o m System.out.println("Stack is empty: " + deque.isEmpty()); }
From source file:drpc.BptiEnsembleQuery.java
public static void main(final String[] args) throws IOException, TException, DRPCExecutionException { if (args.length < 3) { System.err.println("Where are the arguments? args -- DrpcServer DrpcFunctionName folder"); return;//from w ww . ja va2s . c o m } final DRPCClient client = new DRPCClient(args[0], 3772, 1000000 /*timeout*/); final Queue<String> featureFiles = new ArrayDeque<String>(); SpoutUtils.listFilesForFolder(new File(args[2]), featureFiles); Scanner scanner = new Scanner(featureFiles.peek()); int i = 0; while (scanner.hasNextLine() && i++ < 1) { List<Map<String, List<Double>>> dict = SpoutUtils.pythonDictToJava(scanner.nextLine()); for (Map<String, List<Double>> map : dict) { final Double[] features = map.get("chi1").toArray(new Double[0]); final Double[] moreFeatures = map.get("chi2").toArray(new Double[0]); final Double[] both = (Double[]) ArrayUtils.addAll(features, moreFeatures); final String parameters = serializeFeatureVector(ArrayUtils.toPrimitive(both)); Logger.getAnonymousLogger().log(Level.INFO, runQuery(args[1], parameters, client)); } } client.close(); }
From source file:drpc.KMeansDrpcQuery.java
public static void main(final String[] args) throws IOException, TException, DRPCExecutionException, DecoderException, ClassNotFoundException { if (args.length < 3) { System.err.println("Where are the arguments? args -- DrpcServer DrpcFunctionName folder"); return;// www. j a va2 s .c o m } final DRPCClient client = new DRPCClient(args[0], 3772, 1000000 /*timeout*/); final Queue<String> featureFiles = new ArrayDeque<String>(); SpoutUtils.listFilesForFolder(new File(args[2]), featureFiles); Scanner scanner = new Scanner(featureFiles.peek()); int i = 0; while (scanner.hasNextLine() && i++ < 10) { List<Map<String, List<Double>>> dict = SpoutUtils.pythonDictToJava(scanner.nextLine()); for (Map<String, List<Double>> map : dict) { i++; Double[] features = map.get("chi2").toArray(new Double[0]); Double[] moreFeatures = map.get("chi1").toArray(new Double[0]); Double[] rmsd = map.get("rmsd").toArray(new Double[0]); Double[] both = (Double[]) ArrayUtils.addAll(features, moreFeatures); String parameters = serializeFeatureVector(ArrayUtils.toPrimitive(both)); String centroidsSerialized = runQuery(args[1], parameters, client); Gson gson = new Gson(); Object[] deserialized = gson.fromJson(centroidsSerialized, Object[].class); for (Object obj : deserialized) { // result we get is of the form List<result> List l = ((List) obj); centroidsSerialized = (String) l.get(0); String[] centroidSerializedArrays = centroidsSerialized .split(MlStormClustererQuery.KmeansClustererQuery.CENTROID_DELIM); List<double[]> centroids = new ArrayList<double[]>(); for (String centroid : centroidSerializedArrays) { centroids.add(MlStormFeatureVectorUtils.deserializeToFeatureVector(centroid)); } double[] rmsdPrimitive = ArrayUtils.toPrimitive(both); double[] rmsdKmeans = new double[centroids.size()]; for (int k = 0; k < centroids.size(); k++) { System.out.println("centroid -- " + Arrays.toString(centroids.get(k))); double[] centroid = centroids.get(k); rmsdKmeans[k] = computeRootMeanSquare(centroid); } System.out.println("1 rmsd original -- " + Arrays.toString(rmsd)); System.out.println("2 rmsd k- Means -- " + Arrays.toString(rmsdKmeans)); System.out.println(); } } } client.close(); }
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 {/*from w ww .j ava 2 s. com*/ 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:Main.java
public static <E> ArrayDeque<E> getArrayQueue() { return new ArrayDeque<E>(); }
From source file:Main.java
public static <E> ArrayDeque<E> getArrayDeque() { return new ArrayDeque<E>(); }
From source file:Main.java
public static <E> ArrayDeque<E> createArrayDeque() { return new ArrayDeque<E>(); }
From source file:edu.oregonstate.eecs.mcplan.domains.spbj.SpBjSimulator.java
public static void main(final String[] argv) throws IOException { final int seed = 43; final RandomGenerator rng = new MersenneTwister(seed); // final Deck deck = new InfiniteSpanishDeck( rng ); // TODO: Debugging code final Deque<Card> stacked = new ArrayDeque<Card>(); for (int i = 0; i < 20; ++i) { stacked.push(Card.C_2c);/*from www . j ava2 s . co m*/ stacked.push(Card.C_2d); stacked.push(Card.C_2h); stacked.push(Card.C_2s); } final Deck deck = new StackedDeck(stacked); // final ArrayList<ArrayList<Card>> test_hands = new ArrayList<ArrayList<Card>>(); // test_hands.add( new ArrayList<Card>( Arrays.asList( Card.C_Kc, Card.C_9h, Card.C_2c ) ) ); // test_hands.add( new ArrayList<Card>( Arrays.asList( Card.C_6c, Card.C_7h, Card.C_8c ) ) ); // test_hands.add( new ArrayList<Card>( Arrays.asList( Card.C_6c, Card.C_7c, Card.C_8c ) ) ); // test_hands.add( new ArrayList<Card>( Arrays.asList( Card.C_6s, Card.C_7s, Card.C_8s ) ) ); // test_hands.add( new ArrayList<Card>( Arrays.asList( Card.C_7c, Card.C_7h, Card.C_7c ) ) ); // test_hands.add( new ArrayList<Card>( Arrays.asList( Card.C_7c, Card.C_7c, Card.C_7c ) ) ); // test_hands.add( new ArrayList<Card>( Arrays.asList( Card.C_7s, Card.C_7s, Card.C_7s ) ) ); // test_hands.add( new ArrayList<Card>( Arrays.asList( Card.C_3c, Card.C_3c, Card.C_3c, Card.C_3c, Card.C_9c ) ) ); // test_hands.add( new ArrayList<Card>( Arrays.asList( Card.C_3c, Card.C_3c, Card.C_3c, Card.C_3c, Card.C_3c, Card.C_6c ) ) ); // test_hands.add( new ArrayList<Card>( Arrays.asList( Card.C_3c, Card.C_3c, Card.C_3c, Card.C_3c, Card.C_3c, Card.C_3c, Card.C_3c ) ) ); // test_hands.add( new ArrayList<Card>( Arrays.asList( Card.C_3c, Card.C_3c, Card.C_3c, Card.C_3c, Card.C_3c, Card.C_3c, Card.C_2c, Card.C_Ac ) ) ); // // final ArrayList<ArrayList<Card>> dealer_test_hands = new ArrayList<ArrayList<Card>>(); // dealer_test_hands.add( new ArrayList<Card>( Arrays.asList( Card.C_Kc, Card.C_Kc ) ) ); // dealer_test_hands.add( new ArrayList<Card>( Arrays.asList( Card.C_Kc, Card.C_Ac ) ) ); // // for( final ArrayList<Card> dealer_cards : dealer_test_hands ) { // for( final ArrayList<Card> cards : test_hands ) { // final SpBjState s = new SpBjState( deck ); // s.init(); // s.dealer_hand.clear(); // s.dealer_hand.addAll( dealer_cards ); // s.player_hand.hands.set( 0, cards ); // final SpBjSimulator sim = new SpBjSimulator( s ); // sim.takeAction( new JointAction<SpBjAction>( // new SpBjAction( new SpBjActionCategory[] { SpBjActionCategory.Pass } ) ) ); // // System.out.print( "Hand: " ); // System.out.print( sim.state().player_hand ); // System.out.print( " (" ); // final ArrayList<int[]> values = sim.state().player_hand.values(); // for( int i = 0; i < values.size(); ++i ) { // if( i > 0 ) { // System.out.print( ", " ); // } // System.out.print( Arrays.toString( values.get( i ) ) ); // } // System.out.println( ")" ); // // System.out.print( "Reward: " ); // System.out.println( Arrays.toString( sim.reward() ) ); // System.out.print( "Dealer hand: " ); // System.out.print( sim.state().dealerHand().toString() ); // System.out.print( " (" ); // System.out.print( SpBjHand.handValue( sim.state().dealerHand() )[0] ); // System.out.println( ")" ); // System.out.println( "----------------------------------------" ); // } // } while (true) { final SpBjState s = new SpBjState(deck); s.init(); final SpBjSimulator sim = new SpBjSimulator(s); final BufferedReader reader = new BufferedReader(new InputStreamReader(System.in)); while (!s.isTerminal()) { System.out.print("Dealer showing: "); System.out.println(sim.state().dealerUpcard()); System.out.print("Hand: "); System.out.print(sim.state().player_hand); System.out.print(" ("); final ArrayList<int[]> values = sim.state().player_hand.values(); for (int i = 0; i < values.size(); ++i) { if (i > 0) { System.out.print(", "); } System.out.print(Arrays.toString(values.get(i))); } System.out.println(")"); final SpBjActionGenerator actions = new SpBjActionGenerator(); actions.setState(sim.state(), 0); for (final SpBjAction a : Fn.in(actions)) { System.out.println(a); } final String cmd = reader.readLine(); assert (cmd.length() == sim.state().player_hand.Nhands); final SpBjActionCategory[] cat = new SpBjActionCategory[cmd.length()]; for (int i = 0; i < cmd.length(); ++i) { final char c = cmd.charAt(i); if ('h' == c) { cat[i] = SpBjActionCategory.Hit; } else if ('p' == c) { cat[i] = SpBjActionCategory.Pass; } else if ('d' == c) { cat[i] = SpBjActionCategory.Double; } else if ('s' == c) { cat[i] = SpBjActionCategory.Split; } } sim.takeAction(new JointAction<SpBjAction>(new SpBjAction(cat))); } System.out.print("Hand: "); System.out.print(sim.state().player_hand); System.out.print(" ("); final ArrayList<int[]> values = sim.state().player_hand.values(); for (int i = 0; i < values.size(); ++i) { if (i > 0) { System.out.print(", "); } System.out.print(Arrays.toString(values.get(i))); } System.out.println(")"); System.out.print("Reward: "); System.out.println(Arrays.toString(sim.reward())); System.out.print("Dealer hand: "); System.out.print(sim.state().dealerHand().toString()); System.out.print(" ("); System.out.print(SpBjHand.handValue(sim.state().dealerHand())[0]); System.out.println(")"); System.out.println("----------------------------------------"); } }