Advertisement
Guest User

Untitled

a guest
May 26th, 2016
56
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.23 KB | None | 0 0
  1. public class WordProbability extends ProbabilityPair<Str>
  2. {
  3. public WordProbability(String tag)
  4. {
  5. super(tag);
  6. }
  7. ...
  8. }
  9.  
  10. public abstract class ProbabilityPair<T>
  11. {
  12. public T key;
  13. private int count;
  14. private double probability;
  15.  
  16. protected ProbabilityPair(T key)
  17. {
  18. this.key = key;
  19. count = 1;
  20. probability = 0d;
  21. }
  22.  
  23. public void increment()
  24. {
  25. ++count;
  26. }
  27. ...
  28. }
  29.  
  30. public class Words
  31. {
  32. public List<WordProbability> words;
  33. public int totalCount;
  34.  
  35. public Words()
  36. {
  37. words = new ArrayList<>();
  38. totalCount = 0;
  39. }
  40.  
  41. public void add(WordProbability word)
  42. {
  43. if (words.contains(word))
  44. {
  45. words.get(words.indexOf(word)).increment();
  46. } else
  47. {
  48. words.add(word);
  49. }
  50. ++totalCount;
  51. }
  52. ...
  53. }
  54.  
  55. public class Container<ProbabilityPair>
  56. {
  57. private List<ProbabilityPair> members;
  58. private int totalCount;
  59.  
  60. public void add(ProbabilityPair member)
  61. {
  62. if (members.contains(member))
  63. {
  64. members.get(members.indexOf(member)).increment();
  65. } else
  66. {
  67. members.add(member);
  68. }
  69. ++totalCount;
  70. }
  71. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement