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)
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
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
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
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
}
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
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(){
...
}
}
73. Interface examples
‣ They can be combined
‣ objects can be compared and cloned
class MyClass implements Comparable, Cloneable{
...
int compareTo(o){
...
}
MyClass clone(){
...
}
}
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”
}
}
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
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
\n
genetic programming and cloning: back to biology\n
don&#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
don&#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
\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 &#x2018;:&#x2019; is a String by default\n