/** * 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 double} values, possibly empty * @param target a primitive {@code double} 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(double[] array, double target) { return indexOf(array, target, 0, array.length); }
private static int indexOf(double[] array, double target, int start, int end) { for (int i = start; i < end; i++) { if (array[i] == target) { return i; } } return -1; }
/** * 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 double} values, possibly empty * @param target a primitive {@code double} 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(double[] array, double target) { return indexOf(array, target, 0, array.length); }
public void testIndexOf() { assertEquals(-1, Doubles.indexOf(EMPTY, (double) 1)); assertEquals(-1, Doubles.indexOf(ARRAY1, (double) 2)); assertEquals(-1, Doubles.indexOf(ARRAY234, (double) 1)); assertEquals(0, Doubles.indexOf(new double[] {(double) -1}, (double) -1)); assertEquals(0, Doubles.indexOf(ARRAY234, (double) 2)); assertEquals(1, Doubles.indexOf(ARRAY234, (double) 3)); assertEquals(2, Doubles.indexOf(ARRAY234, (double) 4)); assertEquals( 1, Doubles.indexOf(new double[] {(double) 2, (double) 3, (double) 2, (double) 3}, (double) 3)); for (double value : NUMBERS) { assertEquals("" + value, 1, Doubles.indexOf(new double[] {5.0, value}, value)); } assertEquals(-1, Doubles.indexOf(new double[] {5.0, NaN}, NaN)); }
public void testIndexOf_arrayTarget() { assertEquals(0, Doubles.indexOf(EMPTY, EMPTY)); assertEquals(0, Doubles.indexOf(ARRAY234, EMPTY)); assertEquals(-1, Doubles.indexOf(EMPTY, ARRAY234)); assertEquals(-1, Doubles.indexOf(ARRAY234, ARRAY1)); assertEquals(-1, Doubles.indexOf(ARRAY1, ARRAY234)); assertEquals(0, Doubles.indexOf(ARRAY1, ARRAY1)); assertEquals(0, Doubles.indexOf(ARRAY234, ARRAY234)); assertEquals(0, Doubles.indexOf(ARRAY234, new double[] {(double) 2, (double) 3})); assertEquals(1, Doubles.indexOf(ARRAY234, new double[] {(double) 3, (double) 4})); assertEquals(1, Doubles.indexOf(ARRAY234, new double[] {(double) 3})); assertEquals(2, Doubles.indexOf(ARRAY234, new double[] {(double) 4})); assertEquals( 1, Doubles.indexOf( new double[] {(double) 2, (double) 3, (double) 3, (double) 3, (double) 3}, new double[] {(double) 3})); assertEquals( 2, Doubles.indexOf( new double[] { (double) 2, (double) 3, (double) 2, (double) 3, (double) 4, (double) 2, (double) 3 assertEquals( 1, Doubles.indexOf( new double[] { (double) 2, (double) 2, (double) 3, (double) 4, (double) 2, (double) 3, (double) 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 double} values, possibly empty * @param target a primitive {@code double} 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(double[] array, double 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 double} values, possibly empty * @param target a primitive {@code double} 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(double[] array, double 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 double} values, possibly empty * @param target a primitive {@code double} 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(double[] array, double 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 double} values, possibly empty * @param target a primitive {@code double} 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(double[] array, double 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 double} values, possibly empty * @param target a primitive {@code double} 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(double[] array, double 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 double} values, possibly empty * @param target a primitive {@code double} 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(double[] array, double 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 double} values, possibly empty * @param target a primitive {@code double} 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(double[] array, double 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 double} values, possibly empty * @param target a primitive {@code double} 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(double[] array, double 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 double} values, possibly empty * @param target a primitive {@code double} 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(double[] array, double 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 double} values, possibly empty * @param target a primitive {@code double} 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(double[] array, double 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 double} values, possibly empty * @param target a primitive {@code double} 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(double[] array, double 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 double} values, possibly empty * @param target a primitive {@code double} 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(double[] array, double 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 double} values, possibly empty * @param target a primitive {@code double} 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(double[] array, double target) { return indexOf(array, target, 0, array.length); }
static int percentilesIndex(double percentile, double[] percentiles) { int indexOf = Doubles.indexOf(percentiles, percentile); return indexOf == -1 ? 0 : indexOf; }
/** * {@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 Double) { return Doubles.indexOf(array, ((Double) o).doubleValue()); } return -1; }