From 01b072b98fdd19a2d57afc15a4ee4a80d0bfc0cd Mon Sep 17 00:00:00 2001 From: Adrien Hopkins Date: Wed, 22 May 2019 18:47:05 -0400 Subject: Added null checks to Unit's methods, including the new methods. --- src/org/unitConverter/unit/Unit.java | 8 ++++++++ 1 file changed, 8 insertions(+) (limited to 'src/org/unitConverter/unit/Unit.java') diff --git a/src/org/unitConverter/unit/Unit.java b/src/org/unitConverter/unit/Unit.java index 2ac107e..54f0ab5 100755 --- a/src/org/unitConverter/unit/Unit.java +++ b/src/org/unitConverter/unit/Unit.java @@ -48,6 +48,8 @@ public interface Unit { * base. * @return a unit that uses the provided functions to convert. * @since 2019-05-22 + * @throws NullPointerException + * if any argument is null */ public static Unit fromConversionFunctions(final BaseUnit base, final DoubleUnaryOperator converterFrom, final DoubleUnaryOperator converterTo) { @@ -62,8 +64,11 @@ public interface Unit { * @return true if the units are compatible * @since 2019-01-13 * @since v0.1.0 + * @throws NullPointerException + * if other is null */ default boolean canConvertTo(final Unit other) { + Objects.requireNonNull(other, "other must not be null."); return Objects.equals(this.getBase(), other.getBase()); } @@ -97,8 +102,11 @@ public interface Unit { * @throws IllegalArgumentException * if {@code other} is incompatible for conversion with this unit (as tested by * {@link Unit#canConvertTo}). + * @throws NullPointerException + * if other is null */ default double convertTo(final Unit other, final double value) { + Objects.requireNonNull(other, "other must not be null."); if (this.canConvertTo(other)) return other.convertFromBase(this.convertToBase(value)); else -- cgit v1.2.3