PdndMethods.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.statistiche.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 pdnd-methods xsd (tipo:string)
  27.  *
  28.  * @author Poli Andrea (poli@link.it)
  29.  * @author Tommaso Burlon (tommaso.burlon@link.it)
  30.  * @author $Author$
  31.  * @version $Rev$, $Date$
  32.  */
  33. @javax.xml.bind.annotation.XmlType(name = "pdnd-methods")
  34. @javax.xml.bind.annotation.XmlEnum(String.class)
  35. public enum PdndMethods implements IEnumeration , Serializable , Cloneable {

  36.     @javax.xml.bind.annotation.XmlEnumValue("REPLACE")
  37.     REPLACE ("REPLACE"),
  38.     @javax.xml.bind.annotation.XmlEnumValue("RECOVER")
  39.     RECOVER ("RECOVER"),
  40.     @javax.xml.bind.annotation.XmlEnumValue("SUBMIT")
  41.     SUBMIT ("SUBMIT");
  42.    
  43.    
  44.     /** Value */
  45.     private String value;
  46.     @Override
  47.     public String getValue()
  48.     {
  49.         return this.value;
  50.     }


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


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