List of usage examples for com.google.common.base Optional get
public abstract T get();
From source file:org.opendaylight.unimgr.utils.EvcUtils.java
/** * Updates a specific EVC into a specific DataStore type. * @param dataStore The datastore type//ww w .ja va 2 s . c o m * @param evcKey The EVC key * @param evcAugmentation The EVC's data * @param sourceUniIid The Source Uni Instance Identifier * @param destinationUniIid The destination Uni Instance Identifier * @param dataBroker The dataBroker instance to create transactions * @return true if evc is updated */ public static boolean updateEvcNode(final LogicalDatastoreType dataStore, final InstanceIdentifier<?> evcKey, final EvcAugmentation evcAugmentation, final InstanceIdentifier<?> sourceUniIid, final InstanceIdentifier<?> destinationUniIid, final DataBroker dataBroker) { final EvcAugmentationBuilder updatedEvcBuilder = new EvcAugmentationBuilder(evcAugmentation); if ((sourceUniIid != null) && (destinationUniIid != null)) { final List<UniSource> sourceList = new ArrayList<UniSource>(); final UniSource evcUniSource = evcAugmentation.getUniSource().iterator().next(); final UniSourceKey sourceKey = evcUniSource.getKey(); final short sourceOrder = evcUniSource.getOrder(); final IpAddress sourceIp = evcUniSource.getIpAddress(); final UniSource uniSource = new UniSourceBuilder().setOrder(sourceOrder).setKey(sourceKey) .setIpAddress(sourceIp).setUni(sourceUniIid).build(); sourceList.add(uniSource); updatedEvcBuilder.setUniSource(sourceList); final List<UniDest> destinationList = new ArrayList<UniDest>(); final UniDest evcUniDest = evcAugmentation.getUniDest().iterator().next(); final UniDestKey destKey = evcUniDest.getKey(); final short destOrder = evcUniDest.getOrder(); final IpAddress destIp = evcUniDest.getIpAddress(); final UniDest uniDest = new UniDestBuilder().setIpAddress(destIp).setOrder(destOrder).setKey(destKey) .setUni(destinationUniIid).build(); destinationList.add(uniDest); updatedEvcBuilder.setUniDest(destinationList); final Optional<Link> optionalEvcLink = MdsalUtils.readLink(dataBroker, LogicalDatastoreType.CONFIGURATION, evcKey); if (optionalEvcLink.isPresent()) { final Link link = optionalEvcLink.get(); final WriteTransaction transaction = dataBroker.newWriteOnlyTransaction(); final LinkBuilder linkBuilder = new LinkBuilder(); linkBuilder.setKey(link.getKey()); linkBuilder.setLinkId(link.getLinkId()); linkBuilder.setDestination(link.getDestination()); linkBuilder.setSource(link.getSource()); linkBuilder.addAugmentation(EvcAugmentation.class, updatedEvcBuilder.build()); transaction.put(dataStore, evcKey.firstIdentifierOf(Link.class), linkBuilder.build()); transaction.submit(); return true; } else { LOG.info("EvcLink is not present: " + optionalEvcLink.get().getKey()); } } else { LOG.info("Invalid instance identifiers for sourceUni and destUni."); } return false; }
From source file:org.sonar.server.plugins.ws.PluginWSCommons.java
private static List<Plugin> compatiblePlugins(UpdateCenterMatrixFactory updateCenterMatrixFactory) { Optional<UpdateCenter> updateCenter = updateCenterMatrixFactory.getUpdateCenter(false); return updateCenter.isPresent() ? updateCenter.get().findAllCompatiblePlugins() : Collections.<Plugin>emptyList(); }
From source file:org.opendaylight.vtn.manager.internal.util.vnode.VTenantUtils.java
/** * Read the VTN specified by the given name. * * @param rtx A {@link ReadTransaction} instance associated with the * read transaction for the MD-SAL datastore. * @param vname A {@link VnodeName} instance that contains the name of * the VTN.// w ww . j a v a 2 s .c o m * @return A {@link Vtn} instance. * @throws VTNException An error occurred. */ public static Vtn readVtn(ReadTransaction rtx, VnodeName vname) throws VTNException { InstanceIdentifier<Vtn> path = getIdentifier(vname); LogicalDatastoreType oper = LogicalDatastoreType.OPERATIONAL; Optional<Vtn> opt = DataStoreUtils.read(rtx, oper, path); if (!opt.isPresent()) { throw getNotFoundException(vname.getValue()); } return opt.get(); }
From source file:org.icgc.dcc.release.job.join.task.ObservationJoinTask.java
private static Function<Tuple2<String, SsmPrimaryFeatureType>, Boolean> filterControlledRecords() { return t -> { SsmPrimaryFeatureType row = t._2; Optional<Marking> marking = Marking.from(row.getMarking()); checkState(marking.isPresent(), "Failed to resolve marking from %s", row); return !marking.get().isControlled(); };//www . j a v a 2s.co m }
From source file:org.opendaylight.vpnservice.elan.l2gw.utils.L2GatewayConnectionUtils.java
public static List<L2gateway> getL2gatewayList(DataBroker broker) { InstanceIdentifier<L2gateways> inst = InstanceIdentifier.create(Neutron.class).child(L2gateways.class); Optional<L2gateways> l2gateways = MDSALUtil.read(broker, LogicalDatastoreType.CONFIGURATION, inst); if (l2gateways.isPresent()) { return l2gateways.get().getL2gateway(); }//from w ww.j a v a 2 s.com return null; }
From source file:net.caseif.flint.steel.util.helper.ChatHelper.java
public static boolean isRoundBarrierPresent(Player sender, Player recipient) { Optional<Challenger> senderCh = SteelCore.getChallenger(sender.getUniqueId()); Optional<Challenger> recipCh = SteelCore.getChallenger(recipient.getUniqueId()); if (checkRoundBarrier(senderCh) || checkRoundBarrier(recipCh)) { if (senderCh.isPresent() != recipCh.isPresent() || senderCh.get().getRound() != recipCh.get().getRound()) { return true; }/*from w ww. ja v a2 s.c o m*/ } return false; }
From source file:io.mesosphere.mesos.util.ProtoUtils.java
@NotNull public static Credential getCredential(@NotNull final String principal, @NotNull final Optional<String> secret) { if (secret.isPresent()) { return Credential.newBuilder().setPrincipal(principal) .setSecret(ByteString.copyFrom(secret.get().getBytes())).build(); } else {/*from w ww . j av a 2 s . com*/ return Credential.newBuilder().setPrincipal(principal).build(); } }
From source file:com.twitter.common.thrift.Util.java
/** * Maps a {@link ServiceInstance} to an {@link InetSocketAddress} given the {@code endpointName}. * * @param optionalEndpointName the name of the end-point on the service's additional end-points, * if not set, maps to the primary service end-point *//*from w w w .ja v a2s .c om*/ public static Function<ServiceInstance, InetSocketAddress> getAddress( final Optional<String> optionalEndpointName) { if (!optionalEndpointName.isPresent()) { return GET_ADDRESS; } final String endpointName = optionalEndpointName.get(); return getAddress(new Function<ServiceInstance, Endpoint>() { @Override public Endpoint apply(@Nullable ServiceInstance serviceInstance) { Map<String, Endpoint> endpoints = serviceInstance.getAdditionalEndpoints(); Preconditions.checkArgument(endpoints.containsKey(endpointName), "Did not find end-point %s on %s", endpointName, serviceInstance); return endpoints.get(endpointName); } }); }
From source file:org.zanata.service.impl.WebHooksPublisher.java
protected static void publish(@Nonnull String callbackURL, @Nonnull String data, @Nonnull MediaType acceptType, @Nonnull MediaType mediaType, Optional<String> secretKey) { try {/*ww w . jav a2 s . c o m*/ ResteasyClient client = new ResteasyClientBuilder().build(); ResteasyWebTarget target = client.target(callbackURL); Invocation.Builder postBuilder = target.request().accept(acceptType); if (secretKey.isPresent() && StringUtils.isNotBlank(secretKey.get())) { String sha = signWebhookHeader(data, secretKey.get(), callbackURL); postBuilder.header(WEBHOOK_HEADER, sha); } log.debug("firing async webhook: {}:{}", callbackURL, data); postBuilder.async().post(Entity.entity(data, mediaType)); } catch (Exception e) { log.error("Error on webhooks post {}, {}", callbackURL, e); } }
From source file:com.treasuredata.client.TDClientConfig.java
private static <V> void saveProperty(Properties p, Type config, V value) { if (value == null) { return;// w w w .j a va 2 s.c o m } if (value instanceof Optional) { Optional<?> opt = (Optional<?>) value; if (opt.isPresent()) { Object v = opt.get(); saveProperty(p, config, v); } } else { p.setProperty(config.key, value.toString()); } }