Break out the isFloating logic in the GsonEqualsChecker

This commit is contained in:
Olof Larsson 2014-01-30 02:43:33 +01:00
parent 010d91a75d
commit 66de46f0c9
2 changed files with 11 additions and 10 deletions

View File

@ -61,6 +61,7 @@ public abstract class MPlugin extends JavaPlugin implements Listener
// DISABLE // DISABLE
// -------------------------------------------- // // -------------------------------------------- //
@Override
public void onDisable() public void onDisable()
{ {
// Collection shutdowns. // Collection shutdowns.

View File

@ -134,16 +134,7 @@ public class GsonEqualsChecker
Number oneNumber = one.getAsNumber(); Number oneNumber = one.getAsNumber();
Number twoNumber = two.getAsNumber(); Number twoNumber = two.getAsNumber();
boolean floating; boolean floating = isFloating(oneNumber);
if (oneNumber instanceof LazilyParsedNumber)
{
floating = StringUtils.contains(oneNumber.toString(), '.');
}
else
{
floating = (oneNumber instanceof Double || oneNumber instanceof Float);
}
if (floating) if (floating)
{ {
// Our epsilon is pretty big in order to see float and double as the same. // Our epsilon is pretty big in order to see float and double as the same.
@ -174,4 +165,13 @@ public class GsonEqualsChecker
return twoObject == JsonNull.INSTANCE; return twoObject == JsonNull.INSTANCE;
} }
public static boolean isFloating(Number number)
{
if (number instanceof LazilyParsedNumber)
{
return StringUtils.contains(number.toString(), '.');
}
return (number instanceof Double || number instanceof Float);
}
} }