public Pack fromDefault(Pack pack) { Rule rule = pack.getRule(); Target target = rule.getTarget(); TuplePrototype targetPrototype = target.getPrototype(); Function call = pack.getPriorCall(); if (call == null) { throw new DefaultPackExpansionException("Cannot use implicit pack in a call-free chain."); } TuplePrototype callPrototype = target.getPrototype(); if (callPrototype.size() != targetPrototype.size()) { throw new DefaultPackExpansionException( "Default pack cannot be created because tuple prototypes are of different lengths."); } Pack newPack = (Pack) adaptor.dupNode(pack); for (int i = 0; i < targetPrototype.size(); i++) { TupleRef ref = (TupleRef) adaptor.create(TUPLE_REF, ""); adaptor.addChild(ref, adaptor.create(NUMBER, Integer.toString(i))); adaptor.addChild(newPack, ref); } return newPack; }
@Test public void testGet() { pack.put(card); pack.put(card2); pack.put(card3); pack.put(card4); assertTrue(pack.get() == card4); }
@Test public void testPut() { pack.put(card); pack.put(card2); pack.put(card3); pack.put(card4); assertEquals(pack.position, 4); }
public WarehouseAndPack findWarehouseAndPack( Drone drone, Order order, List<Warehouse> warehouses) { for (Warehouse warehouse : warehouses) { Pack pack = warehouse.buildPartialPack(order, drone); if (pack.getWeight() == order.pack.getWeight()) { return new WarehouseAndPack(warehouse, pack); } } return null; }
/** * Deals a new card onto the board. Removes the card it adds from the pack. Prints all the cards * on the board */ private void dealCard() { ; char aChar = 0; char bChar = 0; toggleLock = true; // Makes it so you can no longer change if the log is on or off if (cardsInDeck > 0) { // Only deals a card if there is a card to deal String card = pack.getFirtCard(); // Gets the card on top of the deck cardStrings.add(card); // Adds this card to the arraylist that the frame prints from. for (String c : cardStrings) { // For all the cards on the table aChar = c.charAt(0); bChar = c.charAt(1); StringBuilder sb = new StringBuilder(3); sb.append(aChar).append(bChar).append(" "); if (printBoard) { System.out.print(sb); // Prints the current board to the command line } } frame.cardDisplay(cardStrings); // Prints the cards to the frame System.out.println(""); Pile pile = new Pile(aChar, bChar); // Creates a new pile of the newly laid card piles.addPile(pile); // Adds it to the arrayList of current piles on board cardsInDeck--; saveLog(); // Calls the function to save the new move to the log } else { printFrame(); drawCard = false; // Tells the AI that he cannot draw a card System.out.println("No more cards in deck!"); } }
public final Object clone() { int[] iarr; Object[] oarr; Pack ret = new Pack( (iarr = this.iArray) != null ? iarr.length : -1, (oarr = this.oArray) != null ? oarr.length : -1); if (iarr != null) { System.arraycopy(iarr, 0, ret.iArray, 0, iarr.length); } if (oarr != null) { System.arraycopy(oarr, 0, ret.oArray, 0, oarr.length); } ret.iSize = this.iSize; ret.oSize = this.oSize; return ret; }
/** runMenu() method runs from the main and allows entry of data etc */ private void runMenu() { String response; do { printMenu(); System.out.println("What would you like to do:"); scan = new Scanner(System.in); response = scan.nextLine().toUpperCase(); switch (response) { case "1": pack.printPack(); break; case "2": pack.shuffleDeck(); isShuffled = true; break; case "3": if (isShuffled) { dealCard(); } else { System.out.println("Please shuffle the pack first"); } break; case "4": int lastCard1 = cardStrings.size() - 1; movePileOntoPrevious(lastCard1, isAI, isLegal); break; case "5": int lastCard2 = cardStrings.size(); movePileTwoPlacesLeft(lastCard2, isAI, isLegal); break; case "6": int parameter1 = getInt("What card do you want to move? (By it's position on the board)") - 1; movePileOntoPrevious(parameter1, isAI, isLegal); break; case "7": int parameter2 = getInt("What card do you want to move? (By it's position on the board)"); movePileTwoPlacesLeft(parameter2, isAI, isLegal); break; case "8": AI(); break; case "9": int numMoves = getInt("How many moves do you wish to make?"); for (int i = 0; i < numMoves; i++) { if (!drawCard) { // If there are no cards left to draw, then stop. break; } AI(); } break; case "10": toggleLog(); break; case "11": togglePrintBoard(); break; case "12": lowScores.printScores(); break; case "Q": System.out.println("Your score was: " + cardStrings.size()); saveScore(); frame.closeProgram(); break; default: System.err.println("Incorrect Selection, try again"); } } while (!(response.equals("Q"))); }
@Override public void run() { try { processTime = System.currentTimeMillis(); myPack = (Pack) ois.readObject(); functionName = myPack.getfunctionName(); paramTypes = myPack.getparamTypes(); paramValues = myPack.getparamValues(); state = myPack.getstate(); stateDType = myPack.getstateType(); timestamps = myPack.getTimeStamps(); if (functionName != null && functionName.length() > 0) { try { System.out.println("Trying to load and execute"); Class cls = Class.forName(stateDType.getName()); timestamps.add(processTime + ",server1"); /*System.out.println(""+stateDType.getName()); System.out.println("functionsName: " + functionName.toLowerCase()); System.out.println("paramTypes: " + paramTypes.toString());*/ Method method = cls.getDeclaredMethod(functionName, paramTypes); try { /** support for caching results */ /** cache using the parameters as key of the result can be possible */ // boolean processed = TreeManager.getInstance().exists(paramValues[0]); // System.out.println("param1:" + (int[]) paramValues[0]); // System.out.println("param1:" + paramValues[1]); // System.out.println("param1:" + paramValues[2]); oos.flush(); Object result = method.invoke(state, paramValues); ResultPack rp = new ResultPack(result, state); rp.setTimeStamps(timestamps); // System.out.println("Size in bytes: " + sizeInBytes(rp)); oos.flush(); oos.writeObject(rp); // System.out.println("Object wrote it"); oos.flush(); // System.out.println("Object executed and flushed: " + (System.currentTimeMillis() - // processTime)); System.out.println("Object executed and flushed:"); // System.out.println("Object executed and flushed: " + (System.currentTimeMillis() - // processTime)); } catch (IllegalAccessException ex1) { returnnull(oos); System.out.println("Hubo problema 1: " + ex1.getMessage()); } catch (InvocationTargetException ex2) { returnnull(oos); System.out.println("Hubo problema 2: " + ex2.getCause()); } catch (Exception ex3) { ResultPack rp = new ResultPack(null, state); oos.writeObject(rp); oos.flush(); System.out.println("Hubo problema 3" + ex3.getCause()); } } catch (ClassNotFoundException ex) { returnnull(oos); System.out.println("Hubo problema 4"); } catch (IllegalArgumentException ex) { returnnull(oos); System.out.println("Hubo problema 5"); } catch (NoSuchMethodException ex) { returnnull(oos); System.out.println("Hubo problema 6"); } catch (SecurityException ex) { returnnull(oos); System.out.println("Hubo problema 7"); } finally { oos.close(); ois.close(); in.close(); out.close(); mysocket.close(); oos = null; ois = null; in = null; out = null; mysocket = null; } } else { returnnull(oos); } } catch (IOException ex) { returnnull(oos); System.out.println("Hubo problema 8"); } catch (ClassNotFoundException ex) { returnnull(oos); System.out.println("Hubo problema 9"); ex.printStackTrace(); } finally { makeconnection(); } }
@Override public void run() { try { myPack = (Pack) ois.readObject(); functionName = myPack.getfunctionName(); paramTypes = myPack.getparamTypes(); paramValues = myPack.getparamValues(); state = myPack.getstate(); stateDType = myPack.getstateType(); if (functionName != null && functionName.length() > 0) { try { Class cls = Class.forName(stateDType.getName()); Method method = cls.getDeclaredMethod(functionName, paramTypes); try { Object result = method.invoke(state, paramValues); ResultPack rp = new ResultPack(result, state); oos.writeObject(rp); oos.flush(); } catch (IllegalAccessException ex) { returnnull(oos); } catch (InvocationTargetException ex) { returnnull(oos); } catch (Exception ex) { ResultPack rp = new ResultPack(null, state); oos.writeObject(rp); oos.flush(); } } catch (ClassNotFoundException ex) { returnnull(oos); } catch (IllegalArgumentException ex) { returnnull(oos); } catch (NoSuchMethodException ex) { returnnull(oos); } catch (SecurityException ex) { returnnull(oos); } finally { oos.close(); ois.close(); in.close(); out.close(); mysocket.close(); oos = null; ois = null; in = null; out = null; mysocket = null; } } else { returnnull(oos); } } catch (IOException ex) { returnnull(oos); } catch (ClassNotFoundException ex) { returnnull(oos); } finally { makeconnection(); } }