Example usage for org.apache.commons.lang3.mutable MutableDouble setValue

List of usage examples for org.apache.commons.lang3.mutable MutableDouble setValue

Introduction

In this page you can find the example usage for org.apache.commons.lang3.mutable MutableDouble setValue.

Prototype

@Override
public void setValue(final Number value) 

Source Link

Document

Sets the value from any Number instance.

Usage

From source file:ru.org.linux.tag.TagCloudDao.java

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, (rs, rowNum) -> {
        TagDTO result1 = new TagDTO();
        result1.setValue(rs.getString("value"));
        double counter = Math.log(rs.getInt("counter"));
        result1.setCounter(counter);//from w  ww.  j a va2 s . co m

        if (maxc.doubleValue() < counter) {
            maxc.setValue(counter);
        }

        if (minc.doubleValue() < 0 || counter < minc.doubleValue()) {
            minc.setValue(counter);
        }

        return result1;
    }, tagcount);

    if (minc.doubleValue() < 0) {
        minc.setValue(0);
    }

    result.forEach(tag -> tag.setWeight((int) Math
            .round(10 * (tag.getCounter() - minc.doubleValue()) / (maxc.doubleValue() - minc.doubleValue()))));

    Collections.sort(result);

    return result;
}