Bloco.java 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  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 cache;
  7. import java.util.Arrays;
  8. /**
  9. *
  10. * @author Juninho Carlos
  11. */
  12. public class Bloco {
  13. private boolean isDirty;
  14. private Boolean[] palavraComErro;
  15. private boolean valido;
  16. private boolean firstWrite;
  17. private long limiteInf; //valor do menor endereço do bloco
  18. private long limiteSuperior; // valor do maior endereço do bloco
  19. private boolean cachavel;
  20. public Bloco(){
  21. this.cachavel = true;
  22. this.firstWrite = true;
  23. this.valido = false;
  24. this.isDirty = false;
  25. this.palavraComErro = new Boolean[32];
  26. Arrays.fill(palavraComErro, Boolean.FALSE);
  27. }
  28. public void setarComoInvalido(){
  29. this.cachavel = false;
  30. }
  31. public boolean isCachavel(){
  32. return this.cachavel;
  33. }
  34. public void inserirErro(int palavra){
  35. this.palavraComErro[palavra] = true;
  36. }
  37. public boolean isFirstWrite(){
  38. return this.firstWrite;
  39. }
  40. public Boolean[] getErroDasPalavraDoBloco(){
  41. return this.palavraComErro;
  42. }
  43. public boolean isSujo(){
  44. return this.isDirty;
  45. }
  46. public boolean hasErrorInBloco() {
  47. Boolean[] palavras = this.palavraComErro;
  48. for (Boolean erro : palavras) {
  49. if (erro == true) {
  50. return true;
  51. }
  52. }
  53. return false;
  54. }
  55. public void setLimitesDoBloco(long limInf,long limSup){
  56. this.limiteInf = limInf;
  57. this.limiteSuperior = limSup;
  58. }
  59. public boolean getErroFromPalavra(int palavra){
  60. return this.palavraComErro[palavra];
  61. }
  62. public boolean verificaBloco(long address){
  63. return address >= limiteInf && address < limiteSuperior+4;
  64. }
  65. public void setValidadeDoBloco(boolean validade){
  66. this.valido = validade;
  67. }
  68. public void setSujeira(boolean dirty){
  69. this.isDirty = dirty;
  70. }
  71. public boolean isValido(){
  72. return this.valido;
  73. }
  74. @Override
  75. public String toString() {
  76. String s;
  77. s = "Sujo: " + this.isDirty +"\n";
  78. s += "Valido: " + this.valido + "\n";
  79. s += "Erro: " + this.hasErrorInBloco() + "\n";
  80. s += "Cachavel: " + this.cachavel + "\n";
  81. s += "range: " + "[ " + this.limiteInf + " - " + this.limiteSuperior + " ]\n";
  82. /* s += "Palavras com erro: ";
  83. int i = 0;
  84. for (Boolean boolean1 : palavraComErro) {
  85. s += i + " " + boolean1 + "\n";
  86. i++;
  87. } */
  88. return s;
  89. }
  90. }