Last active
May 3, 2017 16:08
-
-
Save jluismm2311/48e163781edb6081bbbac35b344baffa to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.groovy.testDictionary | |
class Dictionary { | |
def key | |
def value | |
def dict = [:] | |
Dictionary (){} | |
Dictionary (def key, def value){ | |
put(key, value) | |
} | |
void validate(def key, def value){ | |
validateNotNullObject(key) | |
validateNotNullObject(value) | |
} | |
void validateNotNullObject(def str){ | |
if(str == null){throw new RuntimeException("can not be null key/value")} | |
} | |
def put(def key, def value){ | |
try{ | |
validate(key, value) | |
this.dict[key] = value | |
println "have this dictionary: ${this.dict}" | |
}catch(RuntimeException e){ | |
println "have a exception ${e.getMessage()}" | |
} | |
} | |
void printInfo(){ | |
println "i have this data in the dictionary \n ${this.dict}" | |
} | |
} | |
def myDictionary = new Dictionary() | |
myDictionary.printInfo() | |
myDictionary.put('Name','Luis') | |
myDictionary.printInfo() | |
myDictionary.put('nullValue',null) | |
myDictionary.put(null,'nullKey') | |
myDictionary.printInfo() | |
myDictionary.put('age',28) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment