planetj.util
Class RoundOMatic

java.lang.Object
  extended byplanetj.util.RoundOMatic

public class RoundOMatic
extends java.lang.Object

This class is not thread safe. For a description, see the reproportion(float[]) method


Constructor Summary
RoundOMatic(int sum)
          Creates a new RoundOMatic for rounding arrays of values such that the arrays' elements total to the specified sum
 
Method Summary
 int[] reproportion(float[] values)
          Returns an array whose elements add up to the value passed into the constructor, and where each element is roughly proportional (by some constant) to the corresponding element in the array which was passed in.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

RoundOMatic

public RoundOMatic(int sum)
Creates a new RoundOMatic for rounding arrays of values such that the arrays' elements total to the specified sum

Method Detail

reproportion

public int[] reproportion(float[] values)
Returns an array whose elements add up to the value passed into the constructor, and where each element is roughly proportional (by some constant) to the corresponding element in the array which was passed in. For example, if this object was created with a value of 150 in the constructor, and this method is invoked with the array [0.2, 0.4, 0.6, 0.8, 1.0] then the array [10, 20, 30, 40, 50] is returned. If the values cannot be exactly proportional to those passed in (due to rounding) then the closest suitable values are chosen.

Parameters:
values - An array which does not contain any negative values