/**
* Returns the index in {@code iterator} of the first element that satisfiesthe provided {@code predicate}, or {@code -1} if the Iterator has no suchelements. <p>More formally, returns the lowest index {@code i} such that{@code predicate.apply(Iterators.get(iterator, i))} is {@code true}, or {@code -1} if there is no such index.<p>If -1 is returned, the iterator will be left exhausted: its {@code hasNext()} method will return {@code false}. Otherwise, the iterator will be set to the element which satisfies the {@code predicate}.
* @since 2010.01.04 <b>tentative</b>
*/
public static <T>int indexOf(Iterator<T> iterator,Predicate<? super T> predicate){
Preconditions.checkNotNull(predicate,"predicate");
int i=0;
while (iterator.hasNext()) {
T current=iterator.next();
if (predicate.apply(current)) {
return i;
}
i++;
}
return -1;
}

Example 6

From project android_external_guava, under directory /src/com/google/common/collect/.

/**
* Creates an instance which routes all commands to a {@code CommandExecutor}. A mock can be passed as an argument to help with testing. This constructor also takes an {@code AdbConnection}, to which all ADB commands will be sent.
* @param executor a command executor through which all commands arerouted. Using a mock eliminates the need to connect to an HTTP server, where the commands are usually routed.
* @param adbConnection receives all ADB commands, such as event injections.If {@code null}, this instance will not support ADB functionality.
* @see AndroidNativeDriverBuilder
*/
protected AndroidNativeDriver(CommandExecutor executor,@Nullable AdbConnection adbConnection){
super(Preconditions.checkNotNull(executor),AndroidCapabilities.get());
setElementConverter(new JsonToWebElementConverter(this){
@Override protected RemoteWebElement newRemoteWebElement(){
return new AndroidNativeElement(AndroidNativeDriver.this);
}
}
);
this.adbConnection=adbConnection;
}

Example 12

From project appdriver, under directory /android/src/com/google/android/testing/nativedriver/client/.