List of usage examples for com.google.common.collect Iterables get
public static <T> T get(Iterable<T> iterable, int position)
From source file:org.jclouds.ec2.compute.strategy.EC2RunNodesAndAddToSetStrategy.java
protected void populateCredentials(Reservation<? extends RunningInstance> reservation) { RunningInstance instance1 = Iterables.get(reservation, 0); Credentials credentials = instanceToCredentials.apply(instance1); if (credentials != null) for (RunningInstance instance : reservation) credentialStore.put("node#" + instance.getRegion() + "/" + instance.getId(), credentials); }
From source file:com.groupon.jenkins.buildsetup.GithubReposController.java
public int getSelectedOrgIndex() throws IOException { Iterable<String> orgs = getOrgs(); for (int i = 0; i < Iterables.size(orgs); i++) { if (Iterables.get(orgs, i).equals(getCurrentOrg())) return i; }//w ww .j ava2s . c o m return 0; }
From source file:utils.form.WebFormUserInputsCollector.java
private void collectUserInputs(Document cleanedDoc, Document originalDoc) throws IOException { for (int j = 0; j < USER_CHANGABLE_INPUT_TAGS.length; j++) { NodeList htmlInputs = cleanedDoc.getElementsByTagName(USER_CHANGABLE_INPUT_TAGS[j]); for (int i = 0; i < htmlInputs.getLength(); i++) { Node coreNode = htmlInputs.item(i); List<Element> parentsUntilForm = $(coreNode).parentsUntil("form").get(); if ((parentsUntilForm.isEmpty() || !Iterables.get(parentsUntilForm, parentsUntilForm.size() - 1) .getNodeName().equalsIgnoreCase("html")) && isUserChangableInputType(coreNode) && webDriver.findElement(By.xpath($(coreNode).xpath())).isDisplayed()) { if (parentsUntilForm.isEmpty()) { userInputs/*from ww w .j a v a 2 s. c o m*/ .add(initUserInputDomInsideOfForm(cleanedDoc, coreNode, coreNode.getParentNode())); } else { List<Element> parents = $(coreNode).parentsUntil("form").parent().get(); userInputs.add(initUserInputDomInsideOfForm(cleanedDoc, coreNode, parents.get(parents.size() - 1))); } } else { // TODO collect input out of form element } } } }
From source file:org.jclouds.savvis.vpdc.compute.strategy.VPDCComputeServiceAdapter.java
@Override public Iterable<VMSpec> listHardwareProfiles() { // TODO don't depend on OS return ImmutableSet.of(VMSpec.builder().operatingSystem(Iterables.get(listImages(), 0)).memoryInGig(2) .addDataDrive("/data01", 25).build()); }
From source file:org.jclouds.googlecompute.config.GoogleComputeRestClientModule.java
@Provides @Singleton//from ww w .j a v a 2s . com @UserProject public Supplier<String> supplyProject(@org.jclouds.location.Provider final Supplier<Credentials> creds) { return compose(new Function<Credentials, String>() { public String apply(Credentials in) { checkState(in.identity.indexOf("@") != 1, "identity should be in project_id@developer.gserviceaccount.com format"); return Iterables.get(Splitter.on("@").split(in.identity), 0); } }, creds); }
From source file:com.opengamma.integration.viewer.status.impl.SimpleViewStatusModel.java
@Override public String getColumnNameAt(int rowIndex, int columnIndex) { if (rowIndex < 0 || rowIndex >= _columnHeaders.size()) { throw new IllegalArgumentException( "RowIndex must be in range 0 >= rowIndex < " + _columnHeaders.size()); }/*w w w . ja v a2s .co m*/ if (columnIndex < 0 || columnIndex >= getColumnCount()) { throw new IllegalArgumentException( "ColumnIndex must be in range 0 >= columnIndex < " + getColumnCount()); } return Iterables.get(Iterables.get(_columnHeaders, rowIndex), columnIndex); }
From source file:org.jage.algorithms.comma.op.islands.action.EncounterAction.java
private <T> T getRandomElement(final Collection<T> collection) { return Iterables.get(collection, rand.nextInt(collection.size())); }
From source file:com.palantir.common.collect.IterableView.java
public T get(int position) { return Iterables.get(delegate(), position); }
From source file:org.apache.lens.server.query.collect.DefaultEstimatedQueryCollection.java
private QueryCost getTotalQueryCost(final Collection<QueryContext> queries) { if (queries.isEmpty()) { return new FactPartitionBasedQueryCost(0); }/*from w w w. j av a 2 s .c om*/ QueryContext query0 = Iterables.get(queries, 0); QueryCost totalQueryCost = query0.getSelectedDriverQueryCost(); for (QueryContext query : queries) { QueryCost queryCost = query.getSelectedDriverQueryCost(); totalQueryCost = totalQueryCost.add(queryCost); } log.debug("Total Query Cost:{}", totalQueryCost); return totalQueryCost; }
From source file:info.magnolia.jcr.node2bean.impl.CollectionPropertyHidingTransformer.java
@Override public void setProperty(TypeMapping mapping, TransformationState state, PropertyTypeDescriptor descriptor, Map<String, Object> values) throws RepositoryException { if (descriptor.getName().equals(collectionName)) { Object bean = state.getCurrentBean(); Map<String, Object> value = Maps.filterValues(values, new Predicate<Object>() { @Override//from w w w . j a v a2s. co m public boolean apply(Object input) { return getPropertyType().getType().isInstance(input); } }); try { if (propertyDescriptor.isMap()) { writeMethod.invoke(bean, value); } else if (propertyDescriptor.isArray()) { Class<?> entryClass = getPropertyType().getType(); Collection<Object> list = new LinkedList<Object>(value.values()); Object[] arr = (Object[]) Array.newInstance(entryClass, list.size()); for (int i = 0; i < arr.length; i++) { arr[i] = Iterables.get(list, i); } writeMethod.invoke(bean, new Object[] { arr }); } else if (propertyDescriptor.isCollection()) { Collection<?> collection = createCollectionFromMap(value, propertyDescriptor.getType().getType()); writeMethod.invoke(bean, collection); } } catch (Exception e) { log.error("Can't call set method " + propertyDescriptor.getWriteMethod(), e); } } else { super.setProperty(mapping, state, descriptor, values); } }