BlockBaseGroup.java 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  1. /*
  2. * To change this license header, choose License Headers in Project Properties.
  3. * To change this template file, choose Tools | Templates
  4. * and open the template in the editor.
  5. */
  6. package middlewares;
  7. import common.Instruction;
  8. import java.util.LinkedList;
  9. /**
  10. *
  11. * @author EUGENIO CARVALHO
  12. */
  13. public class BlockBaseGroup {
  14. protected LinkedList<BlockBaseOcorrences> bbs = new LinkedList<>();
  15. protected BlockBaseOcorrences current = null;
  16. public Integer currentIndex = 0;
  17. protected String name;
  18. BlockBaseGroup(String name) {
  19. this.name = name;
  20. }
  21. public void Init() {
  22. currentIndex = 0;
  23. current = bbs.get(currentIndex);
  24. }
  25. public boolean NextBlock() {
  26. currentIndex++;
  27. if (currentIndex > (bbs.size() - 1)) {
  28. return false;
  29. }
  30. current = bbs.get(currentIndex);
  31. return true;
  32. }
  33. public void RegisterBlock(Integer leader, Integer size) {
  34. if (current != null) {
  35. current.CloseAllIntervals();
  36. }
  37. // System.out.println("Register block:" + name + "." + bbs.size() + "/" + size);
  38. BlockBaseOcorrences c = new BlockBaseOcorrences(name + "." + bbs.size(), leader);
  39. // c.LastPosition = (size - 1);
  40. c.LastPosition = size;
  41. current = c;
  42. bbs.add(c);
  43. }
  44. public LinkedList<BlockBaseOcorrences> getBasicBlocks() {
  45. return bbs;
  46. }
  47. public BlockBaseOcorrences getCurrent() {
  48. return current;
  49. }
  50. public void ParseInstruction(Instruction inst, String attrs) throws Exception {
  51. for (String attr : attrs.split(",")) {
  52. current.Register(inst, attr);
  53. }
  54. current.Position++;
  55. }
  56. // public BlockBaseGroup RegisterInstruction(Instruction inst, String attr) {
  57. // current.Register(inst, attr);
  58. // return this;
  59. // }
  60. @Override
  61. public String toString() {
  62. StringBuilder sb = new StringBuilder();
  63. for (BlockBaseOcorrences blockBaseOcorrences : bbs) {
  64. sb.append(blockBaseOcorrences).append("\n");
  65. }
  66. return sb.toString();
  67. }
  68. public void Close() {
  69. current.CloseAllIntervals();
  70. }
  71. public BlockBaseOcorrences Current() {
  72. return current;
  73. }
  74. public LinkedList<BlockBaseOcorrences> getBbs() {
  75. return bbs;
  76. }
  77. public void setBbs(LinkedList<BlockBaseOcorrences> bbs) {
  78. this.bbs = bbs;
  79. }
  80. public Integer getCurrentIndex() {
  81. return currentIndex;
  82. }
  83. public void setCurrentIndex(Integer currentIndex) {
  84. this.currentIndex = currentIndex;
  85. }
  86. public String getName() {
  87. return name;
  88. }
  89. public void setName(String name) {
  90. this.name = name;
  91. }
  92. public BlockBaseOcorrences getBasicBlocks(Integer i) {
  93. int index = currentIndex + i;
  94. if (index > bbs.size() - 1) {
  95. return null;
  96. }
  97. return bbs.get(index);
  98. }
  99. }