id
stringlengths
36
36
text
stringlengths
1
1.25M
76b5f467-a794-4353-be61-809ed947326c
@Test public void testMultipleCharGuess() { boolean correct = hm.makeGuess('S'); assertTrue(correct); correct = hm.makeGuess('S'); assertFalse(correct); assertEquals(8, hm.numGuessesRemaining()); assertEquals("S _ _ _ _ _ _ _ _ ", hm.displayGameState()); assertEquals("S", hm.lettersGuessed()); assertFalse(hm.gameOver()); }
ddba30f1-e915-4c86-8a23-d38880041def
@Test public void testWin() { // correctly guess the word and see if the game ends hm.makeGuess('S'); hm.makeGuess('P'); hm.makeGuess('O'); hm.makeGuess('N'); hm.makeGuess('G'); hm.makeGuess('E'); hm.makeGuess('B'); assertEquals("S P O N G E B O B ", hm.displayGameState()); assertTrue(hm.gameOver()); assertTrue(hm.isWin()); }
505af3c8-1bed-4109-ba0e-30b8dcfd81c6
@Test public void testLoss() { // use up all guesses and see if game ends hm.makeGuess('A'); hm.makeGuess('C'); hm.makeGuess('D'); hm.makeGuess('F'); hm.makeGuess('H'); hm.makeGuess('I'); hm.makeGuess('J'); hm.makeGuess('K'); assertTrue(hm.gameOver()); assertFalse(hm.isWin()); }
06eb4a5d-4510-48e5-9e24-6e8647a0649e
@Test public void testAlreadyGuessed() { // Test if the letter being guessed is in the secret word assertTrue(hm.updateState('S')); }
4653cc8e-cf62-4daa-ae2a-a8d1df15e65f
@Test public void testWrongGuess() { // Test if the letter being guessed is wrong assertFalse(hm.updateState('A')); }
9a263461-b8a0-488f-8236-c3947b0d473a
public EvilHangMan(int StringLength, int numGuesses) { guessesRemaining = numGuesses; secretStringLength = StringLength; Scanner scanner = null; try { scanner = new Scanner(new File("dictionary.txt"));// read the dictionary } catch (Exception e) { throw new RuntimeException(e); } int i = 0; while (scanner.hasNext()) { String temp = scanner.nextLine().toUpperCase(); if (temp.length() == StringLength) { wordlist.add(temp); numWords++; } } for (i = 0; i < StringLength; i++) { currentState += "_ "; } scanner.close(); }
e2eb70e4-223b-48ef-9f92-7201e35d923e
public int numLettersRemaining() { return 26; // because they never get one right! }
5a211772-7871-411d-b560-4c8162f10a8b
public boolean isWin() { return false; }
ee6ea5db-dc09-4897-98db-62438fe97c9f
public boolean gameOver() { if (guessesRemaining == 0) return true; else return false; }
2df28ce0-fbea-4f94-9b92-cb799f9ccdac
public boolean makeGuess(char ch) { System.out.println("makeGuess: " + ch + "; numWords=" + numWords); guessResult = false; guess = ch; if (Character.isLetter(ch) && !isRepeatInput(ch)) { // adjust the Wordlist in order to avoid the word with the letter // user guessed int tempWordNum = 0; for (int i = 0; i < numWords; i++) { for (int j = 0; j < secretStringLength; j++) { if(wordlist.get(i).charAt(j) == ch){ break; } else { if (j == secretStringLength - 1) { if (wordlist.get(i).charAt(j) != ch) { tempWordNum++; } } } } } // we choose the words that don't contain the letter the user // guessed, and they will be the new possible secret words. if(tempWordNum > 0) { for (int i = 0; i < wordlist.size(); i++) { for (int j = 0; j < secretStringLength; j++) { if (wordlist.get(i).charAt(j) == ch) { wordlist.remove(i); --i; break; } } } } if (tempWordNum == 0) { System.out.println("tempWordNum is zero!"); secretWord = wordlist.get(0); guessResult = true; } else { numWords = tempWordNum; guessesRemaining--; guessResult = false; } secretWord = wordlist.get(0); if (!guessResult) { guessHistory.add(guess); } } else return false; return guessResult; }
a873f68d-9ca8-41a3-8dd4-3e11ab8304d0
public GUI_Loser(String Letters, JFrame frame) { parentFrame = frame; loserFrame = new JFrame("You are the loser!"); loserFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); loserFrame.setSize(new Dimension(300,470)); loserFrame.setLayout(new FlowLayout()); secretWordLabel = new JLabel("The answer is "+Letters+"."); gameResultLabel = new JLabel("You are the Loser!"); returnBtn = new JButton("Return to the main menu"); returnBtn.addActionListener(this); ImageIcon icon = new ImageIcon("loser.gif"); JLabel loserPic = new JLabel(icon); loserFrame.add(secretWordLabel); loserFrame.add(gameResultLabel); loserFrame.add(returnBtn); loserFrame.add(loserPic); loserFrame.setVisible(true); }
75fc0a7e-d2c3-4949-844e-058a467aeb39
public void actionPerformed(ActionEvent e) { loserFrame.dispose(); //close the window parentFrame.dispose(); // and the parent new Start().createAndShowGUI(); // start over }
a345772c-11be-475f-9c48-b5151d8f44fa
public String getSecretWord() { return secretWord; }
6cccb7ec-42b4-4344-9769-7e8e19d2877c
public void setSecretWord(String secretword) { secretWord = secretword; }
b3130bad-f146-4ecd-8434-f47c0895856c
public int numGuessesRemaining() { return guessesRemaining; }
795581bc-7878-4794-b760-d30ce0b73dd7
public String lettersGuessed() { StringBuilder lettersGuessed = new StringBuilder(guessHistory.size()); for(Character ch: guessHistory) { lettersGuessed.append(ch); } return lettersGuessed.toString(); }
409e7f51-b71a-4482-b37c-f2dac6ce5de0
public String displayGameState() { return currentState; }
4bafeb94-8258-458c-868a-5048fa3f9159
public boolean isRepeatInput(char c) { for (int i = 0; i < guessHistory.size(); i++) { if (guessHistory.get(i) == c) return true; } return false; }
c5864440-4748-4c35-8527-baac72cdbe09
public static boolean controller(char inputLetter, boolean isEvil, JLabel label2, JLabel label3, JLabel result, JFrame frame, HangmanGame game) { //handle the user choice, and pass the data to the model char nextLetter = Character.toUpperCase(inputLetter); if (game.makeGuess(nextLetter)) { if (isEvil)//judge whether the hangman is evil { //if in the evil statement, and the user guess right, // it means it is the time to turn the evil to the regular hangmam result.setText("Yes!"); String secretString = game.getSecretWord(); int guessesRemaining = game.numGuessesRemaining(); String letterHistory = game.lettersGuessed(); game = new NormalHangMan(secretString, guessesRemaining,letterHistory);//turn the evil to regular hangman isEvil = false; game.makeGuess(nextLetter);//re-value the user guess when turn to the regular hangman for the first time } else { result.setText("Yes!"); } } else { result.setText("Nope!"); } label2.setText("Secret Word: "+game.displayGameState()); label3.setText(String.valueOf("Guesses Remaining: "+ game.numGuessesRemaining())); if (game.gameOver()) { if (game.isWin()) { new GUI_Winner(game.displayGameState(),frame); } else { new GUI_Loser(game.getSecretWord(),frame); } } return isEvil; }
a4825ece-77fe-4f71-9e2d-b3691936f0d0
public static HangmanGame createNormalHangMan(HangmanGame game,char inputLetter) { game = new NormalHangMan(game.getSecretWord(), game.numGuessesRemaining(),game.lettersGuessed());//turn the evil to regular hangman game.makeGuess(inputLetter); return game; }
a205b3a2-ca2c-4eb8-8dab-565caa211fa6
public String getSecretWord();
62f7c940-c818-49fe-8256-85d3b66a79d4
public boolean makeGuess(char ch);
9c53d5ac-341a-483c-a6f0-daa14e62cb0e
public boolean isWin();
e15c1ba6-61a9-49c0-a343-f1ab5945f386
public boolean gameOver();
9d70d943-b319-470b-b38e-d8ee07637459
public int numGuessesRemaining();
3b373c8c-02ca-4e1f-b593-2107a95ffd59
public int numLettersRemaining();
f998fef3-f9a9-4da3-85a1-c75d1515a35b
public String displayGameState();
296b2f7b-7753-4a19-9787-91d21a90d07b
public String lettersGuessed();
ad9ffd9c-545d-4c75-be56-6d0bffed0fa6
public void setSecretWord(String secretword);
64978112-d1a7-43ef-a03a-3bf3ebe0b6ef
public GUI_PlayGame(int letters, int guesses) { game = new EvilHangMan(letters, guesses); }
fa667fad-c4e2-4d77-bb3b-d035fa3576b9
public void show() { frame = new JFrame("Evil Hangman"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.setSize(new Dimension(360,370)); frame.setLayout(new FlowLayout()); frame.setResizable(false); label1 = new JLabel("Let's play Evil Hangman!"); label2 = new JLabel("Secret Word: "+game.displayGameState()); label2.setFont(new Font("Default",Font.PLAIN,23)); label3 = new JLabel(String.valueOf("Guesses Remaining: "+ game.numGuessesRemaining() +"\n")); result = new JLabel(""); result.setForeground(Color.red); //this generates an image ImageIcon icon = new ImageIcon("blank.gif"); JLabel hangmanPic = new JLabel(icon); frame.add(label1); frame.add(label2); frame.add(label3); frame.add(result); frame.add(hangmanPic); //add user choice for(int i = 65; i<91;i++) { char x = (char)i; JButton tempBtn = new JButton(String.valueOf(x)); tempBtn.addActionListener(this); frame.add(tempBtn); } frame.setResizable(false); frame.setVisible(true); }
fa0c5f8b-8e29-445c-a6c8-2f6b48c7f5b2
public void actionPerformed(ActionEvent e) { //to figure out which button the user pressed JButton temp = (JButton)e.getSource(); temp.setEnabled(false); inputLetter = temp.getText().charAt(0); check(inputLetter); // make sure it's a valid choice isEvil = HangMan.controller(this.inputLetter,this.isEvil,this.label2,this.label3,this.result,this.frame,this.game); if(isEvil == false && isNormalHangman == false) { //first time when game mode is changed from evil to normal hangman game = HangMan.createNormalHangMan(game,this.inputLetter);//turn the evil to regular hangman isNormalHangman = true; } }
753b1636-090b-49d5-91b7-1f996e10c838
public boolean check(char input) { //do the input check. Player can just input the English letters. return ((input >= 'a' && input <= 'z') || (input >= 'A' && input <= 'Z')); }
1efa0745-5c25-47c3-8ea8-75a9cf4238b3
public GUI_GameResult() { super(); }
b6b18dee-2a5e-4d10-95a8-0e9177c8aba7
public Start() { setLayout(new BoxLayout(this, BoxLayout.PAGE_AXIS)); String[] numLettersOptions = { "4", "5", "6", "7", "8", "9", "10", }; numLetters = numLettersOptions[0]; String[] numGuessesOptions = { "4", "5", "6", "7", "8", "9", "10", "11", "12", "13", "14", "15", "16", }; numGuesses = numGuessesOptions[0]; JLabel patternLabel1 = new JLabel("Select the number of letters"); JLabel patternLabel2 = new JLabel("that will be in the word:"); patternList = new JComboBox(numLettersOptions); patternList.setEditable(true); JLabel patternLabel3 = new JLabel("Select the number of incorrect"); JLabel patternLabel4 = new JLabel("guesses that are allowed:"); patternList1 = new JComboBox(numGuessesOptions); patternList1.setEditable(true); JPanel patternPanel = new JPanel(); patternPanel.setLayout(new BoxLayout(patternPanel, BoxLayout.PAGE_AXIS)); patternPanel.add(patternLabel1); patternPanel.add(patternLabel2); patternList.setAlignmentX(Component.LEFT_ALIGNMENT); patternPanel.add(patternList); JPanel guessPanel = new JPanel(); guessPanel.setLayout(new BoxLayout(guessPanel, BoxLayout.PAGE_AXIS)); guessPanel.add(patternLabel3); guessPanel.add(patternLabel4); patternList1.setAlignmentX(Component.LEFT_ALIGNMENT); guessPanel.add(patternList1); patternPanel.setAlignmentX(Component.LEFT_ALIGNMENT); add(patternPanel); add(guessPanel); add(Box.createRigidArea(new Dimension(0, 10))); JButton button = new JButton("Play!"); button.addActionListener(this); add(button); setBorder(BorderFactory.createEmptyBorder(10,10,10,10)); }
96536c75-ef34-44c0-8b4f-36cf66ac290a
public void actionPerformed(ActionEvent e) { numLetters = (String)(patternList.getSelectedItem()); numGuesses = (String)(patternList1.getSelectedItem()); frame.dispose(); new GUI_PlayGame(Integer.parseInt(numLetters), Integer.parseInt(numGuesses)).show(); }
03c1b8a1-d839-4497-8ef3-ec9469b49e05
public static void createAndShowGUI() { //Create and set up the window. frame = new JFrame("Evil Hangman"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); //Create and set up the content pane. JComponent newContentPane = new Start(); newContentPane.setOpaque(true); //content panes must be opaque frame.setContentPane(newContentPane); //Display the window. frame.pack(); frame.setVisible(true); }
79d3c2ed-8114-42d8-928f-e2fc5770dd07
public static void main(String[] args) { createAndShowGUI(); }
723da3e3-9157-43f2-91c7-eb7bc781c971
public GUI_Winner(String Letters,JFrame frame) { parentFrame = frame; congratulationsFrame = new JFrame("You are the winner!!!"); bg(congratulationsFrame); answerLabel = new JLabel("The answer is "); secretWordLabel = new JLabel(Letters); secretWordLabel.setFont(new Font("Default",Font.PLAIN,23)); secretWordLabel.setForeground(Color.red); gameResultLabel = new JLabel("You are winner!"); returnBtn = new JButton("Return to the main menu"); returnBtn.addActionListener(this); congratulationsFrame.add(answerLabel); congratulationsFrame.add(secretWordLabel); congratulationsFrame.add(gameResultLabel); congratulationsFrame.add(returnBtn); congratulationsFrame.setVisible(true); }
427eb571-f322-47e6-864a-5499a952abea
public void bg(JFrame frame) { background = new ImageIcon("Congrats.gif"); JLabel label = new JLabel(background); label.setBounds(0, 0, background.getIconWidth(), background.getIconHeight()); imagePanel = (JPanel) frame.getContentPane(); imagePanel.setOpaque(false); imagePanel.setLayout(new FlowLayout()); frame.getLayeredPane().setLayout(null); frame.getLayeredPane().add(label, new Integer(Integer.MIN_VALUE)); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.setSize(background.getIconWidth(), background.getIconHeight()); frame.setResizable(false); }
755bb56d-e9cd-4fc4-81f1-9e3787fa5747
public void actionPerformed(ActionEvent e) { congratulationsFrame.dispose(); parentFrame.dispose(); new Start().createAndShowGUI(); }
0d02a796-a944-495f-b37c-066b70b61e55
public static void main( String[] args ) throws FileNotFoundException { String handoffName = "C:\\eloans\\handoff\\elnco032014.txt"; String excelDir = "C:\\eloans\\excel\\poi-test.xls"; String excelWorkSheet = "ALS-CO"; parsing.handoffParsing(handoffName, excelDir, excelWorkSheet); }
1c097d72-4d10-46d4-b90c-25d144f332fc
public String getFieldName() { return fieldName; }
8360bd0d-c3d0-4506-9b7b-d1807cb709c2
public void setFieldName(String fieldName) { this.fieldName = fieldName; }
d762f654-8f98-4a39-a067-45d0f68ffd12
public int getFieldLength() { return fieldLength; }
63a33fde-0652-47fc-965a-632e70208079
public void setFieldLength(int fieldLength) { this.fieldLength = fieldLength; }
a2fa0669-a2c7-4f8c-a930-d0816a831046
public String getRowNo() { return rowNo; }
199b1395-ba69-4821-a425-5ba0609be8f8
public void setRowNo(String rowNo) { this.rowNo = rowNo; }
5224e915-220a-4971-a65c-d026aad3552a
public String getFieldValue() { return fieldValue; }
7e1c35a2-a430-4bf9-b920-81f34a869217
public void setFieldValue(String fieldValue) { this.fieldValue = fieldValue; }
4a49cd05-7e55-40f5-9d08-17c7c8cff735
List<FieldMetadataDTO> parsedRowData(String metaDataDir, String sheet);
6d6b696a-ec81-4561-b683-7bcb43d56c62
Map<Integer, String> getRecordRow(String dirname) throws FileNotFoundException;
ef49f22f-44b9-4ce0-be41-c7053f42cbe8
void createTextFile(Map<Integer, Map<Integer, String>> xxx) ;
73eb9b2f-b568-4a71-bec2-5207885dcd62
List<FieldMetadataDTO> readFromExcel(String file, String sheet);
25544714-8bec-4f9c-b8e6-14785b825d0e
void handoffParsing(String handoffName, String excelDir, String excelWorkSheet) throws FileNotFoundException;
517165f1-8f58-4d2c-9f70-2b876c3459bd
public void handoffParsing(String handoffName, String excelDir, String excelWorkSheet) throws FileNotFoundException{ Iterator<Map.Entry<Integer, String>> i = getRowRecord(handoffName).entrySet().iterator(); //While handoff file has row while (i.hasNext()) { Map.Entry<Integer, String> e = (Entry<Integer, String>) i.next(); rfc.createTextFile(getSplitedRowValues(e.getKey(), e.getValue(), excelDir,excelWorkSheet )); } }
bf51bfa9-f179-485c-979c-37f4f8c1d549
private Map<Integer, String> getRowRecord(String handoffName) throws FileNotFoundException{ return rfc.getRecordRow(handoffName); }
0e1448a9-a562-4f5f-94a4-217150d1e02a
private Map<Integer, Map<Integer, String>> getSplitedRowValues( int key, String ...str ) { // value per Row Map<Integer, Map<Integer, String>> rowItem = new HashMap<Integer, Map<Integer, String>>(); // value per record Map<Integer, String> xxx = new HashMap<Integer, String>(); List<FieldMetadataDTO> parsedRowData = refmeta.parsedRowData(str[1],str[2]); int ctrLength = 0; Integer ctr = 0; for (FieldMetadataDTO fmeta: parsedRowData) { xxx.put( ctr, ctr + "\t" + fmeta.getRowNo() + "\t"+ fmeta.getFieldName() + "\t" + fmeta.getFieldLength() + "\t\t\t" + str[0].substring(ctrLength, ctrLength + fmeta.getFieldLength())); ctrLength+=fmeta.getFieldLength(); ctr++; } rowItem.put(key, xxx); return rowItem; }
e739bec2-0378-4ca2-8d59-012ea342d0ad
public List<FieldMetadataDTO> readFromExcel(String file, String sheet) { List<FieldMetadataDTO> lfmd = new ArrayList<FieldMetadataDTO>(); try { FileInputStream fileInputStream = new FileInputStream(file); HSSFWorkbook workbook = new HSSFWorkbook(fileInputStream); HSSFSheet worksheet = workbook.getSheet(sheet); Iterator<?> rows = worksheet.rowIterator(); int x=0; while (rows.hasNext()) { HSSFRow row = (HSSFRow) rows.next(); if(x!=0){ lfmd.add(getMetaData(row)); } x++; } } catch (FileNotFoundException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } return lfmd; }
a8bbe658-9ffa-4b94-9be8-a54f51950a40
private FieldMetadataDTO getMetaData(HSSFRow row){ FieldMetadataDTO fmd = null; fmd = new FieldMetadataDTO(); fmd.setFieldName(row.getCell(0).getStringCellValue()); fmd.setFieldLength(parseToInteger(row.getCell(1).getStringCellValue())); fmd.setRowNo(row.getCell(2).getStringCellValue()); return fmd; }
67d1b0a5-3139-4724-be03-cca63314eba4
private int parseToInteger(String s){ return Integer.parseInt(s); }
f396983a-7c6c-4e3e-aea1-44be177a8cc8
public Map<Integer, String> getRecordRow(String dirname) throws FileNotFoundException{ // dirname == directory + filename FileInputStream fis = new FileInputStream(dirname); Scanner scanner = new Scanner(fis); Map<Integer, String> recordRow = new HashMap<Integer, String>(); recordRow = putRecordToMap(scanner); scanner.close(); return recordRow; }
ab8acf8e-4451-4249-bd03-a37e85698b5a
public void createTextFile(Map<Integer, Map<Integer, String>> xxx) { Set<Map.Entry<Integer, Map<Integer, String>>> s = xxx.entrySet(); Iterator<Map.Entry<Integer, Map<Integer, String>>> i = s.iterator(); while (i.hasNext()) { Map.Entry<Integer, Map<Integer, String>> recordPerRow = (Entry<Integer, Map<Integer, String>>) i .next(); int key = recordPerRow.getKey(); Map<Integer, String> y = recordPerRow.getValue(); Set<Map.Entry<Integer, String>> ss = y.entrySet(); Iterator<Map.Entry<Integer, String>> ii = ss.iterator(); StringBuilder sb = new StringBuilder(); sb.append("=== Handoff File Testing === \n"); sb.append("Total Record: " + xxx.size() + " \n" ); sb.append("Field Name \t\t\tLength\t\tValue\n"); sb.append("-------------------------------------------------------------------------------------\n"); while (ii.hasNext()) { Map.Entry<Integer, String> rowValue = ii.next(); log.debug("Parent Key : " + key + " Key : " + rowValue.getKey() + " value : " + rowValue.getValue()); sb.append(rowValue.getValue()); sb.append('\n'); } createNow(recordPerRow.getKey(), sb.toString()); } }
0ec8e945-3a88-4eac-8723-0f2c05e2d465
private Map<Integer, String> putRecordToMap(Scanner scanner) { Map<Integer, String> recordRow = new HashMap<Integer, String>(); int ctr = 0; while (scanner.hasNextLine()) { recordRow.put(ctr++, scanner.nextLine()); } return recordRow; }
254998db-bb93-4b92-999b-b876bc95bd2f
private void createNow(int key, String value) { BufferedWriter writer = null; String x = "C:\\eloans\\extracted\\"; try { writer = new BufferedWriter(new FileWriter(x + "TestFile_ALS-CO(" + key+1 + ").txt")); writer.write(value); } catch (IOException e) { } finally { try { if (writer != null) writer.close(); } catch (IOException e) { } } }
0abdff61-e54a-471b-9b32-9775142279af
@Override public List<FieldMetadataDTO> parsedRowData(String metaDataDir, String sheet) { List<FieldMetadataDTO> lfm = utilsCore.readFromExcel(metaDataDir, sheet); return lfm; }
9cfe812f-8477-4e03-a37a-c2ea3004f1e2
private ALSCOLLATERAL(String fieldName, int length){ this.fieldName = fieldName; //this.startIndex = startIndex; this.length = length; }
87880c14-fc5a-46a4-87da-d6f0dcd66df2
public String getFieldName(){ return fieldName; }
ad730bd3-41c4-44b1-9604-6c76c44d272a
public int getLength(){ return length; }
6676d79f-6894-4040-9ffe-6f6a4e8a1375
INTF_TYPE(String prefix){ this.prefix = prefix; }
70be33d5-370b-4137-aa8a-8f991c6ef074
public String getPrefix(){ return prefix; }
1fdbb8db-b023-4659-9d83-fcefb82ff6a0
public AppTest( String testName ) { super( testName ); }
f262264c-16a6-4e72-83be-8177b55cff68
public static Test suite() { return new TestSuite( AppTest.class ); }
c0fc976c-0fba-4e64-8369-1f3ef4cec9d3
public void testApp() { assertTrue( true ); }
e4f18ba3-e18f-4b34-8749-35cfe15fc1a0
public static void main(String args[]) { final Configuration configuration = new Configuration(); configuration.setClassForTemplateLoading(SparkFormHandling.class, "/"); Spark.get(new Route("/") { @Override public Object handle(Request rqst, Response rspns) { Map<String, Object> fruitsMap = new HashMap<String, Object>(); fruitsMap.put("fruits", Arrays.asList("apple", "orange", "banana", "peach")); try { Template fruitPickeTemplate = configuration.getTemplate("fruitPicker.ftl"); StringWriter writer = new StringWriter(); fruitPickeTemplate.process(fruitsMap, writer); return writer; } catch (IOException ex) { Logger.getLogger(SparkFormHandling.class.getName()).log(Level.SEVERE, null, ex); } catch (TemplateException ex) { Logger.getLogger(SparkFormHandling.class.getName()).log(Level.SEVERE, null, ex); } return null; } }); Spark.post(new Route("/favorite_fruit") { @Override public Object handle(Request request, Response rspns) { final String fruit = request.queryParams("fruit"); if (fruit == null) { return "Why don't you pick one?"; } else { return "You favorite fruit is " + fruit; } } }); }
83646b2a-983a-49fa-9d57-6f5a34d621ef
@Override public Object handle(Request rqst, Response rspns) { Map<String, Object> fruitsMap = new HashMap<String, Object>(); fruitsMap.put("fruits", Arrays.asList("apple", "orange", "banana", "peach")); try { Template fruitPickeTemplate = configuration.getTemplate("fruitPicker.ftl"); StringWriter writer = new StringWriter(); fruitPickeTemplate.process(fruitsMap, writer); return writer; } catch (IOException ex) { Logger.getLogger(SparkFormHandling.class.getName()).log(Level.SEVERE, null, ex); } catch (TemplateException ex) { Logger.getLogger(SparkFormHandling.class.getName()).log(Level.SEVERE, null, ex); } return null; }
3053e9ab-900d-47c6-808b-3d52a3b08b36
@Override public Object handle(Request request, Response rspns) { final String fruit = request.queryParams("fruit"); if (fruit == null) { return "Why don't you pick one?"; } else { return "You favorite fruit is " + fruit; } }
8f87cc36-73d3-4644-a3cd-ad10efce31c6
public static void main(String args[]) { final Configuration configuration = new Configuration(); configuration.setClassForTemplateLoading(HelloWorldFreemakerStyle.class, "/"); StringWriter writer = new StringWriter(); try { MongoClient client = new MongoClient("localhost", 27017); DB database = client.getDB("students"); DBCollection collection = database.getCollection("grades"); DBCursor cur = collection.find(new BasicDBObject("type", "homework")).sort(new BasicDBObject("student_id", 1).append("score", 1)); int id = -1; int i = 0; while (cur.hasNext()) { DBObject doc = cur.next(); int idStudent = (Integer) doc.get("student_id"); if (idStudent != id) { i++; id = idStudent; System.out.println("##############################"); System.out.println(doc); // collection.remove(doc); } else { System.out.println(doc); } } System.out.println("Removido " + i); } catch (UnknownHostException ex) { Logger.getLogger(HelloWorldFreemakerStyle.class.getName()).log(Level.SEVERE, null, ex); } }
d815527e-58aa-494d-9189-fb5fdff0af0a
public static void main(String args[]) throws UnknownHostException{ MongoClient client = new MongoClient("localhost", 27017); DB database = client.getDB("bytecom"); DBCollection collection = database.getCollection("client"); DBObject document = collection.findOne(); System.out.println(document); }
7dfd32c1-fbd0-4d45-9c0a-f88c6353c0fe
public static void main(String[] args) throws UnknownHostException { final String screenName = args.length > 0 ? args[0] : "ClairtonLuz"; List<DBObject> tweets = getLatestTweets(screenName); MongoClient client = new MongoClient(); DBCollection tweetsCollection = client.getDB("course").getCollection("tweeter"); for (DBObject cur : tweets){ cur.put("screen_name", screenName); massageTweetId(cur); tweetsCollection.update(new BasicDBObject("_id" , cur.get("_id")), cur, true, false); } System.out.println("Tweet count: " + tweetsCollection.count()); client.close(); }
8f20f51c-5efa-4c6d-b105-f7d386cb2262
private static void massageTweetId(DBObject cur) { Object id = cur.get("id"); cur.removeField("id"); cur.put("_id", id); }
a7b14ac0-3c94-4a3b-9784-4d0f3bd93ef3
private static List<DBObject> getLatestTweets(String screenName) { try { URL url = new URL("https://api.twitter.com/1.1/statuses/user_timeline.json?screen_name=" + screenName + "$include_rts=1"); InputStream is = url.openStream(); ByteArrayOutputStream os = new ByteArrayOutputStream(); int retVal; while((retVal = is.read()) != -1){ os.write(retVal); } final String tweetsString = os.toString(); return (List<DBObject>) JSON.parse(tweetsString); } catch (MalformedURLException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } return null; }
9d52a44d-4cb8-47cb-93b2-624baae0cf6a
public static void main(String args[]) { final Configuration configuration = new Configuration(); configuration.setClassForTemplateLoading(HelloWorldFreemakerStyle.class, "/"); Spark.get(new Route("/") { @Override public Object handle(Request rqst, Response rspns) { StringWriter writer = new StringWriter(); try { Template helloTemplate = configuration.getTemplate("hello.ftl"); Map<String, Object> helloMap = new HashMap<String, Object>(); helloMap.put("name", "Clairton"); helloTemplate.process(helloMap, writer); } catch (IOException ex) { Logger.getLogger(HelloWorldFreemakerStyle.class.getName()).log(Level.SEVERE, null, ex); } catch (TemplateException ex) { Logger.getLogger(HelloWorldFreemakerStyle.class.getName()).log(Level.SEVERE, null, ex); } return writer; } }); }
cdf6a53c-c8af-44ad-ae45-1a851ff5770b
@Override public Object handle(Request rqst, Response rspns) { StringWriter writer = new StringWriter(); try { Template helloTemplate = configuration.getTemplate("hello.ftl"); Map<String, Object> helloMap = new HashMap<String, Object>(); helloMap.put("name", "Clairton"); helloTemplate.process(helloMap, writer); } catch (IOException ex) { Logger.getLogger(HelloWorldFreemakerStyle.class.getName()).log(Level.SEVERE, null, ex); } catch (TemplateException ex) { Logger.getLogger(HelloWorldFreemakerStyle.class.getName()).log(Level.SEVERE, null, ex); } return writer; }
e3abf225-7440-47dc-958e-b090a8f74ea5
public static void main(String args[]) { Configuration configuration = new Configuration(); configuration.setClassForTemplateLoading(HelloWorldFreemakerStyle.class, "/"); try { Template helloTemplate = configuration.getTemplate("hello.ftl"); StringWriter writer = new StringWriter(); Map<String, Object> helloMap = new HashMap<String, Object>(); helloMap.put("name", "Bytecom"); helloTemplate.process(helloMap, writer); System.out.println(writer); } catch (IOException ex) { Logger.getLogger(HelloWorldFreemakerStyle.class.getName()).log(Level.SEVERE, null, ex); } catch (TemplateException ex) { Logger.getLogger(HelloWorldFreemakerStyle.class.getName()).log(Level.SEVERE, null, ex); } }
f08985b2-a47e-47cd-9cf6-54c3975fb6b9
public static void main(String args[]) { final Configuration configuration = new Configuration(); configuration.setClassForTemplateLoading(HelloWorldFreemakerStyle.class, "/"); Spark.get(new Route("/") { @Override public Object handle(Request rqst, Response rspns) { StringWriter writer = new StringWriter(); try { MongoClient client = new MongoClient("localhost", 27017); DB database = client.getDB("bytecom"); DBCollection collection = database.getCollection("client"); DBObject document = collection.findOne(); Template helloTemplate = configuration.getTemplate("hello.ftl"); helloTemplate.process(document, writer); } catch (IOException ex) { Logger.getLogger(HelloWorldFreemakerStyle.class.getName()).log(Level.SEVERE, null, ex); } catch (TemplateException ex) { Logger.getLogger(HelloWorldFreemakerStyle.class.getName()).log(Level.SEVERE, null, ex); } return writer; } }); }
1432d7e6-5528-4012-a523-203f8466c5b9
@Override public Object handle(Request rqst, Response rspns) { StringWriter writer = new StringWriter(); try { MongoClient client = new MongoClient("localhost", 27017); DB database = client.getDB("bytecom"); DBCollection collection = database.getCollection("client"); DBObject document = collection.findOne(); Template helloTemplate = configuration.getTemplate("hello.ftl"); helloTemplate.process(document, writer); } catch (IOException ex) { Logger.getLogger(HelloWorldFreemakerStyle.class.getName()).log(Level.SEVERE, null, ex); } catch (TemplateException ex) { Logger.getLogger(HelloWorldFreemakerStyle.class.getName()).log(Level.SEVERE, null, ex); } return writer; }
42f4e2a5-64b6-42e2-8dd5-a44460cbef4b
public static void main(String args[]){ Spark.get(new Route("/") { @Override public Object handle(Request rqst, Response rspns) { return "Hello world from Spark"; } }); }
e3613d41-7d2e-4363-8330-2774b02d16b4
@Override public Object handle(Request rqst, Response rspns) { return "Hello world from Spark"; }
b4531383-8af7-4c42-80c0-035c1ef1fcb7
public AppTest( String testName ) { super( testName ); }
05d8600d-d3bd-4a68-afb4-2f623085b22a
public static Test suite() { return new TestSuite( AppTest.class ); }
cc580008-5b21-4450-82a5-4a4dbbf3afc3
public void testApp() { assertTrue( true ); }
454f4593-127a-46e6-bb2d-6e022b69968e
public static void main( String[] args ) { System.out.println( "Hello World!" ); }
c9c330c1-f407-4790-a69b-1ad3a85ed481
public AppTest( String testName ) { super( testName ); }
7c0f32c4-ff0b-47ef-8b40-9e365718076b
public static Test suite() { return new TestSuite( AppTest.class ); }
abdf8855-9b2b-4c89-8838-7507d40e9a49
public void testApp() { assertTrue( true ); }
445fe773-41bc-433c-a6ca-b4a140ffbae2
@Override public @WebResult(name = "outHelloWord") OutHelloWord dizerOi(InHelloWord inHelloWord) throws ServiceNotFoundException{ OutHelloWord outHelloWord = new OutHelloWord(); return outHelloWord; }
ad246337-7a6b-4ddf-9503-54287845fac2
public OutHelloWord() { mensagem = ""; }
a1109204-e80c-4483-a846-ffefd94f05d6
public String getMensagem() { return mensagem; }
d2f137ff-62f0-4602-8122-bed90ee657a2
public void setMensagem(String mensagem) { this.mensagem = mensagem; }