Groovy web console

subscribe to the feed Subscribe
to this
site

Languages Enum

Published 3 months ago by SE
Actions  ➤ Edit in console Back to console Show/hide line numbers View recent scripts
class Main {                                    
    static void main(String... args) {          
        println 'Start'
        try{
            println Languages.valueOf("java2").getLanguage()
        }
        catch(Exception e){
            println Languages.java;
        }
    }

    enum Languages {	
       java("java"), dotnet("dotnet");

       public Languages(String language) {
         this.language = language;
       }

       private final String language;

       public String getLanguage() {
         return language;
       }

    }
   
    class ParamStore {	
        private final String language = "java"; // Simulo la stringa letta da config.yaml
        private final def context;
        private Languages l;

         ParamStore(context){
          this.context = context;
         }

         def store(){
            try{
                this.l = Languages.valueOf(language);
            }
            catch(Exception e){
               this.l = Languages.java;
            }
            this.context.env.LANGUAGE = this.l.getLanguage();
        }
    }
}