From 7a29febd721b74c58cb480c601f3c3660841b200 Mon Sep 17 00:00:00 2001 From: Jason Tedor Date: Tue, 15 Sep 2015 10:07:15 -0400 Subject: [PATCH] Remove and forbid use of com.google.common.math.LongMath This commit removes and now forbids all uses of com.google.common.math.LongMath across the codebase. This is one step of many in the eventual removal of Guava as a dependency. --- .../org/elasticsearch/common/util/BloomFilter.java | 10 +++++++--- .../src/main/resources/forbidden/all-signatures.txt | 1 + 2 files changed, 8 insertions(+), 3 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 8a2acba8d28..0f72d6d62b1 100644 --- a/core/src/main/java/org/elasticsearch/common/util/BloomFilter.java +++ b/core/src/main/java/org/elasticsearch/common/util/BloomFilter.java @@ -18,7 +18,6 @@ */ package org.elasticsearch.common.util; -import com.google.common.math.LongMath; import com.google.common.primitives.Ints; import org.apache.lucene.store.DataInput; import org.apache.lucene.store.DataOutput; @@ -33,7 +32,6 @@ import org.elasticsearch.common.io.stream.StreamOutput; import org.elasticsearch.common.unit.SizeValue; import java.io.IOException; -import java.math.RoundingMode; import java.util.Arrays; import java.util.Comparator; @@ -321,7 +319,13 @@ public class BloomFilter { long bitCount; BitArray(long bits) { - this(new long[Ints.checkedCast(LongMath.divide(bits, 64, RoundingMode.CEILING))]); + this(new long[size(bits)]); + } + + private static int size(long bits) { + long quotient = bits / 64; + long remainder = bits - quotient * 64; + return Ints.checkedCast(remainder == 0 ? quotient : 1 + quotient); } // Used by serialization diff --git a/dev-tools/src/main/resources/forbidden/all-signatures.txt b/dev-tools/src/main/resources/forbidden/all-signatures.txt index c79dc5c7d26..c133fd51004 100644 --- a/dev-tools/src/main/resources/forbidden/all-signatures.txt +++ b/dev-tools/src/main/resources/forbidden/all-signatures.txt @@ -119,6 +119,7 @@ com.google.common.collect.UnmodifiableIterator com.google.common.collect.ObjectArrays com.google.common.collect.Multimap com.google.common.collect.MultimapBuilder +com.google.common.math.LongMath @defaultMessage Do not violate java's access system java.lang.reflect.AccessibleObject#setAccessible(boolean)