/** * Returns the index of the last appearance of the value {@code target} in {@code array}. * * @param array an array of {@code byte} values, possibly empty * @param target a primitive {@code byte} value * @return the greatest index {@code i} for which {@code array[i] == target}, or {@code -1} if no * such index exists. */ public static int lastIndexOf(byte[] array, byte target) { return lastIndexOf(array, target, 0, array.length); }
/** * Returns the index of the last appearance of the value {@code target} in {@code array}. * * @param array an array of {@code byte} values, possibly empty * @param target a primitive {@code byte} value * @return the greatest index {@code i} for which {@code array[i] == target}, or {@code -1} if no * such index exists. */ public static int lastIndexOf(byte[] array, byte target) { return lastIndexOf(array, target, 0, array.length); }
/** * Returns the index of the last appearance of the value {@code target} in {@code array}. * * @param array an array of {@code byte} values, possibly empty * @param target a primitive {@code byte} value * @return the greatest index {@code i} for which {@code array[i] == target}, or {@code -1} if no * such index exists. */ public static int lastIndexOf(byte[] array, byte target) { return lastIndexOf(array, target, 0, array.length); }
public void testLastIndexOf() { assertEquals(-1, Bytes.lastIndexOf(EMPTY, (byte) 1)); assertEquals(-1, Bytes.lastIndexOf(ARRAY1, (byte) 2)); assertEquals(-1, Bytes.lastIndexOf(ARRAY234, (byte) 1)); assertEquals(0, Bytes.lastIndexOf(new byte[] {(byte) -1}, (byte) -1)); assertEquals(0, Bytes.lastIndexOf(ARRAY234, (byte) 2)); assertEquals(1, Bytes.lastIndexOf(ARRAY234, (byte) 3)); assertEquals(2, Bytes.lastIndexOf(ARRAY234, (byte) 4)); assertEquals( 3, Bytes.lastIndexOf(new byte[] {(byte) 2, (byte) 3, (byte) 2, (byte) 3}, (byte) 3)); }
/** * Returns the index of the last appearance of the value {@code target} in * {@code array}. * * @param array an array of {@code byte} values, possibly empty * @param target a primitive {@code byte} value * @return the greatest index {@code i} for which {@code array[i] == target}, * or {@code -1} if no such index exists. */ public static int lastIndexOf(byte[] array, byte target) { return lastIndexOf(array, target, 0, array.length); }
/** * Returns the index of the last appearance of the value {@code target} in * {@code array}. * * @param array an array of {@code byte} values, possibly empty * @param target a primitive {@code byte} value * @return the greatest index {@code i} for which {@code array[i] == target}, * or {@code -1} if no such index exists. */ public static int lastIndexOf(byte[] array, byte target) { return lastIndexOf(array, target, 0, array.length); }
/** * Returns the index of the last appearance of the value {@code target} in * {@code array}. * * @param array an array of {@code byte} values, possibly empty * @param target a primitive {@code byte} value * @return the greatest index {@code i} for which {@code array[i] == target}, * or {@code -1} if no such index exists. */ public static int lastIndexOf(byte[] array, byte target) { return lastIndexOf(array, target, 0, array.length); }
/** * Returns the index of the last appearance of the value {@code target} in {@code array}. * * @param array an array of {@code byte} values, possibly empty * @param target a primitive {@code byte} value * @return the greatest index {@code i} for which {@code array[i] == target}, or {@code -1} if no * such index exists. */ public static int lastIndexOf(byte[] array, byte target) { return lastIndexOf(array, target, 0, array.length); }
/** * Returns the index of the last appearance of the value {@code target} in * {@code array}. * * @param array an array of {@code byte} values, possibly empty * @param target a primitive {@code byte} value * @return the greatest index {@code i} for which {@code array[i] == target}, * or {@code -1} if no such index exists. */ public static int lastIndexOf(byte[] array, byte target) { return lastIndexOf(array, target, 0, array.length); }
/** * Returns the index of the last appearance of the value {@code target} in * {@code array}. * * @param array an array of {@code byte} values, possibly empty * @param target a primitive {@code byte} value * @return the greatest index {@code i} for which {@code array[i] == target}, * or {@code -1} if no such index exists. */ public static int lastIndexOf(byte[] array, byte target) { return lastIndexOf(array, target, 0, array.length); }
/** * Returns the index of the last appearance of the value {@code target} in * {@code array}. * * @param array an array of {@code byte} values, possibly empty * @param target a primitive {@code byte} value * @return the greatest index {@code i} for which {@code array[i] == target}, * or {@code -1} if no such index exists. */ public static int lastIndexOf(byte[] array, byte target) { return lastIndexOf(array, target, 0, array.length); }
/** * Returns the index of the last appearance of the value {@code target} in * {@code array}. * * @param array an array of {@code byte} values, possibly empty * @param target a primitive {@code byte} value * @return the greatest index {@code i} for which {@code array[i] == target}, * or {@code -1} if no such index exists. */ public static int lastIndexOf(byte[] array, byte target) { return lastIndexOf(array, target, 0, array.length); }
/** * Returns the index of the last appearance of the value {@code target} in * {@code array}. * * @param array an array of {@code byte} values, possibly empty * @param target a primitive {@code byte} value * @return the greatest index {@code i} for which {@code array[i] == target}, * or {@code -1} if no such index exists. */ public static int lastIndexOf(byte[] array, byte target) { return lastIndexOf(array, target, 0, array.length); }
/** * Returns the index of the last appearance of the value {@code target} in * {@code array}. * * @param array an array of {@code byte} values, possibly empty * @param target a primitive {@code byte} value * @return the greatest index {@code i} for which {@code array[i] == target}, * or {@code -1} if no such index exists. */ public static int lastIndexOf(byte[] array, byte target) { return lastIndexOf(array, target, 0, array.length); }
/** * Returns the index of the last appearance of the value {@code target} in * {@code array}. * * @param array an array of {@code byte} values, possibly empty * @param target a primitive {@code byte} value * @return the greatest index {@code i} for which {@code array[i] == target}, * or {@code -1} if no such index exists. */ public static int lastIndexOf(byte[] array, byte target) { return lastIndexOf(array, target, 0, array.length); }
/** * Returns the index of the last appearance of the value {@code target} in * {@code array}. * * @param array an array of {@code byte} values, possibly empty * @param target a primitive {@code byte} value * @return the greatest index {@code i} for which {@code array[i] == target}, * or {@code -1} if no such index exists. */ public static int lastIndexOf(byte[] array, byte target) { return lastIndexOf(array, target, 0, array.length); }
/** * Returns the index of the last appearance of the value {@code target} in {@code array}. * * @param array an array of {@code byte} values, possibly empty * @param target a primitive {@code byte} value * @return the greatest index {@code i} for which {@code array[i] == target}, or {@code -1} if no * such index exists. */ public static int lastIndexOf(byte[] array, byte target) { return lastIndexOf(array, target, 0, array.length); }
/** * {@inheritDoc} * * @throws NullPointerException * if the wrapped array was <code>null</code>. */ @Override public int lastIndexOf(Object o) { // Will make the method fail if array is null. if (size() < 1) { return -1; } if (o instanceof Byte) { return Bytes.lastIndexOf(array, ((Byte) o).byteValue()); } return -1; }
public void testLastIndexOf() { assertEquals(-1, Bytes.lastIndexOf(EMPTY, (byte) 1)); assertEquals(-1, Bytes.lastIndexOf(ARRAY1, (byte) 2)); assertEquals(-1, Bytes.lastIndexOf(ARRAY234, (byte) 1)); assertEquals(0, Bytes.lastIndexOf( new byte[] {(byte) -1}, (byte) -1)); assertEquals(0, Bytes.lastIndexOf(ARRAY234, (byte) 2)); assertEquals(1, Bytes.lastIndexOf(ARRAY234, (byte) 3)); assertEquals(2, Bytes.lastIndexOf(ARRAY234, (byte) 4)); assertEquals(3, Bytes.lastIndexOf( new byte[] { (byte) 2, (byte) 3, (byte) 2, (byte) 3 }, (byte) 3)); }
final byte[] row = tripleRow.getRow(); final int firstIndex = Bytes.indexOf(row, DELIM_BYTE); final int secondIndex = Bytes.lastIndexOf(row, DELIM_BYTE); final int typeIndex = Bytes.indexOf(row, TYPE_DELIM_BYTE); final byte[] first = Arrays.copyOf(row, firstIndex);