[jira] [Updated] (LANG-536) Add isSorted() to ArrayUtils

2014-10-17 Thread James Sawle (JIRA)

 [ 
https://issues.apache.org/jira/browse/LANG-536?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
 ]

James Sawle updated LANG-536:
-
Attachment: LANG-536.diff

> Add isSorted() to ArrayUtils
> 
>
> Key: LANG-536
> URL: https://issues.apache.org/jira/browse/LANG-536
> Project: Commons Lang
>  Issue Type: New Feature
>  Components: lang.*
>Reporter: Sergei Ivanov
>Assignee: Duncan Jones
>Priority: Minor
> Fix For: Review Patch
>
> Attachments: LANG-536.diff, perftest.zip
>
>
> In my unit tests I often need to verify that an array is correctly sorted.
> In order to achieve this, I've got two helper methods as follows.
> Is it possible to integrate these methods into ArrayUtils?
> {code}
> /**
>  * Checks that the specified array of objects is in an ascending order
>  * according to the specified comparator.  All elements in the array must 
> be
>  * mutually comparable by the specified comparator (that is,
>  * c.compare(e1, e2) must not throw a ClassCastException
>  * for any elements e1 and e2 in the array).
>  *
>  * @param a the array to be checked.
>  * @param c the comparator to determine the order of the array.  A
>  * null value indicates that the elements'
>  * {@linkplain Comparable natural ordering} should be used.
>  * @return {@code true}, if the array is sorted; {@code false}, otherwise.
>  * @throws ClassCastException if the array contains elements that are
>  * not mutually comparable using the specified comparator.
>  */
> public static  boolean isSorted(final T[] a, final Comparator T> c) {
> if (a.length <= 1) {
> // Empty or singleton arrays are always sorted
> return true;
> }
> // Otherwise, check that every element is not smaller than the 
> previous
> T previous = a[0];
> for (int i = 1, n = a.length; i < n; i++) {
> final T current = a[i];
> if (c.compare(previous, current) > 0) {
> return false;
> }
> previous = current;
> }
> return true;
> }
> /**
>  * Checks that the specified array of objects is in an ascending order,
>  * according to the {@linkplain Comparable natural ordering} of its 
> elements.
>  * All elements in the array must implement the {@link Comparable} 
> interface.
>  * Furthermore, all elements in the array must be mutually 
> comparable
>  * (that is, e1.compareTo(e2) must not throw a 
> ClassCastException
>  * for any elements e1 and e2 in the array).
>  *
>  * @param a the array to be checked.
>  * @return {@code true}, if the array is sorted; {@code false}, otherwise.
>  * @throws ClassCastException if the array contains elements that are not
>  * mutually comparable (for example, strings and integers).
>  */
> @SuppressWarnings({"unchecked"})
> public static  boolean isSorted(final T[] a) {
> if (a.length <= 1) {
> // Empty or singleton arrays are always sorted
> return true;
> }
> // Otherwise, check that every element is not smaller than the 
> previous
> T previous = a[0];
> for (int i = 1, n = a.length; i < n; i++) {
> final T current = a[i];
> if (((Comparable) previous).compareTo(previous) > 0) {
> return false;
> }
> previous = current;
> }
> return true;
> }
> {code}



--
This message was sent by Atlassian JIRA
(v6.3.4#6332)


[jira] [Updated] (LANG-536) Add isSorted() to ArrayUtils

2014-10-17 Thread James Sawle (JIRA)

 [ 
https://issues.apache.org/jira/browse/LANG-536?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
 ]

James Sawle updated LANG-536:
-
Attachment: (was: LANG-536.diff)

> Add isSorted() to ArrayUtils
> 
>
> Key: LANG-536
> URL: https://issues.apache.org/jira/browse/LANG-536
> Project: Commons Lang
>  Issue Type: New Feature
>  Components: lang.*
>Reporter: Sergei Ivanov
>Assignee: Duncan Jones
>Priority: Minor
> Fix For: Review Patch
>
> Attachments: LANG-536.diff, perftest.zip
>
>
> In my unit tests I often need to verify that an array is correctly sorted.
> In order to achieve this, I've got two helper methods as follows.
> Is it possible to integrate these methods into ArrayUtils?
> {code}
> /**
>  * Checks that the specified array of objects is in an ascending order
>  * according to the specified comparator.  All elements in the array must 
> be
>  * mutually comparable by the specified comparator (that is,
>  * c.compare(e1, e2) must not throw a ClassCastException
>  * for any elements e1 and e2 in the array).
>  *
>  * @param a the array to be checked.
>  * @param c the comparator to determine the order of the array.  A
>  * null value indicates that the elements'
>  * {@linkplain Comparable natural ordering} should be used.
>  * @return {@code true}, if the array is sorted; {@code false}, otherwise.
>  * @throws ClassCastException if the array contains elements that are
>  * not mutually comparable using the specified comparator.
>  */
> public static  boolean isSorted(final T[] a, final Comparator T> c) {
> if (a.length <= 1) {
> // Empty or singleton arrays are always sorted
> return true;
> }
> // Otherwise, check that every element is not smaller than the 
> previous
> T previous = a[0];
> for (int i = 1, n = a.length; i < n; i++) {
> final T current = a[i];
> if (c.compare(previous, current) > 0) {
> return false;
> }
> previous = current;
> }
> return true;
> }
> /**
>  * Checks that the specified array of objects is in an ascending order,
>  * according to the {@linkplain Comparable natural ordering} of its 
> elements.
>  * All elements in the array must implement the {@link Comparable} 
> interface.
>  * Furthermore, all elements in the array must be mutually 
> comparable
>  * (that is, e1.compareTo(e2) must not throw a 
> ClassCastException
>  * for any elements e1 and e2 in the array).
>  *
>  * @param a the array to be checked.
>  * @return {@code true}, if the array is sorted; {@code false}, otherwise.
>  * @throws ClassCastException if the array contains elements that are not
>  * mutually comparable (for example, strings and integers).
>  */
> @SuppressWarnings({"unchecked"})
> public static  boolean isSorted(final T[] a) {
> if (a.length <= 1) {
> // Empty or singleton arrays are always sorted
> return true;
> }
> // Otherwise, check that every element is not smaller than the 
> previous
> T previous = a[0];
> for (int i = 1, n = a.length; i < n; i++) {
> final T current = a[i];
> if (((Comparable) previous).compareTo(previous) > 0) {
> return false;
> }
> previous = current;
> }
> return true;
> }
> {code}



--
This message was sent by Atlassian JIRA
(v6.3.4#6332)


[jira] [Updated] (LANG-536) Add isSorted() to ArrayUtils

2014-10-17 Thread James Sawle (JIRA)

 [ 
https://issues.apache.org/jira/browse/LANG-536?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
 ]

James Sawle updated LANG-536:
-
Attachment: LANG-536.diff

> Add isSorted() to ArrayUtils
> 
>
> Key: LANG-536
> URL: https://issues.apache.org/jira/browse/LANG-536
> Project: Commons Lang
>  Issue Type: New Feature
>  Components: lang.*
>Reporter: Sergei Ivanov
>Assignee: Duncan Jones
>Priority: Minor
> Fix For: Review Patch
>
> Attachments: LANG-536.diff, perftest.zip
>
>
> In my unit tests I often need to verify that an array is correctly sorted.
> In order to achieve this, I've got two helper methods as follows.
> Is it possible to integrate these methods into ArrayUtils?
> {code}
> /**
>  * Checks that the specified array of objects is in an ascending order
>  * according to the specified comparator.  All elements in the array must 
> be
>  * mutually comparable by the specified comparator (that is,
>  * c.compare(e1, e2) must not throw a ClassCastException
>  * for any elements e1 and e2 in the array).
>  *
>  * @param a the array to be checked.
>  * @param c the comparator to determine the order of the array.  A
>  * null value indicates that the elements'
>  * {@linkplain Comparable natural ordering} should be used.
>  * @return {@code true}, if the array is sorted; {@code false}, otherwise.
>  * @throws ClassCastException if the array contains elements that are
>  * not mutually comparable using the specified comparator.
>  */
> public static  boolean isSorted(final T[] a, final Comparator T> c) {
> if (a.length <= 1) {
> // Empty or singleton arrays are always sorted
> return true;
> }
> // Otherwise, check that every element is not smaller than the 
> previous
> T previous = a[0];
> for (int i = 1, n = a.length; i < n; i++) {
> final T current = a[i];
> if (c.compare(previous, current) > 0) {
> return false;
> }
> previous = current;
> }
> return true;
> }
> /**
>  * Checks that the specified array of objects is in an ascending order,
>  * according to the {@linkplain Comparable natural ordering} of its 
> elements.
>  * All elements in the array must implement the {@link Comparable} 
> interface.
>  * Furthermore, all elements in the array must be mutually 
> comparable
>  * (that is, e1.compareTo(e2) must not throw a 
> ClassCastException
>  * for any elements e1 and e2 in the array).
>  *
>  * @param a the array to be checked.
>  * @return {@code true}, if the array is sorted; {@code false}, otherwise.
>  * @throws ClassCastException if the array contains elements that are not
>  * mutually comparable (for example, strings and integers).
>  */
> @SuppressWarnings({"unchecked"})
> public static  boolean isSorted(final T[] a) {
> if (a.length <= 1) {
> // Empty or singleton arrays are always sorted
> return true;
> }
> // Otherwise, check that every element is not smaller than the 
> previous
> T previous = a[0];
> for (int i = 1, n = a.length; i < n; i++) {
> final T current = a[i];
> if (((Comparable) previous).compareTo(previous) > 0) {
> return false;
> }
> previous = current;
> }
> return true;
> }
> {code}



--
This message was sent by Atlassian JIRA
(v6.3.4#6332)


[jira] [Updated] (LANG-536) Add isSorted() to ArrayUtils

2014-10-17 Thread James Sawle (JIRA)

 [ 
https://issues.apache.org/jira/browse/LANG-536?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
 ]

James Sawle updated LANG-536:
-
Attachment: (was: LANG-536.diff)

> Add isSorted() to ArrayUtils
> 
>
> Key: LANG-536
> URL: https://issues.apache.org/jira/browse/LANG-536
> Project: Commons Lang
>  Issue Type: New Feature
>  Components: lang.*
>Reporter: Sergei Ivanov
>Assignee: Duncan Jones
>Priority: Minor
> Fix For: Review Patch
>
> Attachments: LANG-536.diff, perftest.zip
>
>
> In my unit tests I often need to verify that an array is correctly sorted.
> In order to achieve this, I've got two helper methods as follows.
> Is it possible to integrate these methods into ArrayUtils?
> {code}
> /**
>  * Checks that the specified array of objects is in an ascending order
>  * according to the specified comparator.  All elements in the array must 
> be
>  * mutually comparable by the specified comparator (that is,
>  * c.compare(e1, e2) must not throw a ClassCastException
>  * for any elements e1 and e2 in the array).
>  *
>  * @param a the array to be checked.
>  * @param c the comparator to determine the order of the array.  A
>  * null value indicates that the elements'
>  * {@linkplain Comparable natural ordering} should be used.
>  * @return {@code true}, if the array is sorted; {@code false}, otherwise.
>  * @throws ClassCastException if the array contains elements that are
>  * not mutually comparable using the specified comparator.
>  */
> public static  boolean isSorted(final T[] a, final Comparator T> c) {
> if (a.length <= 1) {
> // Empty or singleton arrays are always sorted
> return true;
> }
> // Otherwise, check that every element is not smaller than the 
> previous
> T previous = a[0];
> for (int i = 1, n = a.length; i < n; i++) {
> final T current = a[i];
> if (c.compare(previous, current) > 0) {
> return false;
> }
> previous = current;
> }
> return true;
> }
> /**
>  * Checks that the specified array of objects is in an ascending order,
>  * according to the {@linkplain Comparable natural ordering} of its 
> elements.
>  * All elements in the array must implement the {@link Comparable} 
> interface.
>  * Furthermore, all elements in the array must be mutually 
> comparable
>  * (that is, e1.compareTo(e2) must not throw a 
> ClassCastException
>  * for any elements e1 and e2 in the array).
>  *
>  * @param a the array to be checked.
>  * @return {@code true}, if the array is sorted; {@code false}, otherwise.
>  * @throws ClassCastException if the array contains elements that are not
>  * mutually comparable (for example, strings and integers).
>  */
> @SuppressWarnings({"unchecked"})
> public static  boolean isSorted(final T[] a) {
> if (a.length <= 1) {
> // Empty or singleton arrays are always sorted
> return true;
> }
> // Otherwise, check that every element is not smaller than the 
> previous
> T previous = a[0];
> for (int i = 1, n = a.length; i < n; i++) {
> final T current = a[i];
> if (((Comparable) previous).compareTo(previous) > 0) {
> return false;
> }
> previous = current;
> }
> return true;
> }
> {code}



--
This message was sent by Atlassian JIRA
(v6.3.4#6332)


[jira] [Updated] (LANG-536) Add isSorted() to ArrayUtils

2014-10-17 Thread James Sawle (JIRA)

 [ 
https://issues.apache.org/jira/browse/LANG-536?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
 ]

James Sawle updated LANG-536:
-
Attachment: LANG-536.diff

The patch version of the Git pull request.

> Add isSorted() to ArrayUtils
> 
>
> Key: LANG-536
> URL: https://issues.apache.org/jira/browse/LANG-536
> Project: Commons Lang
>  Issue Type: New Feature
>  Components: lang.*
>Reporter: Sergei Ivanov
>Assignee: Duncan Jones
>Priority: Minor
> Fix For: Review Patch
>
> Attachments: LANG-536.diff, perftest.zip
>
>
> In my unit tests I often need to verify that an array is correctly sorted.
> In order to achieve this, I've got two helper methods as follows.
> Is it possible to integrate these methods into ArrayUtils?
> {code}
> /**
>  * Checks that the specified array of objects is in an ascending order
>  * according to the specified comparator.  All elements in the array must 
> be
>  * mutually comparable by the specified comparator (that is,
>  * c.compare(e1, e2) must not throw a ClassCastException
>  * for any elements e1 and e2 in the array).
>  *
>  * @param a the array to be checked.
>  * @param c the comparator to determine the order of the array.  A
>  * null value indicates that the elements'
>  * {@linkplain Comparable natural ordering} should be used.
>  * @return {@code true}, if the array is sorted; {@code false}, otherwise.
>  * @throws ClassCastException if the array contains elements that are
>  * not mutually comparable using the specified comparator.
>  */
> public static  boolean isSorted(final T[] a, final Comparator T> c) {
> if (a.length <= 1) {
> // Empty or singleton arrays are always sorted
> return true;
> }
> // Otherwise, check that every element is not smaller than the 
> previous
> T previous = a[0];
> for (int i = 1, n = a.length; i < n; i++) {
> final T current = a[i];
> if (c.compare(previous, current) > 0) {
> return false;
> }
> previous = current;
> }
> return true;
> }
> /**
>  * Checks that the specified array of objects is in an ascending order,
>  * according to the {@linkplain Comparable natural ordering} of its 
> elements.
>  * All elements in the array must implement the {@link Comparable} 
> interface.
>  * Furthermore, all elements in the array must be mutually 
> comparable
>  * (that is, e1.compareTo(e2) must not throw a 
> ClassCastException
>  * for any elements e1 and e2 in the array).
>  *
>  * @param a the array to be checked.
>  * @return {@code true}, if the array is sorted; {@code false}, otherwise.
>  * @throws ClassCastException if the array contains elements that are not
>  * mutually comparable (for example, strings and integers).
>  */
> @SuppressWarnings({"unchecked"})
> public static  boolean isSorted(final T[] a) {
> if (a.length <= 1) {
> // Empty or singleton arrays are always sorted
> return true;
> }
> // Otherwise, check that every element is not smaller than the 
> previous
> T previous = a[0];
> for (int i = 1, n = a.length; i < n; i++) {
> final T current = a[i];
> if (((Comparable) previous).compareTo(previous) > 0) {
> return false;
> }
> previous = current;
> }
> return true;
> }
> {code}



--
This message was sent by Atlassian JIRA
(v6.3.4#6332)


[jira] [Updated] (LANG-536) Add isSorted() to ArrayUtils

2014-10-17 Thread James Sawle (JIRA)

 [ 
https://issues.apache.org/jira/browse/LANG-536?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
 ]

James Sawle updated LANG-536:
-
Attachment: (was: LANG-536.patch)

> Add isSorted() to ArrayUtils
> 
>
> Key: LANG-536
> URL: https://issues.apache.org/jira/browse/LANG-536
> Project: Commons Lang
>  Issue Type: New Feature
>  Components: lang.*
>Reporter: Sergei Ivanov
>Assignee: Duncan Jones
>Priority: Minor
> Fix For: Review Patch
>
> Attachments: perftest.zip
>
>
> In my unit tests I often need to verify that an array is correctly sorted.
> In order to achieve this, I've got two helper methods as follows.
> Is it possible to integrate these methods into ArrayUtils?
> {code}
> /**
>  * Checks that the specified array of objects is in an ascending order
>  * according to the specified comparator.  All elements in the array must 
> be
>  * mutually comparable by the specified comparator (that is,
>  * c.compare(e1, e2) must not throw a ClassCastException
>  * for any elements e1 and e2 in the array).
>  *
>  * @param a the array to be checked.
>  * @param c the comparator to determine the order of the array.  A
>  * null value indicates that the elements'
>  * {@linkplain Comparable natural ordering} should be used.
>  * @return {@code true}, if the array is sorted; {@code false}, otherwise.
>  * @throws ClassCastException if the array contains elements that are
>  * not mutually comparable using the specified comparator.
>  */
> public static  boolean isSorted(final T[] a, final Comparator T> c) {
> if (a.length <= 1) {
> // Empty or singleton arrays are always sorted
> return true;
> }
> // Otherwise, check that every element is not smaller than the 
> previous
> T previous = a[0];
> for (int i = 1, n = a.length; i < n; i++) {
> final T current = a[i];
> if (c.compare(previous, current) > 0) {
> return false;
> }
> previous = current;
> }
> return true;
> }
> /**
>  * Checks that the specified array of objects is in an ascending order,
>  * according to the {@linkplain Comparable natural ordering} of its 
> elements.
>  * All elements in the array must implement the {@link Comparable} 
> interface.
>  * Furthermore, all elements in the array must be mutually 
> comparable
>  * (that is, e1.compareTo(e2) must not throw a 
> ClassCastException
>  * for any elements e1 and e2 in the array).
>  *
>  * @param a the array to be checked.
>  * @return {@code true}, if the array is sorted; {@code false}, otherwise.
>  * @throws ClassCastException if the array contains elements that are not
>  * mutually comparable (for example, strings and integers).
>  */
> @SuppressWarnings({"unchecked"})
> public static  boolean isSorted(final T[] a) {
> if (a.length <= 1) {
> // Empty or singleton arrays are always sorted
> return true;
> }
> // Otherwise, check that every element is not smaller than the 
> previous
> T previous = a[0];
> for (int i = 1, n = a.length; i < n; i++) {
> final T current = a[i];
> if (((Comparable) previous).compareTo(previous) > 0) {
> return false;
> }
> previous = current;
> }
> return true;
> }
> {code}



--
This message was sent by Atlassian JIRA
(v6.3.4#6332)


[jira] [Updated] (LANG-536) Add isSorted() to ArrayUtils

2014-10-15 Thread James Sawle (JIRA)

 [ 
https://issues.apache.org/jira/browse/LANG-536?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
 ]

James Sawle updated LANG-536:
-
Attachment: (was: LANG-536 partial.patch)

> Add isSorted() to ArrayUtils
> 
>
> Key: LANG-536
> URL: https://issues.apache.org/jira/browse/LANG-536
> Project: Commons Lang
>  Issue Type: New Feature
>  Components: lang.*
>Reporter: Sergei Ivanov
>Priority: Minor
> Fix For: Review Patch
>
> Attachments: LANG-536.patch, perftest.zip
>
>
> In my unit tests I often need to verify that an array is correctly sorted.
> In order to achieve this, I've got two helper methods as follows.
> Is it possible to integrate these methods into ArrayUtils?
> {code}
> /**
>  * Checks that the specified array of objects is in an ascending order
>  * according to the specified comparator.  All elements in the array must 
> be
>  * mutually comparable by the specified comparator (that is,
>  * c.compare(e1, e2) must not throw a ClassCastException
>  * for any elements e1 and e2 in the array).
>  *
>  * @param a the array to be checked.
>  * @param c the comparator to determine the order of the array.  A
>  * null value indicates that the elements'
>  * {@linkplain Comparable natural ordering} should be used.
>  * @return {@code true}, if the array is sorted; {@code false}, otherwise.
>  * @throws ClassCastException if the array contains elements that are
>  * not mutually comparable using the specified comparator.
>  */
> public static  boolean isSorted(final T[] a, final Comparator T> c) {
> if (a.length <= 1) {
> // Empty or singleton arrays are always sorted
> return true;
> }
> // Otherwise, check that every element is not smaller than the 
> previous
> T previous = a[0];
> for (int i = 1, n = a.length; i < n; i++) {
> final T current = a[i];
> if (c.compare(previous, current) > 0) {
> return false;
> }
> previous = current;
> }
> return true;
> }
> /**
>  * Checks that the specified array of objects is in an ascending order,
>  * according to the {@linkplain Comparable natural ordering} of its 
> elements.
>  * All elements in the array must implement the {@link Comparable} 
> interface.
>  * Furthermore, all elements in the array must be mutually 
> comparable
>  * (that is, e1.compareTo(e2) must not throw a 
> ClassCastException
>  * for any elements e1 and e2 in the array).
>  *
>  * @param a the array to be checked.
>  * @return {@code true}, if the array is sorted; {@code false}, otherwise.
>  * @throws ClassCastException if the array contains elements that are not
>  * mutually comparable (for example, strings and integers).
>  */
> @SuppressWarnings({"unchecked"})
> public static  boolean isSorted(final T[] a) {
> if (a.length <= 1) {
> // Empty or singleton arrays are always sorted
> return true;
> }
> // Otherwise, check that every element is not smaller than the 
> previous
> T previous = a[0];
> for (int i = 1, n = a.length; i < n; i++) {
> final T current = a[i];
> if (((Comparable) previous).compareTo(previous) > 0) {
> return false;
> }
> previous = current;
> }
> return true;
> }
> {code}



--
This message was sent by Atlassian JIRA
(v6.3.4#6332)


[jira] [Updated] (LANG-536) Add isSorted() to ArrayUtils

2014-10-15 Thread Duncan Jones (JIRA)

 [ 
https://issues.apache.org/jira/browse/LANG-536?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
 ]

Duncan Jones updated LANG-536:
--
Attachment: perftest.zip

> Add isSorted() to ArrayUtils
> 
>
> Key: LANG-536
> URL: https://issues.apache.org/jira/browse/LANG-536
> Project: Commons Lang
>  Issue Type: New Feature
>  Components: lang.*
>Reporter: Sergei Ivanov
>Priority: Minor
> Fix For: Review Patch
>
> Attachments: LANG-536 partial.patch, LANG-536.patch, perftest.zip
>
>
> In my unit tests I often need to verify that an array is correctly sorted.
> In order to achieve this, I've got two helper methods as follows.
> Is it possible to integrate these methods into ArrayUtils?
> {code}
> /**
>  * Checks that the specified array of objects is in an ascending order
>  * according to the specified comparator.  All elements in the array must 
> be
>  * mutually comparable by the specified comparator (that is,
>  * c.compare(e1, e2) must not throw a ClassCastException
>  * for any elements e1 and e2 in the array).
>  *
>  * @param a the array to be checked.
>  * @param c the comparator to determine the order of the array.  A
>  * null value indicates that the elements'
>  * {@linkplain Comparable natural ordering} should be used.
>  * @return {@code true}, if the array is sorted; {@code false}, otherwise.
>  * @throws ClassCastException if the array contains elements that are
>  * not mutually comparable using the specified comparator.
>  */
> public static  boolean isSorted(final T[] a, final Comparator T> c) {
> if (a.length <= 1) {
> // Empty or singleton arrays are always sorted
> return true;
> }
> // Otherwise, check that every element is not smaller than the 
> previous
> T previous = a[0];
> for (int i = 1, n = a.length; i < n; i++) {
> final T current = a[i];
> if (c.compare(previous, current) > 0) {
> return false;
> }
> previous = current;
> }
> return true;
> }
> /**
>  * Checks that the specified array of objects is in an ascending order,
>  * according to the {@linkplain Comparable natural ordering} of its 
> elements.
>  * All elements in the array must implement the {@link Comparable} 
> interface.
>  * Furthermore, all elements in the array must be mutually 
> comparable
>  * (that is, e1.compareTo(e2) must not throw a 
> ClassCastException
>  * for any elements e1 and e2 in the array).
>  *
>  * @param a the array to be checked.
>  * @return {@code true}, if the array is sorted; {@code false}, otherwise.
>  * @throws ClassCastException if the array contains elements that are not
>  * mutually comparable (for example, strings and integers).
>  */
> @SuppressWarnings({"unchecked"})
> public static  boolean isSorted(final T[] a) {
> if (a.length <= 1) {
> // Empty or singleton arrays are always sorted
> return true;
> }
> // Otherwise, check that every element is not smaller than the 
> previous
> T previous = a[0];
> for (int i = 1, n = a.length; i < n; i++) {
> final T current = a[i];
> if (((Comparable) previous).compareTo(previous) > 0) {
> return false;
> }
> previous = current;
> }
> return true;
> }
> {code}



--
This message was sent by Atlassian JIRA
(v6.3.4#6332)


[jira] [Updated] (LANG-536) Add isSorted() to ArrayUtils

2014-10-14 Thread James Sawle (JIRA)

 [ 
https://issues.apache.org/jira/browse/LANG-536?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
 ]

James Sawle updated LANG-536:
-
Attachment: LANG-536 partial.patch

Whilst this is by no means complete (have only made the Javadoc changes and 
started the adaption to Iterators), this is what I had in mind on the train 
home with the IntegerIterator method at the bottom of the class.

Using Arrays.asList as a thin wrapper around the provided array will work for 
the generic methods. From the perspective of the primitives the new iterators 
could prove to be useful in many other situations (all a bit mute when comes to 
Java 8 though :s).

If the concept holds, I will create the Iterator wrappers and tests for them 
and modify the other tests. I enjoy these sorts of issues :p

> Add isSorted() to ArrayUtils
> 
>
> Key: LANG-536
> URL: https://issues.apache.org/jira/browse/LANG-536
> Project: Commons Lang
>  Issue Type: New Feature
>  Components: lang.*
>Reporter: Sergei Ivanov
>Priority: Minor
> Fix For: Review Patch
>
> Attachments: LANG-536 partial.patch, LANG-536.patch
>
>
> In my unit tests I often need to verify that an array is correctly sorted.
> In order to achieve this, I've got two helper methods as follows.
> Is it possible to integrate these methods into ArrayUtils?
> {code}
> /**
>  * Checks that the specified array of objects is in an ascending order
>  * according to the specified comparator.  All elements in the array must 
> be
>  * mutually comparable by the specified comparator (that is,
>  * c.compare(e1, e2) must not throw a ClassCastException
>  * for any elements e1 and e2 in the array).
>  *
>  * @param a the array to be checked.
>  * @param c the comparator to determine the order of the array.  A
>  * null value indicates that the elements'
>  * {@linkplain Comparable natural ordering} should be used.
>  * @return {@code true}, if the array is sorted; {@code false}, otherwise.
>  * @throws ClassCastException if the array contains elements that are
>  * not mutually comparable using the specified comparator.
>  */
> public static  boolean isSorted(final T[] a, final Comparator T> c) {
> if (a.length <= 1) {
> // Empty or singleton arrays are always sorted
> return true;
> }
> // Otherwise, check that every element is not smaller than the 
> previous
> T previous = a[0];
> for (int i = 1, n = a.length; i < n; i++) {
> final T current = a[i];
> if (c.compare(previous, current) > 0) {
> return false;
> }
> previous = current;
> }
> return true;
> }
> /**
>  * Checks that the specified array of objects is in an ascending order,
>  * according to the {@linkplain Comparable natural ordering} of its 
> elements.
>  * All elements in the array must implement the {@link Comparable} 
> interface.
>  * Furthermore, all elements in the array must be mutually 
> comparable
>  * (that is, e1.compareTo(e2) must not throw a 
> ClassCastException
>  * for any elements e1 and e2 in the array).
>  *
>  * @param a the array to be checked.
>  * @return {@code true}, if the array is sorted; {@code false}, otherwise.
>  * @throws ClassCastException if the array contains elements that are not
>  * mutually comparable (for example, strings and integers).
>  */
> @SuppressWarnings({"unchecked"})
> public static  boolean isSorted(final T[] a) {
> if (a.length <= 1) {
> // Empty or singleton arrays are always sorted
> return true;
> }
> // Otherwise, check that every element is not smaller than the 
> previous
> T previous = a[0];
> for (int i = 1, n = a.length; i < n; i++) {
> final T current = a[i];
> if (((Comparable) previous).compareTo(previous) > 0) {
> return false;
> }
> previous = current;
> }
> return true;
> }
> {code}



--
This message was sent by Atlassian JIRA
(v6.3.4#6332)


[jira] [Updated] (LANG-536) Add isSorted() to ArrayUtils

2014-10-10 Thread Duncan Jones (JIRA)

 [ 
https://issues.apache.org/jira/browse/LANG-536?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
 ]

Duncan Jones updated LANG-536:
--
Fix Version/s: (was: Patch Needed)
   Review Patch

> Add isSorted() to ArrayUtils
> 
>
> Key: LANG-536
> URL: https://issues.apache.org/jira/browse/LANG-536
> Project: Commons Lang
>  Issue Type: New Feature
>  Components: lang.*
>Reporter: Sergei Ivanov
>Priority: Minor
> Fix For: Review Patch
>
> Attachments: LANG-536.patch
>
>
> In my unit tests I often need to verify that an array is correctly sorted.
> In order to achieve this, I've got two helper methods as follows.
> Is it possible to integrate these methods into ArrayUtils?
> {code}
> /**
>  * Checks that the specified array of objects is in an ascending order
>  * according to the specified comparator.  All elements in the array must 
> be
>  * mutually comparable by the specified comparator (that is,
>  * c.compare(e1, e2) must not throw a ClassCastException
>  * for any elements e1 and e2 in the array).
>  *
>  * @param a the array to be checked.
>  * @param c the comparator to determine the order of the array.  A
>  * null value indicates that the elements'
>  * {@linkplain Comparable natural ordering} should be used.
>  * @return {@code true}, if the array is sorted; {@code false}, otherwise.
>  * @throws ClassCastException if the array contains elements that are
>  * not mutually comparable using the specified comparator.
>  */
> public static  boolean isSorted(final T[] a, final Comparator T> c) {
> if (a.length <= 1) {
> // Empty or singleton arrays are always sorted
> return true;
> }
> // Otherwise, check that every element is not smaller than the 
> previous
> T previous = a[0];
> for (int i = 1, n = a.length; i < n; i++) {
> final T current = a[i];
> if (c.compare(previous, current) > 0) {
> return false;
> }
> previous = current;
> }
> return true;
> }
> /**
>  * Checks that the specified array of objects is in an ascending order,
>  * according to the {@linkplain Comparable natural ordering} of its 
> elements.
>  * All elements in the array must implement the {@link Comparable} 
> interface.
>  * Furthermore, all elements in the array must be mutually 
> comparable
>  * (that is, e1.compareTo(e2) must not throw a 
> ClassCastException
>  * for any elements e1 and e2 in the array).
>  *
>  * @param a the array to be checked.
>  * @return {@code true}, if the array is sorted; {@code false}, otherwise.
>  * @throws ClassCastException if the array contains elements that are not
>  * mutually comparable (for example, strings and integers).
>  */
> @SuppressWarnings({"unchecked"})
> public static  boolean isSorted(final T[] a) {
> if (a.length <= 1) {
> // Empty or singleton arrays are always sorted
> return true;
> }
> // Otherwise, check that every element is not smaller than the 
> previous
> T previous = a[0];
> for (int i = 1, n = a.length; i < n; i++) {
> final T current = a[i];
> if (((Comparable) previous).compareTo(previous) > 0) {
> return false;
> }
> previous = current;
> }
> return true;
> }
> {code}



--
This message was sent by Atlassian JIRA
(v6.3.4#6332)


[jira] [Updated] (LANG-536) Add isSorted() to ArrayUtils

2014-10-10 Thread James Sawle (JIRA)

 [ 
https://issues.apache.org/jira/browse/LANG-536?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
 ]

James Sawle updated LANG-536:
-
Attachment: LANG-536.patch

A patch for the proposed new methods.

Have not implemented the Iterator version of the methods as this would fit 
better within another class.

All methods eventually delegate to public static ' boolean isSorted(T[] a, 
Comparator c)' to aid code reuse; however this has meant that an 
anonymous implementation of the Comparable class is generated on each primitive 
method and the isSorted(T[]) method. Personally, this leads to a cleaner 
implementation than having the same logic in each of the two methods.

> Add isSorted() to ArrayUtils
> 
>
> Key: LANG-536
> URL: https://issues.apache.org/jira/browse/LANG-536
> Project: Commons Lang
>  Issue Type: New Feature
>  Components: lang.*
>Reporter: Sergei Ivanov
>Priority: Minor
> Fix For: Patch Needed
>
> Attachments: LANG-536.patch
>
>
> In my unit tests I often need to verify that an array is correctly sorted.
> In order to achieve this, I've got two helper methods as follows.
> Is it possible to integrate these methods into ArrayUtils?
> {code}
> /**
>  * Checks that the specified array of objects is in an ascending order
>  * according to the specified comparator.  All elements in the array must 
> be
>  * mutually comparable by the specified comparator (that is,
>  * c.compare(e1, e2) must not throw a ClassCastException
>  * for any elements e1 and e2 in the array).
>  *
>  * @param a the array to be checked.
>  * @param c the comparator to determine the order of the array.  A
>  * null value indicates that the elements'
>  * {@linkplain Comparable natural ordering} should be used.
>  * @return {@code true}, if the array is sorted; {@code false}, otherwise.
>  * @throws ClassCastException if the array contains elements that are
>  * not mutually comparable using the specified comparator.
>  */
> public static  boolean isSorted(final T[] a, final Comparator T> c) {
> if (a.length <= 1) {
> // Empty or singleton arrays are always sorted
> return true;
> }
> // Otherwise, check that every element is not smaller than the 
> previous
> T previous = a[0];
> for (int i = 1, n = a.length; i < n; i++) {
> final T current = a[i];
> if (c.compare(previous, current) > 0) {
> return false;
> }
> previous = current;
> }
> return true;
> }
> /**
>  * Checks that the specified array of objects is in an ascending order,
>  * according to the {@linkplain Comparable natural ordering} of its 
> elements.
>  * All elements in the array must implement the {@link Comparable} 
> interface.
>  * Furthermore, all elements in the array must be mutually 
> comparable
>  * (that is, e1.compareTo(e2) must not throw a 
> ClassCastException
>  * for any elements e1 and e2 in the array).
>  *
>  * @param a the array to be checked.
>  * @return {@code true}, if the array is sorted; {@code false}, otherwise.
>  * @throws ClassCastException if the array contains elements that are not
>  * mutually comparable (for example, strings and integers).
>  */
> @SuppressWarnings({"unchecked"})
> public static  boolean isSorted(final T[] a) {
> if (a.length <= 1) {
> // Empty or singleton arrays are always sorted
> return true;
> }
> // Otherwise, check that every element is not smaller than the 
> previous
> T previous = a[0];
> for (int i = 1, n = a.length; i < n; i++) {
> final T current = a[i];
> if (((Comparable) previous).compareTo(previous) > 0) {
> return false;
> }
> previous = current;
> }
> return true;
> }
> {code}



--
This message was sent by Atlassian JIRA
(v6.3.4#6332)


[jira] [Updated] (LANG-536) Add isSorted() to ArrayUtils

2013-10-20 Thread Henri Yandell (JIRA)

 [ 
https://issues.apache.org/jira/browse/LANG-536?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
 ]

Henri Yandell updated LANG-536:
---

Fix Version/s: (was: 3.x)
   Patch Needed

> Add isSorted() to ArrayUtils
> 
>
> Key: LANG-536
> URL: https://issues.apache.org/jira/browse/LANG-536
> Project: Commons Lang
>  Issue Type: New Feature
>  Components: lang.*
>Reporter: Sergei Ivanov
>Priority: Minor
> Fix For: Patch Needed
>
>
> In my unit tests I often need to verify that an array is correctly sorted.
> In order to achieve this, I've got two helper methods as follows.
> Is it possible to integrate these methods into ArrayUtils?
> {code}
> /**
>  * Checks that the specified array of objects is in an ascending order
>  * according to the specified comparator.  All elements in the array must 
> be
>  * mutually comparable by the specified comparator (that is,
>  * c.compare(e1, e2) must not throw a ClassCastException
>  * for any elements e1 and e2 in the array).
>  *
>  * @param a the array to be checked.
>  * @param c the comparator to determine the order of the array.  A
>  * null value indicates that the elements'
>  * {@linkplain Comparable natural ordering} should be used.
>  * @return {@code true}, if the array is sorted; {@code false}, otherwise.
>  * @throws ClassCastException if the array contains elements that are
>  * not mutually comparable using the specified comparator.
>  */
> public static  boolean isSorted(final T[] a, final Comparator T> c) {
> if (a.length <= 1) {
> // Empty or singleton arrays are always sorted
> return true;
> }
> // Otherwise, check that every element is not smaller than the 
> previous
> T previous = a[0];
> for (int i = 1, n = a.length; i < n; i++) {
> final T current = a[i];
> if (c.compare(previous, current) > 0) {
> return false;
> }
> previous = current;
> }
> return true;
> }
> /**
>  * Checks that the specified array of objects is in an ascending order,
>  * according to the {@linkplain Comparable natural ordering} of its 
> elements.
>  * All elements in the array must implement the {@link Comparable} 
> interface.
>  * Furthermore, all elements in the array must be mutually 
> comparable
>  * (that is, e1.compareTo(e2) must not throw a 
> ClassCastException
>  * for any elements e1 and e2 in the array).
>  *
>  * @param a the array to be checked.
>  * @return {@code true}, if the array is sorted; {@code false}, otherwise.
>  * @throws ClassCastException if the array contains elements that are not
>  * mutually comparable (for example, strings and integers).
>  */
> @SuppressWarnings({"unchecked"})
> public static  boolean isSorted(final T[] a) {
> if (a.length <= 1) {
> // Empty or singleton arrays are always sorted
> return true;
> }
> // Otherwise, check that every element is not smaller than the 
> previous
> T previous = a[0];
> for (int i = 1, n = a.length; i < n; i++) {
> final T current = a[i];
> if (((Comparable) previous).compareTo(previous) > 0) {
> return false;
> }
> previous = current;
> }
> return true;
> }
> {code}



--
This message was sent by Atlassian JIRA
(v6.1#6144)


[jira] [Updated] (LANG-536) Add isSorted() to ArrayUtils

2011-12-27 Thread Henri Yandell (Updated) (JIRA)

 [ 
https://issues.apache.org/jira/browse/LANG-536?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
 ]

Henri Yandell updated LANG-536:
---

Fix Version/s: (was: 3.2)
   3.x

> Add isSorted() to ArrayUtils
> 
>
> Key: LANG-536
> URL: https://issues.apache.org/jira/browse/LANG-536
> Project: Commons Lang
>  Issue Type: New Feature
>  Components: lang.*
>Reporter: Sergei Ivanov
>Priority: Minor
> Fix For: 3.x
>
>
> In my unit tests I often need to verify that an array is correctly sorted.
> In order to achieve this, I've got two helper methods as follows.
> Is it possible to integrate these methods into ArrayUtils?
> {code}
> /**
>  * Checks that the specified array of objects is in an ascending order
>  * according to the specified comparator.  All elements in the array must 
> be
>  * mutually comparable by the specified comparator (that is,
>  * c.compare(e1, e2) must not throw a ClassCastException
>  * for any elements e1 and e2 in the array).
>  *
>  * @param a the array to be checked.
>  * @param c the comparator to determine the order of the array.  A
>  * null value indicates that the elements'
>  * {@linkplain Comparable natural ordering} should be used.
>  * @return {@code true}, if the array is sorted; {@code false}, otherwise.
>  * @throws ClassCastException if the array contains elements that are
>  * not mutually comparable using the specified comparator.
>  */
> public static  boolean isSorted(final T[] a, final Comparator T> c) {
> if (a.length <= 1) {
> // Empty or singleton arrays are always sorted
> return true;
> }
> // Otherwise, check that every element is not smaller than the 
> previous
> T previous = a[0];
> for (int i = 1, n = a.length; i < n; i++) {
> final T current = a[i];
> if (c.compare(previous, current) > 0) {
> return false;
> }
> previous = current;
> }
> return true;
> }
> /**
>  * Checks that the specified array of objects is in an ascending order,
>  * according to the {@linkplain Comparable natural ordering} of its 
> elements.
>  * All elements in the array must implement the {@link Comparable} 
> interface.
>  * Furthermore, all elements in the array must be mutually 
> comparable
>  * (that is, e1.compareTo(e2) must not throw a 
> ClassCastException
>  * for any elements e1 and e2 in the array).
>  *
>  * @param a the array to be checked.
>  * @return {@code true}, if the array is sorted; {@code false}, otherwise.
>  * @throws ClassCastException if the array contains elements that are not
>  * mutually comparable (for example, strings and integers).
>  */
> @SuppressWarnings({"unchecked"})
> public static  boolean isSorted(final T[] a) {
> if (a.length <= 1) {
> // Empty or singleton arrays are always sorted
> return true;
> }
> // Otherwise, check that every element is not smaller than the 
> previous
> T previous = a[0];
> for (int i = 1, n = a.length; i < n; i++) {
> final T current = a[i];
> if (((Comparable) previous).compareTo(previous) > 0) {
> return false;
> }
> previous = current;
> }
> return true;
> }
> {code}

--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators: 
https://issues.apache.org/jira/secure/ContactAdministrators!default.jspa
For more information on JIRA, see: http://www.atlassian.com/software/jira




[jira] [Updated] (LANG-536) Add isSorted() to ArrayUtils

2011-10-09 Thread Henri Yandell (Updated) (JIRA)

 [ 
https://issues.apache.org/jira/browse/LANG-536?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
 ]

Henri Yandell updated LANG-536:
---

Fix Version/s: (was: 3.0.2)
   3.0.3

> Add isSorted() to ArrayUtils
> 
>
> Key: LANG-536
> URL: https://issues.apache.org/jira/browse/LANG-536
> Project: Commons Lang
>  Issue Type: New Feature
>  Components: lang.*
>Reporter: Sergei Ivanov
>Priority: Minor
> Fix For: 3.0.3
>
>
> In my unit tests I often need to verify that an array is correctly sorted.
> In order to achieve this, I've got two helper methods as follows.
> Is it possible to integrate these methods into ArrayUtils?
> {code}
> /**
>  * Checks that the specified array of objects is in an ascending order
>  * according to the specified comparator.  All elements in the array must 
> be
>  * mutually comparable by the specified comparator (that is,
>  * c.compare(e1, e2) must not throw a ClassCastException
>  * for any elements e1 and e2 in the array).
>  *
>  * @param a the array to be checked.
>  * @param c the comparator to determine the order of the array.  A
>  * null value indicates that the elements'
>  * {@linkplain Comparable natural ordering} should be used.
>  * @return {@code true}, if the array is sorted; {@code false}, otherwise.
>  * @throws ClassCastException if the array contains elements that are
>  * not mutually comparable using the specified comparator.
>  */
> public static  boolean isSorted(final T[] a, final Comparator T> c) {
> if (a.length <= 1) {
> // Empty or singleton arrays are always sorted
> return true;
> }
> // Otherwise, check that every element is not smaller than the 
> previous
> T previous = a[0];
> for (int i = 1, n = a.length; i < n; i++) {
> final T current = a[i];
> if (c.compare(previous, current) > 0) {
> return false;
> }
> previous = current;
> }
> return true;
> }
> /**
>  * Checks that the specified array of objects is in an ascending order,
>  * according to the {@linkplain Comparable natural ordering} of its 
> elements.
>  * All elements in the array must implement the {@link Comparable} 
> interface.
>  * Furthermore, all elements in the array must be mutually 
> comparable
>  * (that is, e1.compareTo(e2) must not throw a 
> ClassCastException
>  * for any elements e1 and e2 in the array).
>  *
>  * @param a the array to be checked.
>  * @return {@code true}, if the array is sorted; {@code false}, otherwise.
>  * @throws ClassCastException if the array contains elements that are not
>  * mutually comparable (for example, strings and integers).
>  */
> @SuppressWarnings({"unchecked"})
> public static  boolean isSorted(final T[] a) {
> if (a.length <= 1) {
> // Empty or singleton arrays are always sorted
> return true;
> }
> // Otherwise, check that every element is not smaller than the 
> previous
> T previous = a[0];
> for (int i = 1, n = a.length; i < n; i++) {
> final T current = a[i];
> if (((Comparable) previous).compareTo(previous) > 0) {
> return false;
> }
> previous = current;
> }
> return true;
> }
> {code}

--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators: 
https://issues.apache.org/jira/secure/ContactAdministrators!default.jspa
For more information on JIRA, see: http://www.atlassian.com/software/jira




[jira] [Updated] (LANG-536) Add isSorted() to ArrayUtils

2011-08-07 Thread Henri Yandell (JIRA)

 [ 
https://issues.apache.org/jira/browse/LANG-536?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
 ]

Henri Yandell updated LANG-536:
---

Fix Version/s: (was: 3.x)
   3.0.2

> Add isSorted() to ArrayUtils
> 
>
> Key: LANG-536
> URL: https://issues.apache.org/jira/browse/LANG-536
> Project: Commons Lang
>  Issue Type: New Feature
>  Components: lang.*
>Reporter: Sergei Ivanov
>Priority: Minor
> Fix For: 3.0.2
>
>
> In my unit tests I often need to verify that an array is correctly sorted.
> In order to achieve this, I've got two helper methods as follows.
> Is it possible to integrate these methods into ArrayUtils?
> {code}
> /**
>  * Checks that the specified array of objects is in an ascending order
>  * according to the specified comparator.  All elements in the array must 
> be
>  * mutually comparable by the specified comparator (that is,
>  * c.compare(e1, e2) must not throw a ClassCastException
>  * for any elements e1 and e2 in the array).
>  *
>  * @param a the array to be checked.
>  * @param c the comparator to determine the order of the array.  A
>  * null value indicates that the elements'
>  * {@linkplain Comparable natural ordering} should be used.
>  * @return {@code true}, if the array is sorted; {@code false}, otherwise.
>  * @throws ClassCastException if the array contains elements that are
>  * not mutually comparable using the specified comparator.
>  */
> public static  boolean isSorted(final T[] a, final Comparator T> c) {
> if (a.length <= 1) {
> // Empty or singleton arrays are always sorted
> return true;
> }
> // Otherwise, check that every element is not smaller than the 
> previous
> T previous = a[0];
> for (int i = 1, n = a.length; i < n; i++) {
> final T current = a[i];
> if (c.compare(previous, current) > 0) {
> return false;
> }
> previous = current;
> }
> return true;
> }
> /**
>  * Checks that the specified array of objects is in an ascending order,
>  * according to the {@linkplain Comparable natural ordering} of its 
> elements.
>  * All elements in the array must implement the {@link Comparable} 
> interface.
>  * Furthermore, all elements in the array must be mutually 
> comparable
>  * (that is, e1.compareTo(e2) must not throw a 
> ClassCastException
>  * for any elements e1 and e2 in the array).
>  *
>  * @param a the array to be checked.
>  * @return {@code true}, if the array is sorted; {@code false}, otherwise.
>  * @throws ClassCastException if the array contains elements that are not
>  * mutually comparable (for example, strings and integers).
>  */
> @SuppressWarnings({"unchecked"})
> public static  boolean isSorted(final T[] a) {
> if (a.length <= 1) {
> // Empty or singleton arrays are always sorted
> return true;
> }
> // Otherwise, check that every element is not smaller than the 
> previous
> T previous = a[0];
> for (int i = 1, n = a.length; i < n; i++) {
> final T current = a[i];
> if (((Comparable) previous).compareTo(previous) > 0) {
> return false;
> }
> previous = current;
> }
> return true;
> }
> {code}

--
This message is automatically generated by JIRA.
For more information on JIRA, see: http://www.atlassian.com/software/jira




[jira] Updated: (LANG-536) Add isSorted() to ArrayUtils

2010-01-24 Thread Henri Yandell (JIRA)

 [ 
https://issues.apache.org/jira/browse/LANG-536?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
 ]

Henri Yandell updated LANG-536:
---

Fix Version/s: (was: 3.0)
   3.1

No backwards compat issues, so moving to 3.1. If resolved before 3.0 is 
released please assign to 3.0. 

> Add isSorted() to ArrayUtils
> 
>
> Key: LANG-536
> URL: https://issues.apache.org/jira/browse/LANG-536
> Project: Commons Lang
>  Issue Type: New Feature
>  Components: lang.*
>Reporter: Sergei Ivanov
>Priority: Minor
> Fix For: 3.1
>
>
> In my unit tests I often need to verify that an array is correctly sorted.
> In order to achieve this, I've got two helper methods as follows.
> Is it possible to integrate these methods into ArrayUtils?
> {code}
> /**
>  * Checks that the specified array of objects is in an ascending order
>  * according to the specified comparator.  All elements in the array must 
> be
>  * mutually comparable by the specified comparator (that is,
>  * c.compare(e1, e2) must not throw a ClassCastException
>  * for any elements e1 and e2 in the array).
>  *
>  * @param a the array to be checked.
>  * @param c the comparator to determine the order of the array.  A
>  * null value indicates that the elements'
>  * {...@linkplain Comparable natural ordering} should be used.
>  * @return {...@code true}, if the array is sorted; {...@code false}, 
> otherwise.
>  * @throws ClassCastException if the array contains elements that are
>  * not mutually comparable using the specified comparator.
>  */
> public static  boolean isSorted(final T[] a, final Comparator T> c) {
> if (a.length <= 1) {
> // Empty or singleton arrays are always sorted
> return true;
> }
> // Otherwise, check that every element is not smaller than the 
> previous
> T previous = a[0];
> for (int i = 1, n = a.length; i < n; i++) {
> final T current = a[i];
> if (c.compare(previous, current) > 0) {
> return false;
> }
> previous = current;
> }
> return true;
> }
> /**
>  * Checks that the specified array of objects is in an ascending order,
>  * according to the {...@linkplain Comparable natural ordering} of its 
> elements.
>  * All elements in the array must implement the {...@link Comparable} 
> interface.
>  * Furthermore, all elements in the array must be mutually 
> comparable
>  * (that is, e1.compareTo(e2) must not throw a 
> ClassCastException
>  * for any elements e1 and e2 in the array).
>  *
>  * @param a the array to be checked.
>  * @return {...@code true}, if the array is sorted; {...@code false}, 
> otherwise.
>  * @throws ClassCastException if the array contains elements that are not
>  * mutually comparable (for example, strings and integers).
>  */
> @SuppressWarnings({"unchecked"})
> public static  boolean isSorted(final T[] a) {
> if (a.length <= 1) {
> // Empty or singleton arrays are always sorted
> return true;
> }
> // Otherwise, check that every element is not smaller than the 
> previous
> T previous = a[0];
> for (int i = 1, n = a.length; i < n; i++) {
> final T current = a[i];
> if (((Comparable) previous).compareTo(previous) > 0) {
> return false;
> }
> previous = current;
> }
> return true;
> }
> {code}

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.



[jira] Updated: (LANG-536) Add isSorted() to ArrayUtils

2009-10-12 Thread Henri Yandell (JIRA)

 [ 
https://issues.apache.org/jira/browse/LANG-536?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
 ]

Henri Yandell updated LANG-536:
---

Fix Version/s: 3.0

Setting to 3.0. Iterable to be considered if Lang absorbs a bit of Collections 
(ie: if it doesn't appear to have restarted after the merge). 

Sergei, is the @SuppressWarnings({"unchecked"}) necessary?

> Add isSorted() to ArrayUtils
> 
>
> Key: LANG-536
> URL: https://issues.apache.org/jira/browse/LANG-536
> Project: Commons Lang
>  Issue Type: New Feature
>Reporter: Sergei Ivanov
>Priority: Minor
> Fix For: 3.0
>
>
> In my unit tests I often need to verify that an array is correctly sorted.
> In order to achieve this, I've got two helper methods as follows.
> Is it possible to integrate these methods into ArrayUtils?
> {code}
> /**
>  * Checks that the specified array of objects is in an ascending order
>  * according to the specified comparator.  All elements in the array must 
> be
>  * mutually comparable by the specified comparator (that is,
>  * c.compare(e1, e2) must not throw a ClassCastException
>  * for any elements e1 and e2 in the array).
>  *
>  * @param a the array to be checked.
>  * @param c the comparator to determine the order of the array.  A
>  * null value indicates that the elements'
>  * {...@linkplain Comparable natural ordering} should be used.
>  * @return {...@code true}, if the array is sorted; {...@code false}, 
> otherwise.
>  * @throws ClassCastException if the array contains elements that are
>  * not mutually comparable using the specified comparator.
>  */
> public static  boolean isSorted(final T[] a, final Comparator T> c) {
> if (a.length <= 1) {
> // Empty or singleton arrays are always sorted
> return true;
> }
> // Otherwise, check that every element is not smaller than the 
> previous
> T previous = a[0];
> for (int i = 1, n = a.length; i < n; i++) {
> final T current = a[i];
> if (c.compare(previous, current) > 0) {
> return false;
> }
> previous = current;
> }
> return true;
> }
> /**
>  * Checks that the specified array of objects is in an ascending order,
>  * according to the {...@linkplain Comparable natural ordering} of its 
> elements.
>  * All elements in the array must implement the {...@link Comparable} 
> interface.
>  * Furthermore, all elements in the array must be mutually 
> comparable
>  * (that is, e1.compareTo(e2) must not throw a 
> ClassCastException
>  * for any elements e1 and e2 in the array).
>  *
>  * @param a the array to be checked.
>  * @return {...@code true}, if the array is sorted; {...@code false}, 
> otherwise.
>  * @throws ClassCastException if the array contains elements that are not
>  * mutually comparable (for example, strings and integers).
>  */
> @SuppressWarnings({"unchecked"})
> public static  boolean isSorted(final T[] a) {
> if (a.length <= 1) {
> // Empty or singleton arrays are always sorted
> return true;
> }
> // Otherwise, check that every element is not smaller than the 
> previous
> T previous = a[0];
> for (int i = 1, n = a.length; i < n; i++) {
> final T current = a[i];
> if (((Comparable) previous).compareTo(previous) > 0) {
> return false;
> }
> previous = current;
> }
> return true;
> }
> {code}

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.