TipoBanda.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-banda 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-banda")
  33. @javax.xml.bind.annotation.XmlEnum(String.class)
  34. public enum TipoBanda implements IEnumeration , Serializable , Cloneable {

  35.     @javax.xml.bind.annotation.XmlEnumValue("complessiva")
  36.     COMPLESSIVA ("complessiva"),
  37.     @javax.xml.bind.annotation.XmlEnumValue("interna")
  38.     INTERNA ("interna"),
  39.     @javax.xml.bind.annotation.XmlEnumValue("esterna")
  40.     ESTERNA ("esterna");
  41.    
  42.    
  43.     /** Value */
  44.     private String value;
  45.     @Override
  46.     public String getValue()
  47.     {
  48.         return this.value;
  49.     }


  50.     /** Official Constructor */
  51.     TipoBanda(String value)
  52.     {
  53.         this.value = value;
  54.     }


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