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:org.jclouds.virtualbox.functions.CreateMediumIfNotAlreadyExists.java
private void onAlreadyAttachedExceptionDetachOrPropagate(IVirtualBox vBox, final IMedium medium, VBoxException e) {/* w ww . ja v a2s . c o m*/ Matcher matcher = ATTACHED_PATTERN.matcher(e.getMessage()); if (matcher.find()) { String machineId = matcher.group(1); IMachine immutableMachine = vBox.findMachine(machineId); IMediumAttachment mediumAttachment = Iterables.find(immutableMachine.getMediumAttachments(), new Predicate<IMediumAttachment>() { public boolean apply(IMediumAttachment in) { return in.getMedium().getId().equals(medium.getId()); } }); machineUtils.writeLockMachineAndApply(immutableMachine.getName(), new DetachDistroMediumFromMachine( mediumAttachment.getController(), mediumAttachment.getPort(), mediumAttachment.getDevice())); deleteMediumAndBlockUntilComplete(medium); } else { throw e; } }
From source file:org.richfaces.cdk.templatecompiler.statements.FreeMarkerTestBase.java
protected void verifyImports(TemplateStatement statement, String... expected) { Iterable<JavaImport> requiredImports = statement.getRequiredImports(); for (final String expectedImport : expected) { try {/*from w w w . jav a 2s . c o m*/ Iterables.find(requiredImports, new Predicate<JavaImport>() { @Override public boolean apply(JavaImport input) { return input.getName().equals(expectedImport); } }); } catch (NoSuchElementException e) { assertTrue("Import for " + expectedImport + " not found in statement", false); } } }
From source file:org.zanata.webtrans.test.GWTTestData.java
@SuppressWarnings({ "rawtypes", "unchecked" }) public static <E extends GwtEvent<?>> E extractFromEvents(List<? extends GwtEvent> events, final Class<E> eventType) { GwtEvent gwtEvent = Iterables.find(events, (Predicate<GwtEvent>) input -> eventType.isAssignableFrom(input.getClass())); return (E) gwtEvent; }
From source file:com.ignorelist.kassandra.steam.scraper.SharedConfig.java
public static VdfNode getTagNode(VdfNode gameNode) { return Iterables.find(gameNode.getChildren(), PREDICATE_TAGS_NODE); }
From source file:com.isotrol.impe3.pms.core.obj.CIPsObject.java
CIPObject getSpace() { try { return Iterables.find(values(), CIPObject.SPACE); } catch (NoSuchElementException e) { return null; } }
From source file:org.jnario.jnario.test.util.Resources.java
public static <T extends EObject> T getRoot(Resource resource, final Class<T> type) { return type.cast(Iterables.find(resource.getContents(), new Predicate<EObject>() { public boolean apply(EObject input) { return type.isInstance(input); }// w w w . j av a 2s . co m })); }
From source file:org.polymap.kaps.ui.form.WohnungSearcher.java
public void run() { try {// www . j a va2 s. c o m WohnungTableDialog dialog = new WohnungTableDialog(); dialog.setBlockOnOpen(true); int returnCode = dialog.open(); if (returnCode == IDialogConstants.OK_ID || returnCode == IDialogConstants.NEXT_ID) { assert dialog.sel.length == 1 : "Selected: " + dialog.sel.length; final IFeatureTableElement sel = dialog.sel[0]; WohnungComposite wohnung = Iterables.find(content, new Predicate<WohnungComposite>() { public boolean apply(WohnungComposite input) { return input.id().equals(sel.fid()); } }); if (returnCode == IDialogConstants.NEXT_ID) { // fortfhrung erstellen wohnung = KapsRepository.instance().clone(WohnungComposite.class, wohnung); Integer fortf = wohnung.wohnungsFortfuehrung().get(); wohnung.wohnungsFortfuehrung() .set(fortf == null ? Integer.valueOf(0) : Integer.valueOf(fortf.intValue() + 1)); } adopt(wohnung); } } catch (Exception e) { PolymapWorkbench.handleError(KapsPlugin.PLUGIN_ID, this, "Fehler beim ffnen der Wohnungstabelle.", e); } }
From source file:dagger.internal.codegen.BindingGraphConverter.java
private ComponentNode rootComponentNode(Network<Node, Edge> network) { return (ComponentNode) Iterables.find(network.nodes(), node -> node instanceof ComponentNode && node.componentPath().atRoot()); }
From source file:com.eviware.soapui.utils.ContainerWalker.java
public JLabel findLabelWithName(String labelName) { return (JLabel) Iterables.find(containedComponents, new ComponentClassAndNamePredicate(JLabel.class, labelName)); }
From source file:org.jclouds.deltacloud.compute.functions.InstanceToNodeMetadata.java
protected Hardware parseHardware(Instance from) { try {/* ww w.ja va 2 s. c o m*/ return Iterables.find(hardwares.get(), new FindHardwareForInstance(from)); } catch (NoSuchElementException e) { logger.warn("could not find a matching hardware for instance %s", from); } return null; }