/** * Returns the index of the first appearance of the value {@code target} in {@code array}. * * @param array an array of {@code char} values, possibly empty * @param target a primitive {@code char} value * @return the least index {@code i} for which {@code array[i] == target}, or {@code -1} if no * such index exists. */ public static int indexOf(char[] array, char target) { return indexOf(array, target, 0, array.length); }
/** * Returns the index of the first appearance of the value {@code target} in {@code array}. * * @param array an array of {@code char} values, possibly empty * @param target a primitive {@code char} value * @return the least index {@code i} for which {@code array[i] == target}, or {@code -1} if no * such index exists. */ public static int indexOf(char[] array, char target) { return indexOf(array, target, 0, array.length); }
/** * Returns the index of the first appearance of the value {@code target} in {@code array}. * * @param array an array of {@code char} values, possibly empty * @param target a primitive {@code char} value * @return the least index {@code i} for which {@code array[i] == target}, or {@code -1} if no * such index exists. */ public static int indexOf(char[] array, char target) { return indexOf(array, target, 0, array.length); }
public void testIndexOf() { assertEquals(-1, Chars.indexOf(EMPTY, (char) 1)); assertEquals(-1, Chars.indexOf(ARRAY1, (char) 2)); assertEquals(-1, Chars.indexOf(ARRAY234, (char) 1)); assertEquals(0, Chars.indexOf(new char[] {(char) -1}, (char) -1)); assertEquals(0, Chars.indexOf(ARRAY234, (char) 2)); assertEquals(1, Chars.indexOf(ARRAY234, (char) 3)); assertEquals(2, Chars.indexOf(ARRAY234, (char) 4)); assertEquals(1, Chars.indexOf(new char[] {(char) 2, (char) 3, (char) 2, (char) 3}, (char) 3)); }
public void testIndexOf_arrayTarget() { assertEquals(0, Chars.indexOf(EMPTY, EMPTY)); assertEquals(0, Chars.indexOf(ARRAY234, EMPTY)); assertEquals(-1, Chars.indexOf(EMPTY, ARRAY234)); assertEquals(-1, Chars.indexOf(ARRAY234, ARRAY1)); assertEquals(-1, Chars.indexOf(ARRAY1, ARRAY234)); assertEquals(0, Chars.indexOf(ARRAY1, ARRAY1)); assertEquals(0, Chars.indexOf(ARRAY234, ARRAY234)); assertEquals(0, Chars.indexOf(ARRAY234, new char[] {(char) 2, (char) 3})); assertEquals(1, Chars.indexOf(ARRAY234, new char[] {(char) 3, (char) 4})); assertEquals(1, Chars.indexOf(ARRAY234, new char[] {(char) 3})); assertEquals(2, Chars.indexOf(ARRAY234, new char[] {(char) 4})); assertEquals( 1, Chars.indexOf( new char[] {(char) 2, (char) 3, (char) 3, (char) 3, (char) 3}, new char[] {(char) 3})); assertEquals( 2, Chars.indexOf( new char[] {(char) 2, (char) 3, (char) 2, (char) 3, (char) 4, (char) 2, (char) 3}, new char[] {(char) 2, (char) 3, (char) 4})); assertEquals( 1, Chars.indexOf( new char[] {(char) 2, (char) 2, (char) 3, (char) 4, (char) 2, (char) 3, (char) 4}, new char[] {(char) 2, (char) 3, (char) 4})); assertEquals( -1, Chars.indexOf( new char[] {(char) 4, (char) 3, (char) 2}, new char[] {(char) 2, (char) 3, (char) 4}));
/** * Returns the index of the first appearance of the value {@code target} in * {@code array}. * * @param array an array of {@code char} values, possibly empty * @param target a primitive {@code char} value * @return the least index {@code i} for which {@code array[i] == target}, or * {@code -1} if no such index exists. */ public static int indexOf(char[] array, char target) { return indexOf(array, target, 0, array.length); }
/** * Returns the index of the first appearance of the value {@code target} in * {@code array}. * * @param array an array of {@code char} values, possibly empty * @param target a primitive {@code char} value * @return the least index {@code i} for which {@code array[i] == target}, or * {@code -1} if no such index exists. */ public static int indexOf(char[] array, char target) { return indexOf(array, target, 0, array.length); }
/** * Returns the index of the first appearance of the value {@code target} in * {@code array}. * * @param array an array of {@code char} values, possibly empty * @param target a primitive {@code char} value * @return the least index {@code i} for which {@code array[i] == target}, or * {@code -1} if no such index exists. */ public static int indexOf(char[] array, char target) { return indexOf(array, target, 0, array.length); }
/** * Returns the index of the first appearance of the value {@code target} in {@code array}. * * @param array an array of {@code char} values, possibly empty * @param target a primitive {@code char} value * @return the least index {@code i} for which {@code array[i] == target}, or {@code -1} if no * such index exists. */ public static int indexOf(char[] array, char target) { return indexOf(array, target, 0, array.length); }
/** * Returns the index of the first appearance of the value {@code target} in * {@code array}. * * @param array an array of {@code char} values, possibly empty * @param target a primitive {@code char} value * @return the least index {@code i} for which {@code array[i] == target}, or * {@code -1} if no such index exists. */ public static int indexOf(char[] array, char target) { return indexOf(array, target, 0, array.length); }
/** * Returns the index of the first appearance of the value {@code target} in * {@code array}. * * @param array an array of {@code char} values, possibly empty * @param target a primitive {@code char} value * @return the least index {@code i} for which {@code array[i] == target}, or * {@code -1} if no such index exists. */ public static int indexOf(char[] array, char target) { return indexOf(array, target, 0, array.length); }
/** * Returns the index of the first appearance of the value {@code target} in * {@code array}. * * @param array an array of {@code char} values, possibly empty * @param target a primitive {@code char} value * @return the least index {@code i} for which {@code array[i] == target}, or * {@code -1} if no such index exists. */ public static int indexOf(char[] array, char target) { return indexOf(array, target, 0, array.length); }
/** * Returns the index of the first appearance of the value {@code target} in * {@code array}. * * @param array an array of {@code char} values, possibly empty * @param target a primitive {@code char} value * @return the least index {@code i} for which {@code array[i] == target}, or * {@code -1} if no such index exists. */ public static int indexOf(char[] array, char target) { return indexOf(array, target, 0, array.length); }
/** * Returns the index of the first appearance of the value {@code target} in * {@code array}. * * @param array an array of {@code char} values, possibly empty * @param target a primitive {@code char} value * @return the least index {@code i} for which {@code array[i] == target}, or * {@code -1} if no such index exists. */ public static int indexOf(char[] array, char target) { return indexOf(array, target, 0, array.length); }
/** * Returns the index of the first appearance of the value {@code target} in * {@code array}. * * @param array an array of {@code char} values, possibly empty * @param target a primitive {@code char} value * @return the least index {@code i} for which {@code array[i] == target}, or * {@code -1} if no such index exists. */ public static int indexOf(char[] array, char target) { return indexOf(array, target, 0, array.length); }
/** * Returns the index of the first appearance of the value {@code target} in * {@code array}. * * @param array an array of {@code char} values, possibly empty * @param target a primitive {@code char} value * @return the least index {@code i} for which {@code array[i] == target}, or * {@code -1} if no such index exists. */ public static int indexOf(char[] array, char target) { return indexOf(array, target, 0, array.length); }
/** * Returns the index of the first appearance of the value {@code target} in {@code array}. * * @param array an array of {@code char} values, possibly empty * @param target a primitive {@code char} value * @return the least index {@code i} for which {@code array[i] == target}, or {@code -1} if no * such index exists. */ public static int indexOf(char[] array, char target) { return indexOf(array, target, 0, array.length); }
/** * Returns the index of the first appearance of the value {@code target} in * {@code array}. * * @param array an array of {@code char} values, possibly empty * @param target a primitive {@code char} value * @return the least index {@code i} for which {@code array[i] == target}, or * {@code -1} if no such index exists. */ public static int indexOf(char[] array, char target) { return indexOf(array, target, 0, array.length); }
/** * {@inheritDoc} * * @throws NullPointerException * if the wrapped array was <code>null</code>. */ @Override public int indexOf(Object o) { // Will make the method fail if array is null. if (size() < 1) { return -1; } if (o instanceof Character) { return Chars.indexOf(array, ((Character) o).charValue()); } return -1; }
public void testIndexOf() { assertEquals(-1, Chars.indexOf(EMPTY, (char) 1)); assertEquals(-1, Chars.indexOf(ARRAY1, (char) 2)); assertEquals(-1, Chars.indexOf(ARRAY234, (char) 1)); assertEquals(0, Chars.indexOf( new char[] {(char) -1}, (char) -1)); assertEquals(0, Chars.indexOf(ARRAY234, (char) 2)); assertEquals(1, Chars.indexOf(ARRAY234, (char) 3)); assertEquals(2, Chars.indexOf(ARRAY234, (char) 4)); assertEquals(1, Chars.indexOf( new char[] { (char) 2, (char) 3, (char) 2, (char) 3 }, (char) 3)); }