123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136 |
- /*
- * To change this license header, choose License Headers in Project Properties.
- * To change this template file, choose Tools | Templates
- * and open the template in the editor.
- */
- package common;
- import java.util.Map;
- import java.util.regex.Pattern;
- /**
- *
- * @author Eugenio
- * @param
- */
- public class Instruction extends RegistroBase {
- public Instruction(String type, String inst) {
- super.Set("type", type).Set("inst", inst);
- }
- public Instruction(String inst) {
- super.Set("inst", inst);
- }
- public Instruction() {
- }
- @Override
- public Instruction Set(String attrib, Boolean valor) {
- super.Set(attrib, valor); //To change body of generated methods, choose Tools | Templates.
- return this;
- }
- @Override
- public Instruction Set(String attrib, int valor) {
- super.Set(attrib, valor); //To change body of generated methods, choose Tools | Templates.
- return this;
- }
- @Override
- public Instruction Set(String attrib, Long valor) {
- super.Set(attrib, valor); //To change body of generated methods, choose Tools | Templates.
- return this;
- }
- @Override
- public Instruction Set(String attrib, String value) {
- super.Set(attrib, value); //To change body of generated methods, choose Tools | Templates.
- return this;
- }
- // public Instruction S(String attrib, int value) {
- // super.Set(attrib, value); //To change body of generated methods, choose Tools | Templates.
- // return this;
- // }
- @Override
- public String toString() {
- return "Instruction {\n" + super.toString() + "\n}\n"; //To change body of generated methods, choose Tools | Templates.
- }
- @Override
- public Instruction R(String attributes) {
- super.R(attributes); //To change body of generated methods, choose Tools | Templates.
- return this;
- }
- public boolean igual(String atributo, Instruction r2) {
- return eq(atributo, r2.Get(atributo));
- }
- public boolean maior(String atributo, int i) throws Exception {
- if (!isNumber(atributo)) {
- return false;
- }
- return GetInt(atributo) > i;
- }
- public boolean menor(String atributo, int i) throws Exception {
- if (!isNumber(atributo)) {
- return false;
- }
- return GetInt(atributo) < i;
- }
- public int getInt(String indice, int val) {
- try {
- return GetInt(indice);
- } catch (Exception e) {
- return val;
- }
- }
- public Instruction copy(String atrib, Instruction r) {
- super.copy(atrib, r);
- return this;
- }
- public Instruction Merge(String attrs, Instruction src) {
- if (src != null) {
- for (String a : attrs.split(",")) {
- if (!this.Has(a) && src.Has(a)) {
- this.Set(a, src.Get(a));
- }
- }
- }
- return this;
- }
- public void Prepend(String attrib, String p) {
- if (Has(attrib)) {
- Instruction.this.Set(attrib, p + Get(attrib));
- }
- }
- public void Append(String attrib, String p) {
- if (Has(attrib)) {
- Instruction.this.Set(attrib, Get(attrib) + p);
- }
- }
- public Instruction copy() {
- Instruction rb = new Instruction();
- for (Map.Entry<String, String> entry : attr.entrySet()) {
- rb.Set(entry.getKey(), entry.getValue());
- }
- return rb;
- }
- protected static Pattern NUMBER_EXPR = Pattern.compile("-?\\d+(\\.\\d+)?");
- public boolean IsValue(String attr) {
- return NUMBER_EXPR.matcher(Get(attr)).matches();
- }
- }
|