be.webtechie.resistorcalculator.util.CalculateTotal Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of resistor-calculator Show documentation
Show all versions of resistor-calculator Show documentation
Java library to calculate resistor values and their use in circuits
package be.webtechie.resistorcalculator.util;
import java.util.List;
/**
* Calculates the total value for a list of resistor values.
*/
public class CalculateTotal {
/**
* Calculate the total for a list of serial resistors.
*
* @param values {@link List} of {@link Double} values
* @return The calculate total value
*/
public static double serial(List values) {
return values.stream().reduce(0D, (a, b) -> a + b);
}
/**
* Calculate the total for a list of parallel resistors.
*
* @param values {@link List} of {@link Double} values
* @return The calculate total value
*/
public static double parallel(List values) {
return 1 / values.stream().reduce(0D, (a, b) -> a + (1/b));
}
}