mirror of
https://github.com/apache/commons-lang.git
synced 2025-02-06 10:08:32 +00:00
Applying Ben's patch of Brian Egge's improvement in LANG-321
git-svn-id: https://svn.apache.org/repos/asf/commons/proper/lang/trunk@594388 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
930b389bac
commit
da6569b4a6
@ -381,4 +381,17 @@ public String toString() {
|
|||||||
return toString;
|
return toString;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* <p>Returns an array containing all the integer values in the range.</p>
|
||||||
|
*
|
||||||
|
* @return the <code>int[]</code> representation of this range
|
||||||
|
*/
|
||||||
|
public int[] toArray() {
|
||||||
|
int[] array = new int[max - min + 1];
|
||||||
|
for (int i = 0; i < array.length; i++) {
|
||||||
|
array[i] = min + i;
|
||||||
|
}
|
||||||
|
|
||||||
|
return array;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -394,4 +394,17 @@ public String toString() {
|
|||||||
return toString;
|
return toString;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* <p>Returns an array containing all the long values in the range.</p>
|
||||||
|
*
|
||||||
|
* @return the <code>long[]</code> representation of this range
|
||||||
|
*/
|
||||||
|
public long[] toArray() {
|
||||||
|
long[] array = new long[(int)(max - min + 1L)];
|
||||||
|
for(int i = 0; i < array.length; i++) {
|
||||||
|
array[i] = min + i;
|
||||||
|
}
|
||||||
|
return array;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -21,6 +21,8 @@
|
|||||||
import junit.framework.Test;
|
import junit.framework.Test;
|
||||||
import junit.framework.TestSuite;
|
import junit.framework.TestSuite;
|
||||||
|
|
||||||
|
import java.util.Arrays;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Test cases for the {@link IntRange} class.
|
* Test cases for the {@link IntRange} class.
|
||||||
*
|
*
|
||||||
@ -160,6 +162,13 @@ public void testContainsIntegerBig() {
|
|||||||
assertEquals(false, big.containsInteger(Integer.MAX_VALUE - 3));
|
assertEquals(false, big.containsInteger(Integer.MAX_VALUE - 3));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void testToArray() {
|
||||||
|
int[] threeItems = new IntRange(3, 5).toArray();
|
||||||
|
assertTrue(Arrays.equals(new int[]{3, 4, 5}, threeItems));
|
||||||
|
int[] oneItem = new IntRange(4).toArray();
|
||||||
|
assertTrue(Arrays.equals(new int[]{4}, oneItem));
|
||||||
|
}
|
||||||
|
|
||||||
//--------------------------------------------------------------------------
|
//--------------------------------------------------------------------------
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -21,6 +21,8 @@
|
|||||||
import junit.framework.Test;
|
import junit.framework.Test;
|
||||||
import junit.framework.TestSuite;
|
import junit.framework.TestSuite;
|
||||||
|
|
||||||
|
import java.util.Arrays;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Test cases for the {@link LongRange} class.
|
* Test cases for the {@link LongRange} class.
|
||||||
*
|
*
|
||||||
@ -148,6 +150,13 @@ public void testContainsLongBig() {
|
|||||||
assertEquals(false, big.containsLong(Long.MAX_VALUE - 3));
|
assertEquals(false, big.containsLong(Long.MAX_VALUE - 3));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void testToArray() {
|
||||||
|
long[] threeItems = new LongRange(3, 5).toArray();
|
||||||
|
assertTrue(Arrays.equals(new long[]{3, 4, 5}, threeItems));
|
||||||
|
long[] oneItem = new LongRange(4).toArray();
|
||||||
|
assertTrue(Arrays.equals(new long[]{4}, oneItem));
|
||||||
|
}
|
||||||
|
|
||||||
//--------------------------------------------------------------------------
|
//--------------------------------------------------------------------------
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user