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.jpmml.rattle.visitors.ScoreDistributionCleaner.java
private TreeModel getTreeModel() { Deque<PMMLObject> parents = getParents(); return (TreeModel) Iterables.find(parents, Predicates.instanceOf(TreeModel.class)); }
From source file:com.facebook.buck.apple.FatBinaryInfos.java
/** * Inspect the given build target and return information about it if its a fat binary. * * @return non-empty when the target represents a fat binary. * @throws com.facebook.buck.util.HumanReadableException * when the target is a fat binary but has incompatible flavors. */// w w w . jav a 2s .co m public static Optional<FatBinaryInfo> create( final Map<Flavor, AppleCxxPlatform> platformFlavorsToAppleCxxPlatforms, BuildTarget target) { ImmutableList<ImmutableSortedSet<Flavor>> thinFlavorSets = generateThinFlavors( platformFlavorsToAppleCxxPlatforms.keySet(), target.getFlavors()); if (thinFlavorSets.size() <= 1) { // Actually a thin binary return Optional.absent(); } if (!Sets.intersection(target.getFlavors(), FORBIDDEN_BUILD_ACTIONS).isEmpty()) { throw new HumanReadableException("%s: Fat binaries is only supported when building an actual binary.", target); } Predicate<Flavor> isPlatformFlavor = Predicates.in(platformFlavorsToAppleCxxPlatforms.keySet()); AppleCxxPlatform representativePlatform = null; AppleSdk sdk = null; for (SortedSet<Flavor> flavorSet : thinFlavorSets) { AppleCxxPlatform platform = Preconditions.checkNotNull( platformFlavorsToAppleCxxPlatforms.get(Iterables.find(flavorSet, isPlatformFlavor))); if (sdk == null) { sdk = platform.getAppleSdk(); representativePlatform = platform; } else if (sdk != platform.getAppleSdk()) { throw new HumanReadableException( "%s: Fat binaries can only be generated from binaries compiled for the same SDK.", target); } } FatBinaryInfo.Builder builder = FatBinaryInfo.builder().setFatTarget(target) .setRepresentativePlatform(Preconditions.checkNotNull(representativePlatform)); BuildTarget platformFreeTarget = target.withoutFlavors(platformFlavorsToAppleCxxPlatforms.keySet()); for (SortedSet<Flavor> flavorSet : thinFlavorSets) { builder.addThinTargets(platformFreeTarget.withFlavors(flavorSet)); } return Optional.of(builder.build()); }
From source file:org.jclouds.vcloud.director.v1_5.functions.OrgNameVdcNameNetworkNameToEndpoint.java
protected URI getEndpointOfResourceInVdc(Object org, Object Vdc, Object resource, org.jclouds.vcloud.director.v1_5.domain.Vdc VdcObject) { Reference resourceEntity = Iterables.find(VdcObject.getAvailableNetworks(), nameEquals((String) Vdc)); if (resourceEntity == null) throw new NoSuchElementException("network " + resource + " in Vdc " + Vdc + ", org " + org + " not found in " + VdcObject.getAvailableNetworks()); return resourceEntity.getHref(); }
From source file:org.yakindu.sct.domain.extension.DomainRegistry.java
public static IDomain getDomain(final String id) { final String defaultDomainID = BasePackage.Literals.DOMAIN_ELEMENT__DOMAIN_ID.getDefaultValueLiteral(); try {//from ww w .j a va 2s .c o m return Iterables.find(getDomains(), new Predicate<IDomain>() { @Override public boolean apply(IDomain input) { return input.getDomainID().equals(id != null ? id : defaultDomainID); } }); } catch (NoSuchElementException e) { if (defaultDomainID.equals(id)) { throw new IllegalArgumentException("No default domain found!"); } return getDomain(defaultDomainID); } }
From source file:org.jclouds.vcloud.director.v1_5.functions.OrgNameVdcNameResourceEntityNameToEndpoint.java
protected URI getEndpointOfResourceInVdc(Object org, Object Vdc, Object resource, org.jclouds.vcloud.director.v1_5.domain.Vdc VdcObject) { Reference resourceEntity = Iterables.find(VdcObject.getResourceEntities(), nameEquals((String) resource)); if (resourceEntity == null) throw new NoSuchElementException("entity " + resource + " in Vdc " + Vdc + ", org " + org + " not found in " + VdcObject.getResourceEntities()); return resourceEntity.getHref(); }
From source file:org.richfaces.tests.annotationtool.processor.groups.command.AnnotationAttribute.java
public T getValueFromAnnotation(Annotation annotation) { List<Method> listOfMethods = Lists.<Method>newArrayList(annotation.getClass().getDeclaredMethods()); Method method = Iterables.find(listOfMethods, new MethodNamePredicate()); try {//w w w . ja v a2s. co m return (T) method.invoke(annotation); } catch (IllegalAccessException ex) { Logger.getLogger(AnnotationAttribute.class.getName()).log(Level.SEVERE, null, ex); } catch (IllegalArgumentException ex) { Logger.getLogger(AnnotationAttribute.class.getName()).log(Level.SEVERE, null, ex); } catch (InvocationTargetException ex) { Logger.getLogger(AnnotationAttribute.class.getName()).log(Level.SEVERE, null, ex); } return null; }
From source file:com.complexible.common.collect.Iterables2.java
/** * Same as {@link Iterables#find} except it does not throw {@link NoSuchElementException} if the result is not found. * * @param theIterable the iterable to search * @param thePredicate the predicate to use * * @return true if an element in the Iterable satisfies the predicate, false otherwise */// w w w . j a v a 2 s .c om public static <T> boolean find(final Iterable<T> theIterable, final Predicate<? super T> thePredicate) { try { return Iterables.find(theIterable, thePredicate) != null; } catch (NoSuchElementException e) { // find throws this exception when it can't find the element, which is not really helpful // we just want the boolean of whether or not it was found. return false; } }
From source file:brooklyn.entity.messaging.rabbit.RabbitDestination.java
@Override public void onManagementStarting() { super.onManagementStarting(); exchange = (getConfig(EXCHANGE_NAME) != null) ? getConfig(EXCHANGE_NAME) : getDefaultExchangeName(); virtualHost = getConfig(RabbitBroker.VIRTUAL_HOST_NAME); setAttribute(RabbitBroker.VIRTUAL_HOST_NAME, virtualHost); machine = (SshMachineLocation) Iterables.find(getParent().getLocations(), Predicates.instanceOf(SshMachineLocation.class)); shellEnvironment = getParent().getShellEnvironment(); }
From source file:com.bennavetta.vetinari.build.SiteBuilder.java
/** * Build the site. The site loaded from a {@link SiteLoader} is passed through the ordered sequence * of build phases, each receiving the result of the previous. * @throws Exception if any phase throws an exception, or there is an error loading the site *///w w w . j a v a2s . c o m public void build() throws VetinariException { Site site = siteLoader.load(context); List<BuildPhase> runList = context.getSiteConfig().getStringList("phases").stream() .map(name -> Iterables.find(phases, phase -> name.equals(phase.getName()))) .collect(Collectors.toList()); for (BuildPhase phase : runList) { log.info("Running phase {}", phase.getName()); site = phase.process(site); } // File output should be a phase, so we don't have to handle it here. }
From source file:brooklyn.entity.container.docker.application.VanillaDockerApplicationImpl.java
@Override public DockerContainer getDockerContainer() { DockerContainerLocation location = (DockerContainerLocation) Iterables.find(getLocations(), Predicates.instanceOf(DockerContainerLocation.class)); return location.getOwner(); }