Check it out.
Also, I created a quick Google project for it just in case anyone is interested in expanding it into a full fledged pet store implementation.
Pseudo random thoughts on software development.
Just write a simple helper. I guarantee that it will be 20 times faster than Groovy.So I wrote some quick and dirty code to test exactly that. It's not scientific by any means, but my simple test showed that the Groovy version was about (edit: 7.5) times slower than the Java version.
GroovyListExamples.groovy:
-------------------------
class GroovyListExamples {
public List listSubtractionTest() {
def smallList = [1,3,5]
def bigList = [1,1,1,2,3,4,4,4,5,6,7,7,8,9]
def result = bigList - smallList
}
}
JavaListExamples.java:
---------------------
import java.util.*;
public class JavaListExamples {
public List listSubtractionTest() {
List smallList = Arrays.asList(new Object[] { 1, 3, 5});
List bigList = Arrays.asList(new Object[] { 1,1,1,2,3,4,4,4,5,6,7,7,8,9 });
return subtractList(bigList, smallList);
}
public List subtractList(List sourceList, List removeList) {
Set removeSet = new HashSet();
removeSet.addAll(removeList);
List result = new ArrayList();
for (Object item : sourceList) {
if (!removeSet.contains(item)) {
result.add(item);
}
}
return result;
}
}
ListExamplesDriver.java:
-----------------------
public class ListExamplesDriver {
public static void main(String[] args) {
GroovyListExamples groovyWay = new GroovyListExamples();
JavaListExamples javaWay = new JavaListExamples();
System.out.println("GROOVY:");
System.out.println(groovyWay.listSubtractionTest());
System.out.println("JAVA:");
System.out.println(javaWay.listSubtractionTest());
int NUMITERS = 1000000;
long start, stop;
start = System.currentTimeMillis();
for (int i = 0; i < NUMITERS; i++) {
groovyWay.listSubtractionTest();
}
stop = System.currentTimeMillis();
System.out.println("GROOVY TIME: " + (stop - start) + "ms");
start = System.currentTimeMillis();
for (int i = 0; i < NUMITERS; i++) {
javaWay.listSubtractionTest();
}
stop = System.currentTimeMillis();
System.out.println("JAVA TIME: " + (stop - start) + "ms");
}
}
User->A: DoWork
activate A
A->B: <>
activate B
B->C: DoWorkactivate C
C-->B: WorkDone
destroy C
B-->A: RequestCreated
deactivate BA->User: Done
public class AllTestsRecursively extends TestCase {Not rocket science, but it makes it pretty easy to write a lot of generic code. For example, you could use it to write tests that assert characteristics that might otherwise require aspects to enforce.
public static TestSuite suite() throws Exception {
TestSuite suite = new TestSuite();
ClassPathScanner scanner = new ClassPathScanner()
.basePackage(AllTestsRecursively.class.getPackage().getName())
.assignableFrom(TestCase.class)
.includeFilter(".*Test");
for (Class testClass : scanner.findClasses()) {
suite.addTestSuite(testClass);
}
return suite;
}
}