AbstractModel.java

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


/**
 * AbstractModel
 * 
 * @author Poli Andrea (apoli@link.it)
 * @author $Author$
 * @version $Rev$, $Date$
 */
public abstract class AbstractModel<T> implements IModel<T> {

	public AbstractModel(){
	}
	
	public AbstractModel(IField father){
		this._BASE = father;
	}
	
	private IField _BASE = null;
	
	@Override
	public IField getBaseField() {
		return this._BASE;
	}


	// Non lo si vuole realizzare, si demanda eventualmente alla classe che lo implementa
//	@Override
//	public int hashCode(){
//		return this.getClass().getName().hashCode();
//	}
	
	@Override
	public boolean equals(Object o){
		if(o==null){
			return false;
		}
		if(!(o instanceof IModel)){
			return false;
		}
		IModel<?> oIModel = (IModel<?>) o;
		
		// 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
		// il caso viene riprodotto dal test FruitoreModel che contiene il fruitore ed una parte specifica con erogatore. 
		// Sia il fruitore che l'erogatore possiedono la stessa getModeledClass 'IdSoggettoModel' e quindi l'equals non era veritiero.
		if(this._BASE==null){
			if(oIModel.getBaseField()!=null){
				return false;
			}
			else{
				String modeledClassName = this.getModeledClass().getName() + "";
				String oIModelClassName = oIModel.getModeledClass().getName() + "";
				return modeledClassName.equals(oIModelClassName);
			}
		}
		else{
			String modeledClassName = this.getModeledClass().getName() + "";
			String oIModelClassName = oIModel.getModeledClass().getName() + "";
			return modeledClassName.equals(oIModelClassName)  
						&& this.getBaseField().equals(oIModel.getBaseField()); 
		}
		
	}
}