del.icio.us/nicolaslecoz Headline Animator

Wednesday, 3 October 2007

JDK recipe #1 : convert 1.4 collection to generic collection


package com.enterprise.soft.util;

import java.util.Collection;
import java.util.Iterator;

public class CollectionUtil {
public static <T> void convertToGenerics(Class<T> type,
Collection raw,
Collection<T> generics) {
for (Iterator i = raw.iterator(); i.hasNext();) {
generics.add(type.cast(i.next()));
}
}
}
I can notice that we must add element by element.

The convertion method is invoked of following way :

Collection raw = sqlMapClient.queryForList("getCategories");
Collection<Category> result = new ArrayList<Category>();

CollectionUtil.convertToGenerics(Category.class, raw, result);
source: Developer Forums Generics - How to convert List.add() from old code?

Monday, 20 August 2007

Good link about architecture (google, digg, flickr, ...)

Excellent link which gives informations about traffic volumetry, servers, ... the choices of google, digg, flickr for example

highscalability.com

Thursday, 28 June 2007

Re : Eclipse Shortcut : WinRun4J may be an alternative

WinRun4J : Configurable Java Launcher for Windows may be an alternative but the project starts.

This, may be a solution after the java program installing, to easily configure JVM for installation program according constraints programs (memomry, threading, debugging, logging, ...)

Eclipse Shortcut

With an Eclipse shortcut we easily launch differents workspaces (with specific configuration) with the same Eclipse :

$ECLIPSE_HOME/eclipse -vm $JAVA_HOME/bin/java 
-data /path/my_eclipse_workspace
-vmargs -Xms128M -Xmx512M
  • vm : Java Virtual Machine which launchs Eclipse
  • data : root folder of Eclipse Workspace
  • vmargs : Arguments of JVM which launchs Eclipse (for example to increase the memory of Eclipse)

Friday, 8 June 2007

Like me, you know shell scripting but you always forget the syntax

I don't pratice enough the shell scripting in order to remember all of syntactics elements.

According to me, Shell is essential tool for developers. It increases the productivity, for example to find a file with filters, this is easier and more powerful than with gui tools. But also, to realize indicatives metrics in source code :

  • Number of source code files
  • Number of source code lines
  • Number of source code lines by file => quickly detect the files to refactor
  • ...
Moreover, i hate when i do several times the same thing

I really like this link Introduction To Bash Shell Scripting, because it's very short and effective, thus you find quickly your shell syntactic information.

This link helps me to remember the difference between ${VAR##VALUE} and ${VAR%%VALUE}, for instance.

This is an other link which is useful Web Man Page.

Monday, 28 May 2007

I reorganize my del.icio.us bookmark

I reorganize my del.icio.us bookmark, this is the categories :

  • AS Application Server
  • Architecture
  • Database
  • Documentation
  • Test
  • Tuning,monitoring
  • dotNet
  • infra
  • Java
  • Web
  • Work in progress
  • unclassified

My del.icio.us bookmark

Tiny Java tools to view Eclipse Project Dependences

I quickly developed a tool to view and document Eclipe Project Dependences.
Several things will have to be to improve and perhaps you could help me.

A good tool as Ivy could document artifact dependences.

I will do post about the importance of the dependence management, especially in modular application (we can imagine to use Ivy to help the building and the deployment of OSGi application).

This is an example on workspace with about 30 projects without library :
example of image which is generated by EDA
Click here to enlarge

it works in the following way :

  • we give the file name of output picture and all ".project" files to analyze
  • it opens the file .project (to find project name) and associates .classpath (to find dependences)
  • it parses these xml files to build java model
  • it generates graph from java model thanks of Dot/Dotty

This is an example of program invocation :

java -jar outputpicturefile.gif file:./myproject1/.project
file:./myproject2/.project file:./myproject3/.project

I developed it with Java 6. I use the xml parser STaX. Theses things must be improved :
  • The library to generate the picture of graph, i want a library (not external application as dotty) and a prettier picture. Moreover i want parametrize this generating as the size of picture, the icons of node, ...
  • We could give parameters to view as example libraries in picture (it's not difficult just i must spend time on it)
  • I must improve packaging futhermore it's more difficult with external tool

Do you know a better free library than dotty to generate graph picture in Java?

EclipseDependenceAnalyze binary
EclipseDependenceAnalyze source
Dotty works in the following way :
dotty.exe ... "a -> b;"

Dotty will generate a picture with one graph with 2 nodes ("a" and "b") with one arrow from "a" towards "b".

Sunday, 6 May 2007

How to find the good example of source code java

I referred my preferred sites thanks to del.icio.us in order to find the good example of source code :

http://del.icio.us/nicolaslecoz/codeatabase

There is two kinds of sites :
  • Java recipes (as JavaAlmanach, Java Pratices, Java Tips Weblog, ...)
  • Search engine of code source (as Koders, Google code search, KickJava, Krugle, ...)
Generally in Java, the difficulty isn't to find good API but is to well use this API. Moreover, the Java API is too large to memorize all. That's why, the search engine of code source is effective solution.

There is other sites to learn lot of Java aspects :