List of usage examples for com.google.common.collect Iterables find
@Nullable public static <T> T find(Iterable<? extends T> iterable, Predicate<? super T> predicate, @Nullable T defaultValue)
From source file:org.netbeans.modules.android.grammars.resources.ResourcesGrammar.java
private ResElementDescriptor findElement(Node n) { List<String> parentTags = Lists.newArrayList(); String parentTagName = null;/*w ww.jav a2s.c om*/ Node parent = n; while (parent != null && parent.getNodeType() == Node.ELEMENT_NODE) { parentTagName = ((Element) parent).getTagName(); parentTags.add(parentTagName); parent = parent.getParentNode(); } ResElementDescriptor resElem = model.getRootElement(); if (!parentTags.isEmpty()) { boolean isFirst = true; while (!parentTags.isEmpty()) { final String tag = parentTags.remove(parentTags.size() - 1); if (!isFirst) { resElem = Iterables.find(resElem.getChildren(), new Predicate<ResElementDescriptor>() { @Override public boolean apply(ResElementDescriptor input) { return input.getName().equals(tag); } }, null); } else { isFirst = false; if (!resElem.getName().equals(tag)) { // something wrong with the hierarchy resElem = null; } } if (resElem == null) { break; } } } LOG.log(Level.FINE, "find element({0}) > {1}", new Object[] { n, resElem }); return resElem; }
From source file:brooklyn.launcher.BrooklynLauncherRebindTestFixture.java
@Test public void testRebindCanAddNewApps() throws Exception { populatePersistenceDir(persistenceDir, EntitySpec.create(TestApplication.class).displayName("myorig")); // Rebind to the app we started last time newLauncherDefault(PersistMode.REBIND) .application(EntitySpec.create(TestApplication.class).displayName("mynew")).start(); // New app was added, and orig app was rebound assertEquals(lastMgmt().getApplications().size(), 2, "apps=" + lastMgmt().getApplications()); assertNotNull(// w ww . jav a 2 s.c om Iterables.find(lastMgmt().getApplications(), EntityPredicates.displayNameEqualTo("mynew"), null), "apps=" + lastMgmt().getApplications()); // And subsequently can create new apps StartableApplication app3 = lastMgmt().getEntityManager() .createEntity(EntitySpec.create(TestApplication.class).displayName("mynew2")); app3.start(ImmutableList.<Location>of()); }
From source file:org.sonar.server.startup.CopyRequirementsFromCharacteristicsToRules.java
private static RequirementMigrationDto enabledRequirement( Collection<RequirementMigrationDto> requirementsForRule) { return Iterables.find(requirementsForRule, new Predicate<RequirementMigrationDto>() { @Override//from w w w . j a v a 2s . c om public boolean apply(@Nullable RequirementMigrationDto input) { return input != null && input.isEnabled(); } }, null); }
From source file:org.jclouds.rimuhosting.miro.compute.strategy.RimuHostingComputeServiceAdapter.java
@Override public Image getImage(final String id) { return Iterables.find(listImages(), new Predicate<Image>() { @Override/*from w w w.j ava2s . c o m*/ public boolean apply(Image input) { return input.getId().equals(id); } }, null); }
From source file:org.jclouds.savvis.vpdc.compute.strategy.VPDCComputeServiceAdapter.java
@Override public CIMOperatingSystem getImage(final String id) { return Iterables.find(listImages(), new Predicate<CIMOperatingSystem>() { @Override/*w ww .j a v a 2 s .com*/ public boolean apply(CIMOperatingSystem input) { return (input.getOsType().getCode() + "").equals(id); } }, null); }
From source file:it.anyplace.sync.core.beans.DeviceAddress.java
public @Nullable String getUriParam(final String key) { Preconditions.checkNotNull(emptyToNull(key)); try {//w w w . j a v a2s . c om NameValuePair record = Iterables.find( URLEncodedUtils.parse(getUriSafe(), StandardCharsets.UTF_8.name()), new Predicate<NameValuePair>() { @Override public boolean apply(NameValuePair input) { return equal(input.getName(), key); } }, null); return record == null ? null : record.getValue(); } catch (Exception ex) { logger.warn("ex", ex); return null; } }
From source file:fr.putnami.pwt.doc.shared.page.sample.service.ContactService.java
public Contact getPerson(final String name) { return Iterables.find(this.contacts, new Predicate<Person>() { @Override//www . j a va 2 s . c o m public boolean apply(Person input) { return name != null && name.equals(input.getName()); } }, null); }
From source file:com.eucalyptus.tokens.SecurityTokenManagerImpl.java
/** * *///from ww w. j av a 2 s.c o m @Nonnull public SecurityToken doIssueSecurityToken(@Nonnull final User user, @Nullable final AccessKey accessKey, final int durationTruncationSeconds, final int durationSeconds) throws AuthException { Preconditions.checkNotNull(user, "User is required"); final AccessKey key = accessKey != null ? accessKey : Iterables.find(Objects.firstNonNull(user.getKeys(), Collections.<AccessKey>emptyList()), AccessKeys.isActive(), null); if (key == null) throw new AuthException("Key not found for user"); final long restrictedDurationMillis = restrictDuration(36, durationTruncationSeconds, durationSeconds); if (!key.getPrincipal().getUserId().equals(user.getUserId())) { throw new AuthException("Key not valid for user"); } final EncryptedSecurityToken encryptedToken = new EncryptedSecurityToken(key.getAccessKey(), user.getUserId(), getCurrentTimeMillis(), restrictedDurationMillis); return new SecurityToken(encryptedToken.getAccessKeyId(), encryptedToken.getSecretKey(key.getSecretKey()), encryptedToken.encrypt(getEncryptionKey(encryptedToken.getAccessKeyId())), encryptedToken.getExpires()); }
From source file:org.apache.brooklyn.launcher.AbstractBrooklynLauncherRebindTestFixture.java
protected void assertOnlyApp(ManagementContext managementContext, Class<? extends Application> expectedType) { assertEquals(managementContext.getApplications().size(), 1, "apps=" + managementContext.getApplications()); assertNotNull(Iterables.find(managementContext.getApplications(), Predicates.instanceOf(TestApplication.class), null), "apps=" + managementContext.getApplications()); }
From source file:org.sonar.updatecenter.common.Release.java
@Nullable @VisibleForTesting//from w w w.ja va 2 s.c o m Release getChild(final String key) { return Iterables.find(children, new Predicate<Release>() { public boolean apply(Release input) { return input.getArtifact().getKey().equals(key); } }, null); }