Your SlideShare is downloading. ×
0
groovy & grails - lecture 7
groovy & grails - lecture 7
groovy & grails - lecture 7
groovy & grails - lecture 7
groovy & grails - lecture 7
groovy & grails - lecture 7
groovy & grails - lecture 7
groovy & grails - lecture 7
groovy & grails - lecture 7
groovy & grails - lecture 7
groovy & grails - lecture 7
groovy & grails - lecture 7
groovy & grails - lecture 7
groovy & grails - lecture 7
groovy & grails - lecture 7
groovy & grails - lecture 7
groovy & grails - lecture 7
groovy & grails - lecture 7
groovy & grails - lecture 7
groovy & grails - lecture 7
groovy & grails - lecture 7
groovy & grails - lecture 7
groovy & grails - lecture 7
groovy & grails - lecture 7
groovy & grails - lecture 7
groovy & grails - lecture 7
groovy & grails - lecture 7
groovy & grails - lecture 7
groovy & grails - lecture 7
groovy & grails - lecture 7
groovy & grails - lecture 7
groovy & grails - lecture 7
groovy & grails - lecture 7
groovy & grails - lecture 7
groovy & grails - lecture 7
groovy & grails - lecture 7
groovy & grails - lecture 7
groovy & grails - lecture 7
groovy & grails - lecture 7
groovy & grails - lecture 7
groovy & grails - lecture 7
groovy & grails - lecture 7
groovy & grails - lecture 7
groovy & grails - lecture 7
groovy & grails - lecture 7
groovy & grails - lecture 7
groovy & grails - lecture 7
groovy & grails - lecture 7
groovy & grails - lecture 7
groovy & grails - lecture 7
groovy & grails - lecture 7
groovy & grails - lecture 7
groovy & grails - lecture 7
groovy & grails - lecture 7
groovy & grails - lecture 7
groovy & grails - lecture 7
groovy & grails - lecture 7
groovy & grails - lecture 7
groovy & grails - lecture 7
groovy & grails - lecture 7
groovy & grails - lecture 7
groovy & grails - lecture 7
groovy & grails - lecture 7
groovy & grails - lecture 7
groovy & grails - lecture 7
groovy & grails - lecture 7
groovy & grails - lecture 7
groovy & grails - lecture 7
groovy & grails - lecture 7
groovy & grails - lecture 7
groovy & grails - lecture 7
groovy & grails - lecture 7
groovy & grails - lecture 7
groovy & grails - lecture 7
groovy & grails - lecture 7
groovy & grails - lecture 7
groovy & grails - lecture 7
groovy & grails - lecture 7
groovy & grails - lecture 7
groovy & grails - lecture 7
groovy & grails - lecture 7
groovy & grails - lecture 7
groovy & grails - lecture 7
groovy & grails - lecture 7
groovy & grails - lecture 7
Upcoming SlideShare
Loading in...5
×

Thanks for flagging this SlideShare!

Oops! An error has occurred.

×
Saving this for later? Get the SlideShare app to save on your phone or tablet. Read anywhere, anytime – even offline.
Text the download link to your phone
Standard text messaging rates apply

groovy & grails - lecture 7

458

Published on

Eclipse tips …

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

Published in: Technology
0 Comments
0 Likes
Statistics
Notes
  • Be the first to comment

  • Be the first to like this

No Downloads
Views
Total Views
458
On Slideshare
0
From Embeds
0
Number of Embeds
0
Actions
Shares
0
Downloads
15
Comments
0
Likes
0
Embeds 0
No embeds

Report content
Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
No notes for slide
  • \n
  • genetic programming and cloning: back to biology\n
  • don’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
  • don’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
  • \n
  • 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
  • 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
  • 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
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • in a map, value on the left hand side of ‘:’ is a String by default\n
  • \n
  • remember of implements comparable\n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • Transcript

    • 1. Groovy: Efficiency Oriented ProgrammingLecture 7Master Proteomics & Bioinformatics - University of GenevaAlexandre 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
    • 10. Exception: example
    • 11. Exception: exampleorg.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: exampleorg.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 messageorg.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 messageorg.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 messageorg.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 messageorg.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 messageorg.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 130 220 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 130 this line is never reached 220 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 130 220 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 130 220 error with (5): Negative array index [-5] too large for array size 4 error with (3): For input string: "a" 410
    • 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 130 220 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 130 220 out of bound! cannot to convert a to int 410
    • 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 Exceptionint 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)}//Scripttry{ computeFactorial(i)}catch(Exception e){....}
    • 44. Throwing your Exceptionint 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)}//Scripttry{ 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 Abstractioninterface 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> ....

    ×