Instruction.java 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  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 common;
  7. import java.util.Map;
  8. /**
  9. *
  10. * @author Eugenio
  11. * @param
  12. */
  13. public class Instruction extends RegistroBase {
  14. public Instruction(String type, String inst) {
  15. super.Set("type", type).Set("inst", inst);
  16. }
  17. public Instruction(String inst) {
  18. super.Set("inst", inst);
  19. }
  20. public Instruction() {
  21. }
  22. @Override
  23. public Instruction Set(String attrib, Boolean valor) {
  24. super.Set(attrib, valor); //To change body of generated methods, choose Tools | Templates.
  25. return this;
  26. }
  27. @Override
  28. public Instruction Set(String attrib, int valor) {
  29. super.Set(attrib, valor); //To change body of generated methods, choose Tools | Templates.
  30. return this;
  31. }
  32. @Override
  33. public Instruction Set(String attrib, Long valor) {
  34. super.Set(attrib, valor); //To change body of generated methods, choose Tools | Templates.
  35. return this;
  36. }
  37. @Override
  38. public Instruction Set(String attrib, String value) {
  39. super.Set(attrib, value); //To change body of generated methods, choose Tools | Templates.
  40. return this;
  41. }
  42. // public Instruction S(String attrib, int value) {
  43. // super.Set(attrib, value); //To change body of generated methods, choose Tools | Templates.
  44. // return this;
  45. // }
  46. @Override
  47. public String toString() {
  48. return "Instruction {\n" + super.toString() + "\n}\n"; //To change body of generated methods, choose Tools | Templates.
  49. }
  50. @Override
  51. public Instruction R(String attributes) {
  52. super.R(attributes); //To change body of generated methods, choose Tools | Templates.
  53. return this;
  54. }
  55. public boolean igual(String atributo, Instruction r2) {
  56. return eq(atributo, r2.Get(atributo));
  57. }
  58. public boolean maior(String atributo, int i) throws Exception {
  59. if (!isNumber(atributo)) {
  60. return false;
  61. }
  62. return GetInt(atributo) > i;
  63. }
  64. public boolean menor(String atributo, int i) throws Exception {
  65. if (!isNumber(atributo)) {
  66. return false;
  67. }
  68. return GetInt(atributo) < i;
  69. }
  70. public int getInt(String indice, int val) {
  71. try {
  72. return GetInt(indice);
  73. } catch (Exception e) {
  74. return val;
  75. }
  76. }
  77. public Instruction copy(String atrib, Instruction r) {
  78. super.copy(atrib, r);
  79. return this;
  80. }
  81. public Instruction Merge(String attrs, Instruction src) {
  82. if (src != null) {
  83. for (String a : attrs.split(",")) {
  84. if (!this.Has(a) && src.Has(a)) {
  85. this.Set(a, src.Get(a));
  86. }
  87. }
  88. }
  89. return this;
  90. }
  91. public void Prepend(String attrib, String p) {
  92. if (Has(attrib)) {
  93. Instruction.this.Set(attrib, p + Get(attrib));
  94. }
  95. }
  96. public void Append(String attrib, String p) {
  97. if (Has(attrib)) {
  98. Instruction.this.Set(attrib, Get(attrib) + p);
  99. }
  100. }
  101. public Instruction copy() {
  102. Instruction rb = new Instruction();
  103. for (Map.Entry<String, String> entry : attr.entrySet()) {
  104. rb.Set(entry.getKey(), entry.getValue());
  105. }
  106. return rb;
  107. }
  108. }