@Test public void outputTest() throws CloneNotSupportedException, InterruptedException { StartLetterRankMP clone1 = mp.clone(); Assert.assertNull(clone1.map); Assert.assertNull(clone1.sortedset); LetterCount T1 = new LetterCount(new Letter('T'), 10); clone1.handleWordCount(T1); LetterCount A = new LetterCount(new Letter('A'), 20); clone1.handleWordCount(A); LetterCount S = new LetterCount(new Letter('S'), 30); clone1.handleWordCount(S); LetterCount B = new LetterCount(new Letter('B'), 27); clone1.handleWordCount(B); LetterCount D = new LetterCount(new Letter('D'), 2); clone1.handleWordCount(D); LetterCount K = new LetterCount(new Letter('K'), 5); clone1.handleWordCount(K); LetterCount P = new LetterCount(new Letter('P'), 11); clone1.handleWordCount(P); LetterCount T2 = new LetterCount(new Letter('T'), 19); clone1.handleWordCount(T2); clone1.output(); Assert.assertNotNull(clone1.sortedset); Assert.assertEquals(7, clone1.sortedset.size()); Assert.assertEquals(S, clone1.sortedset.pollFirst()); Assert.assertEquals(B, clone1.sortedset.pollFirst()); Assert.assertEquals(A, clone1.sortedset.pollFirst()); Assert.assertEquals(T2, clone1.sortedset.pollFirst()); Assert.assertEquals(P, clone1.sortedset.pollFirst()); Assert.assertEquals(K, clone1.sortedset.pollFirst()); Assert.assertEquals(D, clone1.sortedset.pollFirst()); }
@Output public void output() { sortedset = new TreeSet<LetterCount>(new Comparator<LetterCount>() { @Override public int compare(LetterCount o1, LetterCount o2) { if(o1 == o2) { return 0; } if(o1 == null) { return 2; } if(o2 == null) { return -2; } if(o1.getCount() < o2.getCount()) { return 2; } else if(o1.getCount() > o2.getCount()) { return -2; } else if(o1.getLetter().equals(o2.getLetter())) { return 0; } else return 1; } }); sortedset.addAll(map.values()); StringBuilder sb = new StringBuilder("Sorted output \n"); for(LetterCount letter: sortedset) { sb.append(" Letter:" + letter.getLetter() + " count:" + letter.getCount() +"\n"); } logger.info(sb.toString()); }
StartLetterRankMP implements Cloneable { @Output public void output() { sortedset = new TreeSet<LetterCount>(new Comparator<LetterCount>() { @Override public int compare(LetterCount o1, LetterCount o2) { if(o1 == o2) { return 0; } if(o1 == null) { return 2; } if(o2 == null) { return -2; } if(o1.getCount() < o2.getCount()) { return 2; } else if(o1.getCount() > o2.getCount()) { return -2; } else if(o1.getLetter().equals(o2.getLetter())) { return 0; } else return 1; } }); sortedset.addAll(map.values()); StringBuilder sb = new StringBuilder("Sorted output \n"); for(LetterCount letter: sortedset) { sb.append(" Letter:" + letter.getLetter() + " count:" + letter.getCount() +"\n"); } logger.info(sb.toString()); } }
StartLetterRankMP implements Cloneable { @Output public void output() { sortedset = new TreeSet<LetterCount>(new Comparator<LetterCount>() { @Override public int compare(LetterCount o1, LetterCount o2) { if(o1 == o2) { return 0; } if(o1 == null) { return 2; } if(o2 == null) { return -2; } if(o1.getCount() < o2.getCount()) { return 2; } else if(o1.getCount() > o2.getCount()) { return -2; } else if(o1.getLetter().equals(o2.getLetter())) { return 0; } else return 1; } }); sortedset.addAll(map.values()); StringBuilder sb = new StringBuilder("Sorted output \n"); for(LetterCount letter: sortedset) { sb.append(" Letter:" + letter.getLetter() + " count:" + letter.getCount() +"\n"); } logger.info(sb.toString()); }  }
StartLetterRankMP implements Cloneable { @Output public void output() { sortedset = new TreeSet<LetterCount>(new Comparator<LetterCount>() { @Override public int compare(LetterCount o1, LetterCount o2) { if(o1 == o2) { return 0; } if(o1 == null) { return 2; } if(o2 == null) { return -2; } if(o1.getCount() < o2.getCount()) { return 2; } else if(o1.getCount() > o2.getCount()) { return -2; } else if(o1.getLetter().equals(o2.getLetter())) { return 0; } else return 1; } }); sortedset.addAll(map.values()); StringBuilder sb = new StringBuilder("Sorted output \n"); for(LetterCount letter: sortedset) { sb.append(" Letter:" + letter.getLetter() + " count:" + letter.getCount() +"\n"); } logger.info(sb.toString()); }  @MessageHandler void handleWordCount(LetterCount letterCount); @Override StartLetterRankMP clone(); @Output void output(); }
StartLetterRankMP implements Cloneable { @Output public void output() { sortedset = new TreeSet<LetterCount>(new Comparator<LetterCount>() { @Override public int compare(LetterCount o1, LetterCount o2) { if(o1 == o2) { return 0; } if(o1 == null) { return 2; } if(o2 == null) { return -2; } if(o1.getCount() < o2.getCount()) { return 2; } else if(o1.getCount() > o2.getCount()) { return -2; } else if(o1.getLetter().equals(o2.getLetter())) { return 0; } else return 1; } }); sortedset.addAll(map.values()); StringBuilder sb = new StringBuilder("Sorted output \n"); for(LetterCount letter: sortedset) { sb.append(" Letter:" + letter.getLetter() + " count:" + letter.getCount() +"\n"); } logger.info(sb.toString()); }  @MessageHandler void handleWordCount(LetterCount letterCount); @Override StartLetterRankMP clone(); @Output void output();  }