Instruction.java 3.6 KB

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