Instruction.java 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142
  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. S("type", type).S("inst", inst);
  16. }
  17. public Instruction(String inst) {
  18. S("inst", inst);
  19. }
  20. public Instruction() {
  21. }
  22. @Override
  23. public Instruction set(String attrib, int 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, Long valor) {
  29. super.set(attrib, valor); //To change body of generated methods, choose Tools | Templates.
  30. return this;
  31. }
  32. @Override
  33. public String toString() {
  34. return "Instruction" + super.toString(); //To change body of generated methods, choose Tools | Templates.
  35. }
  36. /**
  37. *
  38. * @param attrib
  39. * @param value
  40. * @return
  41. */
  42. @Override
  43. public Instruction S(String attrib, String value) {
  44. super.S(attrib, value); //To change body of generated methods, choose Tools | Templates.
  45. return this;
  46. }
  47. public Instruction S(String attrib, long value) {
  48. super.S(attrib, "" + value); //To change body of generated methods, choose Tools | Templates.
  49. return this;
  50. }
  51. @Override
  52. public Instruction R(String attributes) {
  53. super.R(attributes); //To change body of generated methods, choose Tools | Templates.
  54. return this;
  55. }
  56. public Instruction S(String attrib, int value) {
  57. super.set(attrib, value); //To change body of generated methods, choose Tools | Templates.
  58. return this;
  59. }
  60. public boolean igual(String atributo, Instruction r2) {
  61. return eq(atributo, r2.G(atributo));
  62. }
  63. public boolean maior(String atributo, int i) throws Exception {
  64. if (!isNumber(atributo)) {
  65. return false;
  66. }
  67. return getInt(atributo) > i;
  68. }
  69. public boolean menor(String atributo, int i) throws Exception {
  70. if (!isNumber(atributo)) {
  71. return false;
  72. }
  73. return getInt(atributo) < i;
  74. }
  75. public int getInt(String indice, int val) {
  76. try {
  77. return getInt(indice);
  78. } catch (Exception e) {
  79. return val;
  80. }
  81. }
  82. public Instruction copy(String atrib, Instruction r) {
  83. if (r != null) {
  84. for (String a : atrib.split(",")) {
  85. a = a.trim();
  86. if (r.Has(a)) {
  87. this.S(a, r.G(a));
  88. }
  89. }
  90. }
  91. return this;
  92. }
  93. public Instruction Merge(String attrs, Instruction src) {
  94. if (src != null) {
  95. for (String a : attrs.split(",")) {
  96. if (!this.Has(a) && src.Has(a)) {
  97. this.S(a, src.G(a));
  98. }
  99. }
  100. }
  101. return this;
  102. }
  103. public void Prepend(String attrib, String p) {
  104. if (Has(attrib)) {
  105. S(attrib, p + G(attrib));
  106. }
  107. }
  108. public void Append(String attrib, String p) {
  109. if (Has(attrib)) {
  110. S(attrib, G(attrib) + p);
  111. }
  112. }
  113. public Instruction copy() {
  114. Instruction rb = new Instruction();
  115. for (Map.Entry<String, String> entry : attr.entrySet()) {
  116. rb.S(entry.getKey(), entry.getValue());
  117. }
  118. return rb;
  119. }
  120. }