Example usage for com.google.common.base Optional isPresent

List of usage examples for com.google.common.base Optional isPresent

Introduction

In this page you can find the example usage for com.google.common.base Optional isPresent.

Prototype

public abstract boolean isPresent();

Source Link

Document

Returns true if this holder contains a (non-null) instance.

Usage

From source file:org.opendaylight.yangtools.yang.binding.util.RpcMethodInvoker.java

protected static RpcMethodInvoker from(final Method method) {
    Optional<Class<? extends DataContainer>> input = BindingReflections.resolveRpcInputClass(method);
    try {//from   w  w w  . ja  v  a  2  s  .com
        MethodHandle methodHandle = LOOKUP.unreflect(method);
        if (input.isPresent()) {
            return new RpcMethodInvokerWithInput(methodHandle);
        }
        return new RpcMethodInvokerWithoutInput(methodHandle);
    } catch (IllegalAccessException e) {
        throw new IllegalStateException("Lookup on public method failed.", e);
    }

}

From source file:org.opendaylight.tl1.impl.MDSal.java

public static List<String> getAllDevices() {

    InstanceIdentifier<DeviceRegistry> identifier = InstanceIdentifier.create(DeviceRegistry.class);
    ReadOnlyTransaction transaction = dbroker.newReadOnlyTransaction();

    ReadOnlyTransaction readTx = dbroker.newReadOnlyTransaction();
    ListenableFuture<Optional<DeviceRegistry>> dataFuture = readTx.read(LogicalDatastoreType.OPERATIONAL,
            identifier);//from   www . j a v a2  s  .c om
    Futures.addCallback(dataFuture, new FutureCallback<Optional<DeviceRegistry>>() {
        @Override
        public void onSuccess(final Optional<DeviceRegistry> result) {
            if (result.isPresent()) {
                // data are present in data store.
                allDevices = ExtractIps(result.get().getDeviceRegistryEntry());
                //doSomething(result.get());
            } else {
                // data are not present in data store.
                allDevices = null;
            }
        }

        @Override
        public void onFailure(final Throwable t) {
            // Error during read
        }

    });

    return allDevices;
}

From source file:org.apache.gobblin.hive.HiveConfFactory.java

/**
 *
 * @param hcatURI User specified hcatURI.
 * @param broker A shared resource broker
 * @return a {@link HiveConf} with specified hcatURI if any.
 * @throws IOException//from  w  w  w .j  ava2s .  c  o  m
 */
public static <S extends ScopeType<S>> HiveConf get(Optional<String> hcatURI, SharedResourcesBroker<S> broker)
        throws IOException {
    try {
        SharedHiveConfKey confKey = hcatURI.isPresent() && StringUtils.isNotBlank(hcatURI.get())
                ? new SharedHiveConfKey(hcatURI.get())
                : SharedHiveConfKey.INSTANCE;
        return broker.getSharedResource(new HiveConfFactory<>(), confKey);
    } catch (NotConfiguredException nce) {
        throw new IOException(nce);
    }
}

From source file:org.opendaylight.openflowplugin.applications.topology.manager.TopologyManagerUtil.java

static void removeAffectedLinks(final NodeId id, Optional<Topology> topologyOptional,
        ReadWriteTransaction transaction, final InstanceIdentifier<Topology> topology) {
    if (!topologyOptional.isPresent()) {
        return;//from  w w w  .ja  v  a 2  s  .  co  m
    }

    List<Link> linkList = topologyOptional.get().getLink() != null ? topologyOptional.get().getLink()
            : Collections.<Link>emptyList();
    for (Link link : linkList) {
        if (id.equals(link.getSource().getSourceNode()) || id.equals(link.getDestination().getDestNode())) {
            transaction.delete(LogicalDatastoreType.OPERATIONAL, linkPath(link, topology));
        }
    }
}

From source file:org.opendaylight.openflowplugin.applications.topology.manager.TopologyManagerUtil.java

static void removeAffectedLinks(final TpId id, Optional<Topology> topologyOptional,
        ReadWriteTransaction transaction, final InstanceIdentifier<Topology> topology) {
    if (!topologyOptional.isPresent()) {
        return;//  www .  java2s .  c  o m
    }

    List<Link> linkList = topologyOptional.get().getLink() != null ? topologyOptional.get().getLink()
            : Collections.<Link>emptyList();
    for (Link link : linkList) {
        if (id.equals(link.getSource().getSourceTp()) || id.equals(link.getDestination().getDestTp())) {
            transaction.delete(LogicalDatastoreType.OPERATIONAL, linkPath(link, topology));
        }
    }
}

From source file:org.eclipse.buildship.core.workspace.internal.ProjectNatureUpdater.java

private static Set<String> toNatures(Optional<List<OmniEclipseProjectNature>> projectNatures,
        IProjectDescription description) {
    Set<String> natures = Sets.newLinkedHashSet();
    if (projectNatures.isPresent()) {
        natures.addAll(toNatures(projectNatures.get()));
    } else {/*from  w  w  w. j a  v  a 2  s.  c  o m*/
        natures.addAll(Arrays.asList(description.getNatureIds()));
    }
    natures.add(GradleProjectNature.ID);
    return natures;
}

From source file:org.anhonesteffort.flock.crypto.KeyHelper.java

public static Optional<String> buildEncodedSalt(Context context) throws IOException {
    Optional<byte[]> salt = KeyStore.getKeyMaterialSalt(context);

    if (!salt.isPresent())
        return Optional.absent();

    return Optional.of(Base64.encodeBytes(salt.get()));
}

From source file:org.opendaylight.netvirt.vpnmanager.api.VpnExtraRouteHelper.java

public static List<String> getUsedRds(DataBroker broker, long vpnId, String destPrefix) {
    InstanceIdentifier<DestPrefixes> usedRdsId = getUsedRdsIdentifier(vpnId, destPrefix);
    Optional<DestPrefixes> usedRds = MDSALUtil.read(broker, LogicalDatastoreType.CONFIGURATION, usedRdsId);
    return usedRds.isPresent() ? usedRds.get().getRds() : new ArrayList<String>();
}

From source file:at.ac.univie.isc.asio.d2rq.D2rqTools.java

/**
 * Find the embedded base resource IRI if present.
 *
 * @param model given configuration/*from   w ww . ja v a2s.c o m*/
 * @return base resource IRI embedded in model.
 */
static Optional<String> findEmbeddedBaseUri(final Model model) {
    final Optional<Resource> server = findSingleOfType(model, D2RConfig.Server);
    if (server.isPresent()) {
        final Resource baseUriProperty = server.get().getPropertyResourceValue(D2RConfig.baseURI);
        return baseUriProperty != null ? Optional.fromNullable(baseUriProperty.getURI())
                : Optional.<String>absent();
    } else {
        return Optional.absent();
    }
}

From source file:li.klass.fhem.behavior.dim.DimmableBehavior.java

public static Optional<DimmableBehavior> behaviorFor(FhemDevice fhemDevice) {
    SetList setList = fhemDevice.getSetList();

    Optional<DiscreteDimmableBehavior> discrete = DiscreteDimmableBehavior.behaviorFor(setList);
    if (discrete.isPresent()) {
        return Optional.of(new DimmableBehavior(fhemDevice, discrete.get()));
    }/*from   w  w  w  .  jav  a 2  s . c om*/

    Optional<ContinuousDimmableBehavior> continuous = ContinuousDimmableBehavior.behaviorFor(setList);
    if (continuous.isPresent()) {
        DimmableTypeBehavior behavior = continuous.get();
        return Optional.of(new DimmableBehavior(fhemDevice, behavior));
    }

    return Optional.absent();
}