TipologiaServizio.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.constants;

  21. import java.io.Serializable;
  22. import java.util.List;

  23. import org.openspcoop2.generic_project.beans.IEnumeration;
  24. import org.openspcoop2.generic_project.exception.NotFoundException;

  25. /**    
  26.  * TipologiaServizio
  27.  *
  28.  * @author Poli Andrea (poli@link.it)
  29.  * @author $Author$
  30.  * @version $Rev$, $Date$
  31.  */
  32. public enum TipologiaServizio implements IEnumeration , Serializable , Cloneable {

  33.     NORMALE ("normale"),
  34.     CORRELATO ("correlato");
  35.    
  36.    
  37.     /** Value */
  38.     private String value;
  39.     @Override
  40.     public String getValue()
  41.     {
  42.         return this.value;
  43.     }


  44.     /** Official Constructor */
  45.     TipologiaServizio(String value)
  46.     {
  47.         this.value = value;
  48.     }


  49.    
  50.     @Override
  51.     public String toString(){
  52.         return this.value;
  53.     }
  54.     public boolean equals(String object){
  55.         if(object==null)
  56.             return false;
  57.         return object.equals(this.getValue());  
  58.     }
  59.    
  60.        
  61.    
  62.     /** compatibility with the generated bean (reflection) */
  63.     public boolean equals(Object object,List<String> fieldsNotCheck){
  64.         if( !(object instanceof TipologiaServizio) ){
  65.             throw new RuntimeException("Wrong type: "+object.getClass().getName());
  66.         }
  67.         return this.equals(((TipologiaServizio)object));
  68.     }
  69.     public String toString(boolean reportHTML){
  70.         return toString();
  71.     }
  72.     public String toString(boolean reportHTML,List<String> fieldsNotIncluded){
  73.         return toString();
  74.     }
  75.     public String diff(Object object,StringBuilder bf,boolean reportHTML){
  76.         return bf.toString();
  77.     }
  78.     public String diff(Object object,StringBuilder bf,boolean reportHTML,List<String> fieldsNotIncluded){
  79.         return bf.toString();
  80.     }
  81.    
  82.    
  83.     /** Utilities */
  84.    
  85.     public static String[] toArray(){
  86.         String[] res = new String[values().length];
  87.         int i=0;
  88.         for (TipologiaServizio tmp : values()) {
  89.             res[i]=tmp.getValue();
  90.             i++;
  91.         }
  92.         return res;
  93.     }  
  94.     public static String[] toStringArray(){
  95.         String[] res = new String[values().length];
  96.         int i=0;
  97.         for (TipologiaServizio tmp : values()) {
  98.             res[i]=tmp.toString();
  99.             i++;
  100.         }
  101.         return res;
  102.     }
  103.     public static String[] toEnumNameArray(){
  104.         String[] res = new String[values().length];
  105.         int i=0;
  106.         for (TipologiaServizio tmp : values()) {
  107.             res[i]=tmp.name();
  108.             i++;
  109.         }
  110.         return res;
  111.     }
  112.    
  113.     public static boolean contains(String value){
  114.         return toEnumConstant(value)!=null;
  115.     }
  116.    
  117.     public static TipologiaServizio toEnumConstant(String value){
  118.         try{
  119.             return toEnumConstant(value,false);
  120.         }catch(NotFoundException notFound){
  121.             return null;
  122.         }
  123.     }
  124.     public static TipologiaServizio toEnumConstant(String value, boolean throwNotFoundException) throws NotFoundException{
  125.         TipologiaServizio res = null;
  126.         for (TipologiaServizio tmp : values()) {
  127.             if(tmp.getValue().equals(value)){
  128.                 res = tmp;
  129.                 break;
  130.             }
  131.         }
  132.         if(res==null && throwNotFoundException){
  133.             throw new NotFoundException("Enum with value ["+value+"] not found");
  134.         }
  135.         return res;
  136.     }
  137.    
  138.     public static IEnumeration toEnumConstantFromString(String value){
  139.         try{
  140.             return toEnumConstantFromString(value,false);
  141.         }catch(NotFoundException notFound){
  142.             return null;
  143.         }
  144.     }
  145.     public static IEnumeration toEnumConstantFromString(String value, boolean throwNotFoundException) throws NotFoundException{
  146.         TipologiaServizio res = null;
  147.         for (TipologiaServizio tmp : values()) {
  148.             if(tmp.toString().equals(value)){
  149.                 res = tmp;
  150.                 break;
  151.             }
  152.         }
  153.         if(res==null && throwNotFoundException){
  154.             throw new NotFoundException("Enum with value ["+value+"] not found");
  155.         }
  156.         return res;
  157.     }
  158. }