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:com.google.devtools.build.lib.rules.proto.ProtoCompileAction.java

/**
 * A convenience method to register an action, if it's present.
 * @param protoCompileActionOptional//w ww.  j  a v  a  2s. co m
 */
public static void registerAction(Optional<ProtoCompileAction> protoCompileActionOptional) {
    if (protoCompileActionOptional.isPresent()) {
        protoCompileActionOptional.get().registerAction();
    }
}

From source file:org.spongepowered.common.service.scheduler.SpongeScheduler.java

/**
 * Check the object is a plugin instance.
 *
 * @param plugin The plugin to check//from w w w . ja va  2 s. c  o m
 * @return The plugin container of the plugin instance
 * @throws NullPointerException If the passed in plugin instance is null
 * @throws IllegalArgumentException If the object is not a plugin instance
 */
static PluginContainer checkPluginInstance(Object plugin) {
    Optional<PluginContainer> optPlugin = Sponge.getGame().getPluginManager()
            .fromInstance(checkNotNull(plugin, "plugin"));
    checkArgument(optPlugin.isPresent(), "Provided object is not a plugin instance");
    return optPlugin.get();
}

From source file:org.onos.yangtools.yang.model.repo.api.SourceIdentifier.java

/**
 * Returns filename for this YANG module as specified in RFC 6020.
 *
 * Returns filename in format/*from   ww  w . j  a v  a2 s .  co m*/
 * <code>moduleName ['@' revision] '.yang'</code>
 *
 * Where Where revision-date is in format YYYY-mm-dd.
 *
 * <p>
 * See
 * http://tools.ietf.org/html/rfc6020#section-5.2
 *
 * @return Filename for this source identifier.
 */
public static final String toYangFileName(final String moduleName, final Optional<String> revision) {
    StringBuilder filename = new StringBuilder(moduleName);
    if (revision.isPresent()) {
        filename.append('@');
        filename.append(revision.get());
    }
    filename.append(".yang");
    return filename.toString();
}

From source file:org.apache.gobblin.source.extractor.extract.kafka.ConfigStoreUtils.java

/**
 * Shortlist topics from config store based on whitelist/blacklist tags and
 * add it to {@param whitelist}/{@param blacklist}
 *
 * If tags are not provided, blacklist and whitelist won't be modified
 *//*from   w w w .  ja  va 2s .  c o m*/
public static void setTopicsFromConfigStore(Properties properties, Set<String> blacklist, Set<String> whitelist,
        final String _blacklistTopicKey, final String _whitelistTopicKey) {
    Optional<String> configStoreUri = getConfigStoreUri(properties);
    if (!configStoreUri.isPresent()) {
        return;
    }
    ConfigClient configClient = ConfigClient.createConfigClient(VersionStabilityPolicy.WEAK_LOCAL_STABILITY);
    Optional<Config> runtimeConfig = ConfigClientUtils.getOptionalRuntimeConfig(properties);

    if (properties.containsKey(GOBBLIN_CONFIG_TAGS_WHITELIST)) {
        Preconditions.checkArgument(properties.containsKey(GOBBLIN_CONFIG_FILTER),
                "Missing required property " + GOBBLIN_CONFIG_FILTER);
        String filterString = properties.getProperty(GOBBLIN_CONFIG_FILTER);
        Path whiteListTagUri = PathUtils.mergePaths(new Path(configStoreUri.get()),
                new Path(properties.getProperty(GOBBLIN_CONFIG_TAGS_WHITELIST)));
        getTopicsURIFromConfigStore(configClient, whiteListTagUri, filterString, runtimeConfig).stream()
                .filter((URI u) -> ConfigUtils.getBoolean(getConfig(configClient, u, runtimeConfig),
                        _whitelistTopicKey, false))
                .forEach(((URI u) -> whitelist.add(getTopicNameFromURI(u))));
    } else if (properties.containsKey(GOBBLIN_CONFIG_TAGS_BLACKLIST)) {
        Preconditions.checkArgument(properties.containsKey(GOBBLIN_CONFIG_FILTER),
                "Missing required property " + GOBBLIN_CONFIG_FILTER);
        String filterString = properties.getProperty(GOBBLIN_CONFIG_FILTER);
        Path blackListTagUri = PathUtils.mergePaths(new Path(configStoreUri.get()),
                new Path(properties.getProperty(GOBBLIN_CONFIG_TAGS_BLACKLIST)));
        getTopicsURIFromConfigStore(configClient, blackListTagUri, filterString, runtimeConfig).stream()
                .filter((URI u) -> ConfigUtils.getBoolean(getConfig(configClient, u, runtimeConfig),
                        _blacklistTopicKey, false))
                .forEach(((URI u) -> blacklist.add(getTopicNameFromURI(u))));
    } else {
        log.warn("None of the blacklist or whitelist tags are provided");
    }
}

From source file:org.opendaylight.genius.utils.cache.DataStoreCache.java

public static <T extends DataObject> Object get(String cacheName, InstanceIdentifier<T> identifier, String key,
        DataBroker broker, boolean isConfig) {
    Object dataObject = getCache(cacheName).get(key);
    if (dataObject == null) {
        Optional<T> datastoreObject = MDSALDataStoreUtils.read(broker,
                isConfig ? LogicalDatastoreType.CONFIGURATION : LogicalDatastoreType.OPERATIONAL, identifier);
        if (datastoreObject.isPresent()) {
            dataObject = datastoreObject.get();
            add(cacheName, key, dataObject);
        }/*from www . j  a va 2 s  .c  om*/
    }
    return dataObject;
}

From source file:com.fourmob.datetimepicker.date.DatePickerDialog.java

public static DatePickerDialog newInstance(final OnDateSetListener onDateSetListener, Optional<Calendar> date,
        final boolean dark) {
    final Calendar notNullDate = date.or(new GregorianCalendar());
    final boolean hasNoDate = !date.isPresent();
    final int year = notNullDate.get(Calendar.YEAR);
    final int month = notNullDate.get(Calendar.MONTH);
    final int day = notNullDate.get(Calendar.DAY_OF_MONTH);
    return newInstance(onDateSetListener, year, month, day, dark, hasNoDate);
}

From source file:com.palantir.atlasdb.keyvalue.cassandra.jmx.CassandraJmxCompactionManagers.java

/**
 * return a empty set if not client can be created
 * @param config/*from   w  w w. j a va2s  . co m*/
 * @return
 */
public static Set<CassandraJmxCompactionClient> createCompactionClients(CassandraKeyValueServiceConfig config) {
    if (!config.jmx().isPresent()) {
        return Collections.emptySet();
    }

    CassandraJmxCompactionConfig jmxConfig = config.jmx().get();
    // need to set the property before creating the JMX compaction client
    setJmxSslProperty(jmxConfig);

    Set<CassandraJmxCompactionClient> clients = Sets.newHashSet();
    Set<String> thriftEndPoints = config.servers();
    Preconditions.checkState(!thriftEndPoints.isEmpty(), "address_list should not be empty.");

    // jmxEndPoints are using different ports specified in address_list
    int jmxPort = jmxConfig.port();
    for (String endPointHost : thriftEndPoints) {
        Optional<CassandraJmxCompactionClient> client = new CassandraJmxCompactionClient.Builder(endPointHost,
                jmxPort).username(jmxConfig.username()).password(jmxConfig.password()).build();
        if (client.isPresent()) {
            clients.add(client.get());
        }
    }

    return clients;
}

From source file:org.sonar.server.computation.task.projectanalysis.qualitymodel.NewQualityModelMeasuresVisitor.java

private static long getLongValue(Optional<Measure> measure, Period period) {
    if (!measure.isPresent()) {
        return 0L;
    }//from w w  w. j  a va2s  .com
    return getLongValue(measure.get(), period);
}

From source file:org.opendaylight.yangtools.sal.binding.generator.impl.BindingSchemaContextUtils.java

private static DataNodeContainer findInCases(final ChoiceSchemaNode choiceNode, final QName targetQName) {
    for (ChoiceCaseNode caze : choiceNode.getCases()) {
        Optional<DataNodeContainer> potential = findDataNodeContainer(caze, targetQName);
        if (potential.isPresent()) {
            return potential.get();
        }//www  .jav a  2 s. c om
    }
    return null;
}

From source file:org.opendaylight.vtn.manager.it.util.inventory.InventoryUtils.java

/**
 * Find a VTN port that meets the specified condition.
 *
 * @param rtx   A read-only MD-SAL datastore transaction.
 * @param nid   The node identifier string.
 * @param pid   A string representation of the port ID.
 * @param name  The name of the port./* ww w. ja va  2 s  .  c  om*/
 * @return  A {@link VtnPort} instance if found.
 *          {@code null} otherwise.
 */
public static VtnPort findPort(ReadTransaction rtx, String nid, String pid, String name) {
    Optional<VtnNode> opt = DataStoreUtils.read(rtx, getVtnNodeIdentifier(nid));
    VtnPort found = null;
    if (opt.isPresent()) {
        List<VtnPort> ports = opt.get().getVtnPort();
        if (ports != null) {
            for (VtnPort vport : ports) {
                if (match(vport, nid, pid, name)) {
                    found = vport;
                    break;
                }
            }
        }
    }

    return found;
}