Collection of useful utilities for Java games and apps. A lot of interesting utilities that could maybe still find some use if you work with Java...
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
mightyutils/src/mightypork/utils/math/constraints/num/batch/NumSum.java

51 lines
792 B

package mightypork.utils.math.constraints.num.batch;
import java.util.ArrayList;
import java.util.List;
import mightypork.utils.math.constraints.num.Num;
/**
* Expandable sum of multiple numbers
*
* @author Ondřej Hruška (MightyPork)
*/
public class NumSum extends Num {
private final List<Num> summands = new ArrayList<>();
@Override
public double value()
{
double v = 0;
for (final Num n : summands) {
if (n != null) v += n.value();
}
return v;
}
/**
* Add a number to the sum
*
* @param summand added number
*/
public void addSummand(Num summand)
{
summands.add(summand);
}
/**
* Add a number to the sum
*
* @param summand added number
*/
public void addSummand(double summand)
{
summands.add(Num.make(summand));
}
}