Groovy web console

subscribe to the feed Subscribe
to this
site
AllowListFileExtension Validation (via #groovywebconsole)
tweet this snippet Tweet
this
script

AllowListFileExtension Validation

Published 7 months ago by Anonymous
Actions  ➤ Edit in console Back to console Show/hide line numbers View recent scripts
class AllowListFileExtension {
   public AllowListFileExtension (String extension) {
       this.extension = extension
   }
   boolean isValid() {
      return extension != null && !extension.isEmpty()
   }
   String extension
}

List<AllowListFileExtension > lst = [new AllowListFileExtension ("a"),
                                     new AllowListFileExtension ("z"),
                                     new AllowListFileExtension ("")]

if(lst.count{!it.isValid()} != 0) {
    println("Invalid :-(")
} else {
   println("Valid :-)")
}