O Space4J é um sistema de prevalência com API simples e suporte a cluster e indexação. Essa nova versão traz várias melhorias, entre elas:
:arrow: Suporte total a generics, principalmente na parte de indexação que antes não tinha.
:arrow: Melhoria no suporte a índices to tipo MULTI_SORTED (não-únicos ordenados).
Qualquer dúvida pode ser tirado no forum do projeto em inglês: http://s4j.mentaframework.org/forums/list.page
[color=red]Antes era assim quando tínhamos um índice MULTI_SORTED:[/color]
@Override
public Collection<Object> findUsers(int minAge, int maxAge) {
// Remember that our index is of the type MULTI_SORTED.
// That's why we are doing this cast here.
MultiSortedMap map = (MultiSortedMap) indexByAge.getMap();
// A multi-sorted-map will store a Map for each key.
// That's why our index is NON-UNIQUE meaning the same
// key can be associated with many entries in the map.
// The map is also sorted by its key, meaning we can
// perform range searches efficiently.
ConcurrentNavigableMap<Key, Object> subMap = map.subMap(new Key(minAge), true, new Key(maxAge), true);
Collection<Object> users = new ArrayList<Object>(subMap.size() * 3);
Iterator<Object> iter = subMap.values().iterator();
while(iter.hasNext()) {
// our collection here is actually a ConcurrentHashMap!
Map<Object, Boolean> m = (Map<Object, Boolean>) iter.next();
// this is not good as we are transversing the whole list twice!
// TODO: Create custom iterator for MultiSortedMap to avoid this?
Iterator<Object> iter2 = m.keySet().iterator();
while(iter2.hasNext()) {
users.add(iter2.next());
}
}
return users;
}
[color=blue]Agora ficou assim:[/color]
@Override
public Collection<User> findUsers(int minAge, int maxAge) {
// Remember that our index is of the type MULTI_SORTED.
MultiSortedMap<User> map = indexByAge.getMap();
// A multi-sorted-map will store a Set for each key.
// That's why our index is NON-UNIQUE meaning the same
// key (minAge, maxAge) can be associated with different entries in the map.
// The map is also sorted by its key, meaning we can
// perform range searches efficiently like below.
return map.subMapValues(new Key(minAge), true, new Key(maxAge), true);
}