BaseUniqueIdentifier.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.utils.id;




  21. /**
  22.  * UniversallyUniqueIdentifier
  23.  *
  24.  * @author Poli Andrea (apoli@link.it)
  25.  * @author $Author$
  26.  * @version $Rev$, $Date$
  27.  */
  28. public class BaseUniqueIdentifier implements IUniqueIdentifier {
  29.    
  30.     /**
  31.      *
  32.      */
  33.     private static final long serialVersionUID = 1L;
  34.    
  35.     private String uniqueId;
  36.    
  37.     public BaseUniqueIdentifier(String uniqueId){
  38.         this.uniqueId = uniqueId;
  39.     }
  40.     public BaseUniqueIdentifier(Long uniqueId){
  41.         this.uniqueId = uniqueId.longValue()+"";
  42.     }
  43.     public BaseUniqueIdentifier(Integer uniqueId){
  44.         this.uniqueId = uniqueId.intValue()+"";
  45.     }
  46.     public BaseUniqueIdentifier(Object uniqueId) throws UniqueIdentifierException{
  47.         if(uniqueId instanceof String){
  48.             this.uniqueId = (String) uniqueId;
  49.         }
  50.         else if(uniqueId instanceof Long){
  51.             this.uniqueId = ((Long) uniqueId).longValue()+"";
  52.         }
  53.         else if(uniqueId instanceof Integer){
  54.             this.uniqueId = ((Integer) uniqueId).intValue()+"";
  55.         }
  56.         else{
  57.             throw new UniqueIdentifierException("Tipo ["+uniqueId.getClass().getName()+"] non supportato");
  58.         }
  59.     }

  60.    
  61.     @Override
  62.     public String getAsString() {
  63.         return this.uniqueId;
  64.     }
  65.        
  66.     @Override
  67.     public String toString(){
  68.         return this.uniqueId;
  69.     }
  70. }