Move checkFinite methods to a util class.

By: md_5 <git@md-5.net>
This commit is contained in:
Bukkit/Spigot 2015-02-26 21:23:26 +11:00
parent 70bfc4d702
commit 55b9c40dda
3 changed files with 16 additions and 20 deletions

View file

@ -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);
}
}
}

View file

@ -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);
}
}
}

View file

@ -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);
}
}
}