jdbcTemplate = new JdbcTemplate(dataSource);
}
public List<TagDTO> getTags(int tagcount) {
String sql = "select value,counter from tags_values where counter>=10 order by counter desc limit ?";
final MutableDouble maxc = new MutableDouble(1);
final MutableDouble minc = new MutableDouble(-1);
List<TagDTO> result = jdbcTemplate.query(sql, new RowMapper<TagDTO>() {
@Override
public TagDTO mapRow(ResultSet rs, int rowNum) throws SQLException {
TagDTO result = new TagDTO();
result.setValue(rs.getString("value"));
double counter = Math.log(rs.getInt("counter"));
result.setCounter(counter);
if (maxc.doubleValue() < counter){
maxc.setValue(counter);
}
if (minc.doubleValue() < 0 || counter < minc.doubleValue()){
minc.setValue(counter);
}
return result;
}
}, tagcount);
if (minc.doubleValue() < 0){
minc.setValue(0);
}
CollectionUtils.forAllDo(result, new Closure() {
@Override
public void execute(Object o) {
TagDTO tag = (TagDTO) o;
tag.setWeight((int) Math.round(10*(tag.getCounter() - minc.doubleValue())
/ (maxc.doubleValue() - minc.doubleValue())));
}
});
Collections.sort(result);