[GitHub] commons-lang issue #362: Add a check to StringUtils.repeat() for large lengt...
Github user MarkDacek commented on the issue: https://github.com/apache/commons-lang/pull/362 I'm somewhat wary of simply comparing the values, as it's not always intuitive and doesn't save us much in the way of performance. Perhaps comparing it to Integer.MAX_VALUE is a bit more appropriate? ---
[GitHub] commons-lang issue #336: LANG-1402: Null/index safe get methods for ArrayUti...
Github user MarkDacek commented on the issue: https://github.com/apache/commons-lang/pull/336 @sebbASF Thanks for your patience and efforts to make this a worthy contribution. I have removed the other methods per your suggestion. ---
[GitHub] commons-lang pull request #336: LANG-1402: Null/index safe get methods for A...
Github user MarkDacek commented on a diff in the pull request: https://github.com/apache/commons-lang/pull/336#discussion_r200858239 --- Diff: src/main/java/org/apache/commons/lang3/ArrayUtils.java --- @@ -8672,4 +8672,53 @@ public static void shuffle(final double[] array, final Random random) { swap(array, i - 1, random.nextInt(i), 1); } } + +/** + * Gets an element from the array if the array is non-null and appropriately long, otherwise returns null + * @param the component type of the array + * @param array the array holding the desired element + * @param index the index of the element in the array + * @return The element in the array at the index, or null if it is ill-formatted + * @since 3.8 + */ +public static T get(T[] array, int index){ +return get(array, index, null); +} + +/** + * Gets an element from the array if the array is non-null and appropriately long, otherwise returns the specified value + * @param the component type of the array + * @param array the array holding the desired element + * @param index the index of the element in the array + * @param defaultReturn the object to be returned if the array is null or shorter than the index + * @return The element in the array at the specified index, or the given argument if it is ill-formatted --- End diff -- The usefulness of these would be to reduce some clutter in everyday development. Checking for both null and then length can be a tedious situation for developers striving to get high unit-test coverage. isArrayIndexValid would reduce the number of branches in a typical use case, whereas get is probably a bit simpler. I'm can't say this with any degree of certainty, but a correctly-placed null element probably requires yet another check after the fact. Something like: if(isArrayIndexValid(array, 0) && array[0] != null) ---
[GitHub] commons-lang pull request #336: LANG-1402: Null/index safe get methods for A...
Github user MarkDacek commented on a diff in the pull request: https://github.com/apache/commons-lang/pull/336#discussion_r200857900 --- Diff: src/main/java/org/apache/commons/lang3/ArrayUtils.java --- @@ -8672,4 +8672,53 @@ public static void shuffle(final double[] array, final Random random) { swap(array, i - 1, random.nextInt(i), 1); } } + +/** + * Gets an element from the array if the array is non-null and appropriately long, otherwise returns null + * @param the component type of the array + * @param array the array holding the desired element + * @param index the index of the element in the array + * @return The element in the array at the index, or null if it is ill-formatted + * @since 3.8 + */ +public static T get(T[] array, int index){ +return get(array, index, null); +} + +/** + * Gets an element from the array if the array is non-null and appropriately long, otherwise returns the specified value + * @param the component type of the array + * @param array the array holding the desired element + * @param index the index of the element in the array + * @param defaultReturn the object to be returned if the array is null or shorter than the index + * @return The element in the array at the specified index, or the given argument if it is ill-formatted --- End diff -- My thought process was something similar to this https://github.com/apache/commons-lang/blob/master/src/main/java/org/apache/commons/lang3/StringUtils.java#L7456-L7458 I would understand if Strings are understood well-enough to merit a true default value and generic arrays aren't. ---
[GitHub] commons-lang pull request #336: LANG-1402: Null/index safe get methods for A...
Github user MarkDacek commented on a diff in the pull request: https://github.com/apache/commons-lang/pull/336#discussion_r200857848 --- Diff: src/main/java/org/apache/commons/lang3/ArrayUtils.java --- @@ -8672,4 +8672,53 @@ public static void shuffle(final double[] array, final Random random) { swap(array, i - 1, random.nextInt(i), 1); } } + +/** + * Gets an element from the array if the array is non-null and appropriately long, otherwise returns null + * @param the component type of the array + * @param array the array holding the desired element + * @param index the index of the element in the array + * @return The element in the array at the index, or null if it is ill-formatted + * @since 3.8 + */ +public static T get(T[] array, int index){ +return get(array, index, null); +} + +/** + * Gets an element from the array if the array is non-null and appropriately long, otherwise returns the specified value + * @param the component type of the array + * @param array the array holding the desired element + * @param index the index of the element in the array + * @param defaultReturn the object to be returned if the array is null or shorter than the index + * @return The element in the array at the specified index, or the given argument if it is ill-formatted + * @since 3.8 + */ +public static T get(T[] array, int index, T defaultReturn){ +if(getLength(array) == 0 || array.length <= index){ +return defaultReturn; +} + +if(index < 0 ){ +index = 0; --- End diff -- Fixed. ---
[GitHub] commons-lang pull request #336: LANG-1402: Null/index safe get methods for A...
Github user MarkDacek commented on a diff in the pull request: https://github.com/apache/commons-lang/pull/336#discussion_r200857547 --- Diff: src/main/java/org/apache/commons/lang3/ArrayUtils.java --- @@ -8672,4 +8672,53 @@ public static void shuffle(final double[] array, final Random random) { swap(array, i - 1, random.nextInt(i), 1); } } + +/** + * Gets an element from the array if the array is non-null and appropriately long, otherwise returns null + * @param the component type of the array + * @param array the array holding the desired element + * @param index the index of the element in the array + * @return The element in the array at the index, or null if it is ill-formatted + * @since 3.8 + */ +public static T get(T[] array, int index){ +return get(array, index, null); +} + +/** + * Gets an element from the array if the array is non-null and appropriately long, otherwise returns the specified value + * @param the component type of the array + * @param array the array holding the desired element + * @param index the index of the element in the array + * @param defaultReturn the object to be returned if the array is null or shorter than the index + * @return The element in the array at the specified index, or the given argument if it is ill-formatted + * @since 3.8 + */ +public static T get(T[] array, int index, T defaultReturn){ +if(getLength(array) == 0 || array.length <= index){ +return defaultReturn; +} + +if(index < 0 ){ +index = 0; +} + +return array[index]; +} + +/** + * Gets an element from the array if the array is non-null and appropriately long, otherwise returns the specified value --- End diff -- Sorry, mistaken copy-paste there. Feel free to use this as a tutorial for how NOT to contribute. ---
[GitHub] commons-lang issue #336: LANG-1402: Null/index safe get methods for ArrayUti...
Github user MarkDacek commented on the issue: https://github.com/apache/commons-lang/pull/336 I added your suggested method and refactored the other to use generics. ---
[GitHub] commons-lang pull request #336: LANG-1402: Null/index safe get methods for A...
GitHub user MarkDacek opened a pull request: https://github.com/apache/commons-lang/pull/336 LANG-1402: Null/index safe get methods for ArrayUtils @chtompki If this is deemed worthy or needs improvement - let me know. You can merge this pull request into a Git repository by running: $ git pull https://github.com/MarkDacek/commons-lang LANG-1402 Alternatively you can review and apply these changes as the patch at: https://github.com/apache/commons-lang/pull/336.patch To close this pull request, make a commit to your master/trunk branch with (at least) the following in the commit message: This closes #336 commit 6dacc2a421790770657f6e1f7ca8d6ec2e7f3a82 Author: MarkDacek Date: 2017-04-02T01:19:01Z Merge remote-tracking branch 'APACHE/master' commit a99631af9e24c2489ea63656decf89f506274519 Author: MarkDacek Date: 2017-04-22T13:59:14Z Merge remote-tracking branch 'APACHE/master' commit 95530e0be9bf6ab70c627295517d018ad3280489 Author: MarkDacek Date: 2017-04-24T22:18:28Z Merge remote-tracking branch 'APACHE/master' commit f4430b63a1bebc74ccb8519474d56c0918c9aea4 Author: MarkDacek Date: 2017-06-19T01:23:56Z Merge remote-tracking branch 'APACHE/master' commit 7ee1c65dc88ef3d9a83271b67fc210e7520762e1 Author: MarkDacek Date: 2017-09-05T00:56:27Z Merge remote-tracking branch 'APACHE/master' commit ce79ff2c77a2bcdf77300d470f418c1645742c5d Author: MarkDacek Date: 2017-09-24T16:00:22Z Merge remote-tracking branch 'APACHE/master' commit 622824a51cd4f6cfee86c2ad3029821c7f096a36 Author: MarkDacek Date: 2017-10-23T22:57:29Z Merge remote-tracking branch 'APACHE/master' commit 56ac7bb06a7ff91358ffa837ce5dbfe4ad551454 Author: MarkDacek Date: 2018-02-14T23:44:54Z Merge remote-tracking branch 'APACHE/master' commit 526d1999b62d521a6c7bd9e1c9d1207809032a2e Author: MarkDacek Date: 2018-07-07T15:27:05Z Merge remote-tracking branch 'APACHE/master' commit 91e0050de89c1430dfe98e4e8423c9dd82449fd2 Author: MarkDacek Date: 2018-07-07T16:45:15Z LANG-1402: added get methods to ArrayUtils ---
[GitHub] commons-lang pull request #259: LANG-1167: Add null filter to ReflectionToSt...
GitHub user MarkDacek opened a pull request: https://github.com/apache/commons-lang/pull/259 LANG-1167: Add null filter to ReflectionToStringBuilder @chtompki First attempt at this. In order to avoid a large refactor or breaking existing implementations, the boolean has to be a negative (isExcludeNullValues instead of appendNullValues). You can merge this pull request into a Git repository by running: $ git pull https://github.com/MarkDacek/commons-lang LANG-1167 Alternatively you can review and apply these changes as the patch at: https://github.com/apache/commons-lang/pull/259.patch To close this pull request, make a commit to your master/trunk branch with (at least) the following in the commit message: This closes #259 commit 3072c655e0d163f0f38d610c37fd7f3cc727714e Author: MarkDacek <mark.da...@richmond.edu> Date: 2017-03-06T01:36:39Z This closes #250 commit 40b8ecd3faa8df655ee8b4141ff309553eccfc88 Author: MarkDacek <mark.da...@richmond.edu> Date: 2017-03-17T21:43:15Z Merge remote-tracking branch 'APACHE/master' commit 661d16d190708a1a396d8b75ba10738e4574c11d Author: MarkDacek <mark.da...@richmond.edu> Date: 2017-03-18T19:47:09Z LANG-1167: Added isExcludeNullValues to ReflectionToStringBuilder and test commit 3c2673e82d33b6c9bef3005a896e5b0d52b108dd Author: MarkDacek <mark.da...@richmond.edu> Date: 2017-03-18T20:00:46Z LANG-1167: Added more test cases for ReflectionToStringBuilderExcludeNullValuesTest --- If your project is set up for it, you can reply to this email and have your reply appear on GitHub as well. If your project does not have this feature enabled and wishes so, or if the feature is enabled but not working, please contact infrastructure at infrastruct...@apache.org or file a JIRA ticket with INFRA. ---
[GitHub] commons-lang issue #251: LANG-1300: Change CharSequenceUtils to support supp...
Github user MarkDacek commented on the issue: https://github.com/apache/commons-lang/pull/251 Chiming in here. I'd recommend using code units so that it's compatible with the other operations like substring. Of course, this would still break if you called substring(index+1) since you'd be taking the second byte of a supplementary character, but I'd still argue that this is the path to take. --- If your project is set up for it, you can reply to this email and have your reply appear on GitHub as well. If your project does not have this feature enabled and wishes so, or if the feature is enabled but not working, please contact infrastructure at infrastruct...@apache.org or file a JIRA ticket with INFRA. ---
[GitHub] commons-lang issue #251: LANG-1300: Change CharSequenceUtils to support supp...
Github user MarkDacek commented on the issue: https://github.com/apache/commons-lang/pull/251 @chtompki Please look this over. We have some interesting conflicts here. 1. The issue mentioned above. indexOf("a") will double-count surrogate-pairs if they exist. We can fix this if need be. 2. A string with two surrogate-pairs will read as length 4, though we will treat it as length 2 for the purpose of these operations. E.G. : ``` final int CODE_POINT = 0x2070E; StringBuilder builder = new StringBuilder(); builder.appendCodePoint(CODE_POINT); builder.appendCodePoint(CODE_POINT); StringUtils.lastIndexOf(builder, CODE_POINT, 2) ``` the bottom line will return -1, wheras the builder.toString()... version returns 2. I suspect this is just that they disregarded our issue and start at charAt(2) instead of our iterative approach here. --- If your project is set up for it, you can reply to this email and have your reply appear on GitHub as well. If your project does not have this feature enabled and wishes so, or if the feature is enabled but not working, please contact infrastructure at infrastruct...@apache.org or file a JIRA ticket with INFRA. ---
[GitHub] commons-lang issue #251: LANG-1300: Change CharSequenceUtils to support supp...
Github user MarkDacek commented on the issue: https://github.com/apache/commons-lang/pull/251 Just a question I have on this. Are we to do this for ALL calls to this method, or only those where the search char is a supplementary char? --- If your project is set up for it, you can reply to this email and have your reply appear on GitHub as well. If your project does not have this feature enabled and wishes so, or if the feature is enabled but not working, please contact infrastructure at infrastruct...@apache.org or file a JIRA ticket with INFRA. ---
[GitHub] commons-lang pull request #250: LANG-1300: Convert CharSequence to String fo...
Github user MarkDacek closed the pull request at: https://github.com/apache/commons-lang/pull/250 --- If your project is set up for it, you can reply to this email and have your reply appear on GitHub as well. If your project does not have this feature enabled and wishes so, or if the feature is enabled but not working, please contact infrastructure at infrastruct...@apache.org or file a JIRA ticket with INFRA. ---
[GitHub] commons-lang pull request #251: Lang1300: Change CharSequenceUtils to suppor...
GitHub user MarkDacek opened a pull request: https://github.com/apache/commons-lang/pull/251 Lang1300: Change CharSequenceUtils to support supplementary characters @chtompki I'm tackling the root cause now. You can merge this pull request into a Git repository by running: $ git pull https://github.com/MarkDacek/commons-lang Lang1300CharSequenceUtilsChange Alternatively you can review and apply these changes as the patch at: https://github.com/apache/commons-lang/pull/251.patch To close this pull request, make a commit to your master/trunk branch with (at least) the following in the commit message: This closes #251 commit cde4c529034e182a982fd842252ec410d213c34c Author: MarkDacek <mark.da...@richmond.edu> Date: 2017-03-05T02:23:00Z changed CharSequence lastIndexOf to handle supplementary characters commit b5f5449cf338376d12404d0190054525987f4276 Author: MarkDacek <mark.da...@richmond.edu> Date: 2017-03-05T04:16:44Z fixed CharSequenceUtils to check for supplementary chars --- If your project is set up for it, you can reply to this email and have your reply appear on GitHub as well. If your project does not have this feature enabled and wishes so, or if the feature is enabled but not working, please contact infrastructure at infrastruct...@apache.org or file a JIRA ticket with INFRA. ---
[GitHub] commons-lang issue #250: LANG-1300: Convert CharSequence to String for int-m...
Github user MarkDacek commented on the issue: https://github.com/apache/commons-lang/pull/250 If this is too simplistic of a change, consider the minor change I did here. I based it off of the JDK implementation that handles supplementary characters. https://github.com/MarkDacek/commons-lang/commit/cde4c529034e182a982fd842252ec410d213c34c --- If your project is set up for it, you can reply to this email and have your reply appear on GitHub as well. If your project does not have this feature enabled and wishes so, or if the feature is enabled but not working, please contact infrastructure at infrastruct...@apache.org or file a JIRA ticket with INFRA. ---
[GitHub] commons-lang pull request #250: LANG-1300: Convert CharSequence to String fo...
GitHub user MarkDacek opened a pull request: https://github.com/apache/commons-lang/pull/250 LANG-1300: Convert CharSequence to String for int-methods in StringUtils @chtompki [https://issues.apache.org/jira/browse/LANG-1300](url) You can merge this pull request into a Git repository by running: $ git pull https://github.com/MarkDacek/commons-lang LANG-1300 Alternatively you can review and apply these changes as the patch at: https://github.com/apache/commons-lang/pull/250.patch To close this pull request, make a commit to your master/trunk branch with (at least) the following in the commit message: This closes #250 commit 8139e1279866bdd115350445c4ea5c4c05679c98 Author: MarkDacek <mark.da...@richmond.edu> Date: 2017-03-04T22:09:24Z convert CharSequence to String for numerous methods commit ada212927caecd41c35f4e42a481022ed29e98d9 Author: MarkDacek <mark.da...@richmond.edu> Date: 2017-03-04T22:20:44Z remove unnecessary whitespace --- If your project is set up for it, you can reply to this email and have your reply appear on GitHub as well. If your project does not have this feature enabled and wishes so, or if the feature is enabled but not working, please contact infrastructure at infrastruct...@apache.org or file a JIRA ticket with INFRA. ---