TipoApplicabilita.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.controllo_traffico.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.  * Enumeration dell'elemento tipo-applicabilita xsd (tipo:string)
  27.  *
  28.  * @author Poli Andrea (poli@link.it)
  29.  * @author $Author$
  30.  * @version $Rev$, $Date$
  31.  */
  32. @javax.xml.bind.annotation.XmlType(name = "tipo-applicabilita")
  33. @javax.xml.bind.annotation.XmlEnum(String.class)
  34. public enum TipoApplicabilita implements IEnumeration , Serializable , Cloneable {

  35.     @javax.xml.bind.annotation.XmlEnumValue("sempre")
  36.     SEMPRE ("sempre"),
  37.     @javax.xml.bind.annotation.XmlEnumValue("condizionale")
  38.     CONDIZIONALE ("condizionale");
  39.    
  40.    
  41.     /** Value */
  42.     private String value;
  43.     @Override
  44.     public String getValue()
  45.     {
  46.         return this.value;
  47.     }


  48.     /** Official Constructor */
  49.     TipoApplicabilita(String value)
  50.     {
  51.         this.value = value;
  52.     }


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