More Related Content Similar to Apache Commons - Don\'t re-invent the wheel (20) Apache Commons - Don\'t re-invent the wheel1. Apache
Commons
Torsten Curdt
don’t re-invent the wheel
17. Charter
“Creation of small re-useable
components that can be used across
projects. They are supposed to have as
few dependencies as possible, meant
to be well tested and compatible with
the current de-facto standard version of
the JDK”
21. Collections
Map map = new CaseInsensitiveMap();
map.put(quot;Onequot;, quot;Onequot;);
map.get(quot;ONEquot;);
Map colorMap = MapUtils.toMap(new String[][] {{
{quot;redquot;, quot;#FF0000quot;},
{quot;greenquot;, quot;#00FF00quot;},
{quot;bluequot;, quot;#0000FFquot;}
});
24. Lang
String s = “Apache Jakarta Commons”;
StringUtils.right(s, 7); // “Commons”
String n = “0”;
StringUtils.leftPad(s, 4, ‘0’); // “0000”
25. Logging
public class C {
private Log log = LogFactory.getLog(C.class);
...
if (log.isDebugEnabled()) {
log.debug(quot;log messagequot;);
}
26. CLI
Options options = new Options();
options.addOption(quot;hquot;, false, quot;display usagequot;);
CommandLine line = parser.parse(options, args);
if(line.hasOption(quot;hquot;)) {
HelpFormatter f = new HelpFormatter();
f.printHelp(quot;myprogramquot;, options);
...
27. Email
SimpleEmail email = new SimpleEmail();
email.setHostName(quot;mail.myserver.comquot;);
email.addTo(quot;jdoe@somewhere.orgquot;, quot;John Doequot;);
email.setFrom(quot;me@apache.orgquot;, quot;Mequot;);
email.setSubject(quot;Test messagequot;);
email.setMsg(quot;A simple test of commons-emailquot;);
email.send();
28. Net
NNTPClient client = new NNTPClient();
client.connect(quot;news.server.netquot;);
NewsgroupInfo[] = client.listNewsgroups();
client.disconnect();
30. VFS
FileSystemManager fs = VFS.getManager();
FileObject jar = fs.resolveFile(
quot;jar:lib/aJarFile.jarquot; );
FileObject[] childs = jar.getChildren();
for (int i=0; i < childs.length; i++ ) {
...
31. JCI
JavaCompiler compiler =
new EclipseJavaCompiler();
ResourceStore store =
new MemoryResourceStore();
CompilationResult result = compiler.compile(
new String[] { quot;org/MyClass.javaquot; },
new FileResourceReader(directory),
store );
33. Proxy
o = (MyObject) new CglibProxyFactory()
.createInterceptorProxy(
new MyObjectImpl(),
new LoggingInterceptor(log),
new Class[]{ MyObject.class });
o.test(”test”);
[DEBUG] - BEGIN test(test)
[DEBUG] - END test()
34. Overview
attributes, beanutils, betwixt, chain,
cli, codec, collections, configuration,
daemon, dbcp, dbutils, digester,
discovery, el, email, fileupload,
httpclient, io, jci, jelly, jexl, jxpath,
lang, launcher, logging, math,
modeler, net, pool, primitives,
proxy, scxml, transaction, validator,
vfs
36. CSV
String[][] data = CSVParser.parse(string);
CSVParser parser = new CSVParser(reader,’;’);
String[][] data = parser.getAllValues();
37. Javaflow
class MyRunnable implements Runnable {
public void run() {
for(int i=0; i<10; i++ )
Continuation.suspend();
}}
Continuation c = Continuation.startWith(
new MyRunnable());
Continuation d = Continuation.continueWith(c);
...
38. OpenPGP
keyRing = new BouncyCastleKeyRing(
secret, public, password);
signer = new BouncyCastleOpenPgpSigner();
signer.detachedSign(
fileInputStream
signatureOutputStream,
keyId,
keyRing,
true );
39. Overview
compress, csv, expression,
finder, flatfile, functor, i18n,
id, javaflow, jnet, js2j, me,
monitoring, nabla, openpgp,
performance, pipeline,
validator2
41. Overview
benchmark, cache, clazz, codec-
mulipart, combo, contract, events,
feedparser, filters, functor, grant,
graph2, http, jex, jjar, jpath, jrcs, jux,
latka, mapper, messenger, pattern,
periodicity, reflect, resources, rupert,
scaffold, services, servlet,
simplestore, tbm, test, threading,
threadpool, workflow, xmlio, xmlunit,
xo