-
Notifications
You must be signed in to change notification settings - Fork 24.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Use Set instead of LongSet in long script field #85417
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -1098,7 +1098,7 @@ public static double objectToDouble(Object value) { | |
* Converts an Object to a {@code long} by checking it against known | ||
* types and checking its range. | ||
*/ | ||
public static long objectToLong(Object value, boolean coerce) { | ||
public static Long objectToLong(Object value, boolean coerce) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'd probably keep the return type on this one too. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Changed back to primitive. |
||
if (value instanceof Long) { | ||
return (Long) value; | ||
} | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -16,20 +16,21 @@ | |
import java.math.BigInteger; | ||
import java.util.concurrent.atomic.AtomicInteger; | ||
|
||
import static org.hamcrest.Matchers.equalTo; | ||
import static org.hamcrest.Matchers.is; | ||
|
||
public class NumbersTests extends ESTestCase { | ||
|
||
@Timeout(millis = 10000) | ||
public void testToLong() { | ||
assertEquals(3L, Numbers.toLong("3", false)); | ||
assertEquals(3L, Numbers.toLong("3.1", true)); | ||
assertEquals(9223372036854775807L, Numbers.toLong("9223372036854775807.00", false)); | ||
assertEquals(-9223372036854775808L, Numbers.toLong("-9223372036854775808.00", false)); | ||
assertEquals(9223372036854775807L, Numbers.toLong("9223372036854775807.00", true)); | ||
assertEquals(-9223372036854775808L, Numbers.toLong("-9223372036854775808.00", true)); | ||
assertEquals(9223372036854775807L, Numbers.toLong("9223372036854775807.99", true)); | ||
assertEquals(-9223372036854775808L, Numbers.toLong("-9223372036854775808.99", true)); | ||
assertThat(Numbers.toLong("3", false), equalTo(3L)); | ||
assertThat(Numbers.toLong("3.1", true), equalTo(3L)); | ||
assertThat(Numbers.toLong("9223372036854775807.00", false), equalTo(9223372036854775807L)); | ||
assertThat(Numbers.toLong("-9223372036854775808.00", false), equalTo(-9223372036854775808L)); | ||
assertThat(Numbers.toLong("9223372036854775807.00", true), equalTo(9223372036854775807L)); | ||
assertThat(Numbers.toLong("-9223372036854775808.00", true), equalTo(-9223372036854775808L)); | ||
assertThat(Numbers.toLong("9223372036854775807.99", true), equalTo(9223372036854775807L)); | ||
assertThat(Numbers.toLong("-9223372036854775808.99", true), equalTo(-9223372036854775808L)); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 👍 |
||
|
||
assertEquals( | ||
"Value [9223372036854775808] is out of range for a long", | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think I'd keep the return type on this one.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I moved this to return the boxed type so that we do not rely on the JIT to inline+elide this boxing. Otherwise we would parse into a primitive
long
, then need to box when actually inserting into the set. I don't feel strongly about this, though.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I thought about it more, and I changed back to primitive.