/** * Returns the element at the specified position in an iterable. * * <p><b>{@code Stream} equivalent:</b> {@code stream.skip(position).findFirst().get()} (throws * {@code NoSuchElementException} if out of bounds) * * @param position position of the element to return * @return the element at the specified position in {@code iterable} * @throws IndexOutOfBoundsException if {@code position} is negative or greater than or equal to * the size of {@code iterable} */ public static <T> T get(Iterable<T> iterable, int position) { checkNotNull(iterable); return (iterable instanceof List) ? ((List<T>) iterable).get(position) : Iterators.get(iterable.iterator(), position); }
/** * Returns the element at the specified position in an iterable. * * <p><b>{@code Stream} equivalent:</b> {@code stream.skip(position).findFirst().get()} (throws * {@code NoSuchElementException} if out of bounds) * * @param position position of the element to return * @return the element at the specified position in {@code iterable} * @throws IndexOutOfBoundsException if {@code position} is negative or greater than or equal to * the size of {@code iterable} */ public static <T> T get(Iterable<T> iterable, int position) { checkNotNull(iterable); return (iterable instanceof List) ? ((List<T>) iterable).get(position) : Iterators.get(iterable.iterator(), position); }
@Override public QueryableDruidServer pick(Set<QueryableDruidServer> servers, DataSegment segment) { return Iterators.get(servers.iterator(), ThreadLocalRandom.current().nextInt(servers.size())); }
/** * @deprecated as of 1.485 * {@link RunList}, despite its name, should be really used as {@link Iterable}, not as {@link List}. */ @Override @Deprecated public R get(int index) { return Iterators.get(iterator(),index); }
/** * Returns the element at the specified position in an iterable. * * <p><b>{@code Stream} equivalent:</b> {@code stream.skip(position).findFirst().get()} (throws * {@code NoSuchElementException} if out of bounds) * * @param position position of the element to return * @return the element at the specified position in {@code iterable} * @throws IndexOutOfBoundsException if {@code position} is negative or greater than or equal to * the size of {@code iterable} */ public static <T> T get(Iterable<T> iterable, int position) { checkNotNull(iterable); return (iterable instanceof List) ? ((List<T>) iterable).get(position) : Iterators.get(iterable.iterator(), position); }
@Override public Input get() { return Iterators.get(config.getBinds(bindUri).iterator(), position, null); }
public void testGet_negativeIndex() { List<String> list = newArrayList("a", "b", "c"); Iterator<String> iterator = list.iterator(); try { get(iterator, -1); fail(); } catch (IndexOutOfBoundsException expected) { } }
public void testGet_withDefault_basic() { List<String> list = newArrayList(); list.add("a"); list.add("b"); Iterator<String> iterator = list.iterator(); assertEquals("a", get(iterator, 0, "c")); assertTrue(iterator.hasNext()); }
public void testGet_withDefault_atSize() { List<String> list = newArrayList(); list.add("a"); list.add("b"); Iterator<String> iterator = list.iterator(); assertEquals("c", get(iterator, 2, "c")); assertFalse(iterator.hasNext()); }
public void testGet_atSize() { List<String> list = newArrayList(); list.add("a"); list.add("b"); Iterator<String> iterator = list.iterator(); try { get(iterator, 2); fail(); } catch (IndexOutOfBoundsException expected) { } assertFalse(iterator.hasNext()); }
public void testGet_pastEnd() { List<String> list = newArrayList(); list.add("a"); list.add("b"); Iterator<String> iterator = list.iterator(); try { get(iterator, 5); fail(); } catch (IndexOutOfBoundsException expected) { } assertFalse(iterator.hasNext()); }
public void testGet_basic() { List<String> list = newArrayList(); list.add("a"); list.add("b"); Iterator<String> iterator = list.iterator(); assertEquals("b", get(iterator, 1)); assertFalse(iterator.hasNext()); }
public void testGet_withDefault_pastEnd() { List<String> list = newArrayList(); list.add("a"); list.add("b"); Iterator<String> iterator = list.iterator(); assertEquals("c", get(iterator, 3, "c")); assertFalse(iterator.hasNext()); }
public void testGet_withDefault_negativeIndex() { List<String> list = newArrayList(); list.add("a"); list.add("b"); Iterator<String> iterator = list.iterator(); try { get(iterator, -1, "c"); fail(); } catch (IndexOutOfBoundsException expected) { // pass } assertTrue(iterator.hasNext()); }
public void testGet_empty() { List<String> list = newArrayList(); Iterator<String> iterator = list.iterator(); try { get(iterator, 0); fail(); } catch (IndexOutOfBoundsException expected) { } assertFalse(iterator.hasNext()); }
@Test public void testPatternMatcherLeavesUnbalancedQuoteJavaOptions() { Assert.assertEquals("\"", Iterators.get(new QuotableWhiteSpaceSplitter("\"").iterator(), 0)); }
private void initializeInstance(InstanceId instanceId) { InstanceConfig instanceConfig = Iterators.get(instanceAdminClient.listInstanceConfigs().iterateAll().iterator(), 0, null); checkState(instanceConfig != null, "No instance configs found"); InstanceConfigId configId = instanceConfig.getId(); logger.log(Level.FINE, "Creating instance using config {0}", configId); InstanceInfo instance = InstanceInfo.newBuilder(instanceId) .setNodeCount(1) .setDisplayName("Test instance") .setInstanceConfigId(configId) .build(); OperationFuture<Instance, CreateInstanceMetadata> op = instanceAdminClient.createInstance(instance); Instance createdInstance; try { createdInstance = op.get(500L, TimeUnit.MILLISECONDS); } catch (Exception e) { throw SpannerExceptionFactory.newSpannerException(e); } logger.log(Level.INFO, "Created test instance: {0}", createdInstance.getId()); }
@Override public QueryableDruidServer pick(Set<QueryableDruidServer> servers, DataSegment segment) { return Iterators.get(servers.iterator(), ThreadLocalRandom.current().nextInt(servers.size())); }
/** * @deprecated as of 1.485 * {@link RunList}, despite its name, should be really used as {@link Iterable}, not as {@link List}. */ @Override @Deprecated public R get(int index) { return Iterators.get(iterator(),index); }
@Test public void noSpecialSensors() throws Exception { long agentId = 13L; when(environment.isClassLoadingDelegation()).thenReturn(false); when(environment.getJmxSensorConfig()).thenReturn(null); AgentConfig agentConfiguration = creator.environmentToConfiguration(environment, agentId); Collection<MethodSensorTypeConfig> sensorTypeConfigs = agentConfiguration.getSpecialMethodSensorTypeConfigs(); assertThat(Iterators.get(sensorTypeConfigs.iterator(), 0).getClassName(), is(equalTo(eisc.getClassName()))); assertThat(Iterators.get(sensorTypeConfigs.iterator(), 1).getClassName(), is(equalTo(closeableHttpAsyncCLient.getClassName()))); }