diff options
Diffstat (limited to 'src/org/unitConverter/unit/FunctionalUnit.java')
-rw-r--r-- | src/org/unitConverter/unit/FunctionalUnit.java | 45 |
1 files changed, 23 insertions, 22 deletions
diff --git a/src/org/unitConverter/unit/FunctionalUnit.java b/src/org/unitConverter/unit/FunctionalUnit.java index 7ddd876..e2ab6e7 100644 --- a/src/org/unitConverter/unit/FunctionalUnit.java +++ b/src/org/unitConverter/unit/FunctionalUnit.java @@ -29,7 +29,21 @@ import org.unitConverter.math.ObjectProduct; */ final class FunctionalUnit extends Unit { /** - * Returns a unit from its base and the functions it uses to convert to and from its base. + * A function that accepts a value expressed in the unit's base and returns that value expressed in this unit. + * + * @since 2019-05-22 + */ + private final DoubleUnaryOperator converterFrom; + + /** + * A function that accepts a value expressed in the unit and returns that value expressed in the unit's base. + * + * @since 2019-05-22 + */ + private final DoubleUnaryOperator converterTo; + + /** + * Creates the {@code FunctionalUnit}. * * @param base * unit's base @@ -39,31 +53,18 @@ final class FunctionalUnit extends Unit { * @param converterTo * function that accepts a value expressed in the unit and returns that value expressed in the unit's * base. - * @return a unit that uses the provided functions to convert. - * @since 2019-05-22 * @throws NullPointerException * if any argument is null + * @since 2019-05-22 */ - public static FunctionalUnit valueOf(final ObjectProduct<BaseUnit> base, final DoubleUnaryOperator converterFrom, + public FunctionalUnit(final ObjectProduct<BaseUnit> base, final DoubleUnaryOperator converterFrom, final DoubleUnaryOperator converterTo) { - return new FunctionalUnit(base, converterFrom, converterTo); + super(base, NameSymbol.EMPTY); + this.converterFrom = Objects.requireNonNull(converterFrom, "converterFrom must not be null."); + this.converterTo = Objects.requireNonNull(converterTo, "converterTo must not be null."); } /** - * A function that accepts a value expressed in the unit's base and returns that value expressed in this unit. - * - * @since 2019-05-22 - */ - private final DoubleUnaryOperator converterFrom; - - /** - * A function that accepts a value expressed in the unit and returns that value expressed in the unit's base. - * - * @since 2019-05-22 - */ - private final DoubleUnaryOperator converterTo; - - /** * Creates the {@code FunctionalUnit}. * * @param base @@ -78,9 +79,9 @@ final class FunctionalUnit extends Unit { * if any argument is null * @since 2019-05-22 */ - private FunctionalUnit(final ObjectProduct<BaseUnit> base, final DoubleUnaryOperator converterFrom, - final DoubleUnaryOperator converterTo) { - super(base); + public FunctionalUnit(final ObjectProduct<BaseUnit> base, final DoubleUnaryOperator converterFrom, + final DoubleUnaryOperator converterTo, final NameSymbol ns) { + super(base, ns); this.converterFrom = Objects.requireNonNull(converterFrom, "converterFrom must not be null."); this.converterTo = Objects.requireNonNull(converterTo, "converterTo must not be null."); } |