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/NumMul.java

51 lines
813 B

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