예제 #1
0
  private List<String> TrocearExpresion(String expresion) {
    expresion = eliminarParentesisRedundantesExternos(expresion);
    Map<TipoOperacionCriterioEmun, List<Integer>> posicionOperacionessExternas =
        obtenerPosicionOperancionesExternas(expresion);
    Map<TipoOperacionCriterioEmun, Integer> mapaOperacion =
        obtenerOperacionExterna(posicionOperacionessExternas);

    if (mapaOperacion.isEmpty() || mapaOperacion.size() != 1) return null;

    List<String> result = new ArrayList<String>();

    for (TipoOperacionCriterioEmun tipoOperacionEmun : mapaOperacion.keySet()) {
      result.add(0, tipoOperacionEmun.getRepresentacion());

      if (tipoOperacionEmun.equals(TipoOperacionCriterioEmun.NOT)) {
        result.add(
            1,
            expresion.substring(
                mapaOperacion.get(tipoOperacionEmun)
                    + tipoOperacionEmun.getRepresentacion().length()
                    + 1,
                expresion.length() - 1));
        return result;
      }
      result.add(1, expresion.substring(0, mapaOperacion.get(tipoOperacionEmun)));
      result.add(
          2,
          expresion.substring(
              mapaOperacion.get(tipoOperacionEmun) + tipoOperacionEmun.getRepresentacion().length(),
              expresion.length()));
    }

    return result;
  }
예제 #2
0
  private Boolean operaTexto(TipoOperacionCriterioEmun operacion, String valorIzq, String valorDch)
      throws Exception {

    int resultado = valorIzq.toUpperCase().compareTo(valorDch.toUpperCase());

    if (operacion.equals(TipoOperacionCriterioEmun.IGUAL)) return resultado == 0;

    if (operacion.equals(TipoOperacionCriterioEmun.DISTINTO)) return resultado != 0;

    throw new Exception("Fallo Operando Texto");
  }
예제 #3
0
  private Boolean operaLogica(
      TipoOperacionCriterioEmun operacion, Boolean valorIzq, Boolean valorDch) throws Exception {

    if (operacion.equals(TipoOperacionCriterioEmun.AND)) return valorIzq & valorDch;

    if (operacion.equals(TipoOperacionCriterioEmun.OR)) return valorIzq | valorDch;

    if (operacion.equals(TipoOperacionCriterioEmun.NOT)) return !valorIzq;

    throw new Exception("Fallo Operando Logica");
  }
예제 #4
0
  private Boolean operacionInequivoca(
      TipoOperacionCriterioEmun tipoOperacionEmun, String operacion) {
    if (tipoOperacionEmun.equals(TipoOperacionCriterioEmun.MAYOR)
        || tipoOperacionEmun.equals(TipoOperacionCriterioEmun.MENOR)
        || tipoOperacionEmun.equals(TipoOperacionCriterioEmun.IGUAL)) {
      if (operacion.contains(TipoOperacionCriterioEmun.MAYOR_IGUAL.getRepresentacion())
          || operacion.contains(TipoOperacionCriterioEmun.MENOR_IGUAL.getRepresentacion())
          || operacion.contains(TipoOperacionCriterioEmun.DISTINTO.getRepresentacion()))
        return false;
    }

    return true;
  }
예제 #5
0
  private Map<TipoOperacionCriterioEmun, List<Integer>> obtenerPosicionOperancionesExternas(
      String expresion) {
    Map<TipoOperacionCriterioEmun, List<Integer>> result =
        new HashMap<TipoOperacionCriterioEmun, List<Integer>>();
    Map<Integer, Integer> mapaParentesis = obtenerPosicionesParentesisExternos(expresion);

    Integer lastPosicionView = 0;
    for (TipoOperacionCriterioEmun tipoOperacionEmun :
        TipoOperacionCriterioEmun.getListaValoresEvaluacion()) {
      lastPosicionView = 0;
      List<Integer> listaPosicines = new ArrayList<Integer>();

      if (tipoOperacionEmun.equals(TipoOperacionCriterioEmun.NOT)) {
        if ((lastPosicionView =
                expresion.indexOf(tipoOperacionEmun.getRepresentacion() + "(", lastPosicionView))
            != -1) {
          if (!estaEntreParentesis(mapaParentesis, lastPosicionView)
              && mapaParentesis.get(
                      lastPosicionView + TipoOperacionCriterioEmun.NOT.getRepresentacion().length())
                  == expresion.length() - 1) {
            listaPosicines.add(lastPosicionView);
            result.put(tipoOperacionEmun, listaPosicines);
            return result;
          }
        }
        result.put(tipoOperacionEmun, listaPosicines);
        continue;
      }

      while ((lastPosicionView =
              expresion.indexOf(tipoOperacionEmun.getRepresentacion(), lastPosicionView))
          != -1) {
        if (!estaEntreParentesis(mapaParentesis, lastPosicionView)
            && operacionInequivoca(
                tipoOperacionEmun, expresion.substring(lastPosicionView - 1, lastPosicionView + 2)))
          listaPosicines.add(lastPosicionView);
        lastPosicionView++;
      }
      result.put(tipoOperacionEmun, listaPosicines);
    }

    return result;
  }
예제 #6
0
  private Map<TipoOperacionCriterioEmun, Integer> obtenerOperacionExterna(
      Map<TipoOperacionCriterioEmun, List<Integer>> mapa) {
    Map<TipoOperacionCriterioEmun, Integer> result =
        new HashMap<TipoOperacionCriterioEmun, Integer>();

    if (!mapa.get(TipoOperacionCriterioEmun.NOT).isEmpty()) {
      result.put(TipoOperacionCriterioEmun.NOT, mapa.get(TipoOperacionCriterioEmun.NOT).get(0));
      return result;
    }

    if (!mapa.get(TipoOperacionCriterioEmun.AND).isEmpty()) {
      if (!mapa.get(TipoOperacionCriterioEmun.OR).isEmpty()) {
        if (mapa.get(TipoOperacionCriterioEmun.OR).get(0)
            < mapa.get(TipoOperacionCriterioEmun.AND).get(0))
          result.put(TipoOperacionCriterioEmun.OR, mapa.get(TipoOperacionCriterioEmun.OR).get(0));
        return result;
      }
      result.put(TipoOperacionCriterioEmun.AND, mapa.get(TipoOperacionCriterioEmun.AND).get(0));
      return result;
    }

    if (!mapa.get(TipoOperacionCriterioEmun.OR).isEmpty()) {
      result.put(TipoOperacionCriterioEmun.OR, mapa.get(TipoOperacionCriterioEmun.OR).get(0));
      return result;
    }

    // EVALUAR LA OPERACION EXTERNA MAS A LA IZQUIERDA

    TipoOperacionCriterioEmun operacionE = null;
    Integer posicionIZ = null;

    for (TipoOperacionCriterioEmun op : TipoOperacionCriterioEmun.getComparaciones()) {
      if (!(mapa.get(op).isEmpty()) && (posicionIZ == null || posicionIZ > mapa.get(op).get(0))) {
        posicionIZ = mapa.get(op).get(0);
        operacionE = op;
      }
    }

    result.put(operacionE, mapa.get(operacionE).get(0));
    return result;
  }
예제 #7
0
  private Boolean operaAritmetica(
      TipoOperacionCriterioEmun operacion, Double valorIzq, Double valorDch) throws Exception {
    int resultado = valorIzq.compareTo(valorDch);

    if (operacion.equals(TipoOperacionCriterioEmun.MAYOR)) return resultado > 0;

    if (operacion.equals(TipoOperacionCriterioEmun.MAYOR_IGUAL)) return resultado >= 0;

    if (operacion.equals(TipoOperacionCriterioEmun.MENOR)) return resultado < 0;

    if (operacion.equals(TipoOperacionCriterioEmun.MENOR_IGUAL)) return resultado <= 0;

    if (operacion.equals(TipoOperacionCriterioEmun.IGUAL)) return resultado == 0;

    if (operacion.equals(TipoOperacionCriterioEmun.DISTINTO)) return resultado != 0;

    throw new Exception("Fallo Operando Aritmetica");
  }
예제 #8
0
  private CriterioDto guardaCriterio(
      String expresion, String tipoColumna, EncapsuladorErroresSW errores) {
    try {
      List<String> trozos = TrocearExpresion(expresion);
      if (trozos == null) return null;
      CriterioDto criterioDto = new CriterioDto();

      TipoOperacionCriterioEmun operacion =
          TipoOperacionCriterioEmun.getPorRepresentacion(trozos.get(0));
      criterioDto.setTipoOperacion(operacion);

      // OPERANDO IZQUIERDO
      String operando1 = eliminarParentesisRedundantesExternos(trozos.get(1));
      criterioDto.setTipoOperandoIzq(identificarTipoOperando(operando1));

      if (criterioDto.getTipoOperandoIzq().equals(TipoOperandoCriterioEmun.LITERAL)) {

        if (esCadena(operando1)) {
          if (TipoAtributoFD.VALORFDNUMERICO.getDescripcion().equals(tipoColumna)) {
            errores.setHashErrors(true);
            EncapsuladorErrorSW error = new EncapsuladorErrorSW();
            errores.getListaErrores().add(error);
            return null;
          } else {
            criterioDto.setStrLiteralIzq(operando1.substring(1, operando1.length() - 1));
            criterioDto.setLiteralIzq(null);
          }
        } else {
          // Existe un punto en el valor literal
          if (operando1.indexOf(".") != -1) {
            return null;
          }
          criterioDto.setLiteralIzq(devolverOperandoLiteral(operando1));
          criterioDto.setStrLiteralIzq(null);
        }
      }
      if (criterioDto.getTipoOperandoIzq().equals(TipoOperandoCriterioEmun.CRITERIO))
        criterioDto.setIdCriterioIzq(guardaCriterio(operando1, tipoColumna, errores).getId());

      // operando derecho
      if (!operacion.equals(TipoOperacionCriterioEmun.NOT)) {

        String operando2 = eliminarParentesisRedundantesExternos(trozos.get(2));
        criterioDto.setTipoOperandoDch(identificarTipoOperando(operando2));

        if (criterioDto.getTipoOperandoDch().equals(TipoOperandoCriterioEmun.LITERAL)) {

          if (esCadena(operando2)) {
            if (TipoAtributoFD.VALORFDNUMERICO.getDescripcion().equals(tipoColumna)) {
              errores.setHashErrors(true);
              EncapsuladorErrorSW error = new EncapsuladorErrorSW();
              errores.getListaErrores().add(error);
              return null;
            } else {
              criterioDto.setStrLiteralDch(operando2.substring(1, operando2.length() - 1));
              criterioDto.setLiteralDch(null);
            }
          } else {

            // Existe un punto en el valor literal
            if (operando2.indexOf(".") != -1) {
              return null;
            }

            criterioDto.setLiteralDch(devolverOperandoLiteral(operando2));
            criterioDto.setStrLiteralDch(null);
          }
        }
        if (criterioDto.getTipoOperandoDch().equals(TipoOperandoCriterioEmun.CRITERIO))
          criterioDto.setIdCriterioDch(guardaCriterio(operando2, tipoColumna, errores).getId());

      } else {
        criterioDto.setTipoOperandoDch(TipoOperandoCriterioEmun.SIN_OPERANDO);
      }

      return guarda(criterioDto, errores);
    } catch (Throwable e) {
      LOG.error(e.getMessage());
      return null;
    }
  }
예제 #9
0
 public Boolean cargaEvaluacionCriterioTexto(CriterioDto criterioDto, String valor)
     throws Exception {
   return operaTexto(criterioDto, valor, TipoOperacionCriterioEmun.getComparaciones());
 }
예제 #10
0
 public Boolean cargaEvaluacionCriterio(CriterioDto criterioDto, Double valor) throws Exception {
   return opera(criterioDto, valor, TipoOperacionCriterioEmun.getComparaciones());
 }