59 |
59 |
60 BigDecimal maximum = BigDecimal.ZERO; |
60 BigDecimal maximum = BigDecimal.ZERO; |
61 BigDecimal minimum = BigDecimal.ZERO; |
61 BigDecimal minimum = BigDecimal.ZERO; |
62 int lastIndex = currentHeader.getColumnCount() - 1; |
62 int lastIndex = currentHeader.getColumnCount() - 1; |
63 |
63 |
|
64 Object valueObject = null; |
64 try { |
65 try { |
65 for (Object[] row : currentResultSet) { |
66 for (Object[] row : currentResultSet) { |
66 Object valueObject = row[lastIndex]; |
67 valueObject = row[lastIndex]; |
67 if (valueObject != null) { |
68 if (valueObject != null) { |
68 BigDecimal value = new BigDecimal(valueObject.toString()); |
69 BigDecimal value = new BigDecimal(valueObject.toString()); |
69 maximum = maximum.max(value); |
70 maximum = maximum.max(value); |
70 minimum = minimum.min(value); |
71 minimum = minimum.min(value); |
71 } |
72 } |
72 } |
73 } |
73 |
74 |
74 BigDecimal range = maximum.subtract(minimum); |
75 BigDecimal range = maximum.subtract(minimum); |
75 |
76 |
76 for (Object[] row : currentResultSet) { |
77 for (Object[] row : currentResultSet) { |
77 Object valueObject = row[lastIndex]; |
78 valueObject = row[lastIndex]; |
78 if (valueObject != null) { |
79 if (valueObject == null) { |
|
80 row[lastIndex] = ""; |
|
81 } else { |
79 BigDecimal value = new BigDecimal(valueObject.toString()); |
82 BigDecimal value = new BigDecimal(valueObject.toString()); |
80 BigDecimal valueFromMinimum = value.subtract(minimum); |
83 BigDecimal valueFromMinimum = value.subtract(minimum); |
81 |
84 |
82 BigDecimal points = chartPrecision.divide(range, mathContext).multiply(valueFromMinimum, mathContext); |
85 BigDecimal points = chartPrecision.divide(range, mathContext).multiply(valueFromMinimum, mathContext); |
83 int pointsRounded = points.setScale(0, RoundingMode.HALF_UP).intValue(); |
86 int pointsRounded = points.setScale(0, RoundingMode.HALF_UP).intValue(); |
85 } |
88 } |
86 } |
89 } |
87 |
90 |
88 } catch (NumberFormatException e) { |
91 } catch (NumberFormatException e) { |
89 // https://en.wiktionary.org/wiki/parsable |
92 // https://en.wiktionary.org/wiki/parsable |
90 log.log(Level.SEVERE, "Last column must be number or an object with toString() value parsable to a number."); |
93 log.log(Level.SEVERE, "Last column must be number or an object with toString() value parsable to a number. But was „{0}“", valueObject); |
91 // FIXME: throw FormatterException |
94 // FIXME: throw FormatterException |
92 throw e; |
95 throw e; |
93 } |
96 } |
94 } |
97 } |
95 |
98 |