[ https://issues.apache.org/jira/browse/LANG-1078?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]
haiyang li updated LANG-1078: ----------------------------- Description: what're design insights for below implementation: #1: SHOULD throw exception for negative index? {code:title= org.apache.commons.lang3.ArrayUtils.java|borderStyle=solid} public static int indexOf(final boolean[] array, final boolean valueToFind, int startIndex) { if (ArrayUtils.isEmpty(array)) { return INDEX_NOT_FOUND; } if (startIndex < 0) { startIndex = 0; } for (int i = startIndex; i < array.length; i++) { if (valueToFind == array[i]) { return i; } } return INDEX_NOT_FOUND; } {code} #2, Why does StringUtils.indexOf("", "") return 0, not -1? first of all, "" is an empty String. '0' index doesn't exist in "". secondly, both null and "" strings are considered as none. I think it's inappropriate to say we found a none thing in position 0. so I suggest to return -1(not exists) to the index of any string in a null or "" string or null or "" empty string in any thing. (i read the java doc and a few jira tickets. but didn't find the discussion related to this kind of issue. so i created a new ticket). was: what're design insights for below implementation: #1: SHOULD throw exception for negative index? {code:title= org.apache.commons.lang3.ArrayUtils.java|borderStyle=solid} public static int indexOf(final boolean[] array, final boolean valueToFind, int startIndex) { if (ArrayUtils.isEmpty(array)) { return INDEX_NOT_FOUND; } if (startIndex < 0) { startIndex = 0; } for (int i = startIndex; i < array.length; i++) { if (valueToFind == array[i]) { return i; } } return INDEX_NOT_FOUND; } {code} #2, Why does StringUtils.indexOf("", "") return 0, not -1? first of all, "" is empty String. '0' index doesn't in "". secondly, both null and "" string are considered as none. i think it's inappropriate to say we found a none thing in position 0. so i suggest to return -1(not exists) to the index of any string in a null or "" string or null or "" empty string in any thing. > -1, 0 or error for String/Array opereations > ------------------------------------------- > > Key: LANG-1078 > URL: https://issues.apache.org/jira/browse/LANG-1078 > Project: Commons Lang > Issue Type: Wish > Reporter: haiyang li > > what're design insights for below implementation: > #1: SHOULD throw exception for negative index? > {code:title= org.apache.commons.lang3.ArrayUtils.java|borderStyle=solid} > public static int indexOf(final boolean[] array, final boolean > valueToFind, int startIndex) { > if (ArrayUtils.isEmpty(array)) { > return INDEX_NOT_FOUND; > } > if (startIndex < 0) { > startIndex = 0; > } > for (int i = startIndex; i < array.length; i++) { > if (valueToFind == array[i]) { > return i; > } > } > return INDEX_NOT_FOUND; > } > {code} > #2, Why does StringUtils.indexOf("", "") return 0, not -1? > first of all, "" is an empty String. '0' index doesn't exist in "". secondly, > both null and "" strings are considered as none. I think it's inappropriate > to say we found a none thing in position 0. so I suggest to return -1(not > exists) to the index of any string in a null or "" string or null or "" empty > string in any thing. > (i read the java doc and a few jira tickets. but didn't find the discussion > related to this kind of issue. so i created a new ticket). -- This message was sent by Atlassian JIRA (v6.3.4#6332)