SlideShare a Scribd company logo
1 of 85
Groovy: Efficiency Oriented Programming
Lecture 7
Master Proteomics & Bioinformatics - University of Geneva
Alexandre Masselot - summer 2011
Contents

‣ Eclipse tips
‣ Productivity tip: back to TDD
‣ Exceptions throwing and catching
‣ reference to object and cloning
‣ OOP: interface
Eclipse tips

‣ STS (Springsource Tool Suite) dashboard:
  - keep aware of what is new in the STS environment (new releases, new
    plugins, technologies, future webinars...)
  - help > dashboard
Eclipse tips

‣ STS (Springsource Tool Suite) dashboard:
   - keep aware of what is new in the STS environment (new releases, new
     plugins, technologies, future webinars...)
   - help > dashboard
‣ Jump directly in junit view
   - run junit tests <alt> <shift> X T
   - jump to junit window <shift> <alt> Q U
   - configure your shortcuts with
    preferences > filter “keys” > filter junit
   - use multi screen to put console or junit view on the secondary display
     (drag the view tab and drop it on the secondary display)
4
Productivity : TDD

‣ Test Driven Development
Productivity : TDD

‣ Test Driven Development
‣ Even for a simple task (over 10 lines!)
   - write a simple class (in the same directory if you wish)
   - split the behavior of your problem into simple methods
   - test every method
Productivity : TDD

‣ Test Driven Development
‣ Even for a simple task (over 10 lines!)
   - write a simple class (in the same directory if you wish)
   - split the behavior of your problem into simple methods
   - test every method



       Do not rely on println to
 develop/understand your code
Exceptions: using & surviving




                                6
Exception: example
Exception: example
org.codehaus.groovy.runtime.InvokerInvocationException: groovy.lang.MissingMethodException: No signature of method:
groovy.util.slurpersupport.Attributes.textd() is applicable for argument types: () values: []
Possible solutions: text(), text(), text(), getAt(groovy.lang.IntRange), getAt(int), getAt(java.lang.String)

   at org.codehaus.groovy.reflection.CachedMethod.invoke(CachedMethod.java:95)

   at groovy.lang.MetaMethod.doMethodInvoke(MetaMethod.java:233)

   at groovy.lang.MetaClassImpl.setProperty(MetaClassImpl.java:2395)

   at groovy.lang.MetaClassImpl.setProperty(MetaClassImpl.java:3315)

   at groovy.lang.MetaClassImpl.setProperties(MetaClassImpl.java:1499)

   at groovy.lang.MetaClassImpl.invokeConstructor(MetaClassImpl.java:1476)

   at groovy.lang.MetaClassImpl.invokeConstructor(MetaClassImpl.java:1397)

   at org.codehaus.groovy.runtime.InvokerHelper.invokeConstructorOf(InvokerHelper.java:824)

   at org.codehaus.groovy.runtime.typehandling.DefaultTypeTransformation.castToType(DefaultTypeTransformation.java:
313)

   at org.codehaus.groovy.runtime.ScriptBytecodeAdapter.castToType(ScriptBytecodeAdapter.java:602)

   at unige.mpb.eop.proteomics.uniprot.UniprotEntrySplicerTest.setUp(UniprotEntrySplicerTest.groovy:16)

   at junit.framework.TestCase.runBare(TestCase.java:128)

   at junit.framework.TestResult$1.protect(TestResult.java:106)

   at junit.framework.TestResult.runProtected(TestResult.java:124)

   at junit.framework.TestResult.run(TestResult.java:109)

   at junit.framework.TestCase.run(TestCase.java:120)

   at junit.framework.TestSuite.runTest(TestSuite.java:230)

   at junit.framework.TestSuite.run(TestSuite.java:225)

   at org.eclipse.jdt.internal.junit.runner.junit3.JUnit3TestReference.run(JUnit3TestReference.java:130)

   at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)

   at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:467)

   at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:683)

   at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:390)

   at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:197)
Caused by: groovy.lang.MissingMethodException: No signature of method: groovy.util.slurpersupport.Attributes.textd()
is applicable for argument types: () values: []
Possible solutions: text(), text(), text(), getAt(groovy.lang.IntRange), getAt(int), getAt(java.lang.String)

   at org.codehaus.groovy.runtime.ScriptBytecodeAdapter.unwrap(ScriptBytecodeAdapter.java:54)
Exception: example
org.codehaus.groovy.runtime.InvokerInvocationException: groovy.lang.MissingMethodException: No signature of method:
groovy.util.slurpersupport.Attributes.textd() is applicable for argument types: () values: []
Possible solutions: text(), text(), text(), getAt(groovy.lang.IntRange), getAt(int), getAt(java.lang.String)

   at   org.codehaus.groovy.reflection.CachedMethod.invoke(CachedMethod.java:95)

   at   groovy.lang.MetaMethod.doMethodInvoke(MetaMethod.java:233)

   at   groovy.lang.MetaClassImpl.setProperty(MetaClassImpl.java:2395)

   at   groovy.lang.MetaClassImpl.setProperty(MetaClassImpl.java:3315)

   at   groovy.lang.MetaClassImpl.setProperties(MetaClassImpl.java:1499)

   at   groovy.lang.MetaClassImpl.invokeConstructor(MetaClassImpl.java:1476)

   at   groovy.lang.MetaClassImpl.invokeConstructor(MetaClassImpl.java:1397)

   at   org.codehaus.groovy.runtime.InvokerHelper.invokeConstructorOf(InvokerHelper.java:824)

   at   org.codehaus.groovy.runtime.typehandling.DefaultTypeTransformation.castToType(DefaultTypeTransformation.java:313)

   at   org.codehaus.groovy.runtime.ScriptBytecodeAdapter.castToType(ScriptBytecodeAdapter.java:602)


   at unige.mpb.eop.proteomics.uniprot.UniprotEntrySplicerTest.setUp(UniprotEntrySplicerTest.groovy:16)

   at   junit.framework.TestCase.runBare(TestCase.java:128)

   at   junit.framework.TestResult$1.protect(TestResult.java:106)

   at   junit.framework.TestResult.runProtected(TestResult.java:124)

   at   junit.framework.TestResult.run(TestResult.java:109)

   at   junit.framework.TestCase.run(TestCase.java:120)

   at   junit.framework.TestSuite.runTest(TestSuite.java:230)

   at   junit.framework.TestSuite.run(TestSuite.java:225)

   at   org.eclipse.jdt.internal.junit.runner.junit3.JUnit3TestReference.run(JUnit3TestReference.java:130)

   at   org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)

   at   org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:467)

   at   org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:683)

   at   org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:390)

   at   org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:197)

Caused by: groovy.lang.MissingMethodException: No signature of method: groovy.util.slurpersupport.Attributes.textd()
is applicable for argument types: () values: []
Possible solutions: text(), text(), text(), getAt(groovy.lang.IntRange), getAt(int), getAt(java.lang.String)

   at   org.codehaus.groovy.runtime.ScriptBytecodeAdapter.unwrap(ScriptBytecodeAdapter.java:54)

   at   org.codehaus.groovy.runtime.callsite.PogoMetaClassSite.call(PogoMetaClassSite.java:51)

   at   org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCall(CallSiteArray.java:40)

   at   org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:116)

   at   org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:120)


   at unige.mpb.eop.proteomics.uniprot.UniprotEntrySplicer
$_extractIsoformDescriptors_closure1.doCall(UniprotEntrySplicer.groovy:64)

   at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)

   at   sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)

   at   sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)

   at   java.lang.reflect.Method.invoke(Method.java:597)

   at   org.codehaus.groovy.reflection.CachedMethod.invoke(CachedMethod.java:88)

   at   groovy.lang.MetaMethod.doMethodInvoke(MetaMethod.java:233)

   at   org.codehaus.groovy.runtime.metaclass.ClosureMetaClass.invokeMethod(ClosureMetaClass.java:273)

   at   groovy.lang.MetaClassImpl.invokeMethod(MetaClassImpl.java:886)

   at   groovy.lang.Closure.call(Closure.java:276)

   at   groovy.util.slurpersupport.NodeChildren.find(NodeChildren.java:194)

   at   sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)

   at   sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)

   at   sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)

   at   java.lang.reflect.Method.invoke(Method.java:597)

   at   org.codehaus.groovy.reflection.CachedMethod.invoke(CachedMethod.java:88)
Exception: example                                                                                                           message
org.codehaus.groovy.runtime.InvokerInvocationException: groovy.lang.MissingMethodException: No signature of method:
groovy.util.slurpersupport.Attributes.textd() is applicable for argument types: () values: []
Possible solutions: text(), text(), text(), getAt(groovy.lang.IntRange), getAt(int), getAt(java.lang.String)

   at   org.codehaus.groovy.reflection.CachedMethod.invoke(CachedMethod.java:95)

   at   groovy.lang.MetaMethod.doMethodInvoke(MetaMethod.java:233)

   at   groovy.lang.MetaClassImpl.setProperty(MetaClassImpl.java:2395)

   at   groovy.lang.MetaClassImpl.setProperty(MetaClassImpl.java:3315)

   at   groovy.lang.MetaClassImpl.setProperties(MetaClassImpl.java:1499)

   at   groovy.lang.MetaClassImpl.invokeConstructor(MetaClassImpl.java:1476)

   at   groovy.lang.MetaClassImpl.invokeConstructor(MetaClassImpl.java:1397)

   at   org.codehaus.groovy.runtime.InvokerHelper.invokeConstructorOf(InvokerHelper.java:824)

   at   org.codehaus.groovy.runtime.typehandling.DefaultTypeTransformation.castToType(DefaultTypeTransformation.java:313)

   at   org.codehaus.groovy.runtime.ScriptBytecodeAdapter.castToType(ScriptBytecodeAdapter.java:602)


   at unige.mpb.eop.proteomics.uniprot.UniprotEntrySplicerTest.setUp(UniprotEntrySplicerTest.groovy:16)

   at   junit.framework.TestCase.runBare(TestCase.java:128)

   at   junit.framework.TestResult$1.protect(TestResult.java:106)

   at   junit.framework.TestResult.runProtected(TestResult.java:124)

   at   junit.framework.TestResult.run(TestResult.java:109)

   at   junit.framework.TestCase.run(TestCase.java:120)

   at   junit.framework.TestSuite.runTest(TestSuite.java:230)

   at   junit.framework.TestSuite.run(TestSuite.java:225)

   at   org.eclipse.jdt.internal.junit.runner.junit3.JUnit3TestReference.run(JUnit3TestReference.java:130)

   at   org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)

   at   org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:467)

   at   org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:683)

   at   org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:390)

   at   org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:197)

Caused by: groovy.lang.MissingMethodException: No signature of method: groovy.util.slurpersupport.Attributes.textd()
is applicable for argument types: () values: []
Possible solutions: text(), text(), text(), getAt(groovy.lang.IntRange), getAt(int), getAt(java.lang.String)

   at   org.codehaus.groovy.runtime.ScriptBytecodeAdapter.unwrap(ScriptBytecodeAdapter.java:54)

   at   org.codehaus.groovy.runtime.callsite.PogoMetaClassSite.call(PogoMetaClassSite.java:51)

   at   org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCall(CallSiteArray.java:40)

   at   org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:116)

   at   org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:120)


   at unige.mpb.eop.proteomics.uniprot.UniprotEntrySplicer
$_extractIsoformDescriptors_closure1.doCall(UniprotEntrySplicer.groovy:64)

   at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)

   at   sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)

   at   sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)

   at   java.lang.reflect.Method.invoke(Method.java:597)

   at   org.codehaus.groovy.reflection.CachedMethod.invoke(CachedMethod.java:88)

   at   groovy.lang.MetaMethod.doMethodInvoke(MetaMethod.java:233)

   at   org.codehaus.groovy.runtime.metaclass.ClosureMetaClass.invokeMethod(ClosureMetaClass.java:273)

   at   groovy.lang.MetaClassImpl.invokeMethod(MetaClassImpl.java:886)

   at   groovy.lang.Closure.call(Closure.java:276)

   at   groovy.util.slurpersupport.NodeChildren.find(NodeChildren.java:194)

   at   sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)

   at   sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)

   at   sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)

   at   java.lang.reflect.Method.invoke(Method.java:597)

   at   org.codehaus.groovy.reflection.CachedMethod.invoke(CachedMethod.java:88)
Exception: example                                                                                                                message
org.codehaus.groovy.runtime.InvokerInvocationException: groovy.lang.MissingMethodException: No signature of method:
groovy.util.slurpersupport.Attributes.textd() is applicable for argument types: () values: []
Possible solutions: text(), text(), text(), getAt(groovy.lang.IntRange), getAt(int), getAt(java.lang.String)

   at   org.codehaus.groovy.reflection.CachedMethod.invoke(CachedMethod.java:95)

   at   groovy.lang.MetaMethod.doMethodInvoke(MetaMethod.java:233)

   at   groovy.lang.MetaClassImpl.setProperty(MetaClassImpl.java:2395)

   at   groovy.lang.MetaClassImpl.setProperty(MetaClassImpl.java:3315)

   at   groovy.lang.MetaClassImpl.setProperties(MetaClassImpl.java:1499)

   at   groovy.lang.MetaClassImpl.invokeConstructor(MetaClassImpl.java:1476)

   at   groovy.lang.MetaClassImpl.invokeConstructor(MetaClassImpl.java:1397)

   at   org.codehaus.groovy.runtime.InvokerHelper.invokeConstructorOf(InvokerHelper.java:824)

   at   org.codehaus.groovy.runtime.typehandling.DefaultTypeTransformation.castToType(DefaultTypeTransformation.java:313)

   at   org.codehaus.groovy.runtime.ScriptBytecodeAdapter.castToType(ScriptBytecodeAdapter.java:602)


   at unige.mpb.eop.proteomics.uniprot.UniprotEntrySplicerTest.setUp(UniprotEntrySplicerTest.groovy:16)

   at   junit.framework.TestCase.runBare(TestCase.java:128)

   at   junit.framework.TestResult$1.protect(TestResult.java:106)

   at   junit.framework.TestResult.runProtected(TestResult.java:124)





    at
    at
    at
    at
    at
         junit.framework.TestResult.run(TestResult.java:109)
         junit.framework.TestCase.run(TestCase.java:120)
         junit.framework.TestSuite.runTest(TestSuite.java:230)
         junit.framework.TestSuite.run(TestSuite.java:225)
         org.eclipse.jdt.internal.junit.runner.junit3.JUnit3TestReference.run(JUnit3TestReference.java:130)
                                                                                                                             cause(s) cascade

   at   org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)

   at   org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:467)

   at   org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:683)

   at   org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:390)

   at   org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:197)

Caused by: groovy.lang.MissingMethodException: No signature of method: groovy.util.slurpersupport.Attributes.textd()
is applicable for argument types: () values: []
Possible solutions: text(), text(), text(), getAt(groovy.lang.IntRange), getAt(int), getAt(java.lang.String)

   at   org.codehaus.groovy.runtime.ScriptBytecodeAdapter.unwrap(ScriptBytecodeAdapter.java:54)

   at   org.codehaus.groovy.runtime.callsite.PogoMetaClassSite.call(PogoMetaClassSite.java:51)

   at   org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCall(CallSiteArray.java:40)

   at   org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:116)

   at   org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:120)


   at unige.mpb.eop.proteomics.uniprot.UniprotEntrySplicer
$_extractIsoformDescriptors_closure1.doCall(UniprotEntrySplicer.groovy:64)

   at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)

   at   sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)

   at   sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)

   at   java.lang.reflect.Method.invoke(Method.java:597)

   at   org.codehaus.groovy.reflection.CachedMethod.invoke(CachedMethod.java:88)

   at   groovy.lang.MetaMethod.doMethodInvoke(MetaMethod.java:233)

   at   org.codehaus.groovy.runtime.metaclass.ClosureMetaClass.invokeMethod(ClosureMetaClass.java:273)

   at   groovy.lang.MetaClassImpl.invokeMethod(MetaClassImpl.java:886)

   at   groovy.lang.Closure.call(Closure.java:276)

   at   groovy.util.slurpersupport.NodeChildren.find(NodeChildren.java:194)

   at   sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)

   at   sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)

   at   sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)

   at   java.lang.reflect.Method.invoke(Method.java:597)

   at   org.codehaus.groovy.reflection.CachedMethod.invoke(CachedMethod.java:88)
Exception: example                                                                                                           message
org.codehaus.groovy.runtime.InvokerInvocationException: groovy.lang.MissingMethodException: No signature of method:
groovy.util.slurpersupport.Attributes.textd() is applicable for argument types: () values: []
Possible solutions: text(), text(), text(), getAt(groovy.lang.IntRange), getAt(int), getAt(java.lang.String)

   at   org.codehaus.groovy.reflection.CachedMethod.invoke(CachedMethod.java:95)

   at   groovy.lang.MetaMethod.doMethodInvoke(MetaMethod.java:233)

   at   groovy.lang.MetaClassImpl.setProperty(MetaClassImpl.java:2395)

   at   groovy.lang.MetaClassImpl.setProperty(MetaClassImpl.java:3315)

   at   groovy.lang.MetaClassImpl.setProperties(MetaClassImpl.java:1499)

   at   groovy.lang.MetaClassImpl.invokeConstructor(MetaClassImpl.java:1476)

   at   groovy.lang.MetaClassImpl.invokeConstructor(MetaClassImpl.java:1397)

   at   org.codehaus.groovy.runtime.InvokerHelper.invokeConstructorOf(InvokerHelper.java:824)

   at   org.codehaus.groovy.runtime.typehandling.DefaultTypeTransformation.castToType(DefaultTypeTransformation.java:313)

   at   org.codehaus.groovy.runtime.ScriptBytecodeAdapter.castToType(ScriptBytecodeAdapter.java:602)


   at unige.mpb.eop.proteomics.uniprot.UniprotEntrySplicerTest.setUp(UniprotEntrySplicerTest.groovy:16)

   at   junit.framework.TestCase.runBare(TestCase.java:128)

   at   junit.framework.TestResult$1.protect(TestResult.java:106)

   at   junit.framework.TestResult.runProtected(TestResult.java:124)





    at
    at
    at
    at
    at
         junit.framework.TestResult.run(TestResult.java:109)
         junit.framework.TestCase.run(TestCase.java:120)
         junit.framework.TestSuite.runTest(TestSuite.java:230)
         junit.framework.TestSuite.run(TestSuite.java:225)
                                                                                             exception name
         org.eclipse.jdt.internal.junit.runner.junit3.JUnit3TestReference.run(JUnit3TestReference.java:130)
                                                                                                            cause(s) cascade

   at   org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)

   at   org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:467)

   at   org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:683)

   at   org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:390)

   at   org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:197)

Caused by: groovy.lang.MissingMethodException: No signature of method: groovy.util.slurpersupport.Attributes.textd()
is applicable for argument types: () values: []
Possible solutions: text(), text(), text(), getAt(groovy.lang.IntRange), getAt(int), getAt(java.lang.String)

   at   org.codehaus.groovy.runtime.ScriptBytecodeAdapter.unwrap(ScriptBytecodeAdapter.java:54)

   at   org.codehaus.groovy.runtime.callsite.PogoMetaClassSite.call(PogoMetaClassSite.java:51)

   at   org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCall(CallSiteArray.java:40)

   at   org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:116)

   at   org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:120)


   at unige.mpb.eop.proteomics.uniprot.UniprotEntrySplicer
$_extractIsoformDescriptors_closure1.doCall(UniprotEntrySplicer.groovy:64)

   at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)

   at   sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)

   at   sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)

   at   java.lang.reflect.Method.invoke(Method.java:597)

   at   org.codehaus.groovy.reflection.CachedMethod.invoke(CachedMethod.java:88)

   at   groovy.lang.MetaMethod.doMethodInvoke(MetaMethod.java:233)

   at   org.codehaus.groovy.runtime.metaclass.ClosureMetaClass.invokeMethod(ClosureMetaClass.java:273)

   at   groovy.lang.MetaClassImpl.invokeMethod(MetaClassImpl.java:886)

   at   groovy.lang.Closure.call(Closure.java:276)

   at   groovy.util.slurpersupport.NodeChildren.find(NodeChildren.java:194)

   at   sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)

   at   sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)

   at   sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)

   at   java.lang.reflect.Method.invoke(Method.java:597)

   at   org.codehaus.groovy.reflection.CachedMethod.invoke(CachedMethod.java:88)
Exception: example                                                                                                                    message
org.codehaus.groovy.runtime.InvokerInvocationException: groovy.lang.MissingMethodException: No signature of method:
groovy.util.slurpersupport.Attributes.textd() is applicable for argument types: () values: []
Possible solutions: text(), text(), text(), getAt(groovy.lang.IntRange), getAt(int), getAt(java.lang.String)

   at   org.codehaus.groovy.reflection.CachedMethod.invoke(CachedMethod.java:95)

   at   groovy.lang.MetaMethod.doMethodInvoke(MetaMethod.java:233)

   at   groovy.lang.MetaClassImpl.setProperty(MetaClassImpl.java:2395)

   at   groovy.lang.MetaClassImpl.setProperty(MetaClassImpl.java:3315)

   at   groovy.lang.MetaClassImpl.setProperties(MetaClassImpl.java:1499)

   at   groovy.lang.MetaClassImpl.invokeConstructor(MetaClassImpl.java:1476)

   at   groovy.lang.MetaClassImpl.invokeConstructor(MetaClassImpl.java:1397)

   at   org.codehaus.groovy.runtime.InvokerHelper.invokeConstructorOf(InvokerHelper.java:824)

   at   org.codehaus.groovy.runtime.typehandling.DefaultTypeTransformation.castToType(DefaultTypeTransformation.java:313)

   at   org.codehaus.groovy.runtime.ScriptBytecodeAdapter.castToType(ScriptBytecodeAdapter.java:602)


   at unige.mpb.eop.proteomics.uniprot.UniprotEntrySplicerTest.setUp(UniprotEntrySplicerTest.groovy:16)

   at   junit.framework.TestCase.runBare(TestCase.java:128)

   at   junit.framework.TestResult$1.protect(TestResult.java:106)

   at   junit.framework.TestResult.runProtected(TestResult.java:124)





    at
    at
    at
    at
    at
         junit.framework.TestResult.run(TestResult.java:109)
         junit.framework.TestCase.run(TestCase.java:120)
         junit.framework.TestSuite.runTest(TestSuite.java:230)
         junit.framework.TestSuite.run(TestSuite.java:225)
                                                                                             exception name
         org.eclipse.jdt.internal.junit.runner.junit3.JUnit3TestReference.run(JUnit3TestReference.java:130)
                                                                                                            cause(s) cascade

   at   org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)

   at   org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:467)

   at   org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:683)

   at   org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:390)

   at   org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:197)

Caused by: groovy.lang.MissingMethodException: No signature of method: groovy.util.slurpersupport.Attributes.textd()
is applicable for argument types: () values: []
Possible solutions: text(), text(), text(), getAt(groovy.lang.IntRange), getAt(int), getAt(java.lang.String)

   at   org.codehaus.groovy.runtime.ScriptBytecodeAdapter.unwrap(ScriptBytecodeAdapter.java:54)

   at   org.codehaus.groovy.runtime.callsite.PogoMetaClassSite.call(PogoMetaClassSite.java:51)

   at   org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCall(CallSiteArray.java:40)

   at   org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:116)

   at   org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:120)


   at unige.mpb.eop.proteomics.uniprot.UniprotEntrySplicer
$_extractIsoformDescriptors_closure1.doCall(UniprotEntrySplicer.groovy:64)

   at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)




    at
    at
    at
    at
         sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
         sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
         java.lang.reflect.Method.invoke(Method.java:597)
         org.codehaus.groovy.reflection.CachedMethod.invoke(CachedMethod.java:88)
                                                                                                                      search for your packages

   at   groovy.lang.MetaMethod.doMethodInvoke(MetaMethod.java:233)

   at   org.codehaus.groovy.runtime.metaclass.ClosureMetaClass.invokeMethod(ClosureMetaClass.java:273)

   at   groovy.lang.MetaClassImpl.invokeMethod(MetaClassImpl.java:886)

   at   groovy.lang.Closure.call(Closure.java:276)

   at   groovy.util.slurpersupport.NodeChildren.find(NodeChildren.java:194)

   at   sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)

   at   sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)

   at   sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)

   at   java.lang.reflect.Method.invoke(Method.java:597)

   at   org.codehaus.groovy.reflection.CachedMethod.invoke(CachedMethod.java:88)
Exception: example                                                                                                                    message
org.codehaus.groovy.runtime.InvokerInvocationException: groovy.lang.MissingMethodException: No signature of method:
groovy.util.slurpersupport.Attributes.textd() is applicable for argument types: () values: []
Possible solutions: text(), text(), text(), getAt(groovy.lang.IntRange), getAt(int), getAt(java.lang.String)

   at   org.codehaus.groovy.reflection.CachedMethod.invoke(CachedMethod.java:95)

   at   groovy.lang.MetaMethod.doMethodInvoke(MetaMethod.java:233)

   at   groovy.lang.MetaClassImpl.setProperty(MetaClassImpl.java:2395)

   at   groovy.lang.MetaClassImpl.setProperty(MetaClassImpl.java:3315)

   at   groovy.lang.MetaClassImpl.setProperties(MetaClassImpl.java:1499)

   at   groovy.lang.MetaClassImpl.invokeConstructor(MetaClassImpl.java:1476)

   at   groovy.lang.MetaClassImpl.invokeConstructor(MetaClassImpl.java:1397)

   at   org.codehaus.groovy.runtime.InvokerHelper.invokeConstructorOf(InvokerHelper.java:824)

   at   org.codehaus.groovy.runtime.typehandling.DefaultTypeTransformation.castToType(DefaultTypeTransformation.java:313)

   at   org.codehaus.groovy.runtime.ScriptBytecodeAdapter.castToType(ScriptBytecodeAdapter.java:602)


   at unige.mpb.eop.proteomics.uniprot.UniprotEntrySplicerTest.setUp(UniprotEntrySplicerTest.groovy:16)

   at   junit.framework.TestCase.runBare(TestCase.java:128)

   at   junit.framework.TestResult$1.protect(TestResult.java:106)

   at   junit.framework.TestResult.runProtected(TestResult.java:124)





    at
    at
    at
    at
    at
         junit.framework.TestResult.run(TestResult.java:109)
         junit.framework.TestCase.run(TestCase.java:120)
         junit.framework.TestSuite.runTest(TestSuite.java:230)
         junit.framework.TestSuite.run(TestSuite.java:225)
                                                                                             exception name
         org.eclipse.jdt.internal.junit.runner.junit3.JUnit3TestReference.run(JUnit3TestReference.java:130)
                                                                                                            cause(s) cascade

   at   org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)

   at   org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:467)

   at   org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:683)

   at   org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:390)

   at   org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:197)

Caused by: groovy.lang.MissingMethodException: No signature of method: groovy.util.slurpersupport.Attributes.textd()
is applicable for argument types: () values: []
Possible solutions: text(), text(), text(), getAt(groovy.lang.IntRange), getAt(int), getAt(java.lang.String)

   at   org.codehaus.groovy.runtime.ScriptBytecodeAdapter.unwrap(ScriptBytecodeAdapter.java:54)

   at   org.codehaus.groovy.runtime.callsite.PogoMetaClassSite.call(PogoMetaClassSite.java:51)

   at   org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCall(CallSiteArray.java:40)

   at   org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:116)

   at   org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:120)


   at unige.mpb.eop.proteomics.uniprot.UniprotEntrySplicer
$_extractIsoformDescriptors_closure1.doCall(UniprotEntrySplicer.groovy:64)

   at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)




    at
    at
    at
    at
         sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
         sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
         java.lang.reflect.Method.invoke(Method.java:597)
         org.codehaus.groovy.reflection.CachedMethod.invoke(CachedMethod.java:88)
                                                                                                                      search for your packages

   at   groovy.lang.MetaMethod.doMethodInvoke(MetaMethod.java:233)

   at   org.codehaus.groovy.runtime.metaclass.ClosureMetaClass.invokeMethod(ClosureMetaClass.java:273)


                                                                                               code line number

   at   groovy.lang.MetaClassImpl.invokeMethod(MetaClassImpl.java:886)

   at   groovy.lang.Closure.call(Closure.java:276)

   at   groovy.util.slurpersupport.NodeChildren.find(NodeChildren.java:194)

   at   sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)

   at   sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)

   at   sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)

   at   java.lang.reflect.Method.invoke(Method.java:597)

   at   org.codehaus.groovy.reflection.CachedMethod.invoke(CachedMethod.java:88)
Exceptions: surviving & using

‣ In exceptional situations, an event is thrown
 def list = ['a', 'b', 'c']
 def x = list[-5]
Exceptions: surviving & using

‣ In exceptional situations, an event is thrown
 def list = ['a', 'b', 'c']
 def x = list[-5]
‣ Output
   java.lang.ArrayIndexOutOfBoundsException:
   Negative array index [-5] too large for array size 3
 
   at ConsoleScript7.run(ConsoleScript7:3)
Exceptions: surviving & using

‣ In exceptional situations, an event is thrown
 def list = ['a', 'b', 'c']
 def x = list[-5]
‣ Output
   java.lang.ArrayIndexOutOfBoundsException:
   Negative array index [-5] too large for array size 3
 
   at ConsoleScript7.run(ConsoleScript7:3)
‣ An exception carries three types of information:

  - nature: through it’s class (extends Exception),
  - message: detailing the circumstances of the incident
  - stack trace: the stack of classes (possibly with line number) to track
    where the exception was thrown
Catching exceptions: try / catch

‣ An exception does not mean exiting the program (default behavior)
Catching exceptions: try / catch

‣ An exception does not mean exiting the program (default behavior)
‣ It is possible to catch an exception
 def list = ['10', 'a', '20', '30']
 [1, 2, 5, 3, 4].each{ i ->
         println "$it"+list[-i].toInteger()
 }
 println “coincoin”
Catching exceptions: try / catch

‣ An exception does not mean exiting the program (default behavior)
‣ It is possible to catch an exception   impossible!!!
 def list = ['10', 'a', '20', '30']
 [1, 2, 5, 3, 4].each{ i ->
         println "$it"+list[-i].toInteger()
 }
 println “coincoin”
Catching exceptions: try / catch

‣ An exception does not mean exiting the program (default behavior)
‣ It is possible to catch an exception   impossible!!!
 def list = ['10', 'a', '20', '30']
 [1, 2, 5, 3, 4].each{ i ->
         println "$it"+list[-i].toInteger()
 }
 println “coincoin”
‣ Output
 1
30
 2
20
 java.lang.ArrayIndexOutOfBoundsException: Negative array
 index [-5] too large for array size 4
 
 at ConsoleScript17$_run_closure1.doCall(ConsoleScript17:3)
 
 at ConsoleScript17.run(ConsoleScript17:2)
 and exit (with code > 0)
Catching exceptions: try / catch

‣ An exception does not mean exiting the program (default behavior)
‣ It is possible to catch an exception   impossible!!!
 def list = ['10', 'a', '20', '30']
 [1, 2, 5, 3, 4].each{ i ->
         println "$it"+list[-i].toInteger()
 }
 println “coincoin”
‣ Output
 1
30                          this line is never reached
 2
20
 java.lang.ArrayIndexOutOfBoundsException: Negative array
 index [-5] too large for array size 4
 
 at ConsoleScript17$_run_closure1.doCall(ConsoleScript17:3)
 
 at ConsoleScript17.run(ConsoleScript17:2)
 and exit (with code > 0)
Catching exceptions: try / catch
                           (cont’d)

‣ Surround the piece of code you want to secure with try/catch
 def list = ['10', 'a', '20', '30']
 try{
     [1, 2, 5, 3, 4].each{ i ->
         println "$it"+list[-i].toInteger()
     }
 }catch(Exception e){
    println "error: " + e.message
 }
 println “coincoin”
Catching exceptions: try / catch
                           (cont’d)

‣ Surround the piece of code you want to secure with try/catch
 def list = ['10', 'a', '20', '30']
 try{
     [1, 2, 5, 3, 4].each{ i ->
         println "$it"+list[-i].toInteger()
     }
 }catch(Exception e){
    println "error: " + e.message
 }
 println “coincoin”
‣ Output
 1
30
 2
20
 error: Negative array index [-5] too large for array size 4
 coincoin
Catching exceptions: try / catch
             (cont’d)



def list = ['10', 'a', '20', '30']
try{
    [1, 2, 5, 3, 4].each{ i ->
        println "$it"+list[-i].toInteger()
    }
}catch(Exception e){
   println "error: " + e.message
}
println “coincoin”
Catching exceptions: try / catch
                  (cont’d)



def list = ['10', 'a', '20', '30']
try{
    [1, 2, 5, 3, 4].each{ i ->
        println "$it"+list[-i].toInteger()
    }
}catch(Exception e){               exit the loop
   println "error: " + e.message
}
println “coincoin”
Goal: catch exceptions but continue the loop




                                               13
Catching exceptions: try / catch
   (cont’d)

‣ Adapt the depth of catching
Catching exceptions: try / catch
                                  (cont’d)

‣ Adapt the depth of catching
‣ In the following case, the iteration will continue after an exception is caught
 def list = ['10', 'a', '20', '30']
 [1, 2, 5, 3, 4].each{ i ->
    try{
         println "$it"+list[-i].toInteger()
    }catch(Exception e){
         println "error with ($i): "+e.message
    }
  }
Catching exceptions: try / catch
                                  (cont’d)

‣ Adapt the depth of catching
‣ In the following case, the iteration will continue after an exception is caught
 def list = ['10', 'a', '20', '30']
 [1, 2, 5, 3, 4].each{ i ->
    try{
         println "$it"+list[-i].toInteger()
    }catch(Exception e){
         println "error with ($i): "+e.message
    }
  }
‣ Output
 1
30
 2
20
 error with (5): Negative array index [-5] too        large for array size 4
 error with (3): For input string: "a"
 4
10
catch(Exception e)
is generic (all exceptions are caught)




                                         15
Goal: catch specific exceptions




                                  16
Catching exceptions: try / catch
                    (cont’d)

‣ You can catch only certain classes of Exception
 def list = ['10', 'a', '20', '30']
 [1, 2, 5, 3, 4].each{ i ->
    try{
         println "$it"+list[-i].toInteger()
         }catch(ArrayIndexOutOfBoundsException e){
           println "error with ($i): "+e.message
     }
 }
Catching exceptions: try / catch
                    (cont’d)

‣ You can catch only certain classes of Exception
 def list = ['10', 'a', '20', '30']
 [1, 2, 5, 3, 4].each{ i ->
    try{
         println "$it"+list[-i].toInteger()
         }catch(ArrayIndexOutOfBoundsException e){
           println "error with ($i): "+e.message
     }
 }

‣ Output
 1
30
 2
20
 error with (5): Negative array index [-5] too large for
 array size 4
 + unrecovered stack trace and exit because of
 java.lang.NumberFormatException
=> code exits
Catching exceptions: try / catch
                 (cont’d)

‣ Or even cascade catching
 def list = ['10', 'a', '20', '30']
 [1, 2, 5, 3, 4].each{ i ->
    try{
         println "$it"+list[-i].toInteger()
    }catch(ArrayIndexOutOfBoundsException e){
         println "out of bound!"
    }catch(NumberFormatException e){
         println "cannot to convert '${list[-i]}' to int"
    }
 }
Catching exceptions: try / catch
                 (cont’d)

‣ Or even cascade catching
 def list = ['10', 'a', '20', '30']
 [1, 2, 5, 3, 4].each{ i ->
    try{
         println "$it"+list[-i].toInteger()
    }catch(ArrayIndexOutOfBoundsException e){
         println "out of bound!"
    }catch(NumberFormatException e){
         println "cannot to convert '${list[-i]}' to int"
    }
 }
‣ Output
 1
30
 2
20
 out of bound!
 cannot to convert 'a' to int
 4
10
Throwing your Exception

‣ In some situation, it is powerful to throw an exception in your code (to be
  hopefully caught at a meaningful place...)
Throwing your Exception

‣ In some situation, it is powerful to throw an exception in your code (to be
  hopefully caught at a meaningful place...)
‣ Example:
  - you are in the third level of nested function when some illegal action happens,
  - you do not want to manage all the return statements of your functions up to
    the place where the high level action is to be undertaken
  - you want to carry a meaningful message
Throwing your Exception

‣ In some situation, it is powerful to throw an exception in your code (to be
  hopefully caught at a meaningful place...)
‣ Example:
  - you are in the third level of nested function when some illegal action happens,
  - you do not want to manage all the return statements of your functions up to
    the place where the high level action is to be undertaken
  - you want to carry a meaningful message
‣ Example
 int factorial(int n){
   if(n<0)
     throw new RuntimeException(“cannot pass negative value
 ($n)”)
   //continue
 }
Throwing your Exception

int factorial(int n){
  if(n<0)
     throw new RuntimeException(“cannot pass negative value
($n)”)
  //continue
}
def computeFactorial(int n){
  if(n>100)
      return -1
  factorial(n)
}
//Script
try{
   computeFactorial(i)
}catch(Exception e){....}
Throwing your Exception

int factorial(int n){
  if(n<0)
     throw new RuntimeException(“cannot pass negative value
($n)”)
  //continue
}
def computeFactorial(int n){
  if(n>100)
     throw new IllegalArgumentException(“no fact for >100”)
  factorial(n)
}
//Script
try{
   computeFactorial(i)
}catch(Exception e){....}
Throwing your Exception

‣ You code is more clear & robust:
  - 10 lines per function limits complex if / else construct.
Throwing your Exception

‣ You code is more clear & robust:
  - 10 lines per function limits complex if / else construct.
‣ Document the exception that can be thrown in your function header
  comment
 /**
 ...
 @Throws RuntimeException if argument is negative
 */
Throwing your Exception

‣ You code is more clear & robust:
  - 10 lines per function limits complex if / else construct.
‣ Document the exception that can be thrown in your function header
  comment
 /**
 ...
 @Throws RuntimeException if argument is negative
 */
‣ Make the message meaningful.
Throwing your Exception

‣ You code is more clear & robust:
  - 10 lines per function limits complex if / else construct.
‣ Document the exception that can be thrown in your function header
  comment
 /**
 ...
 @Throws RuntimeException if argument is negative
 */
‣ Make the message meaningful.
‣ You can create your own Exception class that extends whatever existing
  Exception:

  - to have generic behavior or catch only your own exception.
Copying an Object

‣ We want to copy a list, then modify its copy without altering the original
 def l_1 = ('a'..'e').toList()
 def l_2 = l_1

 l_2[2] = 'Z'
 println "l_1t$l_1"
 println "l_2t$l_2"
Copying an Object

‣ We want to copy a list, then modify its copy without altering the original
 def l_1 = ('a'..'e').toList()
 def l_2 = l_1

 l_2[2] = 'Z'
 println "l_1t$l_1"
 println "l_2t$l_2"
‣ Output
 l_1
 [a, b, Z, d, e]            // arghhh! we have a ‘Z’ in l_1
 l_2
 [a, b, Z, d, e]
Copying an Object

‣ We want to copy a list, then modify its copy without altering the original
 def l_1 = ('a'..'e').toList()
 def l_2 = l_1

 l_2[2] = 'Z'
 println "l_1t$l_1"
 println "l_2t$l_2"
‣ Output
 l_1
 [a, b, Z, d, e]            // arghhh! we have a ‘Z’ in l_1
 l_2
 [a, b, Z, d, e]
‣ We do not copy all elements of l_1 to l_2, but rather let l_2 be a
  reference to the same Object as l_1
Copying an Object

‣ We want to copy a list, then modify its copy without altering the original
 def l_1 = ('a'..'e').toList()
 def l_2 = l_1

 l_2[2] = 'Z'
 println "l_1t$l_1"
 println "l_2t$l_2"
‣ Output
 l_1
 [a, b, Z, d, e]            // arghhh! we have a ‘Z’ in l_1
 l_2
 [a, b, Z, d, e]
‣ We do not copy all elements of l_1 to l_2, but rather let l_2 be a
  reference to the same Object as l_1

‣ Modifying l_1 modifies l_2 as a side effect
Copying an Object

‣ We want to copy a list, then modify its copy without altering the original
 def l_1 = ('a'..'e').toList()
 def l_2 = l_1

 l_2[2] = 'Z'
 println "l_1t$l_1"
 println "l_2t$l_2"
‣ Output
 l_1
 [a, b, Z, d, e]            // arghhh! we have a ‘Z’ in l_1
 l_2
 [a, b, Z, d, e]
‣ We do not copy all elements of l_1 to l_2, but rather let l_2 be a
  reference to the same Object as l_1

‣ Modifying l_1 modifies l_2 as a side effect
‣ This feature can be meaningful (memory, consistency...)
Cloning an Object: o.clone()

‣ The solution is to explicitly clone the object
 def l_1 = ('a'..'e').toList()
 def l_2 = l_1.clone()
 l_2[2] = 'Z'
 println "l_1t$l_1"
 println "l_2t$l_2"
Cloning an Object: o.clone()

‣ The solution is to explicitly clone the object
 def l_1 = ('a'..'e').toList()
 def l_2 = l_1.clone()
 l_2[2] = 'Z'
 println "l_1t$l_1"
 println "l_2t$l_2"
‣ Output
 l_1
 [a, b, c, d, e]
 l_2
 [a, b, Z, d, e]
Cloning an Object: o.clone()

‣ The solution is to explicitly clone the object
 def l_1 = ('a'..'e').toList()
 def l_2 = l_1.clone()
 l_2[2] = 'Z'
 println "l_1t$l_1"
 println "l_2t$l_2"
‣ Output
 l_1
 [a, b, c, d, e]
 l_2
 [a, b, Z, d, e]
‣ l_1 is effectively duplicated: further modifications on l_2 do not alter l_1
Cloning an Object                          (cont’d)

‣ The same applies to a class
 class Foo{
     String name
     List values
 }
 Foo f_1=[name:'donald', values:[1,2,3]]
 Foo f_2=f_1
 f_2.name='mickey'

 println "f_1t$f_1.namet$f_1.values"
 println "f_2t$f_2.namet$f_2.values"
Cloning an Object                          (cont’d)

‣ The same applies to a class
 class Foo{
     String name
     List values
 }
 Foo f_1=[name:'donald', values:[1,2,3]]
 Foo f_2=f_1
 f_2.name='mickey'

 println "f_1t$f_1.namet$f_1.values"
 println "f_2t$f_2.namet$f_2.values"
‣ Output
 f_1
 mickey
     [1, 2, 3]
 f_2
 mickey
     [1, 2, 3]
Cloning an Object                               (cont’d)




‣ If we try
 f_2 = f_1.clone()
‣ We obtain
 java.lang.CloneNotSupportedException: Foo
 
 at ConsoleScript39.run(ConsoleScript39:13)
We need to define what we mean by cloneable




                                              27
Cloning an Object                                        (cont’d)



‣ The class Foo must implements an interface Cloneable
 class Foo implements Cloneable{
   String name
   List values

     Foo clone(){
       return new Foo(‘name’: name, ‘values’: values.clone())
     }    //explicitly duplicate all fields
 }
Cloning an Object                                        (cont’d)



‣ The class Foo must implements an interface Cloneable
 class Foo implements Cloneable{
   String name
   List values

     Foo clone(){
       return new Foo(‘name’: name, ‘values’: values.clone())
     }    //explicitly duplicate all fields
 }
Cloning an Object   (cont’d)
Cloning an Object                          (cont’d)

‣ We can now safely clone
 Foo f_1=[name:'donald', values:[1,2,3]]
 Foo f_2=f_1.clone()

 f_2.name='mickey'
 f_2.values[1] = 9

 println "f_1t$f_1.namet$f_1.values"
 println "f_2t$f_2.namet$f_2.values"
Cloning an Object                          (cont’d)

‣ We can now safely clone
 Foo f_1=[name:'donald', values:[1,2,3]]
 Foo f_2=f_1.clone()

 f_2.name='mickey'
 f_2.values[1] = 9

 println "f_1t$f_1.namet$f_1.values"
 println "f_2t$f_2.namet$f_2.values"
‣ Output
 f_1
 donald
     [1, 2, 3]
 f_2
 mickey
     [1, 9, 3]
OOP : Interface




‣ An interface is a manner to specify what behavior(s) a class should
  have, without writing any specific code
OOP : Interface




‣ An interface is a manner to specify what behavior(s) a class should
  have, without writing any specific code
‣ A class later implements the interface, thus it is enforced to fulfill the
  mentioned mechanism
How to make a class enforce a behavior?




                                          31
Interface examples

‣ Two examples we already met
Interface examples

‣ Two examples we already met
‣ objects can be compared with <, <=, == etc.
 class MyClass implements Comparable{
   ...
   int compareTo(o){
     ...
   }
 }
Interface examples

‣ Two examples we already met
‣ objects can be compared with <, <=, == etc.
 class MyClass implements Comparable{
   ...
   int compareTo(o){
     ...
   }
 }
‣ objects can be duplicated safely
 class MyClass implements Cloneable{
   ...
   MyClass clone(){
     ...
   }
 }
Interface examples

‣ They can be combined
Interface examples

‣ They can be combined
‣ objects can be compared and cloned
 class MyClass implements Comparable, Cloneable{
   ...
   int compareTo(o){
     ...
   }
   MyClass clone(){
     ...
   }
 }
How to define an interface?




                              34
Interface definition



‣ Like a class file (class is replaced by interface)
Interface definition



‣ Like a class file (class is replaced by interface)
‣ There is no execution code inside the file (on specification)
Interface definition



‣ Like a class file (class is replaced by interface)
‣ There is no execution code inside the file (on specification)
‣ File HasSequence.groovy
 interface HasSequence{
   String getSequence();
   String fastaString();
 }
Interface definition



‣ class file then need to implements those two methods Protein.groovy
 class Protein implements HasSequence{
   String accessionCode
   String sequence   //getSequence() will be automatically
                     //defined

     String fastaString(){
        “>$accessionCoden$sequencen”
     }
 }
Interface versus Abstraction

interface MyInterface {...}
abstract class MyAbstractClass{...}
Interface versus Abstraction

 interface MyInterface {...}
 abstract class MyAbstractClass{...}
‣ Syntax
 class MyClass implements MyInterface{...}
 class MyClass extends MyAbstractClass{...}
Interface versus Abstraction

 interface MyInterface {...}
 abstract class MyAbstractClass{...}
‣ Syntax
 class MyClass implements MyInterface{...}
 class MyClass extends MyAbstractClass{...}
‣ interface cannot contains explicit code (only specifications)
Interface versus Abstraction

 interface MyInterface {...}
 abstract class MyAbstractClass{...}
‣ Syntax
 class MyClass implements MyInterface{...}
 class MyClass extends MyAbstractClass{...}
‣ interface cannot contains explicit code (only specifications)
‣ abstract class contains explicit code (see AminoAcidSequence), but can
  also contain abstract methods (to be implemented by children classes)
Interface versus Abstraction

 interface MyInterface {...}
 abstract class MyAbstractClass{...}
‣ Syntax
 class MyClass implements MyInterface{...}
 class MyClass extends MyAbstractClass{...}
‣ interface cannot contains explicit code (only specifications)
‣ abstract class contains explicit code (see AminoAcidSequence), but can
  also contain abstract methods (to be implemented by children classes)
‣ A class can implements several interfaces, but only one abstract parent
Interface versus Abstraction




‣ Dynamic typing in groovy => interfaces not as important as in java
Interface versus Abstraction




‣ Dynamic typing in groovy => interfaces not as important as in java
‣ Strengthen the code readability and safety
 List<HasSequence> ....

More Related Content

What's hot

Contextual communications and why you should care - Droidcon DE
Contextual communications and why you should care - Droidcon DEContextual communications and why you should care - Droidcon DE
Contextual communications and why you should care - Droidcon DEMarcos Placona
 
Oredev 2015 - Taming Java Agents
Oredev 2015 - Taming Java AgentsOredev 2015 - Taming Java Agents
Oredev 2015 - Taming Java AgentsAnton Arhipov
 
Voxxed Days Vilnius 2015 - Having fun with Javassist
Voxxed Days Vilnius 2015 - Having fun with JavassistVoxxed Days Vilnius 2015 - Having fun with Javassist
Voxxed Days Vilnius 2015 - Having fun with JavassistAnton Arhipov
 
Riga Dev Day 2016 - Having fun with Javassist
Riga Dev Day 2016 - Having fun with JavassistRiga Dev Day 2016 - Having fun with Javassist
Riga Dev Day 2016 - Having fun with JavassistAnton Arhipov
 
ProGuard / DexGuard Tips and Tricks
ProGuard / DexGuard Tips and TricksProGuard / DexGuard Tips and Tricks
ProGuard / DexGuard Tips and Tricksnetomi
 
Apache Groovy: the language and the ecosystem
Apache Groovy: the language and the ecosystemApache Groovy: the language and the ecosystem
Apache Groovy: the language and the ecosystemKostas Saidis
 
exploit-writing-tutorial-part-5-how-debugger-modules-plugins-can-speed-up-bas...
exploit-writing-tutorial-part-5-how-debugger-modules-plugins-can-speed-up-bas...exploit-writing-tutorial-part-5-how-debugger-modules-plugins-can-speed-up-bas...
exploit-writing-tutorial-part-5-how-debugger-modules-plugins-can-speed-up-bas...tutorialsruby
 
GTAC Boosting your Testing Productivity with Groovy
GTAC Boosting your Testing Productivity with GroovyGTAC Boosting your Testing Productivity with Groovy
GTAC Boosting your Testing Productivity with GroovyAndres Almiray
 
JEEConf 2017 - The hitchhiker’s guide to Java class reloading
JEEConf 2017 - The hitchhiker’s guide to Java class reloadingJEEConf 2017 - The hitchhiker’s guide to Java class reloading
JEEConf 2017 - The hitchhiker’s guide to Java class reloadingAnton Arhipov
 
Building a java tracer
Building a java tracerBuilding a java tracer
Building a java tracerrahulrevo
 
Jersey framework
Jersey frameworkJersey framework
Jersey frameworkknight1128
 
YAPC::NA 2007 - Customizing And Extending Perl Critic
YAPC::NA 2007 - Customizing And Extending Perl CriticYAPC::NA 2007 - Customizing And Extending Perl Critic
YAPC::NA 2007 - Customizing And Extending Perl Criticjoshua.mcadams
 
JavaOne 2015 - Having fun with Javassist
JavaOne 2015 - Having fun with JavassistJavaOne 2015 - Having fun with Javassist
JavaOne 2015 - Having fun with JavassistAnton Arhipov
 
Much ado about randomness. What is really a random number?
Much ado about randomness. What is really a random number?Much ado about randomness. What is really a random number?
Much ado about randomness. What is really a random number?Aleksandr Yampolskiy
 
Con-FESS 2015 - Having Fun With Javassist
Con-FESS 2015 - Having Fun With JavassistCon-FESS 2015 - Having Fun With Javassist
Con-FESS 2015 - Having Fun With JavassistAnton Arhipov
 
Java and OpenJDK: disecting the ecosystem
Java and OpenJDK: disecting the ecosystemJava and OpenJDK: disecting the ecosystem
Java and OpenJDK: disecting the ecosystemRafael Winterhalter
 

What's hot (20)

Contextual communications and why you should care - Droidcon DE
Contextual communications and why you should care - Droidcon DEContextual communications and why you should care - Droidcon DE
Contextual communications and why you should care - Droidcon DE
 
Oredev 2015 - Taming Java Agents
Oredev 2015 - Taming Java AgentsOredev 2015 - Taming Java Agents
Oredev 2015 - Taming Java Agents
 
GMock framework
GMock frameworkGMock framework
GMock framework
 
Voxxed Days Vilnius 2015 - Having fun with Javassist
Voxxed Days Vilnius 2015 - Having fun with JavassistVoxxed Days Vilnius 2015 - Having fun with Javassist
Voxxed Days Vilnius 2015 - Having fun with Javassist
 
Riga Dev Day 2016 - Having fun with Javassist
Riga Dev Day 2016 - Having fun with JavassistRiga Dev Day 2016 - Having fun with Javassist
Riga Dev Day 2016 - Having fun with Javassist
 
ProGuard / DexGuard Tips and Tricks
ProGuard / DexGuard Tips and TricksProGuard / DexGuard Tips and Tricks
ProGuard / DexGuard Tips and Tricks
 
Apache Groovy: the language and the ecosystem
Apache Groovy: the language and the ecosystemApache Groovy: the language and the ecosystem
Apache Groovy: the language and the ecosystem
 
exploit-writing-tutorial-part-5-how-debugger-modules-plugins-can-speed-up-bas...
exploit-writing-tutorial-part-5-how-debugger-modules-plugins-can-speed-up-bas...exploit-writing-tutorial-part-5-how-debugger-modules-plugins-can-speed-up-bas...
exploit-writing-tutorial-part-5-how-debugger-modules-plugins-can-speed-up-bas...
 
Roboguice
RoboguiceRoboguice
Roboguice
 
GTAC Boosting your Testing Productivity with Groovy
GTAC Boosting your Testing Productivity with GroovyGTAC Boosting your Testing Productivity with Groovy
GTAC Boosting your Testing Productivity with Groovy
 
JEEConf 2017 - The hitchhiker’s guide to Java class reloading
JEEConf 2017 - The hitchhiker’s guide to Java class reloadingJEEConf 2017 - The hitchhiker’s guide to Java class reloading
JEEConf 2017 - The hitchhiker’s guide to Java class reloading
 
Building a java tracer
Building a java tracerBuilding a java tracer
Building a java tracer
 
Jersey framework
Jersey frameworkJersey framework
Jersey framework
 
YAPC::NA 2007 - Customizing And Extending Perl Critic
YAPC::NA 2007 - Customizing And Extending Perl CriticYAPC::NA 2007 - Customizing And Extending Perl Critic
YAPC::NA 2007 - Customizing And Extending Perl Critic
 
JavaOne 2015 - Having fun with Javassist
JavaOne 2015 - Having fun with JavassistJavaOne 2015 - Having fun with Javassist
JavaOne 2015 - Having fun with Javassist
 
Much ado about randomness. What is really a random number?
Much ado about randomness. What is really a random number?Much ado about randomness. What is really a random number?
Much ado about randomness. What is really a random number?
 
Con-FESS 2015 - Having Fun With Javassist
Con-FESS 2015 - Having Fun With JavassistCon-FESS 2015 - Having Fun With Javassist
Con-FESS 2015 - Having Fun With Javassist
 
Testing Spring Applications
Testing Spring ApplicationsTesting Spring Applications
Testing Spring Applications
 
Java and OpenJDK: disecting the ecosystem
Java and OpenJDK: disecting the ecosystemJava and OpenJDK: disecting the ecosystem
Java and OpenJDK: disecting the ecosystem
 
Java 10, Java 11 and beyond
Java 10, Java 11 and beyondJava 10, Java 11 and beyond
Java 10, Java 11 and beyond
 

Viewers also liked

AWS Paris Summit 2014 - T4 - Créez votre PaaS avec AWS
AWS Paris Summit 2014 - T4 - Créez votre PaaS avec AWSAWS Paris Summit 2014 - T4 - Créez votre PaaS avec AWS
AWS Paris Summit 2014 - T4 - Créez votre PaaS avec AWSAmazon Web Services
 
Scale and Reach: Always Up - Always On - AWS Symposium 2014 - Washington D.C....
Scale and Reach: Always Up - Always On - AWS Symposium 2014 - Washington D.C....Scale and Reach: Always Up - Always On - AWS Symposium 2014 - Washington D.C....
Scale and Reach: Always Up - Always On - AWS Symposium 2014 - Washington D.C....Amazon Web Services
 
Journey Through the Cloud - Digital Media
Journey Through the Cloud - Digital MediaJourney Through the Cloud - Digital Media
Journey Through the Cloud - Digital MediaAmazon Web Services
 
AWS Summit London 2014 | Introduction to Amazon EC2 (100)
AWS Summit London 2014 | Introduction to Amazon EC2 (100)AWS Summit London 2014 | Introduction to Amazon EC2 (100)
AWS Summit London 2014 | Introduction to Amazon EC2 (100)Amazon Web Services
 
AWS Webcast - Explore the AWS Cloud
AWS Webcast - Explore the AWS CloudAWS Webcast - Explore the AWS Cloud
AWS Webcast - Explore the AWS CloudAmazon Web Services
 

Viewers also liked (6)

Jvm2
Jvm2Jvm2
Jvm2
 
AWS Paris Summit 2014 - T4 - Créez votre PaaS avec AWS
AWS Paris Summit 2014 - T4 - Créez votre PaaS avec AWSAWS Paris Summit 2014 - T4 - Créez votre PaaS avec AWS
AWS Paris Summit 2014 - T4 - Créez votre PaaS avec AWS
 
Scale and Reach: Always Up - Always On - AWS Symposium 2014 - Washington D.C....
Scale and Reach: Always Up - Always On - AWS Symposium 2014 - Washington D.C....Scale and Reach: Always Up - Always On - AWS Symposium 2014 - Washington D.C....
Scale and Reach: Always Up - Always On - AWS Symposium 2014 - Washington D.C....
 
Journey Through the Cloud - Digital Media
Journey Through the Cloud - Digital MediaJourney Through the Cloud - Digital Media
Journey Through the Cloud - Digital Media
 
AWS Summit London 2014 | Introduction to Amazon EC2 (100)
AWS Summit London 2014 | Introduction to Amazon EC2 (100)AWS Summit London 2014 | Introduction to Amazon EC2 (100)
AWS Summit London 2014 | Introduction to Amazon EC2 (100)
 
AWS Webcast - Explore the AWS Cloud
AWS Webcast - Explore the AWS CloudAWS Webcast - Explore the AWS Cloud
AWS Webcast - Explore the AWS Cloud
 

Similar to groovy & grails - lecture 7

Metaprogramming with Groovy
Metaprogramming with GroovyMetaprogramming with Groovy
Metaprogramming with GroovyAli Tanwir
 
Metaprogramming Rails
Metaprogramming RailsMetaprogramming Rails
Metaprogramming RailsJustus Eapen
 
New Ideas for Old Code - Greach
New Ideas for Old Code - GreachNew Ideas for Old Code - Greach
New Ideas for Old Code - GreachHamletDRC
 
Bring the fun back to java
Bring the fun back to javaBring the fun back to java
Bring the fun back to javaciklum_ods
 
Concurrency in Eclipse: Best Practices and Gotchas
Concurrency in Eclipse: Best Practices and GotchasConcurrency in Eclipse: Best Practices and Gotchas
Concurrency in Eclipse: Best Practices and Gotchasamccullo
 
JAVASCRIPT TDD(Test driven Development) & Qunit Tutorial
JAVASCRIPT TDD(Test driven Development) & Qunit TutorialJAVASCRIPT TDD(Test driven Development) & Qunit Tutorial
JAVASCRIPT TDD(Test driven Development) & Qunit TutorialAnup Singh
 
Java 7 - New Features - by Mihail Stoynov and Svetlin Nakov
Java 7 - New Features - by Mihail Stoynov and Svetlin NakovJava 7 - New Features - by Mihail Stoynov and Svetlin Nakov
Java 7 - New Features - by Mihail Stoynov and Svetlin NakovSvetlin Nakov
 
Mockito with a hint of PowerMock
Mockito with a hint of PowerMockMockito with a hint of PowerMock
Mockito with a hint of PowerMockYing Zhang
 
[MOPCON2018] Effectively shrink ProGuard rules for reducing APK size
[MOPCON2018] Effectively shrink ProGuard rules for reducing APK size[MOPCON2018] Effectively shrink ProGuard rules for reducing APK size
[MOPCON2018] Effectively shrink ProGuard rules for reducing APK sizeAnsgar Lin
 
Inside the JVM - Follow the white rabbit!
Inside the JVM - Follow the white rabbit!Inside the JVM - Follow the white rabbit!
Inside the JVM - Follow the white rabbit!Sylvain Wallez
 
Groovy in the Enterprise - Case Studies - TSSJS Prague 2008 - Guillaume Laforge
Groovy in the Enterprise - Case Studies - TSSJS Prague 2008 - Guillaume LaforgeGroovy in the Enterprise - Case Studies - TSSJS Prague 2008 - Guillaume Laforge
Groovy in the Enterprise - Case Studies - TSSJS Prague 2008 - Guillaume LaforgeGuillaume Laforge
 
Xopus Application Framework
Xopus Application FrameworkXopus Application Framework
Xopus Application FrameworkJady Yang
 

Similar to groovy & grails - lecture 7 (20)

Java Quiz Questions
Java Quiz QuestionsJava Quiz Questions
Java Quiz Questions
 
Metaprogramming with Groovy
Metaprogramming with GroovyMetaprogramming with Groovy
Metaprogramming with Groovy
 
MetaProgramming with Groovy
MetaProgramming with GroovyMetaProgramming with Groovy
MetaProgramming with Groovy
 
Metaprogramming Rails
Metaprogramming RailsMetaprogramming Rails
Metaprogramming Rails
 
New Ideas for Old Code - Greach
New Ideas for Old Code - GreachNew Ideas for Old Code - Greach
New Ideas for Old Code - Greach
 
Java Quiz - Meetup
Java Quiz - MeetupJava Quiz - Meetup
Java Quiz - Meetup
 
Mastering Java ByteCode
Mastering Java ByteCodeMastering Java ByteCode
Mastering Java ByteCode
 
Test Driven In Groovy
Test Driven In GroovyTest Driven In Groovy
Test Driven In Groovy
 
Bring the fun back to java
Bring the fun back to javaBring the fun back to java
Bring the fun back to java
 
Exploring lambdas and invokedynamic for embedded systems
Exploring lambdas and invokedynamic for embedded systemsExploring lambdas and invokedynamic for embedded systems
Exploring lambdas and invokedynamic for embedded systems
 
Svcc Groovy Testing
Svcc Groovy TestingSvcc Groovy Testing
Svcc Groovy Testing
 
Junit_.pptx
Junit_.pptxJunit_.pptx
Junit_.pptx
 
Concurrency in Eclipse: Best Practices and Gotchas
Concurrency in Eclipse: Best Practices and GotchasConcurrency in Eclipse: Best Practices and Gotchas
Concurrency in Eclipse: Best Practices and Gotchas
 
JAVASCRIPT TDD(Test driven Development) & Qunit Tutorial
JAVASCRIPT TDD(Test driven Development) & Qunit TutorialJAVASCRIPT TDD(Test driven Development) & Qunit Tutorial
JAVASCRIPT TDD(Test driven Development) & Qunit Tutorial
 
Java 7 - New Features - by Mihail Stoynov and Svetlin Nakov
Java 7 - New Features - by Mihail Stoynov and Svetlin NakovJava 7 - New Features - by Mihail Stoynov and Svetlin Nakov
Java 7 - New Features - by Mihail Stoynov and Svetlin Nakov
 
Mockito with a hint of PowerMock
Mockito with a hint of PowerMockMockito with a hint of PowerMock
Mockito with a hint of PowerMock
 
[MOPCON2018] Effectively shrink ProGuard rules for reducing APK size
[MOPCON2018] Effectively shrink ProGuard rules for reducing APK size[MOPCON2018] Effectively shrink ProGuard rules for reducing APK size
[MOPCON2018] Effectively shrink ProGuard rules for reducing APK size
 
Inside the JVM - Follow the white rabbit!
Inside the JVM - Follow the white rabbit!Inside the JVM - Follow the white rabbit!
Inside the JVM - Follow the white rabbit!
 
Groovy in the Enterprise - Case Studies - TSSJS Prague 2008 - Guillaume Laforge
Groovy in the Enterprise - Case Studies - TSSJS Prague 2008 - Guillaume LaforgeGroovy in the Enterprise - Case Studies - TSSJS Prague 2008 - Guillaume Laforge
Groovy in the Enterprise - Case Studies - TSSJS Prague 2008 - Guillaume Laforge
 
Xopus Application Framework
Xopus Application FrameworkXopus Application Framework
Xopus Application Framework
 

More from Alexandre Masselot

Offshoring software development in Switzerland: You can do it
Offshoring software development in Switzerland: You can do itOffshoring software development in Switzerland: You can do it
Offshoring software development in Switzerland: You can do itAlexandre Masselot
 
Dev Wednesday - Swiss Transport in Real Time: Tribulations in the Big Data Stack
Dev Wednesday - Swiss Transport in Real Time: Tribulations in the Big Data StackDev Wednesday - Swiss Transport in Real Time: Tribulations in the Big Data Stack
Dev Wednesday - Swiss Transport in Real Time: Tribulations in the Big Data StackAlexandre Masselot
 
Swiss Transport in Real Time: Tribulations in the Big Data Stack
Swiss Transport in Real Time: Tribulations in the Big Data StackSwiss Transport in Real Time: Tribulations in the Big Data Stack
Swiss Transport in Real Time: Tribulations in the Big Data StackAlexandre Masselot
 

More from Alexandre Masselot (15)

Offshoring software development in Switzerland: You can do it
Offshoring software development in Switzerland: You can do itOffshoring software development in Switzerland: You can do it
Offshoring software development in Switzerland: You can do it
 
Dev Wednesday - Swiss Transport in Real Time: Tribulations in the Big Data Stack
Dev Wednesday - Swiss Transport in Real Time: Tribulations in the Big Data StackDev Wednesday - Swiss Transport in Real Time: Tribulations in the Big Data Stack
Dev Wednesday - Swiss Transport in Real Time: Tribulations in the Big Data Stack
 
Swiss Transport in Real Time: Tribulations in the Big Data Stack
Swiss Transport in Real Time: Tribulations in the Big Data StackSwiss Transport in Real Time: Tribulations in the Big Data Stack
Swiss Transport in Real Time: Tribulations in the Big Data Stack
 
groovy & grails - lecture 8
groovy & grails - lecture 8groovy & grails - lecture 8
groovy & grails - lecture 8
 
groovy & grails - lecture 10
groovy & grails - lecture 10groovy & grails - lecture 10
groovy & grails - lecture 10
 
groovy & grails - lecture 2
groovy & grails - lecture 2groovy & grails - lecture 2
groovy & grails - lecture 2
 
groovy & grails - lecture 1
groovy & grails - lecture 1groovy & grails - lecture 1
groovy & grails - lecture 1
 
groovy & grails - lecture 11
groovy & grails - lecture 11groovy & grails - lecture 11
groovy & grails - lecture 11
 
groovy & grails - lecture 12
groovy & grails - lecture 12groovy & grails - lecture 12
groovy & grails - lecture 12
 
groovy & grails - lecture 13
groovy & grails - lecture 13groovy & grails - lecture 13
groovy & grails - lecture 13
 
groovy & grails - lecture 9
groovy & grails - lecture 9groovy & grails - lecture 9
groovy & grails - lecture 9
 
groovy & grails - lecture 6
groovy & grails - lecture 6groovy & grails - lecture 6
groovy & grails - lecture 6
 
groovy & grails - lecture 5
groovy & grails - lecture 5groovy & grails - lecture 5
groovy & grails - lecture 5
 
groovy & grails - lecture 4
groovy & grails - lecture 4groovy & grails - lecture 4
groovy & grails - lecture 4
 
groovy & grails - lecture 3
groovy & grails - lecture 3groovy & grails - lecture 3
groovy & grails - lecture 3
 

Recently uploaded

Top 5 Benefits OF Using Muvi Live Paywall For Live Streams
Top 5 Benefits OF Using Muvi Live Paywall For Live StreamsTop 5 Benefits OF Using Muvi Live Paywall For Live Streams
Top 5 Benefits OF Using Muvi Live Paywall For Live StreamsRoshan Dwivedi
 
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Igalia
 
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slidevu2urc
 
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...Neo4j
 
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptxHampshireHUG
 
IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsEnterprise Knowledge
 
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfThe Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfEnterprise Knowledge
 
Salesforce Community Group Quito, Salesforce 101
Salesforce Community Group Quito, Salesforce 101Salesforce Community Group Quito, Salesforce 101
Salesforce Community Group Quito, Salesforce 101Paola De la Torre
 
Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024The Digital Insurer
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024The Digital Insurer
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc
 
[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdfhans926745
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘RTylerCroy
 
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEarley Information Science
 
Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024The Digital Insurer
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerThousandEyes
 
Presentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreterPresentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreternaman860154
 
Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)Allon Mureinik
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Drew Madelung
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationSafe Software
 

Recently uploaded (20)

Top 5 Benefits OF Using Muvi Live Paywall For Live Streams
Top 5 Benefits OF Using Muvi Live Paywall For Live StreamsTop 5 Benefits OF Using Muvi Live Paywall For Live Streams
Top 5 Benefits OF Using Muvi Live Paywall For Live Streams
 
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
 
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slide
 
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
 
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
 
IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI Solutions
 
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfThe Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
 
Salesforce Community Group Quito, Salesforce 101
Salesforce Community Group Quito, Salesforce 101Salesforce Community Group Quito, Salesforce 101
Salesforce Community Group Quito, Salesforce 101
 
Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
 
[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘
 
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
 
Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
Presentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreterPresentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreter
 
Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
 

groovy & grails - lecture 7

  • 1. Groovy: Efficiency Oriented Programming Lecture 7 Master Proteomics & Bioinformatics - University of Geneva Alexandre Masselot - summer 2011
  • 2. Contents ‣ Eclipse tips ‣ Productivity tip: back to TDD ‣ Exceptions throwing and catching ‣ reference to object and cloning ‣ OOP: interface
  • 3. Eclipse tips ‣ STS (Springsource Tool Suite) dashboard: - keep aware of what is new in the STS environment (new releases, new plugins, technologies, future webinars...) - help > dashboard
  • 4. Eclipse tips ‣ STS (Springsource Tool Suite) dashboard: - keep aware of what is new in the STS environment (new releases, new plugins, technologies, future webinars...) - help > dashboard ‣ Jump directly in junit view - run junit tests <alt> <shift> X T - jump to junit window <shift> <alt> Q U - configure your shortcuts with preferences > filter “keys” > filter junit - use multi screen to put console or junit view on the secondary display (drag the view tab and drop it on the secondary display)
  • 5. 4
  • 6. Productivity : TDD ‣ Test Driven Development
  • 7. Productivity : TDD ‣ Test Driven Development ‣ Even for a simple task (over 10 lines!) - write a simple class (in the same directory if you wish) - split the behavior of your problem into simple methods - test every method
  • 8. Productivity : TDD ‣ Test Driven Development ‣ Even for a simple task (over 10 lines!) - write a simple class (in the same directory if you wish) - split the behavior of your problem into simple methods - test every method Do not rely on println to develop/understand your code
  • 9. Exceptions: using & surviving 6
  • 11. Exception: example org.codehaus.groovy.runtime.InvokerInvocationException: groovy.lang.MissingMethodException: No signature of method: groovy.util.slurpersupport.Attributes.textd() is applicable for argument types: () values: [] Possible solutions: text(), text(), text(), getAt(groovy.lang.IntRange), getAt(int), getAt(java.lang.String) at org.codehaus.groovy.reflection.CachedMethod.invoke(CachedMethod.java:95) at groovy.lang.MetaMethod.doMethodInvoke(MetaMethod.java:233) at groovy.lang.MetaClassImpl.setProperty(MetaClassImpl.java:2395) at groovy.lang.MetaClassImpl.setProperty(MetaClassImpl.java:3315) at groovy.lang.MetaClassImpl.setProperties(MetaClassImpl.java:1499) at groovy.lang.MetaClassImpl.invokeConstructor(MetaClassImpl.java:1476) at groovy.lang.MetaClassImpl.invokeConstructor(MetaClassImpl.java:1397) at org.codehaus.groovy.runtime.InvokerHelper.invokeConstructorOf(InvokerHelper.java:824) at org.codehaus.groovy.runtime.typehandling.DefaultTypeTransformation.castToType(DefaultTypeTransformation.java: 313) at org.codehaus.groovy.runtime.ScriptBytecodeAdapter.castToType(ScriptBytecodeAdapter.java:602) at unige.mpb.eop.proteomics.uniprot.UniprotEntrySplicerTest.setUp(UniprotEntrySplicerTest.groovy:16) at junit.framework.TestCase.runBare(TestCase.java:128) at junit.framework.TestResult$1.protect(TestResult.java:106) at junit.framework.TestResult.runProtected(TestResult.java:124) at junit.framework.TestResult.run(TestResult.java:109) at junit.framework.TestCase.run(TestCase.java:120) at junit.framework.TestSuite.runTest(TestSuite.java:230) at junit.framework.TestSuite.run(TestSuite.java:225) at org.eclipse.jdt.internal.junit.runner.junit3.JUnit3TestReference.run(JUnit3TestReference.java:130) at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38) at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:467) at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:683) at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:390) at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:197) Caused by: groovy.lang.MissingMethodException: No signature of method: groovy.util.slurpersupport.Attributes.textd() is applicable for argument types: () values: [] Possible solutions: text(), text(), text(), getAt(groovy.lang.IntRange), getAt(int), getAt(java.lang.String) at org.codehaus.groovy.runtime.ScriptBytecodeAdapter.unwrap(ScriptBytecodeAdapter.java:54)
  • 12. Exception: example org.codehaus.groovy.runtime.InvokerInvocationException: groovy.lang.MissingMethodException: No signature of method: groovy.util.slurpersupport.Attributes.textd() is applicable for argument types: () values: [] Possible solutions: text(), text(), text(), getAt(groovy.lang.IntRange), getAt(int), getAt(java.lang.String) at org.codehaus.groovy.reflection.CachedMethod.invoke(CachedMethod.java:95) at groovy.lang.MetaMethod.doMethodInvoke(MetaMethod.java:233) at groovy.lang.MetaClassImpl.setProperty(MetaClassImpl.java:2395) at groovy.lang.MetaClassImpl.setProperty(MetaClassImpl.java:3315) at groovy.lang.MetaClassImpl.setProperties(MetaClassImpl.java:1499) at groovy.lang.MetaClassImpl.invokeConstructor(MetaClassImpl.java:1476) at groovy.lang.MetaClassImpl.invokeConstructor(MetaClassImpl.java:1397) at org.codehaus.groovy.runtime.InvokerHelper.invokeConstructorOf(InvokerHelper.java:824) at org.codehaus.groovy.runtime.typehandling.DefaultTypeTransformation.castToType(DefaultTypeTransformation.java:313) at org.codehaus.groovy.runtime.ScriptBytecodeAdapter.castToType(ScriptBytecodeAdapter.java:602) at unige.mpb.eop.proteomics.uniprot.UniprotEntrySplicerTest.setUp(UniprotEntrySplicerTest.groovy:16) at junit.framework.TestCase.runBare(TestCase.java:128) at junit.framework.TestResult$1.protect(TestResult.java:106) at junit.framework.TestResult.runProtected(TestResult.java:124) at junit.framework.TestResult.run(TestResult.java:109) at junit.framework.TestCase.run(TestCase.java:120) at junit.framework.TestSuite.runTest(TestSuite.java:230) at junit.framework.TestSuite.run(TestSuite.java:225) at org.eclipse.jdt.internal.junit.runner.junit3.JUnit3TestReference.run(JUnit3TestReference.java:130) at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38) at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:467) at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:683) at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:390) at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:197) Caused by: groovy.lang.MissingMethodException: No signature of method: groovy.util.slurpersupport.Attributes.textd() is applicable for argument types: () values: [] Possible solutions: text(), text(), text(), getAt(groovy.lang.IntRange), getAt(int), getAt(java.lang.String) at org.codehaus.groovy.runtime.ScriptBytecodeAdapter.unwrap(ScriptBytecodeAdapter.java:54) at org.codehaus.groovy.runtime.callsite.PogoMetaClassSite.call(PogoMetaClassSite.java:51) at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCall(CallSiteArray.java:40) at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:116) at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:120) at unige.mpb.eop.proteomics.uniprot.UniprotEntrySplicer $_extractIsoformDescriptors_closure1.doCall(UniprotEntrySplicer.groovy:64) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25) at java.lang.reflect.Method.invoke(Method.java:597) at org.codehaus.groovy.reflection.CachedMethod.invoke(CachedMethod.java:88) at groovy.lang.MetaMethod.doMethodInvoke(MetaMethod.java:233) at org.codehaus.groovy.runtime.metaclass.ClosureMetaClass.invokeMethod(ClosureMetaClass.java:273) at groovy.lang.MetaClassImpl.invokeMethod(MetaClassImpl.java:886) at groovy.lang.Closure.call(Closure.java:276) at groovy.util.slurpersupport.NodeChildren.find(NodeChildren.java:194) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25) at java.lang.reflect.Method.invoke(Method.java:597) at org.codehaus.groovy.reflection.CachedMethod.invoke(CachedMethod.java:88)
  • 13. Exception: example message org.codehaus.groovy.runtime.InvokerInvocationException: groovy.lang.MissingMethodException: No signature of method: groovy.util.slurpersupport.Attributes.textd() is applicable for argument types: () values: [] Possible solutions: text(), text(), text(), getAt(groovy.lang.IntRange), getAt(int), getAt(java.lang.String) at org.codehaus.groovy.reflection.CachedMethod.invoke(CachedMethod.java:95) at groovy.lang.MetaMethod.doMethodInvoke(MetaMethod.java:233) at groovy.lang.MetaClassImpl.setProperty(MetaClassImpl.java:2395) at groovy.lang.MetaClassImpl.setProperty(MetaClassImpl.java:3315) at groovy.lang.MetaClassImpl.setProperties(MetaClassImpl.java:1499) at groovy.lang.MetaClassImpl.invokeConstructor(MetaClassImpl.java:1476) at groovy.lang.MetaClassImpl.invokeConstructor(MetaClassImpl.java:1397) at org.codehaus.groovy.runtime.InvokerHelper.invokeConstructorOf(InvokerHelper.java:824) at org.codehaus.groovy.runtime.typehandling.DefaultTypeTransformation.castToType(DefaultTypeTransformation.java:313) at org.codehaus.groovy.runtime.ScriptBytecodeAdapter.castToType(ScriptBytecodeAdapter.java:602) at unige.mpb.eop.proteomics.uniprot.UniprotEntrySplicerTest.setUp(UniprotEntrySplicerTest.groovy:16) at junit.framework.TestCase.runBare(TestCase.java:128) at junit.framework.TestResult$1.protect(TestResult.java:106) at junit.framework.TestResult.runProtected(TestResult.java:124) at junit.framework.TestResult.run(TestResult.java:109) at junit.framework.TestCase.run(TestCase.java:120) at junit.framework.TestSuite.runTest(TestSuite.java:230) at junit.framework.TestSuite.run(TestSuite.java:225) at org.eclipse.jdt.internal.junit.runner.junit3.JUnit3TestReference.run(JUnit3TestReference.java:130) at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38) at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:467) at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:683) at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:390) at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:197) Caused by: groovy.lang.MissingMethodException: No signature of method: groovy.util.slurpersupport.Attributes.textd() is applicable for argument types: () values: [] Possible solutions: text(), text(), text(), getAt(groovy.lang.IntRange), getAt(int), getAt(java.lang.String) at org.codehaus.groovy.runtime.ScriptBytecodeAdapter.unwrap(ScriptBytecodeAdapter.java:54) at org.codehaus.groovy.runtime.callsite.PogoMetaClassSite.call(PogoMetaClassSite.java:51) at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCall(CallSiteArray.java:40) at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:116) at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:120) at unige.mpb.eop.proteomics.uniprot.UniprotEntrySplicer $_extractIsoformDescriptors_closure1.doCall(UniprotEntrySplicer.groovy:64) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25) at java.lang.reflect.Method.invoke(Method.java:597) at org.codehaus.groovy.reflection.CachedMethod.invoke(CachedMethod.java:88) at groovy.lang.MetaMethod.doMethodInvoke(MetaMethod.java:233) at org.codehaus.groovy.runtime.metaclass.ClosureMetaClass.invokeMethod(ClosureMetaClass.java:273) at groovy.lang.MetaClassImpl.invokeMethod(MetaClassImpl.java:886) at groovy.lang.Closure.call(Closure.java:276) at groovy.util.slurpersupport.NodeChildren.find(NodeChildren.java:194) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25) at java.lang.reflect.Method.invoke(Method.java:597) at org.codehaus.groovy.reflection.CachedMethod.invoke(CachedMethod.java:88)
  • 14. Exception: example message org.codehaus.groovy.runtime.InvokerInvocationException: groovy.lang.MissingMethodException: No signature of method: groovy.util.slurpersupport.Attributes.textd() is applicable for argument types: () values: [] Possible solutions: text(), text(), text(), getAt(groovy.lang.IntRange), getAt(int), getAt(java.lang.String) at org.codehaus.groovy.reflection.CachedMethod.invoke(CachedMethod.java:95) at groovy.lang.MetaMethod.doMethodInvoke(MetaMethod.java:233) at groovy.lang.MetaClassImpl.setProperty(MetaClassImpl.java:2395) at groovy.lang.MetaClassImpl.setProperty(MetaClassImpl.java:3315) at groovy.lang.MetaClassImpl.setProperties(MetaClassImpl.java:1499) at groovy.lang.MetaClassImpl.invokeConstructor(MetaClassImpl.java:1476) at groovy.lang.MetaClassImpl.invokeConstructor(MetaClassImpl.java:1397) at org.codehaus.groovy.runtime.InvokerHelper.invokeConstructorOf(InvokerHelper.java:824) at org.codehaus.groovy.runtime.typehandling.DefaultTypeTransformation.castToType(DefaultTypeTransformation.java:313) at org.codehaus.groovy.runtime.ScriptBytecodeAdapter.castToType(ScriptBytecodeAdapter.java:602) at unige.mpb.eop.proteomics.uniprot.UniprotEntrySplicerTest.setUp(UniprotEntrySplicerTest.groovy:16) at junit.framework.TestCase.runBare(TestCase.java:128) at junit.framework.TestResult$1.protect(TestResult.java:106) at junit.framework.TestResult.runProtected(TestResult.java:124) at at at at at junit.framework.TestResult.run(TestResult.java:109) junit.framework.TestCase.run(TestCase.java:120) junit.framework.TestSuite.runTest(TestSuite.java:230) junit.framework.TestSuite.run(TestSuite.java:225) org.eclipse.jdt.internal.junit.runner.junit3.JUnit3TestReference.run(JUnit3TestReference.java:130) cause(s) cascade at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38) at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:467) at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:683) at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:390) at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:197) Caused by: groovy.lang.MissingMethodException: No signature of method: groovy.util.slurpersupport.Attributes.textd() is applicable for argument types: () values: [] Possible solutions: text(), text(), text(), getAt(groovy.lang.IntRange), getAt(int), getAt(java.lang.String) at org.codehaus.groovy.runtime.ScriptBytecodeAdapter.unwrap(ScriptBytecodeAdapter.java:54) at org.codehaus.groovy.runtime.callsite.PogoMetaClassSite.call(PogoMetaClassSite.java:51) at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCall(CallSiteArray.java:40) at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:116) at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:120) at unige.mpb.eop.proteomics.uniprot.UniprotEntrySplicer $_extractIsoformDescriptors_closure1.doCall(UniprotEntrySplicer.groovy:64) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25) at java.lang.reflect.Method.invoke(Method.java:597) at org.codehaus.groovy.reflection.CachedMethod.invoke(CachedMethod.java:88) at groovy.lang.MetaMethod.doMethodInvoke(MetaMethod.java:233) at org.codehaus.groovy.runtime.metaclass.ClosureMetaClass.invokeMethod(ClosureMetaClass.java:273) at groovy.lang.MetaClassImpl.invokeMethod(MetaClassImpl.java:886) at groovy.lang.Closure.call(Closure.java:276) at groovy.util.slurpersupport.NodeChildren.find(NodeChildren.java:194) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25) at java.lang.reflect.Method.invoke(Method.java:597) at org.codehaus.groovy.reflection.CachedMethod.invoke(CachedMethod.java:88)
  • 15. Exception: example message org.codehaus.groovy.runtime.InvokerInvocationException: groovy.lang.MissingMethodException: No signature of method: groovy.util.slurpersupport.Attributes.textd() is applicable for argument types: () values: [] Possible solutions: text(), text(), text(), getAt(groovy.lang.IntRange), getAt(int), getAt(java.lang.String) at org.codehaus.groovy.reflection.CachedMethod.invoke(CachedMethod.java:95) at groovy.lang.MetaMethod.doMethodInvoke(MetaMethod.java:233) at groovy.lang.MetaClassImpl.setProperty(MetaClassImpl.java:2395) at groovy.lang.MetaClassImpl.setProperty(MetaClassImpl.java:3315) at groovy.lang.MetaClassImpl.setProperties(MetaClassImpl.java:1499) at groovy.lang.MetaClassImpl.invokeConstructor(MetaClassImpl.java:1476) at groovy.lang.MetaClassImpl.invokeConstructor(MetaClassImpl.java:1397) at org.codehaus.groovy.runtime.InvokerHelper.invokeConstructorOf(InvokerHelper.java:824) at org.codehaus.groovy.runtime.typehandling.DefaultTypeTransformation.castToType(DefaultTypeTransformation.java:313) at org.codehaus.groovy.runtime.ScriptBytecodeAdapter.castToType(ScriptBytecodeAdapter.java:602) at unige.mpb.eop.proteomics.uniprot.UniprotEntrySplicerTest.setUp(UniprotEntrySplicerTest.groovy:16) at junit.framework.TestCase.runBare(TestCase.java:128) at junit.framework.TestResult$1.protect(TestResult.java:106) at junit.framework.TestResult.runProtected(TestResult.java:124) at at at at at junit.framework.TestResult.run(TestResult.java:109) junit.framework.TestCase.run(TestCase.java:120) junit.framework.TestSuite.runTest(TestSuite.java:230) junit.framework.TestSuite.run(TestSuite.java:225) exception name org.eclipse.jdt.internal.junit.runner.junit3.JUnit3TestReference.run(JUnit3TestReference.java:130) cause(s) cascade at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38) at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:467) at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:683) at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:390) at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:197) Caused by: groovy.lang.MissingMethodException: No signature of method: groovy.util.slurpersupport.Attributes.textd() is applicable for argument types: () values: [] Possible solutions: text(), text(), text(), getAt(groovy.lang.IntRange), getAt(int), getAt(java.lang.String) at org.codehaus.groovy.runtime.ScriptBytecodeAdapter.unwrap(ScriptBytecodeAdapter.java:54) at org.codehaus.groovy.runtime.callsite.PogoMetaClassSite.call(PogoMetaClassSite.java:51) at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCall(CallSiteArray.java:40) at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:116) at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:120) at unige.mpb.eop.proteomics.uniprot.UniprotEntrySplicer $_extractIsoformDescriptors_closure1.doCall(UniprotEntrySplicer.groovy:64) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25) at java.lang.reflect.Method.invoke(Method.java:597) at org.codehaus.groovy.reflection.CachedMethod.invoke(CachedMethod.java:88) at groovy.lang.MetaMethod.doMethodInvoke(MetaMethod.java:233) at org.codehaus.groovy.runtime.metaclass.ClosureMetaClass.invokeMethod(ClosureMetaClass.java:273) at groovy.lang.MetaClassImpl.invokeMethod(MetaClassImpl.java:886) at groovy.lang.Closure.call(Closure.java:276) at groovy.util.slurpersupport.NodeChildren.find(NodeChildren.java:194) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25) at java.lang.reflect.Method.invoke(Method.java:597) at org.codehaus.groovy.reflection.CachedMethod.invoke(CachedMethod.java:88)
  • 16. Exception: example message org.codehaus.groovy.runtime.InvokerInvocationException: groovy.lang.MissingMethodException: No signature of method: groovy.util.slurpersupport.Attributes.textd() is applicable for argument types: () values: [] Possible solutions: text(), text(), text(), getAt(groovy.lang.IntRange), getAt(int), getAt(java.lang.String) at org.codehaus.groovy.reflection.CachedMethod.invoke(CachedMethod.java:95) at groovy.lang.MetaMethod.doMethodInvoke(MetaMethod.java:233) at groovy.lang.MetaClassImpl.setProperty(MetaClassImpl.java:2395) at groovy.lang.MetaClassImpl.setProperty(MetaClassImpl.java:3315) at groovy.lang.MetaClassImpl.setProperties(MetaClassImpl.java:1499) at groovy.lang.MetaClassImpl.invokeConstructor(MetaClassImpl.java:1476) at groovy.lang.MetaClassImpl.invokeConstructor(MetaClassImpl.java:1397) at org.codehaus.groovy.runtime.InvokerHelper.invokeConstructorOf(InvokerHelper.java:824) at org.codehaus.groovy.runtime.typehandling.DefaultTypeTransformation.castToType(DefaultTypeTransformation.java:313) at org.codehaus.groovy.runtime.ScriptBytecodeAdapter.castToType(ScriptBytecodeAdapter.java:602) at unige.mpb.eop.proteomics.uniprot.UniprotEntrySplicerTest.setUp(UniprotEntrySplicerTest.groovy:16) at junit.framework.TestCase.runBare(TestCase.java:128) at junit.framework.TestResult$1.protect(TestResult.java:106) at junit.framework.TestResult.runProtected(TestResult.java:124) at at at at at junit.framework.TestResult.run(TestResult.java:109) junit.framework.TestCase.run(TestCase.java:120) junit.framework.TestSuite.runTest(TestSuite.java:230) junit.framework.TestSuite.run(TestSuite.java:225) exception name org.eclipse.jdt.internal.junit.runner.junit3.JUnit3TestReference.run(JUnit3TestReference.java:130) cause(s) cascade at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38) at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:467) at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:683) at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:390) at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:197) Caused by: groovy.lang.MissingMethodException: No signature of method: groovy.util.slurpersupport.Attributes.textd() is applicable for argument types: () values: [] Possible solutions: text(), text(), text(), getAt(groovy.lang.IntRange), getAt(int), getAt(java.lang.String) at org.codehaus.groovy.runtime.ScriptBytecodeAdapter.unwrap(ScriptBytecodeAdapter.java:54) at org.codehaus.groovy.runtime.callsite.PogoMetaClassSite.call(PogoMetaClassSite.java:51) at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCall(CallSiteArray.java:40) at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:116) at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:120) at unige.mpb.eop.proteomics.uniprot.UniprotEntrySplicer $_extractIsoformDescriptors_closure1.doCall(UniprotEntrySplicer.groovy:64) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at at at at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39) sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25) java.lang.reflect.Method.invoke(Method.java:597) org.codehaus.groovy.reflection.CachedMethod.invoke(CachedMethod.java:88) search for your packages at groovy.lang.MetaMethod.doMethodInvoke(MetaMethod.java:233) at org.codehaus.groovy.runtime.metaclass.ClosureMetaClass.invokeMethod(ClosureMetaClass.java:273) at groovy.lang.MetaClassImpl.invokeMethod(MetaClassImpl.java:886) at groovy.lang.Closure.call(Closure.java:276) at groovy.util.slurpersupport.NodeChildren.find(NodeChildren.java:194) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25) at java.lang.reflect.Method.invoke(Method.java:597) at org.codehaus.groovy.reflection.CachedMethod.invoke(CachedMethod.java:88)
  • 17. Exception: example message org.codehaus.groovy.runtime.InvokerInvocationException: groovy.lang.MissingMethodException: No signature of method: groovy.util.slurpersupport.Attributes.textd() is applicable for argument types: () values: [] Possible solutions: text(), text(), text(), getAt(groovy.lang.IntRange), getAt(int), getAt(java.lang.String) at org.codehaus.groovy.reflection.CachedMethod.invoke(CachedMethod.java:95) at groovy.lang.MetaMethod.doMethodInvoke(MetaMethod.java:233) at groovy.lang.MetaClassImpl.setProperty(MetaClassImpl.java:2395) at groovy.lang.MetaClassImpl.setProperty(MetaClassImpl.java:3315) at groovy.lang.MetaClassImpl.setProperties(MetaClassImpl.java:1499) at groovy.lang.MetaClassImpl.invokeConstructor(MetaClassImpl.java:1476) at groovy.lang.MetaClassImpl.invokeConstructor(MetaClassImpl.java:1397) at org.codehaus.groovy.runtime.InvokerHelper.invokeConstructorOf(InvokerHelper.java:824) at org.codehaus.groovy.runtime.typehandling.DefaultTypeTransformation.castToType(DefaultTypeTransformation.java:313) at org.codehaus.groovy.runtime.ScriptBytecodeAdapter.castToType(ScriptBytecodeAdapter.java:602) at unige.mpb.eop.proteomics.uniprot.UniprotEntrySplicerTest.setUp(UniprotEntrySplicerTest.groovy:16) at junit.framework.TestCase.runBare(TestCase.java:128) at junit.framework.TestResult$1.protect(TestResult.java:106) at junit.framework.TestResult.runProtected(TestResult.java:124) at at at at at junit.framework.TestResult.run(TestResult.java:109) junit.framework.TestCase.run(TestCase.java:120) junit.framework.TestSuite.runTest(TestSuite.java:230) junit.framework.TestSuite.run(TestSuite.java:225) exception name org.eclipse.jdt.internal.junit.runner.junit3.JUnit3TestReference.run(JUnit3TestReference.java:130) cause(s) cascade at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38) at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:467) at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:683) at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:390) at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:197) Caused by: groovy.lang.MissingMethodException: No signature of method: groovy.util.slurpersupport.Attributes.textd() is applicable for argument types: () values: [] Possible solutions: text(), text(), text(), getAt(groovy.lang.IntRange), getAt(int), getAt(java.lang.String) at org.codehaus.groovy.runtime.ScriptBytecodeAdapter.unwrap(ScriptBytecodeAdapter.java:54) at org.codehaus.groovy.runtime.callsite.PogoMetaClassSite.call(PogoMetaClassSite.java:51) at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCall(CallSiteArray.java:40) at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:116) at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:120) at unige.mpb.eop.proteomics.uniprot.UniprotEntrySplicer $_extractIsoformDescriptors_closure1.doCall(UniprotEntrySplicer.groovy:64) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at at at at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39) sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25) java.lang.reflect.Method.invoke(Method.java:597) org.codehaus.groovy.reflection.CachedMethod.invoke(CachedMethod.java:88) search for your packages at groovy.lang.MetaMethod.doMethodInvoke(MetaMethod.java:233) at org.codehaus.groovy.runtime.metaclass.ClosureMetaClass.invokeMethod(ClosureMetaClass.java:273) code line number at groovy.lang.MetaClassImpl.invokeMethod(MetaClassImpl.java:886) at groovy.lang.Closure.call(Closure.java:276) at groovy.util.slurpersupport.NodeChildren.find(NodeChildren.java:194) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25) at java.lang.reflect.Method.invoke(Method.java:597) at org.codehaus.groovy.reflection.CachedMethod.invoke(CachedMethod.java:88)
  • 18. Exceptions: surviving & using ‣ In exceptional situations, an event is thrown def list = ['a', 'b', 'c'] def x = list[-5]
  • 19. Exceptions: surviving & using ‣ In exceptional situations, an event is thrown def list = ['a', 'b', 'c'] def x = list[-5] ‣ Output java.lang.ArrayIndexOutOfBoundsException: Negative array index [-5] too large for array size 3 at ConsoleScript7.run(ConsoleScript7:3)
  • 20. Exceptions: surviving & using ‣ In exceptional situations, an event is thrown def list = ['a', 'b', 'c'] def x = list[-5] ‣ Output java.lang.ArrayIndexOutOfBoundsException: Negative array index [-5] too large for array size 3 at ConsoleScript7.run(ConsoleScript7:3) ‣ An exception carries three types of information: - nature: through it’s class (extends Exception), - message: detailing the circumstances of the incident - stack trace: the stack of classes (possibly with line number) to track where the exception was thrown
  • 21. Catching exceptions: try / catch ‣ An exception does not mean exiting the program (default behavior)
  • 22. Catching exceptions: try / catch ‣ An exception does not mean exiting the program (default behavior) ‣ It is possible to catch an exception def list = ['10', 'a', '20', '30'] [1, 2, 5, 3, 4].each{ i -> println "$it"+list[-i].toInteger() } println “coincoin”
  • 23. Catching exceptions: try / catch ‣ An exception does not mean exiting the program (default behavior) ‣ It is possible to catch an exception impossible!!! def list = ['10', 'a', '20', '30'] [1, 2, 5, 3, 4].each{ i -> println "$it"+list[-i].toInteger() } println “coincoin”
  • 24. Catching exceptions: try / catch ‣ An exception does not mean exiting the program (default behavior) ‣ It is possible to catch an exception impossible!!! def list = ['10', 'a', '20', '30'] [1, 2, 5, 3, 4].each{ i -> println "$it"+list[-i].toInteger() } println “coincoin” ‣ Output 1 30 2 20 java.lang.ArrayIndexOutOfBoundsException: Negative array index [-5] too large for array size 4 at ConsoleScript17$_run_closure1.doCall(ConsoleScript17:3) at ConsoleScript17.run(ConsoleScript17:2) and exit (with code > 0)
  • 25. Catching exceptions: try / catch ‣ An exception does not mean exiting the program (default behavior) ‣ It is possible to catch an exception impossible!!! def list = ['10', 'a', '20', '30'] [1, 2, 5, 3, 4].each{ i -> println "$it"+list[-i].toInteger() } println “coincoin” ‣ Output 1 30 this line is never reached 2 20 java.lang.ArrayIndexOutOfBoundsException: Negative array index [-5] too large for array size 4 at ConsoleScript17$_run_closure1.doCall(ConsoleScript17:3) at ConsoleScript17.run(ConsoleScript17:2) and exit (with code > 0)
  • 26. Catching exceptions: try / catch (cont’d) ‣ Surround the piece of code you want to secure with try/catch def list = ['10', 'a', '20', '30'] try{ [1, 2, 5, 3, 4].each{ i -> println "$it"+list[-i].toInteger() } }catch(Exception e){ println "error: " + e.message } println “coincoin”
  • 27. Catching exceptions: try / catch (cont’d) ‣ Surround the piece of code you want to secure with try/catch def list = ['10', 'a', '20', '30'] try{ [1, 2, 5, 3, 4].each{ i -> println "$it"+list[-i].toInteger() } }catch(Exception e){ println "error: " + e.message } println “coincoin” ‣ Output 1 30 2 20 error: Negative array index [-5] too large for array size 4 coincoin
  • 28. Catching exceptions: try / catch (cont’d) def list = ['10', 'a', '20', '30'] try{ [1, 2, 5, 3, 4].each{ i -> println "$it"+list[-i].toInteger() } }catch(Exception e){ println "error: " + e.message } println “coincoin”
  • 29. Catching exceptions: try / catch (cont’d) def list = ['10', 'a', '20', '30'] try{ [1, 2, 5, 3, 4].each{ i -> println "$it"+list[-i].toInteger() } }catch(Exception e){ exit the loop println "error: " + e.message } println “coincoin”
  • 30. Goal: catch exceptions but continue the loop 13
  • 31. Catching exceptions: try / catch (cont’d) ‣ Adapt the depth of catching
  • 32. Catching exceptions: try / catch (cont’d) ‣ Adapt the depth of catching ‣ In the following case, the iteration will continue after an exception is caught def list = ['10', 'a', '20', '30'] [1, 2, 5, 3, 4].each{ i -> try{ println "$it"+list[-i].toInteger() }catch(Exception e){ println "error with ($i): "+e.message } }
  • 33. Catching exceptions: try / catch (cont’d) ‣ Adapt the depth of catching ‣ In the following case, the iteration will continue after an exception is caught def list = ['10', 'a', '20', '30'] [1, 2, 5, 3, 4].each{ i -> try{ println "$it"+list[-i].toInteger() }catch(Exception e){ println "error with ($i): "+e.message } } ‣ Output 1 30 2 20 error with (5): Negative array index [-5] too large for array size 4 error with (3): For input string: "a" 4 10
  • 34. catch(Exception e) is generic (all exceptions are caught) 15
  • 35. Goal: catch specific exceptions 16
  • 36. Catching exceptions: try / catch (cont’d) ‣ You can catch only certain classes of Exception def list = ['10', 'a', '20', '30'] [1, 2, 5, 3, 4].each{ i -> try{ println "$it"+list[-i].toInteger() }catch(ArrayIndexOutOfBoundsException e){ println "error with ($i): "+e.message } }
  • 37. Catching exceptions: try / catch (cont’d) ‣ You can catch only certain classes of Exception def list = ['10', 'a', '20', '30'] [1, 2, 5, 3, 4].each{ i -> try{ println "$it"+list[-i].toInteger() }catch(ArrayIndexOutOfBoundsException e){ println "error with ($i): "+e.message } } ‣ Output 1 30 2 20 error with (5): Negative array index [-5] too large for array size 4 + unrecovered stack trace and exit because of java.lang.NumberFormatException => code exits
  • 38. Catching exceptions: try / catch (cont’d) ‣ Or even cascade catching def list = ['10', 'a', '20', '30'] [1, 2, 5, 3, 4].each{ i -> try{ println "$it"+list[-i].toInteger() }catch(ArrayIndexOutOfBoundsException e){ println "out of bound!" }catch(NumberFormatException e){ println "cannot to convert '${list[-i]}' to int" } }
  • 39. Catching exceptions: try / catch (cont’d) ‣ Or even cascade catching def list = ['10', 'a', '20', '30'] [1, 2, 5, 3, 4].each{ i -> try{ println "$it"+list[-i].toInteger() }catch(ArrayIndexOutOfBoundsException e){ println "out of bound!" }catch(NumberFormatException e){ println "cannot to convert '${list[-i]}' to int" } } ‣ Output 1 30 2 20 out of bound! cannot to convert 'a' to int 4 10
  • 40. Throwing your Exception ‣ In some situation, it is powerful to throw an exception in your code (to be hopefully caught at a meaningful place...)
  • 41. Throwing your Exception ‣ In some situation, it is powerful to throw an exception in your code (to be hopefully caught at a meaningful place...) ‣ Example: - you are in the third level of nested function when some illegal action happens, - you do not want to manage all the return statements of your functions up to the place where the high level action is to be undertaken - you want to carry a meaningful message
  • 42. Throwing your Exception ‣ In some situation, it is powerful to throw an exception in your code (to be hopefully caught at a meaningful place...) ‣ Example: - you are in the third level of nested function when some illegal action happens, - you do not want to manage all the return statements of your functions up to the place where the high level action is to be undertaken - you want to carry a meaningful message ‣ Example int factorial(int n){ if(n<0) throw new RuntimeException(“cannot pass negative value ($n)”) //continue }
  • 43. Throwing your Exception int factorial(int n){ if(n<0) throw new RuntimeException(“cannot pass negative value ($n)”) //continue } def computeFactorial(int n){ if(n>100) return -1 factorial(n) } //Script try{ computeFactorial(i) }catch(Exception e){....}
  • 44. Throwing your Exception int factorial(int n){ if(n<0) throw new RuntimeException(“cannot pass negative value ($n)”) //continue } def computeFactorial(int n){ if(n>100) throw new IllegalArgumentException(“no fact for >100”) factorial(n) } //Script try{ computeFactorial(i) }catch(Exception e){....}
  • 45. Throwing your Exception ‣ You code is more clear & robust: - 10 lines per function limits complex if / else construct.
  • 46. Throwing your Exception ‣ You code is more clear & robust: - 10 lines per function limits complex if / else construct. ‣ Document the exception that can be thrown in your function header comment /** ... @Throws RuntimeException if argument is negative */
  • 47. Throwing your Exception ‣ You code is more clear & robust: - 10 lines per function limits complex if / else construct. ‣ Document the exception that can be thrown in your function header comment /** ... @Throws RuntimeException if argument is negative */ ‣ Make the message meaningful.
  • 48. Throwing your Exception ‣ You code is more clear & robust: - 10 lines per function limits complex if / else construct. ‣ Document the exception that can be thrown in your function header comment /** ... @Throws RuntimeException if argument is negative */ ‣ Make the message meaningful. ‣ You can create your own Exception class that extends whatever existing Exception: - to have generic behavior or catch only your own exception.
  • 49. Copying an Object ‣ We want to copy a list, then modify its copy without altering the original def l_1 = ('a'..'e').toList() def l_2 = l_1 l_2[2] = 'Z' println "l_1t$l_1" println "l_2t$l_2"
  • 50. Copying an Object ‣ We want to copy a list, then modify its copy without altering the original def l_1 = ('a'..'e').toList() def l_2 = l_1 l_2[2] = 'Z' println "l_1t$l_1" println "l_2t$l_2" ‣ Output l_1 [a, b, Z, d, e] // arghhh! we have a ‘Z’ in l_1 l_2 [a, b, Z, d, e]
  • 51. Copying an Object ‣ We want to copy a list, then modify its copy without altering the original def l_1 = ('a'..'e').toList() def l_2 = l_1 l_2[2] = 'Z' println "l_1t$l_1" println "l_2t$l_2" ‣ Output l_1 [a, b, Z, d, e] // arghhh! we have a ‘Z’ in l_1 l_2 [a, b, Z, d, e] ‣ We do not copy all elements of l_1 to l_2, but rather let l_2 be a reference to the same Object as l_1
  • 52. Copying an Object ‣ We want to copy a list, then modify its copy without altering the original def l_1 = ('a'..'e').toList() def l_2 = l_1 l_2[2] = 'Z' println "l_1t$l_1" println "l_2t$l_2" ‣ Output l_1 [a, b, Z, d, e] // arghhh! we have a ‘Z’ in l_1 l_2 [a, b, Z, d, e] ‣ We do not copy all elements of l_1 to l_2, but rather let l_2 be a reference to the same Object as l_1 ‣ Modifying l_1 modifies l_2 as a side effect
  • 53. Copying an Object ‣ We want to copy a list, then modify its copy without altering the original def l_1 = ('a'..'e').toList() def l_2 = l_1 l_2[2] = 'Z' println "l_1t$l_1" println "l_2t$l_2" ‣ Output l_1 [a, b, Z, d, e] // arghhh! we have a ‘Z’ in l_1 l_2 [a, b, Z, d, e] ‣ We do not copy all elements of l_1 to l_2, but rather let l_2 be a reference to the same Object as l_1 ‣ Modifying l_1 modifies l_2 as a side effect ‣ This feature can be meaningful (memory, consistency...)
  • 54. Cloning an Object: o.clone() ‣ The solution is to explicitly clone the object def l_1 = ('a'..'e').toList() def l_2 = l_1.clone() l_2[2] = 'Z' println "l_1t$l_1" println "l_2t$l_2"
  • 55. Cloning an Object: o.clone() ‣ The solution is to explicitly clone the object def l_1 = ('a'..'e').toList() def l_2 = l_1.clone() l_2[2] = 'Z' println "l_1t$l_1" println "l_2t$l_2" ‣ Output l_1 [a, b, c, d, e] l_2 [a, b, Z, d, e]
  • 56. Cloning an Object: o.clone() ‣ The solution is to explicitly clone the object def l_1 = ('a'..'e').toList() def l_2 = l_1.clone() l_2[2] = 'Z' println "l_1t$l_1" println "l_2t$l_2" ‣ Output l_1 [a, b, c, d, e] l_2 [a, b, Z, d, e] ‣ l_1 is effectively duplicated: further modifications on l_2 do not alter l_1
  • 57. Cloning an Object (cont’d) ‣ The same applies to a class class Foo{ String name List values } Foo f_1=[name:'donald', values:[1,2,3]] Foo f_2=f_1 f_2.name='mickey' println "f_1t$f_1.namet$f_1.values" println "f_2t$f_2.namet$f_2.values"
  • 58. Cloning an Object (cont’d) ‣ The same applies to a class class Foo{ String name List values } Foo f_1=[name:'donald', values:[1,2,3]] Foo f_2=f_1 f_2.name='mickey' println "f_1t$f_1.namet$f_1.values" println "f_2t$f_2.namet$f_2.values" ‣ Output f_1 mickey [1, 2, 3] f_2 mickey [1, 2, 3]
  • 59. Cloning an Object (cont’d) ‣ If we try f_2 = f_1.clone() ‣ We obtain java.lang.CloneNotSupportedException: Foo at ConsoleScript39.run(ConsoleScript39:13)
  • 60. We need to define what we mean by cloneable 27
  • 61. Cloning an Object (cont’d) ‣ The class Foo must implements an interface Cloneable class Foo implements Cloneable{ String name List values Foo clone(){ return new Foo(‘name’: name, ‘values’: values.clone()) } //explicitly duplicate all fields }
  • 62. Cloning an Object (cont’d) ‣ The class Foo must implements an interface Cloneable class Foo implements Cloneable{ String name List values Foo clone(){ return new Foo(‘name’: name, ‘values’: values.clone()) } //explicitly duplicate all fields }
  • 63. Cloning an Object (cont’d)
  • 64. Cloning an Object (cont’d) ‣ We can now safely clone Foo f_1=[name:'donald', values:[1,2,3]] Foo f_2=f_1.clone() f_2.name='mickey' f_2.values[1] = 9 println "f_1t$f_1.namet$f_1.values" println "f_2t$f_2.namet$f_2.values"
  • 65. Cloning an Object (cont’d) ‣ We can now safely clone Foo f_1=[name:'donald', values:[1,2,3]] Foo f_2=f_1.clone() f_2.name='mickey' f_2.values[1] = 9 println "f_1t$f_1.namet$f_1.values" println "f_2t$f_2.namet$f_2.values" ‣ Output f_1 donald [1, 2, 3] f_2 mickey [1, 9, 3]
  • 66. OOP : Interface ‣ An interface is a manner to specify what behavior(s) a class should have, without writing any specific code
  • 67. OOP : Interface ‣ An interface is a manner to specify what behavior(s) a class should have, without writing any specific code ‣ A class later implements the interface, thus it is enforced to fulfill the mentioned mechanism
  • 68. How to make a class enforce a behavior? 31
  • 69. Interface examples ‣ Two examples we already met
  • 70. Interface examples ‣ Two examples we already met ‣ objects can be compared with <, <=, == etc. class MyClass implements Comparable{ ... int compareTo(o){ ... } }
  • 71. Interface examples ‣ Two examples we already met ‣ objects can be compared with <, <=, == etc. class MyClass implements Comparable{ ... int compareTo(o){ ... } } ‣ objects can be duplicated safely class MyClass implements Cloneable{ ... MyClass clone(){ ... } }
  • 72. Interface examples ‣ They can be combined
  • 73. Interface examples ‣ They can be combined ‣ objects can be compared and cloned class MyClass implements Comparable, Cloneable{ ... int compareTo(o){ ... } MyClass clone(){ ... } }
  • 74. How to define an interface? 34
  • 75. Interface definition ‣ Like a class file (class is replaced by interface)
  • 76. Interface definition ‣ Like a class file (class is replaced by interface) ‣ There is no execution code inside the file (on specification)
  • 77. Interface definition ‣ Like a class file (class is replaced by interface) ‣ There is no execution code inside the file (on specification) ‣ File HasSequence.groovy interface HasSequence{ String getSequence(); String fastaString(); }
  • 78. Interface definition ‣ class file then need to implements those two methods Protein.groovy class Protein implements HasSequence{ String accessionCode String sequence //getSequence() will be automatically //defined String fastaString(){ “>$accessionCoden$sequencen” } }
  • 79. Interface versus Abstraction interface MyInterface {...} abstract class MyAbstractClass{...}
  • 80. Interface versus Abstraction interface MyInterface {...} abstract class MyAbstractClass{...} ‣ Syntax class MyClass implements MyInterface{...} class MyClass extends MyAbstractClass{...}
  • 81. Interface versus Abstraction interface MyInterface {...} abstract class MyAbstractClass{...} ‣ Syntax class MyClass implements MyInterface{...} class MyClass extends MyAbstractClass{...} ‣ interface cannot contains explicit code (only specifications)
  • 82. Interface versus Abstraction interface MyInterface {...} abstract class MyAbstractClass{...} ‣ Syntax class MyClass implements MyInterface{...} class MyClass extends MyAbstractClass{...} ‣ interface cannot contains explicit code (only specifications) ‣ abstract class contains explicit code (see AminoAcidSequence), but can also contain abstract methods (to be implemented by children classes)
  • 83. Interface versus Abstraction interface MyInterface {...} abstract class MyAbstractClass{...} ‣ Syntax class MyClass implements MyInterface{...} class MyClass extends MyAbstractClass{...} ‣ interface cannot contains explicit code (only specifications) ‣ abstract class contains explicit code (see AminoAcidSequence), but can also contain abstract methods (to be implemented by children classes) ‣ A class can implements several interfaces, but only one abstract parent
  • 84. Interface versus Abstraction ‣ Dynamic typing in groovy => interfaces not as important as in java
  • 85. Interface versus Abstraction ‣ Dynamic typing in groovy => interfaces not as important as in java ‣ Strengthen the code readability and safety List<HasSequence> ....

Editor's Notes

  1. \n
  2. genetic programming and cloning: back to biology\n
  3. don&amp;#x2019;t hesitate to register and follow webinars: a efficient way to get into a new technology or feature in a small amount of time (maybe ask questions)\nMulti screen is a way to more poductivity\n
  4. don&amp;#x2019;t hesitate to register and follow webinars: a efficient way to get into a new technology or feature in a small amount of time (maybe ask questions)\nMulti screen is a way to more poductivity\n
  5. \n
  6. TDD is not for the exercises! it is for daily life\nGoing back to fix a problem means putting back all the println\nDebugging goes exponential instead of dragging it to the more linear possible\n
  7. TDD is not for the exercises! it is for daily life\nGoing back to fix a problem means putting back all the println\nDebugging goes exponential instead of dragging it to the more linear possible\n
  8. TDD is not for the exercises! it is for daily life\nGoing back to fix a problem means putting back all the println\nDebugging goes exponential instead of dragging it to the more linear possible\n
  9. \n
  10. \n
  11. \n
  12. \n
  13. \n
  14. \n
  15. \n
  16. \n
  17. \n
  18. \n
  19. \n
  20. \n
  21. \n
  22. \n
  23. \n
  24. \n
  25. \n
  26. \n
  27. \n
  28. \n
  29. \n
  30. \n
  31. \n
  32. \n
  33. \n
  34. \n
  35. \n
  36. \n
  37. \n
  38. \n
  39. \n
  40. \n
  41. \n
  42. \n
  43. \n
  44. \n
  45. \n
  46. \n
  47. \n
  48. \n
  49. \n
  50. \n
  51. \n
  52. \n
  53. \n
  54. \n
  55. \n
  56. \n
  57. in a map, value on the left hand side of &amp;#x2018;:&amp;#x2019; is a String by default\n
  58. \n
  59. remember of implements comparable\n
  60. \n
  61. \n
  62. \n
  63. \n
  64. \n
  65. \n
  66. \n
  67. \n
  68. \n
  69. \n
  70. \n
  71. \n
  72. \n
  73. \n
  74. \n
  75. \n
  76. \n
  77. \n
  78. \n
  79. \n
  80. \n
  81. \n