From 55b9c40ddaaa4f1329f6049b7c345e1c578d29e6 Mon Sep 17 00:00:00 2001 From: Bukkit/Spigot Date: Thu, 26 Feb 2015 21:23:26 +1100 Subject: [PATCH] Move checkFinite methods to a util class. By: md_5 --- .../src/main/java/org/bukkit/Location.java | 17 +++-------------- .../java/org/bukkit/util/NumberConversions.java | 12 ++++++++++++ .../src/main/java/org/bukkit/util/Vector.java | 7 +------ 3 files changed, 16 insertions(+), 20 deletions(-) diff --git a/paper-api/src/main/java/org/bukkit/Location.java b/paper-api/src/main/java/org/bukkit/Location.java index 21f98cb5a7..583dbe8f9e 100644 --- a/paper-api/src/main/java/org/bukkit/Location.java +++ b/paper-api/src/main/java/org/bukkit/Location.java @@ -6,6 +6,7 @@ import java.util.Map; import org.bukkit.block.Block; import org.bukkit.configuration.serialization.ConfigurationSerializable; import org.bukkit.util.NumberConversions; +import static org.bukkit.util.NumberConversions.checkFinite; import org.bukkit.util.Vector; /** @@ -188,7 +189,7 @@ public class Location implements Cloneable, ConfigurationSerializable { * @param yaw new rotation's yaw */ public void setYaw(float yaw) { - checkFiniteFloat(yaw, "yaw must be finite"); + checkFinite(yaw, "yaw must be finite"); this.yaw = yaw; } @@ -223,7 +224,7 @@ public class Location implements Cloneable, ConfigurationSerializable { * @param pitch new incline's pitch */ public void setPitch(float pitch) { - checkFiniteFloat(pitch, "pitch must be finite"); + checkFinite(pitch, "pitch must be finite"); this.pitch = pitch; } @@ -601,16 +602,4 @@ public class Location implements Cloneable, ConfigurationSerializable { return new Location(world, NumberConversions.toDouble(args.get("x")), NumberConversions.toDouble(args.get("y")), NumberConversions.toDouble(args.get("z")), NumberConversions.toFloat(args.get("yaw")), NumberConversions.toFloat(args.get("pitch"))); } - - private static void checkFinite(double d, String message) { - if (Double.isNaN(d) || Double.isInfinite(d)) { - throw new IllegalArgumentException(message); - } - } - - private static void checkFiniteFloat(float d, String message) { - if (Float.isNaN(d) || Float.isInfinite(d)) { - throw new IllegalArgumentException(message); - } - } } diff --git a/paper-api/src/main/java/org/bukkit/util/NumberConversions.java b/paper-api/src/main/java/org/bukkit/util/NumberConversions.java index 29f81d011e..4bc79028cd 100644 --- a/paper-api/src/main/java/org/bukkit/util/NumberConversions.java +++ b/paper-api/src/main/java/org/bukkit/util/NumberConversions.java @@ -101,4 +101,16 @@ public final class NumberConversions { } return 0; } + + public static void checkFinite(double d, String message) { + if (Double.isNaN(d) || Double.isInfinite(d)) { + throw new IllegalArgumentException(message); + } + } + + public static void checkFinite(float d, String message) { + if (Float.isNaN(d) || Float.isInfinite(d)) { + throw new IllegalArgumentException(message); + } + } } diff --git a/paper-api/src/main/java/org/bukkit/util/Vector.java b/paper-api/src/main/java/org/bukkit/util/Vector.java index 7cd604819e..be8cf41a41 100644 --- a/paper-api/src/main/java/org/bukkit/util/Vector.java +++ b/paper-api/src/main/java/org/bukkit/util/Vector.java @@ -7,6 +7,7 @@ import org.bukkit.Location; import org.bukkit.World; import org.bukkit.configuration.serialization.ConfigurationSerializable; import org.bukkit.configuration.serialization.SerializableAs; +import static org.bukkit.util.NumberConversions.checkFinite; /** * Represents a mutable vector. Because the components of Vectors are mutable, @@ -646,10 +647,4 @@ public class Vector implements Cloneable, ConfigurationSerializable { return new Vector(x, y, z); } - - private static void checkFinite(double d, String message) { - if (Double.isNaN(d) || Double.isInfinite(d)) { - throw new IllegalArgumentException(message); - } - } }