From 702cf7be72409c5bbc8479329856451701240aae Mon Sep 17 00:00:00 2001 From: Jason Tedor Date: Thu, 17 Sep 2015 23:36:28 -0400 Subject: [PATCH] Replace Integers.checkedCast with built-in method --- .../java/org/elasticsearch/common/util/BloomFilter.java | 3 +-- .../elasticsearch/common/util/primitives/Integers.java | 8 -------- 2 files changed, 1 insertion(+), 10 deletions(-) diff --git a/core/src/main/java/org/elasticsearch/common/util/BloomFilter.java b/core/src/main/java/org/elasticsearch/common/util/BloomFilter.java index 561fff5ab7e..360bd39e800 100644 --- a/core/src/main/java/org/elasticsearch/common/util/BloomFilter.java +++ b/core/src/main/java/org/elasticsearch/common/util/BloomFilter.java @@ -29,7 +29,6 @@ import org.elasticsearch.common.hash.MurmurHash3; import org.elasticsearch.common.io.stream.StreamInput; import org.elasticsearch.common.io.stream.StreamOutput; import org.elasticsearch.common.unit.SizeValue; -import org.elasticsearch.common.util.primitives.Integers; import java.io.IOException; import java.util.Arrays; @@ -325,7 +324,7 @@ public class BloomFilter { private static int size(long bits) { long quotient = bits / 64; long remainder = bits - quotient * 64; - return Integers.checkedCast(remainder == 0 ? quotient : 1 + quotient); + return Math.toIntExact(remainder == 0 ? quotient : 1 + quotient); } // Used by serialization diff --git a/core/src/main/java/org/elasticsearch/common/util/primitives/Integers.java b/core/src/main/java/org/elasticsearch/common/util/primitives/Integers.java index 03f4d06b634..1c49b3f3fa3 100644 --- a/core/src/main/java/org/elasticsearch/common/util/primitives/Integers.java +++ b/core/src/main/java/org/elasticsearch/common/util/primitives/Integers.java @@ -27,12 +27,4 @@ public class Integers { Objects.requireNonNull(ints); return ints.stream().mapToInt(s -> s).toArray(); } - - public static int checkedCast(long value) { - int cast = (int)value; - if ((long)cast != value) { - throw new IllegalArgumentException(Long.toString(value)); - } - return cast; - } }