IDAccordo.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.core.id;


  21. /**
  22.  * Classe utilizzata per rappresentare un identificatore di un Accordo di Servizio nel registro dei Servizi.
  23.  *
  24.  *
  25.  * @author Poli Andrea (apoli@link.it)
  26.  * @author Nardi Lorenzo (nardi@link.it)
  27.  * @author $Author$
  28.  * @version $Rev$, $Date$
  29.  */

  30. public class IDAccordo implements java.io.Serializable, Cloneable {

  31.      /**
  32.      * serialVersionUID
  33.      */
  34.     private static final long serialVersionUID = 1L;


  35.     /** Nome dell'accordo */
  36.     protected String nome;
  37.     /** Soggetto Referente (Puo' non essere definito). */
  38.     protected IDSoggetto soggettoReferente;
  39.     /** Versione. */
  40.     protected Integer versione = 1;


  41.     public String getNome() {
  42.         return this.nome;
  43.     }
  44.     public IDSoggetto getSoggettoReferente() {
  45.         return this.soggettoReferente;
  46.     }
  47.     public Integer getVersione() {
  48.         return this.versione;
  49.     }
  50.    
  51.     @Deprecated
  52.     public void setNome(String nome) {
  53.         this.nome = nome;
  54.     }
  55.     @Deprecated
  56.     public void setSoggettoReferente(IDSoggetto soggettoReferente) {
  57.         this.soggettoReferente = soggettoReferente;
  58.     }
  59.     @Deprecated
  60.     public void setVersione(Integer versione) {
  61.         this.versione = versione;
  62.     }
  63.    
  64.        
  65.     @Override
  66.     public String toString(){
  67.         StringBuilder bf = new StringBuilder();
  68.         if(this.soggettoReferente!=null){
  69.             bf.append(this.soggettoReferente.toString());
  70.             bf.append(":");
  71.         }
  72.         bf.append(this.nome);
  73.         bf.append(":");
  74.         bf.append(this.versione);
  75.         return bf.toString();
  76.     }
  77.        
  78.     @Override
  79.     public boolean equals(Object object){
  80.         return _equals(object, true);
  81.     }
  82.     protected boolean _equals(Object object, boolean verifyClass){
  83.         if(object == null)
  84.             return false;
  85.         if(verifyClass) {
  86.             String objectClassName = object.getClass().getName() + "";
  87.             if(objectClassName.equals(this.getClass().getName()) == false) {
  88.                 return false;
  89.             }
  90.         }
  91.         IDAccordo id = (IDAccordo) object;
  92.        
  93.         if(this.nome==null){
  94.             if(id.nome!=null)
  95.                 return false;
  96.         }else{
  97.             if(this.nome.equals(id.nome)==false)
  98.                 return false;
  99.         }

  100.         if(this.getVersione()==null) {
  101.             if(id.getVersione()!=null) {
  102.                 return false;
  103.             }
  104.         }
  105.         else {
  106.             if(id.getVersione()==null) {
  107.                 return false;
  108.             }
  109.             if(this.getVersione().intValue()!=id.getVersione().intValue()){
  110.                 return false;
  111.             }
  112.         }
  113.        
  114.         if(this.soggettoReferente==null){
  115.             if(id.soggettoReferente!=null)
  116.                 return false;
  117.         }else{
  118.             if(this.soggettoReferente.equals(id.soggettoReferente)==false)
  119.                 return false;
  120.         }
  121.        
  122.         return true;
  123.     }

  124.     // Utile per usare l'oggetto in hashtable come chiave
  125.     @Override
  126.     public int hashCode(){
  127.         return this.toString().hashCode();
  128.     }

  129.     @Override
  130.     public IDAccordo clone(){
  131.         IDAccordo idAccordo = null;
  132.         try {
  133.             idAccordo = (IDAccordo) super.clone();
  134.         }catch(Throwable t) {
  135.             idAccordo = new IDAccordo();
  136.         }
  137.        
  138.         if(this.nome!=null){
  139.             idAccordo.nome = new String(this.nome);
  140.         }
  141.        
  142.         idAccordo.versione = this.versione;
  143.        
  144.         if(this.soggettoReferente!=null){
  145.             idAccordo.soggettoReferente = this.soggettoReferente.clone();
  146.         }
  147.        
  148.         return idAccordo;
  149.     }
  150. }