From 6597c196521af500feef7a02610727eafa7ec1dc Mon Sep 17 00:00:00 2001 From: Allon Mureinik Date: Sat, 4 Mar 2017 05:55:03 +0200 Subject: [PATCH] Use long literals (closes #248) This patch replaces int literals that were cast to longs (e.g., "(long) 1)" with long literals (e.g., "1L"), making the code cleaner and easier to maintain. --- .../lang3/ArrayUtilsRemoveMultipleTest.java | 26 ++++++------ .../commons/lang3/ArrayUtilsRemoveTest.java | 10 ++--- .../org/apache/commons/lang3/RangeTest.java | 2 +- .../lang3/mutable/MutableLongTest.java | 40 +++++++++---------- 4 files changed, 39 insertions(+), 39 deletions(-) diff --git a/src/test/java/org/apache/commons/lang3/ArrayUtilsRemoveMultipleTest.java b/src/test/java/org/apache/commons/lang3/ArrayUtilsRemoveMultipleTest.java index b6f22d558..341402778 100644 --- a/src/test/java/org/apache/commons/lang3/ArrayUtilsRemoveMultipleTest.java +++ b/src/test/java/org/apache/commons/lang3/ArrayUtilsRemoveMultipleTest.java @@ -1158,53 +1158,53 @@ public class ArrayUtilsRemoveMultipleTest { public void testRemoveElementLongArray() { long[] array; - array = ArrayUtils.removeElements((long[]) null, (long) 1); + array = ArrayUtils.removeElements((long[]) null, 1L); assertNull(array); - array = ArrayUtils.removeElements(ArrayUtils.EMPTY_LONG_ARRAY, (long) 1); + array = ArrayUtils.removeElements(ArrayUtils.EMPTY_LONG_ARRAY, 1L); assertTrue(Arrays.equals(ArrayUtils.EMPTY_LONG_ARRAY, array)); assertEquals(Long.TYPE, array.getClass().getComponentType()); - array = ArrayUtils.removeElements(new long[] { 1 }, (long) 1); + array = ArrayUtils.removeElements(new long[] { 1 }, 1L); assertTrue(Arrays.equals(ArrayUtils.EMPTY_LONG_ARRAY, array)); assertEquals(Long.TYPE, array.getClass().getComponentType()); - array = ArrayUtils.removeElements(new long[] { 1, 2 }, (long) 1); + array = ArrayUtils.removeElements(new long[] { 1, 2 }, 1L); assertTrue(Arrays.equals(new long[] { 2 }, array)); assertEquals(Long.TYPE, array.getClass().getComponentType()); - array = ArrayUtils.removeElements(new long[] { 1, 2, 1 }, (long) 1); + array = ArrayUtils.removeElements(new long[] { 1, 2, 1 }, 1L); assertTrue(Arrays.equals(new long[] { 2, 1 }, array)); assertEquals(Long.TYPE, array.getClass().getComponentType()); - array = ArrayUtils.removeElements((long[]) null, (long) 1, (long) 1); + array = ArrayUtils.removeElements((long[]) null, 1L, 1L); assertNull(array); - array = ArrayUtils.removeElements(ArrayUtils.EMPTY_LONG_ARRAY, (long) 1, (long) 1); + array = ArrayUtils.removeElements(ArrayUtils.EMPTY_LONG_ARRAY, 1L, 1L); assertTrue(Arrays.equals(ArrayUtils.EMPTY_LONG_ARRAY, array)); assertEquals(Long.TYPE, array.getClass().getComponentType()); - array = ArrayUtils.removeElements(new long[] { 1 }, (long) 1, (long) 1); + array = ArrayUtils.removeElements(new long[] { 1 }, 1L, 1L); assertTrue(Arrays.equals(ArrayUtils.EMPTY_LONG_ARRAY, array)); assertEquals(Long.TYPE, array.getClass().getComponentType()); - array = ArrayUtils.removeElements(new long[] { 1, 2 }, (long) 1, (long) 2); + array = ArrayUtils.removeElements(new long[] { 1, 2 }, 1L, 2L); assertTrue(Arrays.equals(ArrayUtils.EMPTY_LONG_ARRAY, array)); assertEquals(Long.TYPE, array.getClass().getComponentType()); - array = ArrayUtils.removeElements(new long[] { 1, 2 }, (long) 1, (long) 1); + array = ArrayUtils.removeElements(new long[] { 1, 2 }, 1L, 1L); assertTrue(Arrays.equals(new long[] { 2 }, array)); assertEquals(Long.TYPE, array.getClass().getComponentType()); - array = ArrayUtils.removeElements(new long[] { 1, 2, 1 }, (long) 1, (long) 1); + array = ArrayUtils.removeElements(new long[] { 1, 2, 1 }, 1L, 1L); assertTrue(Arrays.equals(new long[] { 2 }, array)); assertEquals(Long.TYPE, array.getClass().getComponentType()); - array = ArrayUtils.removeElements(new long[] { 1, 2, 1 }, (long) 1, (long) 2); + array = ArrayUtils.removeElements(new long[] { 1, 2, 1 }, 1L, 2L); assertTrue(Arrays.equals(new long[] { 1 }, array)); assertEquals(Long.TYPE, array.getClass().getComponentType()); - array = ArrayUtils.removeElements(new long[] { 1, 2, 1 }, (long) 1, (long) 1, (long) 1, (long) 1); + array = ArrayUtils.removeElements(new long[] { 1, 2, 1 }, 1L, 1L, 1L, 1L); assertTrue(Arrays.equals(new long[] { 2 }, array)); assertEquals(Long.TYPE, array.getClass().getComponentType()); } diff --git a/src/test/java/org/apache/commons/lang3/ArrayUtilsRemoveTest.java b/src/test/java/org/apache/commons/lang3/ArrayUtilsRemoveTest.java index 995afb26c..0572f8cef 100644 --- a/src/test/java/org/apache/commons/lang3/ArrayUtilsRemoveTest.java +++ b/src/test/java/org/apache/commons/lang3/ArrayUtilsRemoveTest.java @@ -447,18 +447,18 @@ public class ArrayUtilsRemoveTest { @SuppressWarnings("cast") public void testRemoveElementLongArray() { long[] array; - array = ArrayUtils.removeElement((long[]) null, (long) 1); + array = ArrayUtils.removeElement((long[]) null, 1L); assertNull(array); - array = ArrayUtils.removeElement(ArrayUtils.EMPTY_LONG_ARRAY, (long) 1); + array = ArrayUtils.removeElement(ArrayUtils.EMPTY_LONG_ARRAY, 1L); assertTrue(Arrays.equals(ArrayUtils.EMPTY_LONG_ARRAY, array)); assertEquals(Long.TYPE, array.getClass().getComponentType()); - array = ArrayUtils.removeElement(new long[] {1}, (long) 1); + array = ArrayUtils.removeElement(new long[] {1}, 1L); assertTrue(Arrays.equals(ArrayUtils.EMPTY_LONG_ARRAY, array)); assertEquals(Long.TYPE, array.getClass().getComponentType()); - array = ArrayUtils.removeElement(new long[] {1, 2}, (long) 1); + array = ArrayUtils.removeElement(new long[] {1, 2}, 1L); assertTrue(Arrays.equals(new long[] {2}, array)); assertEquals(Long.TYPE, array.getClass().getComponentType()); - array = ArrayUtils.removeElement(new long[] {1, 2, 1}, (long) 1); + array = ArrayUtils.removeElement(new long[] {1, 2, 1}, 1L); assertTrue(Arrays.equals(new long[] {2, 1}, array)); assertEquals(Long.TYPE, array.getClass().getComponentType()); } diff --git a/src/test/java/org/apache/commons/lang3/RangeTest.java b/src/test/java/org/apache/commons/lang3/RangeTest.java index ffa31bbc9..03ed509ac 100644 --- a/src/test/java/org/apache/commons/lang3/RangeTest.java +++ b/src/test/java/org/apache/commons/lang3/RangeTest.java @@ -54,7 +54,7 @@ public class RangeTest { byteRange3 = Range.between((byte) 0, (byte) 10); intRange = Range.between(10, 20); - longRange = Range.between((long) 10, (long) 20); + longRange = Range.between(10L, 20L); floatRange = Range.between((float) 10, (float) 20); doubleRange = Range.between((double) 10, (double) 20); } diff --git a/src/test/java/org/apache/commons/lang3/mutable/MutableLongTest.java b/src/test/java/org/apache/commons/lang3/mutable/MutableLongTest.java index fdf8bef49..58efbc693 100644 --- a/src/test/java/org/apache/commons/lang3/mutable/MutableLongTest.java +++ b/src/test/java/org/apache/commons/lang3/mutable/MutableLongTest.java @@ -144,7 +144,7 @@ public class MutableLongTest { @Test public void testIncrementAndGet() { - final MutableLong mutNum = new MutableLong((long) 1); + final MutableLong mutNum = new MutableLong(1L); final long result = mutNum.incrementAndGet(); assertEquals(2, result); @@ -154,7 +154,7 @@ public class MutableLongTest { @Test public void testGetAndIncrement() { - final MutableLong mutNum = new MutableLong((long) 1); + final MutableLong mutNum = new MutableLong(1L); final long result = mutNum.getAndIncrement(); assertEquals(1, result); @@ -173,7 +173,7 @@ public class MutableLongTest { @Test public void testDecrementAndGet() { - final MutableLong mutNum = new MutableLong((long) 1); + final MutableLong mutNum = new MutableLong(1L); final long result = mutNum.decrementAndGet(); assertEquals(0, result); @@ -183,7 +183,7 @@ public class MutableLongTest { @Test public void testGetAndDecrement() { - final MutableLong mutNum = new MutableLong((long) 1); + final MutableLong mutNum = new MutableLong(1L); final long result = mutNum.getAndDecrement(); assertEquals(1, result); @@ -211,38 +211,38 @@ public class MutableLongTest { @Test public void testGetAndAddValuePrimitive() { - final MutableLong mutableLong = new MutableLong((long)0); - final long result = mutableLong.getAndAdd((long) 1); + final MutableLong mutableLong = new MutableLong(0L); + final long result = mutableLong.getAndAdd(1L); - assertEquals((long) 0, result); - assertEquals((long) 1, mutableLong.longValue()); + assertEquals(0L, result); + assertEquals(1L, mutableLong.longValue()); } @Test public void testGetAndAddValueObject() { - final MutableLong mutableLong = new MutableLong((long)0); - final long result = mutableLong.getAndAdd(Long.valueOf((long) 1)); + final MutableLong mutableLong = new MutableLong(0L); + final long result = mutableLong.getAndAdd(Long.valueOf(1L)); - assertEquals((long) 0, result); - assertEquals((long) 1, mutableLong.longValue()); + assertEquals(0L, result); + assertEquals(1L, mutableLong.longValue()); } @Test public void testAddAndGetValuePrimitive() { - final MutableLong mutableLong = new MutableLong((long)0); - final long result = mutableLong.addAndGet((long) 1); + final MutableLong mutableLong = new MutableLong(0L); + final long result = mutableLong.addAndGet(1L); - assertEquals((long) 1, result); - assertEquals((long) 1, mutableLong.longValue()); + assertEquals(1L, result); + assertEquals(1L, mutableLong.longValue()); } @Test public void testAddAndGetValueObject() { - final MutableLong mutableLong = new MutableLong((long)0); - final long result = mutableLong.addAndGet(Long.valueOf((long) 1)); + final MutableLong mutableLong = new MutableLong(0L); + final long result = mutableLong.addAndGet(Long.valueOf(1L)); - assertEquals((long) 1, result); - assertEquals((long) 1, mutableLong.longValue()); + assertEquals(1L, result); + assertEquals(1L, mutableLong.longValue()); } @Test