Rogue: Savage Rats, a retro-themed dungeon crawler
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.
 
 
rogue-savage-rats/src/mightypork/gamecore/util/math/constraints/num/NumSum.java

49 lines
743 B

package mightypork.gamecore.util.math.constraints.num;
import java.util.ArrayList;
import java.util.List;
/**
* 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));
}
}