id
stringlengths
36
36
text
stringlengths
1
1.25M
9f1e37ee-1448-4c17-9b15-0c183866808d
@Test /** * This method simply calls the getEandomQuestion() 300 times. Becuase the * setUp() method (see above) has added 3 word pairs we should be able to * get them all with 300 tries. That is what is asserted at the bottom of * this method. * * This does not test the distribution, but if we belive in the random * generators it tests the "border values" in that all possible values must * be generated. * */ public void testGetRandomQuestion() { int testTries = 300; boolean horseFound = false; boolean houseFound = false; boolean tabelFound = false; for (int i = 0; i < testTries; i++) { String question = wordPairDemo.getRandomQuestion(); if (question.equals("hest")) { horseFound = true; } if (question.equals("hus")) { houseFound = true; } if (question.equals("bord")) { tabelFound = true; } } String errorMessage = "Expected horseFound: true, houseFound: true, tableFound: true. Got: hoserFound: " + horseFound + ", houseFound: " + houseFound + ", tableFound: " + tabelFound; assertTrue(errorMessage, horseFound && houseFound && tabelFound); }
689760b5-a9ed-4a80-a84c-9eb4418221ce
@Test public void testCheckGuessTrue() { assertTrue("Expected true. Got: " + wordPairDemo.checkGuess("hest", "horse") + " for the wordpair hest, horse", wordPairDemo.checkGuess("hest", "horse")); }
2f5d89e2-4df4-436c-9093-be54a265d7a2
@Test public void testCheckGuessBoth() { assertFalse("Expected false. Got: " + wordPairDemo.checkGuess("hest", "cow") + " for the wordpair hest,cow", wordPairDemo.checkGuess("hest", "cow")); }
b95c3265-60a5-43ac-b650-beb2f06793ce
@Test public void testGetSize() { assertTrue("Expected size 3. Got: " + wordPairDemo.size(), wordPairDemo.size() == 3); }
929bed3f-b6be-4882-bca5-e4cd179e574e
@Override public void add(String question, String answer) { engine.add(question, answer); }
22086784-890c-4611-b9ea-200942d939d5
@Override public int size() { return engine.getSize(); }
c4c489de-5e8d-40d5-aa84-b8b493376dea
@Override public String getRandomQuestion() { return engine.getRandomQuestion(); }
f9888c66-fdbb-4e7b-800b-635cc69efbb4
@Override public boolean checkGuess(String question, String guess) { return engine.checkGuess(question, guess); }
a49501ed-cf93-47ff-a2bd-0f1e8f7d187a
@Override public String lookup(String question) { return engine.getAnswer(question); }
5966618d-b6ad-4723-8a8e-74d5079ddd3e
@Override public boolean load(String filename) { return engine.load(filename); }
16afd548-1e03-4505-93cf-d9e909382925
@Override public boolean save(String filename) { return engine.save(filename); }
9978064a-6cd7-45b8-9831-20a46b38ae75
@Override public void clear() { engine.clear(); }
67c5ede1-37c4-4400-8b5e-40bd0accd016
void add(String question, String answer);
b0a609f1-968f-42ae-900e-c9dd21a85440
int size();
f9c79773-cea9-4868-b43f-ebc7eff967a9
String getRandomQuestion();
2166c90e-1e55-4d82-8c9d-367b36d541e9
boolean checkGuess(String question, String quess);
1e7bb977-76ed-4c58-b206-a5fe6427821b
String lookup(String question);
09388c89-e336-49da-8911-59736c291fd8
boolean load(String filename);
8a94aac9-ff16-4652-9cf8-ed2435e15655
boolean save(String filename);
e086d4ea-ee92-4120-b577-3e479eb87f82
void clear();
6d887e83-f79f-449e-ac3f-87e95d3673e4
public boolean load(String filename) { try { solidFH.load_to_Collections(filename, words_load_save, wordMap); } catch (Exception e) { return false; } return true; }
c16ef623-9b25-4ede-bc76-165e7d6370fe
public boolean save(String filename) { try { solidFH.save(filename, words_load_save); } catch (Exception e) { return false; } return true; }
c2291a2a-eb55-43ee-a16f-4bf8cc6ac11b
public void add(String question, String answer) { SolidWordPair wp = new SolidWordPair(question, answer, 1); words_load_save.add(wp); wordMap.put(question, wp); }
cd7cf86d-4068-40aa-9b69-eec91b0db2bd
public String getAnswer(String question) { return wordMap.get(question).getDanish(); }
1872d6db-d0fb-4c0b-9607-c610b89c47a7
public SolidWordPair getWordPair(String question) { return wordMap.get(question); }
5d6cf020-338a-44a4-be29-deb2e1d786e6
public int getSize() { return words_load_save.size(); }
5aafd543-bf1d-459c-8eac-488e3dad7dcb
public boolean checkGuess(String question, String guess) { boolean right = getAnswer(question).equalsIgnoreCase(guess); if (right) { getWordPair(question).incrementProb(); } return right; }
8f6514ff-3d6f-4dd4-bb25-e0b17844eec9
public String getRandomQuestion() { /* int num = ran.nextInt(getSize()); if (num <= 5) { ArrayList<SolidWordPair> prio1 = getWordScore(1); return prio1.get(ran.nextInt(prio1.size())).getEnglish(); } else if (num > 5 && num <= 9) { ArrayList<SolidWordPair> prio2 = getWordScore(2); return prio2.get(ran.nextInt(prio2.size())).getEnglish(); } else if (num > 9 && num <= 12) { ArrayList<SolidWordPair> prio3 = getWordScore(3); return prio3.get(ran.nextInt(prio3.size())).getEnglish(); } else if (num > 13 && num <= 15) { ArrayList<SolidWordPair> prio4 = getWordScore(4); return prio4.get(ran.nextInt(prio4.size())).getEnglish(); } else if (num > 15) { ArrayList<SolidWordPair> prio5 = getWordScore(5); return prio5.get(ran.nextInt(prio5.size())).getEnglish(); } else return null; */ int remainder = 1; int qRoll = 1; while (remainder != 0) { int hunnid = ran.nextInt(100); // qRoll = words_load_save.get(ran.nextInt(getSize())).getProbability(); qRoll = ran.nextInt(getSize()); int qProb = words_load_save.get(qRoll).getProbability(); remainder = hunnid % qProb; } return words_load_save.get(qRoll).getEnglish(); }
0eae7532-1239-4cab-84db-174044ce2c4c
public void clear() { words_load_save.clear(); wordMap.clear(); }
2600c847-b413-47c9-b85a-4e40c844b89d
public SolidWordPair(String english, String danish, int prio) { this.english = english; this.danish = danish; probability = prio; }
da598eb0-9142-4ca8-bb09-23c5ee7d10f4
public void incrementProb() { if (probability < 13) { probability++; } }
f722f1da-808a-47cb-a574-51cc90e5fe7f
public int getProbability() { return probability; }
18a601be-0ef1-4299-9e68-ccd95be0ae64
public void setProbability(int probability) { this.probability = probability; }
f7352318-2b7d-4880-aca9-0910950c6009
public String getEnglish() { return english; }
f9e6232d-9b48-46c4-9ec2-d6490c2e2068
public String getDanish() { return danish; }
322b499a-a14b-419c-a8e6-5e0258a50e3b
public void setEnglish(String english) { this.english = english; }
a56bb456-363b-4d06-8797-f2396374834f
public void setDanish(String danish) { this.danish = danish; }
393b8c63-a499-4513-bced-17a0f1680772
@Override public String toString() { return english + " = " + danish; }
d7497531-6300-4aef-91e7-e240a0fe677d
public void load_to_Collections(String filename, ArrayList<SolidWordPair> pairs, HashMap<String, SolidWordPair> pairsMap) throws Exception { scan = new Scanner(new File(filename)); while (scan.hasNext()) { String str = scan.nextLine(); String[] tokens = str.split(","); String english = tokens[0].trim(); String danish = tokens[1].trim(); int prio = Integer.parseInt(tokens[2].trim()); SolidWordPair solidPair = new SolidWordPair(english, danish, prio); pairs.add(solidPair); pairsMap.put(solidPair.getEnglish(), solidPair); } }
fa2c5662-6908-49a8-bbf5-fd302a76512a
public void create_File(String filename) { File file; file = new File(filename); try { file.createNewFile(); } catch (IOException ex) { Logger.getLogger(SolidFileHandler.class.getName()).log(Level.SEVERE, null, ex); } }
c5709d2b-8de5-42b6-ba37-f597c960ae32
public void save(String filename, ArrayList<SolidWordPair> pairs) { try { create_File(filename); fw = new FileWriter(filename); for (SolidWordPair solidPair : pairs) { fw.append(solidPair.getEnglish() + ", " + solidPair.getDanish() + ", " + solidPair.getProbability()); fw.append("\n"); } fw.close(); } catch (Exception e) { } }
f72d1871-d84a-4c3a-abd0-650686f8bdcc
public SolidGUI() { initComponents(); jLabelWellWhatKnow.setVisible(false); control = new SolidControl(); control.load(output); jTextFieldQuestion.setText(control.getRandomQuestion()); }
7f7309e5-2ec8-472a-8336-da34296ad755
@SuppressWarnings("unchecked") // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents private void initComponents() { jTabbedPaneSolid = new javax.swing.JTabbedPane(); jPanelAddWord = new javax.swing.JPanel(); jTextFieldAddEngWord = new javax.swing.JTextField(); jLabelEngWord = new javax.swing.JLabel(); jLabelDanWord = new javax.swing.JLabel(); jTextFieldAddDanWord = new javax.swing.JTextField(); jButtonSaveToArrayList = new javax.swing.JButton(); jButtonSaveToFile = new javax.swing.JButton(); jPanelGuessWord = new javax.swing.JPanel(); jTextFieldQuestion = new javax.swing.JTextField(); jLabelQuestion = new javax.swing.JLabel(); jLabelGuess = new javax.swing.JLabel(); jTextFieldGuess = new javax.swing.JTextField(); jButtonCheckAnswer = new javax.swing.JButton(); jTextFieldCorrectAnswer = new javax.swing.JTextField(); jLabelGuessResult = new javax.swing.JLabel(); jButtonNextWord = new javax.swing.JButton(); jButton1 = new javax.swing.JButton(); jPanelLookUpWord = new javax.swing.JPanel(); jLabelEnterWord = new javax.swing.JLabel(); jTextFieldEnterWord = new javax.swing.JTextField(); jLabelResult = new javax.swing.JLabel(); jTextFieldResult = new javax.swing.JTextField(); jButtonFindWord = new javax.swing.JButton(); jLabelWellWhatKnow = new javax.swing.JLabel(); setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE); setMinimumSize(new java.awt.Dimension(450, 325)); setResizable(false); getContentPane().setLayout(null); jLabelEngWord.setFont(new java.awt.Font("Modern No. 20", 0, 18)); // NOI18N jLabelEngWord.setText("Enter an English word below:"); jLabelDanWord.setFont(new java.awt.Font("Modern No. 20", 0, 18)); // NOI18N jLabelDanWord.setText("Now, please enter the corresponding Danish word:"); jButtonSaveToArrayList.setFont(new java.awt.Font("Modern No. 20", 0, 24)); // NOI18N jButtonSaveToArrayList.setText("SAVE Wordpair"); jButtonSaveToArrayList.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { jButtonSaveToArrayListActionPerformed(evt); } }); jButtonSaveToFile.setFont(new java.awt.Font("Modern No. 20", 0, 14)); // NOI18N jButtonSaveToFile.setText("SAVE to file.."); jButtonSaveToFile.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { jButtonSaveToFileActionPerformed(evt); } }); javax.swing.GroupLayout jPanelAddWordLayout = new javax.swing.GroupLayout(jPanelAddWord); jPanelAddWord.setLayout(jPanelAddWordLayout); jPanelAddWordLayout.setHorizontalGroup( jPanelAddWordLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(jPanelAddWordLayout.createSequentialGroup() .addGroup(jPanelAddWordLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addComponent(jLabelEngWord) .addComponent(jTextFieldAddEngWord, javax.swing.GroupLayout.PREFERRED_SIZE, 200, javax.swing.GroupLayout.PREFERRED_SIZE) .addComponent(jLabelDanWord) .addComponent(jTextFieldAddDanWord, javax.swing.GroupLayout.PREFERRED_SIZE, 200, javax.swing.GroupLayout.PREFERRED_SIZE)) .addGap(0, 41, Short.MAX_VALUE)) .addGroup(jPanelAddWordLayout.createSequentialGroup() .addGroup(jPanelAddWordLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(jPanelAddWordLayout.createSequentialGroup() .addGap(77, 77, 77) .addComponent(jButtonSaveToArrayList)) .addGroup(jPanelAddWordLayout.createSequentialGroup() .addGap(117, 117, 117) .addComponent(jButtonSaveToFile))) .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)) ); jPanelAddWordLayout.setVerticalGroup( jPanelAddWordLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(jPanelAddWordLayout.createSequentialGroup() .addComponent(jLabelEngWord) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addComponent(jTextFieldAddEngWord, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addComponent(jLabelDanWord) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addComponent(jTextFieldAddDanWord, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) .addGap(51, 51, 51) .addComponent(jButtonSaveToArrayList) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addComponent(jButtonSaveToFile) .addContainerGap(31, Short.MAX_VALUE)) ); jTabbedPaneSolid.addTab("Add Word", jPanelAddWord); jTextFieldQuestion.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { jTextFieldQuestionActionPerformed(evt); } }); jLabelQuestion.setFont(new java.awt.Font("Modern No. 20", 0, 18)); // NOI18N jLabelQuestion.setText("Guess this word!"); jLabelGuess.setFont(new java.awt.Font("Modern No. 20", 0, 18)); // NOI18N jLabelGuess.setText("Enter your guess below:"); jButtonCheckAnswer.setFont(new java.awt.Font("Modern No. 20", 0, 24)); // NOI18N jButtonCheckAnswer.setText("Check Answer"); jButtonCheckAnswer.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { jButtonCheckAnswerActionPerformed(evt); } }); jLabelGuessResult.setFont(new java.awt.Font("Modern No. 20", 0, 18)); // NOI18N jLabelGuessResult.setText("Your guess was.......:"); jButtonNextWord.setFont(new java.awt.Font("Modern No. 20", 0, 18)); // NOI18N jButtonNextWord.setText("Next Word"); jButtonNextWord.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { jButtonNextWordActionPerformed(evt); } }); jButton1.setFont(new java.awt.Font("Modern No. 20", 0, 14)); // NOI18N jButton1.setText("Save Progress"); jButton1.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { jButton1ActionPerformed(evt); } }); javax.swing.GroupLayout jPanelGuessWordLayout = new javax.swing.GroupLayout(jPanelGuessWord); jPanelGuessWord.setLayout(jPanelGuessWordLayout); jPanelGuessWordLayout.setHorizontalGroup( jPanelGuessWordLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(jPanelGuessWordLayout.createSequentialGroup() .addGroup(jPanelGuessWordLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(jPanelGuessWordLayout.createSequentialGroup() .addGroup(jPanelGuessWordLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addComponent(jTextFieldCorrectAnswer, javax.swing.GroupLayout.PREFERRED_SIZE, 200, javax.swing.GroupLayout.PREFERRED_SIZE) .addComponent(jLabelGuessResult)) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) .addComponent(jButton1)) .addGroup(jPanelGuessWordLayout.createSequentialGroup() .addGroup(jPanelGuessWordLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(jPanelGuessWordLayout.createSequentialGroup() .addComponent(jTextFieldQuestion, javax.swing.GroupLayout.PREFERRED_SIZE, 200, javax.swing.GroupLayout.PREFERRED_SIZE) .addGap(18, 18, 18) .addComponent(jButtonNextWord)) .addComponent(jLabelGuess) .addGroup(jPanelGuessWordLayout.createSequentialGroup() .addGap(26, 26, 26) .addComponent(jLabelQuestion)) .addGroup(jPanelGuessWordLayout.createSequentialGroup() .addGap(89, 89, 89) .addComponent(jButtonCheckAnswer)) .addComponent(jTextFieldGuess, javax.swing.GroupLayout.PREFERRED_SIZE, 200, javax.swing.GroupLayout.PREFERRED_SIZE)) .addGap(0, 81, Short.MAX_VALUE))) .addContainerGap()) ); jPanelGuessWordLayout.setVerticalGroup( jPanelGuessWordLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(jPanelGuessWordLayout.createSequentialGroup() .addComponent(jLabelQuestion) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addGroup(jPanelGuessWordLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) .addComponent(jTextFieldQuestion, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) .addComponent(jButtonNextWord)) .addGroup(jPanelGuessWordLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(jPanelGuessWordLayout.createSequentialGroup() .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addComponent(jLabelGuess) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addComponent(jTextFieldGuess, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) .addGap(47, 47, 47) .addComponent(jButtonCheckAnswer) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) .addComponent(jLabelGuessResult) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addComponent(jTextFieldCorrectAnswer, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)) .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanelGuessWordLayout.createSequentialGroup() .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) .addComponent(jButton1) .addContainerGap()))) ); jTabbedPaneSolid.addTab("Guess Word", jPanelGuessWord); jLabelEnterWord.setFont(new java.awt.Font("Modern No. 20", 0, 18)); // NOI18N jLabelEnterWord.setText("Enter the word you wish to know in Danish:"); jLabelResult.setFont(new java.awt.Font("Modern No. 20", 0, 18)); // NOI18N jLabelResult.setText("The word is:"); jButtonFindWord.setFont(new java.awt.Font("Modern No. 20", 0, 24)); // NOI18N jButtonFindWord.setText("FIND word!"); jButtonFindWord.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { jButtonFindWordActionPerformed(evt); } }); jLabelWellWhatKnow.setFont(new java.awt.Font("Modern No. 20", 0, 18)); // NOI18N jLabelWellWhatKnow.setText("Well, what do ya know?!"); javax.swing.GroupLayout jPanelLookUpWordLayout = new javax.swing.GroupLayout(jPanelLookUpWord); jPanelLookUpWord.setLayout(jPanelLookUpWordLayout); jPanelLookUpWordLayout.setHorizontalGroup( jPanelLookUpWordLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanelLookUpWordLayout.createSequentialGroup() .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) .addComponent(jButtonFindWord) .addGap(107, 107, 107)) .addGroup(jPanelLookUpWordLayout.createSequentialGroup() .addGroup(jPanelLookUpWordLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addComponent(jLabelEnterWord) .addComponent(jLabelResult) .addComponent(jTextFieldEnterWord, javax.swing.GroupLayout.PREFERRED_SIZE, 200, javax.swing.GroupLayout.PREFERRED_SIZE) .addGroup(jPanelLookUpWordLayout.createSequentialGroup() .addComponent(jTextFieldResult, javax.swing.GroupLayout.PREFERRED_SIZE, 200, javax.swing.GroupLayout.PREFERRED_SIZE) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED) .addComponent(jLabelWellWhatKnow))) .addGap(0, 38, Short.MAX_VALUE)) ); jPanelLookUpWordLayout.setVerticalGroup( jPanelLookUpWordLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(jPanelLookUpWordLayout.createSequentialGroup() .addComponent(jLabelEnterWord) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addComponent(jTextFieldEnterWord, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) .addGap(53, 53, 53) .addComponent(jButtonFindWord) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 25, Short.MAX_VALUE) .addComponent(jLabelResult) .addGap(18, 18, 18) .addGroup(jPanelLookUpWordLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) .addComponent(jTextFieldResult, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) .addComponent(jLabelWellWhatKnow)) .addGap(31, 31, 31)) ); jTabbedPaneSolid.addTab("Look Up Word", jPanelLookUpWord); getContentPane().add(jTabbedPaneSolid); jTabbedPaneSolid.setBounds(0, 0, 450, 300); pack(); }// </editor-fold>//GEN-END:initComponents
7201cad5-abe4-4242-970a-bbb41c79ed41
public void actionPerformed(java.awt.event.ActionEvent evt) { jButtonSaveToArrayListActionPerformed(evt); }
8207b6de-7715-4411-a37a-345ff1c5a96f
public void actionPerformed(java.awt.event.ActionEvent evt) { jButtonSaveToFileActionPerformed(evt); }
cceca78b-b217-424e-9f76-db3afae77cee
public void actionPerformed(java.awt.event.ActionEvent evt) { jTextFieldQuestionActionPerformed(evt); }
39ec1036-2d05-466b-9d78-0553920d6b9e
public void actionPerformed(java.awt.event.ActionEvent evt) { jButtonCheckAnswerActionPerformed(evt); }
39eb0e0b-27cc-4aea-bcfe-1d785abbebaa
public void actionPerformed(java.awt.event.ActionEvent evt) { jButtonNextWordActionPerformed(evt); }
b34dd365-cbaf-4965-a031-a89e42f77aa0
public void actionPerformed(java.awt.event.ActionEvent evt) { jButton1ActionPerformed(evt); }
16c6a855-842f-45d7-81ce-399c7036dfe2
public void actionPerformed(java.awt.event.ActionEvent evt) { jButtonFindWordActionPerformed(evt); }
00e99461-a42a-405c-85ca-dcc78f27b1e8
private void jButtonSaveToArrayListActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButtonSaveToArrayListActionPerformed String question = jTextFieldAddEngWord.getText(); String answer = jTextFieldAddDanWord.getText(); control.add(question, answer); jTextFieldAddDanWord.setText(""); jTextFieldAddEngWord.setText(""); }//GEN-LAST:event_jButtonSaveToArrayListActionPerformed
a9a3b5c8-7f23-4b88-93ca-246391f863d5
private void jButtonSaveToFileActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButtonSaveToFileActionPerformed control.save(output); jTextFieldAddDanWord.setText(""); jTextFieldAddEngWord.setText(""); }//GEN-LAST:event_jButtonSaveToFileActionPerformed
ebc99ca3-c906-41f5-a5bf-1c5c76f8ced3
private void jTextFieldQuestionActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jTextFieldQuestionActionPerformed jTextFieldQuestion.setText(control.getRandomQuestion()); }//GEN-LAST:event_jTextFieldQuestionActionPerformed
22eb6d43-7006-4fa2-9ebc-d87bea417936
private void jButtonCheckAnswerActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButtonCheckAnswerActionPerformed String question = jTextFieldQuestion.getText(); String guess = jTextFieldGuess.getText(); if (control.checkGuess(question, guess) == true) { jTextFieldCorrectAnswer.setText("CORRECT!!"); } else { jTextFieldCorrectAnswer.setText("WRONG!!"); } //control.save("words.txt"); jTextFieldQuestion.setText(""); jTextFieldGuess.setText(""); }//GEN-LAST:event_jButtonCheckAnswerActionPerformed
92d8e2c4-9eb1-4aa4-a7e3-b0201a0f2222
private void jButtonFindWordActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButtonFindWordActionPerformed String question = jTextFieldEnterWord.getText(); String result = control.lookup(question); jTextFieldResult.setText(result); jLabelWellWhatKnow.setVisible(true); }//GEN-LAST:event_jButtonFindWordActionPerformed
b546add2-763d-4c22-92e0-31594ab14433
private void jButtonNextWordActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButtonNextWordActionPerformed jTextFieldQuestion.setText(control.getRandomQuestion()); jTextFieldCorrectAnswer.setText(""); }//GEN-LAST:event_jButtonNextWordActionPerformed
7f2033ff-1318-4fe6-9486-50095efe738d
private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed control.save(output); }//GEN-LAST:event_jButton1ActionPerformed
11e321b5-d128-4061-81b1-529601c229d6
public static void main(String args[]) { /* Set the Nimbus look and feel */ //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) "> /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel. * For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html */ try { for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) { if ("Nimbus".equals(info.getName())) { javax.swing.UIManager.setLookAndFeel(info.getClassName()); break; } } } catch (ClassNotFoundException ex) { java.util.logging.Logger.getLogger(SolidGUI.class.getName()).log(java.util.logging.Level.SEVERE, null, ex); } catch (InstantiationException ex) { java.util.logging.Logger.getLogger(SolidGUI.class.getName()).log(java.util.logging.Level.SEVERE, null, ex); } catch (IllegalAccessException ex) { java.util.logging.Logger.getLogger(SolidGUI.class.getName()).log(java.util.logging.Level.SEVERE, null, ex); } catch (javax.swing.UnsupportedLookAndFeelException ex) { java.util.logging.Logger.getLogger(SolidGUI.class.getName()).log(java.util.logging.Level.SEVERE, null, ex); } //</editor-fold> /* Create and display the form */ java.awt.EventQueue.invokeLater(new Runnable() { public void run() { new SolidGUI().setVisible(true); } }); }
5682c5bb-245c-49d2-87a4-ff71938cebb0
public void run() { new SolidGUI().setVisible(true); }
a57f69cd-6846-4390-acd5-118b291e8dbd
public final static RollingCharBuffer allocate(int capacity) { return allocate(capacity, false); }
d1be96ae-85cb-426d-99c4-5306ae09db2b
public final static RollingCharBuffer allocate(int capacity, boolean isDirect) { if(capacity < 1) { throw new IllegalArgumentException("buffer's capacity must be a positive integer."); } return isDirect && hasUnsafe() ? new RollingDirectCharBuffer(capacity) : new RollingHeapCharBuffer(capacity); }
81e9c57c-d9ca-4a98-98d0-21348e65817d
public final static RollingCharBuffer wrap(char[] array) { if(array == null || array.length < 1) { throw new IllegalArgumentException("buffer's capacity must be a positive integer."); } return new RollingHeapCharBuffer(array); }
b3cba965-4423-4781-889a-4e0b684ebc49
protected RollingCharBuffer() { isReleased = false; resetIndex(); }
ae8e3c0e-5b68-434f-9ed4-3fa791e3cd14
public final void reset() { checkReleased(); resetIndex(); }
02dc303c-18c4-4f07-ba5b-825594eeda2a
protected final void resetIndex() { takeIndex = putIndex = size = 0; }
a087aa0e-f8f1-4475-979c-646319cc22d5
public final int takeIndex() { checkReleased(); return takeIndex; }
55754744-987c-4ac6-8733-2a27c3705e57
public final int putIndex() { checkReleased(); return putIndex; }
ab0d8792-3479-4b88-8f5a-847560b17c14
public final int capacity() { checkReleased(); return retCapacity(); }
550a7f47-a7ce-4f25-8a66-3d067af36772
protected abstract int retCapacity();
a68b3865-3851-40e6-8562-75fb2ec4688d
public final int size() { checkReleased(); return size; }
979c4e3e-58fd-4fa1-ae5e-a785dad0a552
public final boolean isEmpty() { checkReleased(); return size == 0; }
16aaed41-7769-4675-b566-a9e224db674d
public final boolean isFull() { checkReleased(); return size == capacity(); }
8e338374-3fb6-4b65-9719-4bc1efde042d
public final int remained() { checkReleased(); return capacity() - size; }
6cbcf2e3-0806-4fc2-9091-6911fb0bf4f3
public final void expandCapacity(int incCap) { checkReleased(); ensureCapacity(incCap); }
88fe90d2-0c07-4da5-ab54-d83ba5012f7f
protected abstract void ensureCapacity(int incCap);
07b80c48-dd81-4d57-a7c9-d0136f2a8432
public final void put(char ch) { checkReleased(); if(remained() <= 1) { ensureCapacity(1); } write(ch); shiftPutIndex(1); }
814e5046-f0a7-45b3-9df4-c47184952247
protected abstract void write(char ch);
9ed0b053-8312-43a1-9a38-046c2712c39d
public final void put(char[] arr) { checkReleased(); int len = arr.length; if(remained() <= len) { ensureCapacity(len); } write(arr, 0, len); shiftPutIndex(len); }
b51915fc-029c-48a2-8433-d552e2762783
public final void put(char[] arr, int offset, int size) { checkReleased(); if(arr == null || offset < 0 || (arr.length - offset) < size) { throw new IllegalStateException("array started with offset has no specified size characters"); } if(remained() <= size) { ensureCapacity(size); } write(arr, offset, size); shiftPutIndex(size); }
271078a0-3e73-4605-9a7e-b7898629db2c
protected abstract void write(char[] arr, int offset, int size);
fbc4079b-10b1-4d71-b5c4-36553d391de2
public final char take() { checkReleased(); if(size < 1) { throw new IllegalStateException("no character can be taken"); } char ch = read(); shiftTakeIndex(1); return ch; }
86c5a973-30f0-4268-8d26-4c02d7569223
protected abstract char read();
4c9671b4-2c0e-4af1-9637-649a88e35983
public final char[] take(int size) { checkReleased(); if(size < 1 || size > this.size) { throw new IllegalStateException("taken size less than 1 or more characters taken than the buffer size"); } char[] tmp = new char[size]; read(tmp, 0, size); shiftTakeIndex(size); return tmp; }
51b011a0-4c3b-42bb-b96c-00ed0023b44c
public final void take(char[] arr, int offset, int size) { checkReleased(); if(arr == null || offset < 0 || (arr.length - offset) < size) { throw new IllegalStateException("no enough array space to place the required characters"); } if(size < 1 || size > this.size) { throw new IllegalStateException("taken size less than 1 or more characters taken than the buffer size"); } read(arr, offset, size); shiftTakeIndex(size); }
f9f8e40f-7885-4920-a18e-b702d652a8f3
protected abstract void read(char[] arr, int offset, int size);
3943271d-9a5f-4dbb-96c6-6b78b72c7b20
public final char[] takeAll() { checkReleased(); return take(size); }
1e45c73b-86ef-46cd-a1dd-7cb0b55c2cc1
public final void takeAll(char[] buf, int offset) { checkReleased(); take(buf, offset, size); }
d6268fa1-7922-4251-8921-5949ee18df5a
public final boolean hasArray() { checkReleased(); return isArrayBacked(); }
6a671498-29e4-444e-9b59-60ed9a937572
protected abstract boolean isArrayBacked();
145247a9-f456-4406-a9f0-eb89460a515b
public final char[] array() { checkReleased(); return backendArray(); }
7bb00cfa-42ee-4996-b605-e449f361187d
protected abstract char[] backendArray();
f3bc8400-ac11-43fa-986c-0823a2216560
public final void shiftTakeIndex(int step) { checkReleased(); if(step > size) { throw new IllegalStateException("step exceed the max taken shifted steps"); } takeIndex = (takeIndex + step) % capacity(); size -= step; }
d147d4a9-6538-4870-b506-429488f42d76
public final void shiftPutIndex(int step) { checkReleased(); if(remained() < step) { throw new IllegalStateException("step exceed the max put shifted steps"); } putIndex = (putIndex + step) % capacity(); size += step; }
a7493bfe-b94a-40c5-bda7-916ec7290b58
public final void release() { if(!isReleased) { clean(); isReleased = true; } }
e58d6dc6-5164-442c-9888-3ead29bdb302
protected void checkReleased() { if(isReleased) { throw new IllegalStateException("buffer has been released."); } }
ee185755-6d24-42d7-aff3-abc385785382
protected abstract void clean();
d60f3d45-c4f1-41da-a39d-b907f470cfc0
RollingDirectCharBuffer(int capacity) { super(); block = MemoryBlock.allocate(capacity); this.capacity = capacity; }
6de7cb1b-1784-4474-8ef7-f5b628d37745
@Override protected int retCapacity() { return capacity; }
8f0ea3d0-f803-43f1-8d14-b9705006aa43
@Override protected void ensureCapacity(int incCap) { if(incCap < remained()) { return; } int newCapacity = 0; if(2*incCap <= capacity) { newCapacity = capacity * 3 / 2 + 1; }else { newCapacity = capacity * 2; } MemoryBlock newBlock = MemoryBlock.allocate(newCapacity); if(size > 0) { long oldAddress = block.address; long newAddress = newBlock.address; if(putIndex > takeIndex) { copyMemory(oldAddress, takeIndex, newAddress, 0, size); }else { int len = capacity - takeIndex; copyMemory(oldAddress, takeIndex, newAddress, 0, len); if(size > len) { copyMemory(oldAddress, 0, newAddress, len, putIndex); } } } MemoryBlock.deallocate(block); // clean old memory block = newBlock; capacity = newCapacity; takeIndex = 0; putIndex = size; }
f802662f-abcb-485f-925d-efa884fb68e7
@Override protected void write(char ch) { writeChar(block.address, putIndex, ch); }