IDResource.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. import java.io.Serializable;

  22. import org.openspcoop2.utils.Utilities;


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

  31. public class IDResource implements Serializable, Cloneable {

  32.     /**
  33.      *
  34.      */
  35.     private static final long serialVersionUID = 1L;
  36.    
  37.     protected String nome;

  38.     protected IDAccordo idAccordo;
  39.    
  40.     public String getNome() {
  41.         return this.nome;
  42.     }
  43.     public void setNome(String nome) {
  44.         this.nome = nome;
  45.     }
  46.     public IDAccordo getIdAccordo() {
  47.         return this.idAccordo;
  48.     }
  49.     public void setIdAccordo(IDAccordo idAccordo) {
  50.         this.idAccordo = idAccordo;
  51.     }
  52.    
  53.     @Override
  54.     public String toString(){
  55.         StringBuilder bf = new StringBuilder();
  56.         bf.append(this.nome);
  57.         if(this.idAccordo!=null)
  58.             bf.append("["+this.idAccordo+"]");
  59.         return bf.toString();
  60.     }
  61.    
  62.     @Override
  63.     public boolean equals(Object object){
  64.         if(object == null)
  65.             return false;
  66.         if(!Utilities.equalsClass(object,this))
  67.             return false;
  68.         IDResource id = (IDResource) object;
  69.        
  70.         if(this.nome==null){
  71.             if(id.nome!=null)
  72.                 return false;
  73.         }else{
  74.             if(this.nome.equals(id.nome)==false)
  75.                 return false;
  76.         }

  77.         if(this.idAccordo==null){
  78.             if(id.idAccordo!=null)
  79.                 return false;
  80.         }else{
  81.             if(this.idAccordo.equals(id.idAccordo)==false)
  82.                 return false;
  83.         }
  84.        
  85.         return true;
  86.     }
  87.    
  88.     // Utile per usare l'oggetto in hashtable come chiave
  89.     @Override
  90.     public int hashCode(){
  91.         return this.toString().hashCode();
  92.     }
  93.    
  94.     @Override
  95.     public IDResource clone(){
  96.         IDResource idPT = new IDResource();
  97.         if(this.idAccordo!=null){
  98.             idPT.idAccordo = this.idAccordo.clone();
  99.         }
  100.         if(this.nome!=null){
  101.             idPT.nome = new String(this.nome);
  102.         }
  103.         return idPT;
  104.     }
  105. }