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

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

Introduction

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

Prototype

public abstract T get();

Source Link

Document

Returns the contained instance, which must be present.

Usage

From source file:net.awairo.mcmod.spawnchecker.presetmode.spawncheck.SlimeSpawnChecker.java

private static Optional<Long> findSeed(final Optional<InetSocketAddress> address) {
    if (!address.isPresent())
        return Optional.absent();

    final InetAddress inetAddress = address.get().getAddress();

    final String host = inetAddress.getHostName();
    final String ip = inetAddress.getHostAddress();
    final Integer port = address.get().getPort();

    LOGGER.info("multiplayer server: host={}, ip={}, port={}", host, ip, port);

    return seedConfig().get(host, port).or(seedConfig().get(ip, port));
}

From source file:com.eucalyptus.cloudformation.resources.standard.actions.AWSSQSQueuePolicyResourceAction.java

private static void removePolicyFromQueue(AWSSQSQueuePolicyResourceAction action,
        ServiceConfiguration configuration, String queueUrl) throws Exception {
    SetQueueAttributesType setQueueAttributesType = MessageHelper.createMessage(SetQueueAttributesType.class,
            action.info.getEffectiveUserId());
    setQueueAttributesType.setQueueUrl(queueUrl);
    Attribute attribute = new Attribute();
    attribute.setName("Policy");
    attribute.setValue("");
    setQueueAttributesType.getAttribute().add(attribute);
    try {//ww w . j  a v  a  2s  .c  o  m
        AsyncRequests.sendSync(configuration, setQueueAttributesType);
    } catch (final Exception e) {
        final Optional<AsyncExceptions.AsyncWebServiceError> error = AsyncExceptions.asWebServiceError(e);
        if (error.isPresent())
            switch (Strings.nullToEmpty(error.get().getCode())) {
            case "QueueDoesNotExist":
                break;
            default:
                throw e;
            }
        else {
            throw e;
        }
    }
}

From source file:org.opendaylight.groupbasedpolicy.neutron.ovsdb.util.OvsdbHelper.java

public static Node getTopologyNode(InstanceIdentifier<Node> nodeIid, DataBroker dataBroker) {
    ReadTransaction transaction = dataBroker.newReadOnlyTransaction();
    Optional<Node> nodeOptional = readFromDs(LogicalDatastoreType.OPERATIONAL, nodeIid, transaction);
    if (nodeOptional.isPresent()) {
        return nodeOptional.get();
    }//from   w  w w .  j a va 2s. c  om
    return null;
}

From source file:org.locationtech.geogig.test.integration.remoting.RemotesIndexTestSupport.java

public static List<Index> createIndexes(Repository repo, Ref ref) {
    Envelope bounds = new Envelope(-180, 180, -90, 90);
    List<NodeRef> types = repo.command(FindFeatureTypeTrees.class).setRootTreeRef(ref.getName()).call();

    List<Index> indexes = new ArrayList<>();
    for (NodeRef treeRef : types) {
        Map<String, IndexInfo> typeIndexes = getIndexes(repo, treeRef.path());
        if (typeIndexes.containsKey(treeRef.path())) {
            IndexInfo indexInfo = typeIndexes.get(treeRef.path());
            IndexDatabase indexdb = repo.indexDatabase();
            Optional<ObjectId> indexedTree = indexdb.resolveIndexedTree(indexInfo, treeRef.getObjectId());
            if (indexedTree.isPresent()) {
                indexes.add(new Index(indexInfo, indexedTree.get(), indexdb));
            }/*w  w  w  .  jav a  2 s. c om*/
        } else {
            Index index = repo.command(CreateQuadTree.class).setBounds(bounds).setIndexHistory(true)
                    .setTypeTreeRef(treeRef).call();
            log.info("Created index {} before cloning", index);
            indexes.add(index);
        }
    }
    return indexes;
}

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

/**
 * Get an instance of {@link HiveSerDeManager}.
 *
 * @param type The {@link HiveSerDeManager} type. It should be either AVRO, or the name of a class that implements
 * {@link HiveSerDeManager}. The specified {@link HiveSerDeManager} type must have a constructor that takes a
 * {@link State} object./*  w ww  .  ja  va 2 s.  c o  m*/
 * @param props A {@link State} object. To get a specific implementation of {@link HiveSerDeManager}, specify either
 * one of the values in {@link Implementation} (e.g., AVRO) or the name of a class that implements
 * {@link HiveSerDeManager} in property {@link #HIVE_ROW_FORMAT}. The {@link State} object is also used to
 * instantiate the {@link HiveSerDeManager}.
 */
public static HiveSerDeManager get(State props) {
    String type = props.getProp(HIVE_ROW_FORMAT, Implementation.AVRO.name());
    Optional<Implementation> implementation = Enums.getIfPresent(Implementation.class, type.toUpperCase());

    try {
        if (implementation.isPresent()) {
            return (HiveSerDeManager) ConstructorUtils
                    .invokeConstructor(Class.forName(implementation.get().toString()), props);
        }
        return (HiveSerDeManager) ConstructorUtils.invokeConstructor(Class.forName(type), props);
    } catch (ReflectiveOperationException e) {
        throw new RuntimeException(
                "Unable to instantiate " + HiveSerDeManager.class.getSimpleName() + " with type " + type, e);
    }
}

From source file:de.azapps.mirakel.custom_views.TaskDetailDueReminder.java

private static void setupRecurrenceDrawable(final ImageButton recurrence,
        @NonNull final Optional<Recurring> recurring) {
    final int id;
    if (!recurring.isPresent() || recurring.get().getId() == -1) {
        id = android.R.drawable.ic_menu_mylocation;
    } else {/*w w  w .  j a va  2  s.  com*/
        id = android.R.drawable.ic_menu_rotate;
    }
    recurrence.setImageResource(id);
}

From source file:io.scigraph.services.jersey.MultivaluedMapUtils.java

/***
 * Converts a {@link MultivaluedMap} to a {@link Multimap}.
 * //from w  w w .  ja  v a  2 s  .co  m
 * @param map the original map
 * @param separator an optional separator to further split the values in the map
 * @return the new multimap
 */
public static Multimap<String, Object> multivaluedMapToMultimap(MultivaluedMap<String, String> map,
        Optional<Character> separator) {
    Multimap<String, Object> merged = ArrayListMultimap.create();
    for (Entry<String, List<String>> entry : map.entrySet()) {
        for (String value : entry.getValue()) {
            if (separator.isPresent()) {
                merged.putAll(entry.getKey(), Splitter.on(separator.get()).split(value));
            } else {
                merged.put(entry.getKey(), value);
            }
        }
    }
    return merged;
}

From source file:org.zanata.client.commands.FileMappingRuleHandler.java

@VisibleForTesting
protected static EnumMap<Placeholders, String> parseToMap(@Nonnull String sourceFile,
        @Nonnull LocaleMapping localeMapping, Optional<String> translationFileExtension) {
    EnumMap<Placeholders, String> parts = new EnumMap<Placeholders, String>(Placeholders.class);
    File file = new File(sourceFile);

    String extension = translationFileExtension.isPresent() ? translationFileExtension.get()
            : FilenameUtils.getExtension(sourceFile);
    String filename = FilenameUtils.removeExtension(file.getName());
    parts.put(Placeholders.extension, extension);
    parts.put(Placeholders.filename, filename);
    parts.put(Placeholders.locale, localeMapping.getLocalLocale());
    parts.put(Placeholders.localeWithUnderscore, localeMapping.getLocalLocale().replaceAll("\\-", "_"));
    String pathname = Strings.nullToEmpty(file.getParent());
    parts.put(Placeholders.path, FileUtil.simplifyPath(pathname));
    log.debug("parsed parts: {}", parts);
    return parts;
}

From source file:org.opendaylight.vpnservice.elan.l2gw.utils.L2GatewayConnectionUtils.java

public static L2gateway getNeutronL2gateway(DataBroker broker, Uuid l2GatewayId) {
    LOG.debug("getNeutronL2gateway for {}", l2GatewayId.getValue());
    InstanceIdentifier<L2gateway> inst = InstanceIdentifier.create(Neutron.class).child(L2gateways.class)
            .child(L2gateway.class, new L2gatewayKey(l2GatewayId));
    Optional<L2gateway> l2Gateway = MDSALUtil.read(broker, LogicalDatastoreType.CONFIGURATION, inst);
    if (l2Gateway.isPresent()) {
        return l2Gateway.get();
    }/*from  w  ww . j  a  va  2s  .  co  m*/
    return null;
}

From source file:org.killbill.billing.plugin.cielo.api.mapping.UserDataMappingService.java

public static UserData toUserData(@Nullable final Account account, final Iterable<PluginProperty> properties) {
    final UserData userData = new UserData();

    // determine the customer id
    final String customerId = account.getExternalKey();
    userData.setShopperReference(customerId);

    // determine the customer locale
    final String propertyLocaleString = PluginProperties
            .findPluginPropertyValue(CieloPaymentPluginApi.PROPERTY_CUSTOMER_LOCALE, properties);
    final Optional<Locale> customerLocaleOptional = toCustomerLocale(propertyLocaleString, account);
    final Locale customerLocale = customerLocaleOptional.isPresent() ? customerLocaleOptional.get() : null;
    userData.setShopperLocale(customerLocale);

    // determine the email
    final String propertyEmail = PluginProperties.findPluginPropertyValue(CieloPaymentPluginApi.PROPERTY_EMAIL,
            properties);/*w  w  w  .  java  2s.c om*/
    final Optional<String> optionalEmail = toCustomerEmail(propertyEmail, account);
    final String email = optionalEmail.isPresent() ? optionalEmail.get() : null;
    userData.setShopperEmail(email);

    // determine first Name
    final String propertyFirstName = PluginProperties
            .findPluginPropertyValue(CieloPaymentPluginApi.PROPERTY_FIRST_NAME, properties);
    final Optional<String> optionalFirstName = toFirstName(propertyFirstName, account);
    final String firstName = optionalFirstName.isPresent() ? optionalFirstName.get() : null;
    userData.setFirstName(firstName);

    // determine last Name
    final String propertyLastName = PluginProperties
            .findPluginPropertyValue(CieloPaymentPluginApi.PROPERTY_LAST_NAME, properties);
    final Optional<String> optionalLastName = toLastName(propertyLastName, account);
    final String lastName = optionalLastName.isPresent() ? optionalLastName.get() : null;
    userData.setLastName(lastName);

    // set ip
    userData.setShopperIP(
            PluginProperties.findPluginPropertyValue(CieloPaymentPluginApi.PROPERTY_IP, properties));

    return userData;
}