jgaJava算法包
jga (Generic Algorithms for Java) 是一个 Java 的通用算法函数库,旨在提供一些常用的函数和表达式的封装。
示例代码:
List<Fruit> citrus = Arrays.asList(
grapefruit, lemon, lemon, lemon, lime, lime, orange, orange );
...
for(Fruit f : unique(citrus)) {
System.out.println(f);
}
import net.sf.jga.util.GenericComparator;
...
static public Comparator comp =
new GenericComparator(new GetProperty(Fruit.class, "Name"));
BinaryFunctor<Fruit,Fruit,Boolean> sameKind = new EqualTo<Fruit>(Fruit.comp);
for(Fruit f : unique(citrus, sameKind)) {
System.out.println(f);
}
评论