diff options
author | Adrien Hopkins <adrien.p.hopkins@gmail.com> | 2019-05-22 18:47:05 -0400 |
---|---|---|
committer | Adrien Hopkins <adrien.p.hopkins@gmail.com> | 2019-05-22 18:47:05 -0400 |
commit | 01b072b98fdd19a2d57afc15a4ee4a80d0bfc0cd (patch) | |
tree | 0b835f4196e0e34a9530e014352d89a41096ef97 /src/org/unitConverter/unit/Unit.java | |
parent | 987fd8406d65505aedecd17e51216eb0ce393fbb (diff) |
Added null checks to Unit's methods, including the new methods.
Diffstat (limited to 'src/org/unitConverter/unit/Unit.java')
-rwxr-xr-x | src/org/unitConverter/unit/Unit.java | 8 |
1 files changed, 8 insertions, 0 deletions
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 |