List of usage examples for com.google.common.collect Iterables find
public static <T> T find(Iterable<T> iterable, Predicate<? super T> predicate)
From source file:broadwick.model.Model.java
/** * Get the prior of a paramter for the model given the parameter name (as defined in the config file). * @param name the name of the parameter. * @return the prior defeind in the configuration file. *///from w w w. j av a 2 s.c o m public final UniformPrior getUniformPrior(final String name) { return (UniformPrior) Iterables.find(priors, new Predicate<Prior>() { @Override public boolean apply(final Prior prior) { return name.equals(prior.getId()); } }); }
From source file:org.jclouds.vcloud.director.v1_5.compute.functions.HardwareForVAppTemplate.java
@Override public Hardware apply(VAppTemplate from) { checkNotNull(from, "VAppTemplate"); Envelope ovf = templateToEnvelope.apply(from); if (ovf.getVirtualSystem().getVirtualHardwareSections().size() > 1) { logger.warn("multiple hardware choices found. using first", ovf); }// w ww . ja va 2 s. c om VirtualHardwareSection hardware = Iterables.get(ovf.getVirtualSystem().getVirtualHardwareSections(), 0); HardwareBuilder builder = rasdToHardwareBuilder.apply(hardware.getItems()); Link vdc = Iterables.find(checkNotNull(from, "from").getLinks(), LinkPredicates.typeEquals(VCloudDirectorMediaType.VDC)); if (vdc != null) { builder.location(findLocationForResource.apply(vdc)); } else { // otherwise, it could be in a public catalog, which is not assigned to a VDC } builder.ids(from.getHref().toASCIIString()).name(from.getName()) .supportsImage(ImagePredicates.idEquals(from.getHref().toASCIIString())); builder.hypervisor("VMware"); return builder.build(); }
From source file:org.obiba.onyx.quartz.magma.AbstractQuartzBeanResolver.java
protected CategoryAnswer findCategoryAnswer(final QuestionAnswer qa, final String categoryName) { return Iterables.find(qa.getCategoryAnswers(), new Predicate<CategoryAnswer>() { public boolean apply(CategoryAnswer input) { return input.isActive() && input.getCategoryName().equals(categoryName); }/* www . j a v a 2 s. c o m*/ }); }
From source file:org.midonet.client.resource.ResourceCollection.java
/** * Forwarding method to Iterables.find in Guava * * @param predicate/*from w w w.jav a 2 s. com*/ * @return */ public E find(Predicate<? super E> predicate) { return Iterables.find(delegate, predicate); }
From source file:org.jclouds.trmk.vcloud_0_8.suppliers.OnlyReferenceTypeFirstWithNameMatchingConfigurationKeyOrDefault.java
public ReferenceType findReferenceTypeWithNameMatchingPattern(Iterable<ReferenceType> referenceTypes, String namingPattern) {//from w w w . j a v a2s .c om try { return Iterables.find(referenceTypes, new ReferenceTypeNameMatchesPattern(namingPattern)); } catch (NoSuchElementException e) { throw new NoSuchElementException(String.format( "referenceType matching pattern [%s], corresponding to configuration key %s, not in %s", namingPattern, configurationKey, referenceTypes)); } }
From source file:org.killbill.billing.util.nodes.DefaultKillbillNodesApi.java
@Override public NodeInfo getCurrentNodeInfo() { final List<NodeInfoModelDao> allNodes = nodeInfoDao.getAll(); final NodeInfoModelDao current = Iterables.find(allNodes, new Predicate<NodeInfoModelDao>() { @Override/*from w ww . j a v a 2 s.c om*/ public boolean apply(final NodeInfoModelDao input) { return input.getNodeName().equals(CreatorName.get()); } }); return nodeTransfomer.apply(current); }
From source file:org.polymap.biotop.ui.AddValueArtAction.java
public void run() { try {/*from w w w . ja v a2s . com*/ ArtTableDialog dialog = new ArtTableDialog(); dialog.setBlockOnOpen(true); if (dialog.open() == Window.OK) { assert dialog.sel.length == 1 : "Selected: " + dialog.sel.length; final IFeatureTableElement sel = dialog.sel[0]; execute(Iterables.find(content, new Predicate<A>() { public boolean apply(A input) { return input.id().equals(sel.fid()); } })); } } catch (Exception e) { PolymapWorkbench.handleError(BiotopPlugin.PLUGIN_ID, this, "Fehler beim ffnen Suchtabelle.", e); } }
From source file:com.nirima.jenkins.SelectionTypeProject.java
private BuildableItemWithBuildWrappers getProject(final String project) { BuildableItemWithBuildWrappers item = Iterables.find( Jenkins.getInstance().getAllItems(BuildableItemWithBuildWrappers.class), new Predicate<BuildableItemWithBuildWrappers>() { public boolean apply(BuildableItemWithBuildWrappers buildableItemWithBuildWrappers) { return buildableItemWithBuildWrappers.getName().equals(project); }/*from w ww. jav a 2 s . c om*/ }); return item; }
From source file:org.fenixedu.academic.dto.resourceAllocationManager.PeriodsManagementBean.java
public OccupationPeriodBean getBeanById(String idStr) { final int id = Integer.parseInt(idStr); return Iterables.find(getPeriods(), new Predicate<OccupationPeriodBean>() { @Override/*from ww w. j a v a 2 s . co m*/ public boolean apply(OccupationPeriodBean bean) { return bean.getId() == id; } }); }
From source file:org.jclouds.apis.Apis.java
/** * Returns the type of context/* ww w . jav a2 s . c o m*/ * * @param type * the type of the context to search for * * @return the apis with contexts transformable to the given type */ public static TypeToken<?> findView(final ApiMetadata apiMetadata, final TypeToken<?> view) throws NoSuchElementException { checkNotNull(apiMetadata, "apiMetadata must be defined"); checkNotNull(view, "context must be defined"); return Iterables.find(apiMetadata.getViews(), new Predicate<TypeToken<?>>() { @Override public boolean apply(TypeToken<?> input) { return view.isAssignableFrom(input); } }); }