UnitaTemporale.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.date;

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

  23. import org.openspcoop2.utils.UtilsException;


  24. /**    
  25.  * Enumeration dell'elemento tipo-periodo xsd (tipo:string)
  26.  *
  27.  * @author Poli Andrea (poli@link.it)
  28.  * @author $Author$
  29.  * @version $Rev$, $Date$
  30.  */
  31. @javax.xml.bind.annotation.XmlType(name = "tipo-periodo")
  32. @javax.xml.bind.annotation.XmlEnum(String.class)
  33. public enum UnitaTemporale implements Serializable , Cloneable {

  34.     @javax.xml.bind.annotation.XmlEnumValue("secondi")
  35.     SECONDI ("secondi"),
  36.     @javax.xml.bind.annotation.XmlEnumValue("minuti")
  37.     MINUTI ("minuti"),
  38.     @javax.xml.bind.annotation.XmlEnumValue("orario")
  39.     ORARIO ("orario"),
  40.     @javax.xml.bind.annotation.XmlEnumValue("giornaliero")
  41.     GIORNALIERO ("giornaliero"),
  42.     @javax.xml.bind.annotation.XmlEnumValue("settimanale")
  43.     SETTIMANALE ("settimanale"),
  44.     @javax.xml.bind.annotation.XmlEnumValue("mensile")
  45.     MENSILE ("mensile");
  46.    
  47.    
  48.     /** Value */
  49.     private String value;
  50.     public String getValue()
  51.     {
  52.         return this.value;
  53.     }


  54.     /** Official Constructor */
  55.     UnitaTemporale(String value)
  56.     {
  57.         this.value = value;
  58.     }


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