Return-Path: Delivered-To: apmail-commons-issues-archive@locus.apache.org Received: (qmail 51790 invoked from network); 13 Nov 2007 00:58:15 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (140.211.11.2) by minotaur.apache.org with SMTP; 13 Nov 2007 00:58:15 -0000 Received: (qmail 22519 invoked by uid 500); 13 Nov 2007 00:58:02 -0000 Delivered-To: apmail-commons-issues-archive@commons.apache.org Received: (qmail 22434 invoked by uid 500); 13 Nov 2007 00:58:02 -0000 Mailing-List: contact issues-help@commons.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: issues@commons.apache.org Delivered-To: mailing list issues@commons.apache.org Received: (qmail 22425 invoked by uid 99); 13 Nov 2007 00:58:01 -0000 Received: from nike.apache.org (HELO nike.apache.org) (192.87.106.230) by apache.org (qpsmtpd/0.29) with ESMTP; Mon, 12 Nov 2007 16:58:01 -0800 X-ASF-Spam-Status: No, hits=-100.0 required=10.0 tests=ALL_TRUSTED X-Spam-Check-By: apache.org Received: from [140.211.11.4] (HELO brutus.apache.org) (140.211.11.4) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 13 Nov 2007 00:58:59 +0000 Received: from brutus (localhost [127.0.0.1]) by brutus.apache.org (Postfix) with ESMTP id D9469714211 for ; Mon, 12 Nov 2007 16:57:50 -0800 (PST) Message-ID: <32055691.1194915470887.JavaMail.jira@brutus> Date: Mon, 12 Nov 2007 16:57:50 -0800 (PST) From: "Ben Speakmon (JIRA)" To: issues@commons.apache.org Subject: [jira] Updated: (LANG-321) [patch] Add toArray() method to IntRange and LongRange classes MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 7bit X-Virus-Checked: Checked by ClamAV on apache.org [ https://issues.apache.org/jira/browse/LANG-321?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ] Ben Speakmon updated LANG-321: ------------------------------ Attachment: LANG-321.patch > [patch] Add toArray() method to IntRange and LongRange classes > -------------------------------------------------------------- > > Key: LANG-321 > URL: https://issues.apache.org/jira/browse/LANG-321 > Project: Commons Lang > Issue Type: New Feature > Reporter: Brian Egge > Priority: Trivial > Fix For: 2.4 > > Attachments: LANG-321.patch > > > I've found it useful to use the range class to create an int[] or long[] array of a sequence on numbers. > Index: src/test/org/apache/commons/lang/math/IntRangeTest.java > =================================================================== > --- src/test/org/apache/commons/lang/math/IntRangeTest.java (revision 506779) > +++ src/test/org/apache/commons/lang/math/IntRangeTest.java (working copy) > @@ -21,6 +21,8 @@ > import junit.framework.Test; > import junit.framework.TestSuite; > > +import java.util.Arrays; > + > /** > * Test cases for the {@link IntRange} class. > * > @@ -160,6 +162,13 @@ > 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)); > + } > + > //-------------------------------------------------------------------------- > > } > Index: src/test/org/apache/commons/lang/math/LongRangeTest.java > =================================================================== > --- src/test/org/apache/commons/lang/math/LongRangeTest.java (revision 506779) > +++ src/test/org/apache/commons/lang/math/LongRangeTest.java (working copy) > @@ -21,6 +21,8 @@ > import junit.framework.Test; > import junit.framework.TestSuite; > > +import java.util.Arrays; > + > /** > * Test cases for the {@link LongRange} class. > * > @@ -148,6 +150,12 @@ > 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)); > + } > //-------------------------------------------------------------------------- > > } > Index: src/java/org/apache/commons/lang/math/IntRange.java > =================================================================== > --- src/java/org/apache/commons/lang/math/IntRange.java (revision 506779) > +++ src/java/org/apache/commons/lang/math/IntRange.java (working copy) > @@ -381,4 +381,16 @@ > return toString; > } > > + /** > + *

A built in array containing all the integer values in the range.

> + * > + * @return the int[] 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; > + } > } > Index: src/java/org/apache/commons/lang/math/LongRange.java > =================================================================== > --- src/java/org/apache/commons/lang/math/LongRange.java (revision 506779) > +++ src/java/org/apache/commons/lang/math/LongRange.java (working copy) > @@ -394,4 +394,16 @@ > return toString; > } > > + /** > + *

A built in array containing all the integer values in the range.

> + * > + * @return the long[] 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; > + } > } -- This message is automatically generated by JIRA. - You can reply to this email to add a comment to the issue online.