List of usage examples for com.google.common.base Optional presentInstances
@Beta public static <T> Iterable<T> presentInstances(final Iterable<? extends Optional<? extends T>> optionals)
From source file:org.n52.svalbard.read.NillableReader.java
@Override protected void begin() throws XMLStreamException, DecodingException { Optional<String> attr = attr(W3CConstants.QN_XSI_NIL); if (attr.isPresent() && attr.get().equals("true")) { List<QName> attributeNames = getPossibleNilReasonAttributes(); Iterable<Optional<String>> attributes = attr(attributeNames); Iterable<String> reasons = Optional.presentInstances(attributes); this.nillable = Nillable.nil(Iterables.getFirst(reasons, null)); } else {//from w ww . j av a 2s . co m this.nillable = Nillable.of(delegate(getDelegate())); } }
From source file:brooklyn.location.docker.strategy.affinity.DockerAffinityRuleStrategy.java
@Override public List<DockerHostLocation> filterLocations(List<DockerHostLocation> locations, Entity entity) { List<DockerHostLocation> available = Lists.newArrayList(); // Select hosts that satisfy the affinity rules for (DockerHostLocation machine : locations) { Optional<List<String>> entityRules = Optional .fromNullable(entity.config().get(DockerHost.DOCKER_HOST_AFFINITY_RULES)); Optional<List<String>> hostRules = Optional .fromNullable(machine.getOwner().config().get(DockerHost.DOCKER_HOST_AFFINITY_RULES)); Optional<List<String>> infrastructureRules = Optional.fromNullable( machine.getOwner().getInfrastructure().config().get(DockerHost.DOCKER_HOST_AFFINITY_RULES)); Iterable<String> combined = Iterables.concat( Optional.presentInstances(ImmutableList.of(entityRules, hostRules, infrastructureRules))); AffinityRules rules = AffinityRules.rulesFor(entity).parse(combined); Iterable<Entity> entities = getBrooklynManagementContext().getEntityManager() .findEntities(EntityPredicates.locationsIncludes(machine)); if (Iterables.isEmpty(entities)) { if (rules.allowEmptyLocations()) { available.add(machine);/*www.ja va 2s.c o m*/ } } else { Iterable<Entity> filtered = Iterables.filter(entities, rules); if (Iterables.size(filtered) == Iterables.size(entities)) { available.add(machine); } } } if (LOG.isDebugEnabled()) { LOG.debug("Available Docker hosts: {}", Iterables.toString(available)); } return available; }
From source file:com.eucalyptus.auth.principal.SecurityTokenContentImpl.java
public SecurityTokenContentImpl(final Optional<String> originatingAccessKeyId, final Optional<String> originatingUserId, final Optional<String> originatingRoleId, final String nonce, final long created, final long expires) { Parameters.checkParam("originatingAccessKeyId", originatingAccessKeyId, notNullValue()); Parameters.checkParam("originatingUserId", originatingUserId, notNullValue()); Parameters.checkParam("originatingRoleId", originatingRoleId, notNullValue()); Parameters.checkParam("nonce", nonce, not(isEmptyOrNullString())); if (Iterables.size(Optional.presentInstances( Arrays.asList(originatingAccessKeyId, originatingUserId, originatingRoleId))) != 1) { throw new IllegalArgumentException("One originating identifier expected"); }/*from ww w . j a va2s . c o m*/ this.originatingAccessKeyId = originatingAccessKeyId; this.originatingUserId = originatingUserId; this.originatingRoleId = originatingRoleId; this.nonce = nonce; this.created = created; this.expires = expires; }
From source file:org.n52.sos.decode.xml.stream.NillableReader.java
@Override protected void begin() throws XMLStreamException, OwsExceptionReport { Optional<String> attr = attr(W3CConstants.QN_XSI_NIL); if (attr.isPresent() && attr.get().equals("true")) { List<QName> attributeNames = getPossibleNilReasonAttributes(); Iterable<Optional<String>> attributes = attr(attributeNames); Iterable<String> reasons = Optional.presentInstances(attributes); this.nillable = Nillable.nil(Iterables.getFirst(reasons, null)); } else {/* w w w . java 2 s . com*/ this.nillable = Nillable.of(delegate(getDelegate())); } }
From source file:com.eucalyptus.compute.vpc.VpcConfiguration.java
private static List<Cidr> toCidrs(final String cidrValues) { //noinspection StaticPseudoFunctionalStyleMethod return Lists.newArrayList( Optional.presentInstances(Iterables.transform(LIST_SPLITTER.split(cidrValues), Cidr.parse()))); }
From source file:google.registry.tools.server.CreateGroupsAction.java
@Override public void run() { final Registrar registrar = initAndLoadRegistrar(); if (registrar == null) { return;/*from www. j a va 2 s . com*/ } List<RegistrarContact.Type> types = asList(RegistrarContact.Type.values()); // Concurrently create the groups for each RegistrarContact.Type, collecting the results from // each call (which are either an Exception if it failed, or absent() if it succeeded). List<Optional<Exception>> results = Concurrent.transform(types, NUM_SIMULTANEOUS_CONNECTIONS, new Function<RegistrarContact.Type, Optional<Exception>>() { @Override public Optional<Exception> apply(Type type) { try { String groupKey = getGroupEmailAddressForContactType(registrar.getClientId(), type, publicDomainName); String parentGroup = getGroupEmailAddressForContactType("registrar", type, publicDomainName); // Creates the group, then adds it as a member to the global registrar group for // that type. groupsConnection.createGroup(groupKey); groupsConnection.addMemberToGroup(parentGroup, groupKey, Role.MEMBER); return Optional.<Exception>absent(); } catch (Exception e) { return Optional.of(e); } } }); // Return the correct server response based on the results of the group creations. if (Optional.presentInstances(results).iterator().hasNext()) { StringWriter responseString = new StringWriter(); PrintWriter responseWriter = new PrintWriter(responseString); for (int i = 0; i < results.size(); i++) { Optional<Exception> e = results.get(i); if (e.isPresent()) { responseWriter.append(types.get(i).getDisplayName()).append(" => "); e.get().printStackTrace(responseWriter); logger.severefmt(e.get(), "Could not create Google Group for registrar %s for type %s", registrar.getRegistrarName(), types.get(i).toString()); } else { responseWriter.printf("%s => Success%n", types.get(i).getDisplayName()); } } throw new InternalServerErrorException(responseString.toString()); } else { response.setStatus(SC_OK); response.setPayload("Success!"); logger.info("Successfully created groups for registrar: " + registrar.getRegistrarName()); } }
From source file:brooklyn.location.docker.DockerLocation.java
protected List<DockerHostLocation> getDockerHostLocations() { List<Optional<DockerHostLocation>> result = Lists.newArrayList(); for (Entity entity : getDockerHostList()) { DockerHost host = (DockerHost) entity; DockerHostLocation machine = host.getDynamicLocation(); result.add(Optional.<DockerHostLocation>fromNullable(machine)); }/*from ww w . jav a2s.c o m*/ return ImmutableList.copyOf(Optional.presentInstances(result)); }
From source file:com.twitter.common.args.Args.java
private static Iterable<Field> filterFields(Iterable<ArgInfo> infos, Predicate<Field> filter) { return Iterables.filter(Optional.presentInstances(Iterables.transform(infos, TO_FIELD)), filter); }
From source file:com.eucalyptus.ws.WebServices.java
private static Iterable<Cidr> parse(final Function<String, Optional<Cidr>> cidrTransform, final String cidrList) { return Optional.presentInstances(Iterables.transform( Splitter.on(CharMatcher.anyOf(", ;:")).trimResults().omitEmptyStrings().split(cidrList), cidrTransform));//from w ww.ja v a2 s . c o m }
From source file:org.apache.aurora.common.args.ArgumentInfo.java
private Iterable<ValueVerifier<T>> getVerifiers(final Verifiers verifierOracle) { Function<Annotation, Optional<ValueVerifier<T>>> toVerifier = annotation -> { @Nullable/*from www . ja va2s .co m*/ Verifier<? super T> verifier = verifierOracle.get(type, annotation); if (verifier != null) { return Optional.of(new ValueVerifier<T>(verifier, annotation)); } else { return Optional.absent(); } }; return Optional.presentInstances(Iterables.transform(verifierAnnotations, toVerifier)); }