AbstractModel.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.beans;


  21. /**
  22.  * AbstractModel
  23.  *
  24.  * @author Poli Andrea (apoli@link.it)
  25.  * @author $Author$
  26.  * @version $Rev$, $Date$
  27.  */
  28. public abstract class AbstractModel<T> implements IModel<T> {

  29.     public AbstractModel(){
  30.     }
  31.    
  32.     public AbstractModel(IField father){
  33.         this._BASE = father;
  34.     }
  35.    
  36.     private IField _BASE = null;
  37.    
  38.     @Override
  39.     public IField getBaseField() {
  40.         return this._BASE;
  41.     }


  42.     // Non lo si vuole realizzare, si demanda eventualmente alla classe che lo implementa
  43. //  @Override
  44. //  public int hashCode(){
  45. //      return this.getClass().getName().hashCode();
  46. //  }
  47.    
  48.     @Override
  49.     public boolean equals(Object o){
  50.         if(o==null){
  51.             return false;
  52.         }
  53.         if(!(o instanceof IModel)){
  54.             return false;
  55.         }
  56.         IModel<?> oIModel = (IModel<?>) o;
  57.        
  58.         // la seconda condizione _BASE in and l'ho aggiunto in seguito al fix di due figli di un oggetto che sono model con stesso tipo ma nome diverso
  59.         // il caso viene riprodotto dal test FruitoreModel che contiene il fruitore ed una parte specifica con erogatore.
  60.         // Sia il fruitore che l'erogatore possiedono la stessa getModeledClass 'IdSoggettoModel' e quindi l'equals non era veritiero.
  61.         if(this._BASE==null){
  62.             if(oIModel.getBaseField()!=null){
  63.                 return false;
  64.             }
  65.             else{
  66.                 String modeledClassName = this.getModeledClass().getName() + "";
  67.                 String oIModelClassName = oIModel.getModeledClass().getName() + "";
  68.                 return modeledClassName.equals(oIModelClassName);
  69.             }
  70.         }
  71.         else{
  72.             String modeledClassName = this.getModeledClass().getName() + "";
  73.             String oIModelClassName = oIModel.getModeledClass().getName() + "";
  74.             return modeledClassName.equals(oIModelClassName)  
  75.                         && this.getBaseField().equals(oIModel.getBaseField());
  76.         }
  77.        
  78.     }
  79. }