BetweenExpressionImpl.java

  1. /*
  2.  * GovWay - A customizable API Gateway
  3.  * https://govway.org
  4.  *
  5.  * Copyright (c) 2005-2025 Link.it srl (https://link.it).
  6.  *
  7.  * This program is free software: you can redistribute it and/or modify
  8.  * it under the terms of the GNU General Public License version 3, as published by
  9.  * the Free Software Foundation.
  10.  *
  11.  * This program is distributed in the hope that it will be useful,
  12.  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13.  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  14.  * GNU General Public License for more details.
  15.  *
  16.  * You should have received a copy of the GNU General Public License
  17.  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
  18.  *
  19.  */
  20. package org.openspcoop2.generic_project.expression.impl;

  21. import java.util.ArrayList;
  22. import java.util.List;

  23. import org.openspcoop2.generic_project.beans.ComplexField;
  24. import org.openspcoop2.generic_project.beans.IField;
  25. import org.openspcoop2.generic_project.exception.ExpressionException;
  26. import org.openspcoop2.generic_project.exception.ExpressionNotImplementedException;
  27. import org.openspcoop2.generic_project.expression.impl.formatter.IObjectFormatter;

  28. /**
  29.  * BetweenExpressionImpl
  30.  *
  31.  * @author Poli Andrea (apoli@link.it)
  32.  * @author $Author$
  33.  * @version $Rev$, $Date$
  34.  */
  35. public class BetweenExpressionImpl extends AbstractCommonFieldBaseExpressionImpl {

  36.     private Object lower;
  37.     private Object high;
  38.    
  39.     public BetweenExpressionImpl(IObjectFormatter objectFormatter,IField field,Object lower,Object high){
  40.         super(objectFormatter, field);
  41.         this.lower = lower;
  42.         this.high = high;
  43.     }
  44.    
  45.     public Object getLower() {
  46.         return this.lower;
  47.     }

  48.     public void setLower(Object lower) {
  49.         this.lower = lower;
  50.     }

  51.     public Object getHigh() {
  52.         return this.high;
  53.     }

  54.     public void setHigh(Object high) {
  55.         this.high = high;
  56.     }
  57.    
  58.     @Override
  59.     public String toString(){
  60.         StringBuilder bf = new StringBuilder();
  61.         if(isNot()){
  62.             bf.append("( NOT ");
  63.         }
  64.         bf.append("( ");
  65.         if(this.field instanceof ComplexField){
  66.             ComplexField cf = (ComplexField) this.field;
  67.             if(cf.getFather()!=null){
  68.                 bf.append(cf.getFather().getFieldName());
  69.             }else{
  70.                 bf.append(this.field.getClassName());
  71.             }
  72.         }else{
  73.             bf.append(this.field.getClassName());
  74.         }
  75.         bf.append(".");
  76.         bf.append(this.field.getFieldName());
  77.         bf.append(" BETWEEN ");
  78.         bf.append(" ");
  79.         try{
  80.             bf.append(super.getObjectFormatter().toString(this.lower));
  81.         }catch(Exception e){
  82.             return "ERROR-LOWER: "+e.getMessage();
  83.         }
  84.         bf.append(" AND ");
  85.         try{
  86.             bf.append(super.getObjectFormatter().toString(this.high));
  87.         }catch(Exception e){
  88.             return "ERROR-HIGH: "+e.getMessage();
  89.         }
  90.         bf.append(" )");
  91.         if(isNot()){
  92.             bf.append(" )");
  93.         }
  94.         return bf.toString();
  95.     }
  96.    
  97.     @Override
  98.     public List<Object> getFieldValues(IField field) throws ExpressionNotImplementedException, ExpressionException{
  99.         List<Object> lista = null;
  100.         if(this.field==null){
  101.             return lista;
  102.         }
  103.         if(this.field.equals(field)){
  104.             lista = new ArrayList<>();
  105.             lista.add(this.lower);
  106.             lista.add(this.high);
  107.         }
  108.         return lista;
  109.     }
  110.    
  111. }