LoaderOperationType.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.pdd.config.loader.cli;

  21. import org.openspcoop2.generic_project.exception.NotFoundException;

  22. /**
  23. * LoaderOperationType
  24. *
  25. * @author Poli Andrea (apoli@link.it)
  26. * @author $Author$
  27. * @version $Rev$, $Date$
  28. */
  29. public enum LoaderOperationType {

  30.     CREATE("create"),CREATE_UPDATE("createUpdate"),DELETE("delete");
  31.    
  32.     /** Value */
  33.     private String value;
  34.     public String getValue()
  35.     {
  36.         return this.value;
  37.     }


  38.     /** Official Constructor */
  39.     LoaderOperationType(String value)
  40.     {
  41.         this.value = value;
  42.     }


  43.    
  44.     @Override
  45.     public String toString(){
  46.         return this.value;
  47.     }
  48.     public boolean equalsEnum(String object){
  49.         if(object==null)
  50.             return false;
  51.         return object.equals(this.getValue());  
  52.     }
  53.    
  54.        
  55.    
  56.    
  57.    
  58.     /** Utilities */
  59.    
  60.     public static String[] toArray(){
  61.         String[] res = new String[values().length];
  62.         int i=0;
  63.         for (LoaderOperationType tmp : values()) {
  64.             res[i]=tmp.getValue();
  65.             i++;
  66.         }
  67.         return res;
  68.     }  
  69.     public static String[] toStringArray(){
  70.         String[] res = new String[values().length];
  71.         int i=0;
  72.         for (LoaderOperationType tmp : values()) {
  73.             res[i]=tmp.toString();
  74.             i++;
  75.         }
  76.         return res;
  77.     }
  78.     public static String[] toEnumNameArray(){
  79.         String[] res = new String[values().length];
  80.         int i=0;
  81.         for (LoaderOperationType tmp : values()) {
  82.             res[i]=tmp.name();
  83.             i++;
  84.         }
  85.         return res;
  86.     }
  87.    
  88.     public static boolean contains(String value){
  89.         return toEnumConstant(value)!=null;
  90.     }
  91.    
  92.     public static LoaderOperationType toEnumConstant(String value){
  93.         try{
  94.             return toEnumConstant(value,false);
  95.         }catch(NotFoundException notFound){
  96.             return null;
  97.         }
  98.     }
  99.     public static LoaderOperationType toEnumConstant(String value, boolean throwNotFoundException) throws NotFoundException{
  100.         LoaderOperationType res = null;
  101.         for (LoaderOperationType tmp : values()) {
  102.             if(tmp.getValue().equals(value)){
  103.                 res = tmp;
  104.                 break;
  105.             }
  106.         }
  107.         if(res==null && throwNotFoundException){
  108.             throw new NotFoundException("Enum with value ["+value+"] not found");
  109.         }
  110.         return res;
  111.     }

  112. }