/** * Returns the index of the first appearance of the value {@code target} in {@code array}. Note * that this always returns {@code -1} when {@code target} is {@code NaN}. * * @param array an array of {@code float} values, possibly empty * @param target a primitive {@code float} 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(float[] array, float target) { return indexOf(array, target, 0, array.length); }
/** * Returns the index of the first appearance of the value {@code target} in {@code array}. Note * that this always returns {@code -1} when {@code target} is {@code NaN}. * * @param array an array of {@code float} values, possibly empty * @param target a primitive {@code float} 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(float[] array, float target) { return indexOf(array, target, 0, array.length); }
/** * Returns the index of the first appearance of the value {@code target} in {@code array}. Note * that this always returns {@code -1} when {@code target} is {@code NaN}. * * @param array an array of {@code float} values, possibly empty * @param target a primitive {@code float} 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(float[] array, float target) { return indexOf(array, target, 0, array.length); }
public void testIndexOf() { assertEquals(-1, Floats.indexOf(EMPTY, (float) 1)); assertEquals(-1, Floats.indexOf(ARRAY1, (float) 2)); assertEquals(-1, Floats.indexOf(ARRAY234, (float) 1)); assertEquals(0, Floats.indexOf(new float[] {(float) -1}, (float) -1)); assertEquals(0, Floats.indexOf(ARRAY234, (float) 2)); assertEquals(1, Floats.indexOf(ARRAY234, (float) 3)); assertEquals(2, Floats.indexOf(ARRAY234, (float) 4)); assertEquals( 1, Floats.indexOf(new float[] {(float) 2, (float) 3, (float) 2, (float) 3}, (float) 3)); for (float value : NUMBERS) { assertEquals("" + value, 1, Floats.indexOf(new float[] {5f, value}, value)); } assertEquals(-1, Floats.indexOf(new float[] {5f, NaN}, NaN)); }
public void testIndexOf_arrayTarget() { assertEquals(0, Floats.indexOf(EMPTY, EMPTY)); assertEquals(0, Floats.indexOf(ARRAY234, EMPTY)); assertEquals(-1, Floats.indexOf(EMPTY, ARRAY234)); assertEquals(-1, Floats.indexOf(ARRAY234, ARRAY1)); assertEquals(-1, Floats.indexOf(ARRAY1, ARRAY234)); assertEquals(0, Floats.indexOf(ARRAY1, ARRAY1)); assertEquals(0, Floats.indexOf(ARRAY234, ARRAY234)); assertEquals(0, Floats.indexOf(ARRAY234, new float[] {(float) 2, (float) 3})); assertEquals(1, Floats.indexOf(ARRAY234, new float[] {(float) 3, (float) 4})); assertEquals(1, Floats.indexOf(ARRAY234, new float[] {(float) 3})); assertEquals(2, Floats.indexOf(ARRAY234, new float[] {(float) 4})); assertEquals( 1, Floats.indexOf( new float[] {(float) 2, (float) 3, (float) 3, (float) 3, (float) 3}, new float[] {(float) 3})); assertEquals( 2, Floats.indexOf( new float[] { (float) 2, (float) 3, (float) 2, (float) 3, (float) 4, (float) 2, (float) 3 assertEquals( 1, Floats.indexOf( new float[] { (float) 2, (float) 2, (float) 3, (float) 4, (float) 2, (float) 3, (float) 4 assertEquals(
/** * Returns the index of the first appearance of the value {@code target} in * {@code array}. Note that this always returns {@code -1} when {@code target} * is {@code NaN}. * * @param array an array of {@code float} values, possibly empty * @param target a primitive {@code float} 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(float[] array, float target) { return indexOf(array, target, 0, array.length); }
/** * Returns the index of the first appearance of the value {@code target} in * {@code array}. Note that this always returns {@code -1} when {@code target} * is {@code NaN}. * * @param array an array of {@code float} values, possibly empty * @param target a primitive {@code float} 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(float[] array, float target) { return indexOf(array, target, 0, array.length); }
/** * Returns the index of the first appearance of the value {@code target} in {@code array}. Note * that this always returns {@code -1} when {@code target} is {@code NaN}. * * @param array an array of {@code float} values, possibly empty * @param target a primitive {@code float} 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(float[] array, float target) { return indexOf(array, target, 0, array.length); }
/** * Returns the index of the first appearance of the value {@code target} in {@code array}. Note * that this always returns {@code -1} when {@code target} is {@code NaN}. * * @param array an array of {@code float} values, possibly empty * @param target a primitive {@code float} 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(float[] array, float target) { return indexOf(array, target, 0, array.length); }
/** * Returns the index of the first appearance of the value {@code target} in * {@code array}. Note that this always returns {@code -1} when {@code target} * is {@code NaN}. * * @param array an array of {@code float} values, possibly empty * @param target a primitive {@code float} 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(float[] array, float target) { return indexOf(array, target, 0, array.length); }
/** * Returns the index of the first appearance of the value {@code target} in * {@code array}. Note that this always returns {@code -1} when {@code target} * is {@code NaN}. * * @param array an array of {@code float} values, possibly empty * @param target a primitive {@code float} 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(float[] array, float target) { return indexOf(array, target, 0, array.length); }
/** * Returns the index of the first appearance of the value {@code target} in * {@code array}. Note that this always returns {@code -1} when {@code target} * is {@code NaN}. * * @param array an array of {@code float} values, possibly empty * @param target a primitive {@code float} 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(float[] array, float target) { return indexOf(array, target, 0, array.length); }
/** * Returns the index of the first appearance of the value {@code target} in * {@code array}. Note that this always returns {@code -1} when {@code target} * is {@code NaN}. * * @param array an array of {@code float} values, possibly empty * @param target a primitive {@code float} 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(float[] array, float target) { return indexOf(array, target, 0, array.length); }
/** * Returns the index of the first appearance of the value {@code target} in * {@code array}. Note that this always returns {@code -1} when {@code target} * is {@code NaN}. * * @param array an array of {@code float} values, possibly empty * @param target a primitive {@code float} 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(float[] array, float target) { return indexOf(array, target, 0, array.length); }
/** * Returns the index of the first appearance of the value {@code target} in * {@code array}. Note that this always returns {@code -1} when {@code target} * is {@code NaN}. * * @param array an array of {@code float} values, possibly empty * @param target a primitive {@code float} 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(float[] array, float target) { return indexOf(array, target, 0, array.length); }
/** * Returns the index of the first appearance of the value {@code target} in * {@code array}. Note that this always returns {@code -1} when {@code target} * is {@code NaN}. * * @param array an array of {@code float} values, possibly empty * @param target a primitive {@code float} 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(float[] array, float target) { return indexOf(array, target, 0, array.length); }
/** * Returns the index of the first appearance of the value {@code target} in * {@code array}. Note that this always returns {@code -1} when {@code target} * is {@code NaN}. * * @param array an array of {@code float} values, possibly empty * @param target a primitive {@code float} 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(float[] array, float target) { return indexOf(array, target, 0, array.length); }
/** * Returns the index of the first appearance of the value {@code target} in * {@code array}. Note that this always returns {@code -1} when {@code target} * is {@code NaN}. * * @param array an array of {@code float} values, possibly empty * @param target a primitive {@code float} 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(float[] array, float 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 Float) { return Floats.indexOf(array, ((Float) o).floatValue()); } return -1; }
public void testIndexOf() { assertEquals(-1, Floats.indexOf(EMPTY, (float) 1)); assertEquals(-1, Floats.indexOf(ARRAY1, (float) 2)); assertEquals(-1, Floats.indexOf(ARRAY234, (float) 1)); assertEquals(0, Floats.indexOf( new float[] {(float) -1}, (float) -1)); assertEquals(0, Floats.indexOf(ARRAY234, (float) 2)); assertEquals(1, Floats.indexOf(ARRAY234, (float) 3)); assertEquals(2, Floats.indexOf(ARRAY234, (float) 4)); assertEquals(1, Floats.indexOf( new float[] { (float) 2, (float) 3, (float) 2, (float) 3 }, (float) 3)); for (float value : NUMBERS) { assertEquals("" + value, 1, Floats.indexOf(new float[] {5f, value}, value)); } assertEquals(-1, Floats.indexOf(new float[] {5f, NaN}, NaN)); }