Example usage for java.util Optional get

List of usage examples for java.util Optional get

Introduction

In this page you can find the example usage for java.util Optional get.

Prototype

public T get() 

Source Link

Document

If a value is present, returns the value, otherwise throws NoSuchElementException .

Usage

From source file:com.ikanow.aleph2.data_model.utils.PropertiesUtils.java

/**
 * Reads in the config file and sends back a list of a config data service entries based on the
 * given configPrefix.  This is used by the ModuleUtils to get the requested modules to load.
 * /*from   w ww  .j a va2  s . com*/
 * @param config
 * @param configPrefix
 * @return
 * @throws IOException 
 * @throws JsonMappingException 
 * @throws JsonParseException 
 */
public static List<ConfigDataServiceEntry> getDataServiceProperties(final Config config,
        final String configPrefix) {
    Optional<ConfigObject> sub_config = getSubConfigObject(config, configPrefix);
    if (sub_config.isPresent()) {
        final ConfigObject dataServiceConfig = sub_config.get(); //config.getObject(configPrefix);         
        List<ConfigDataServiceEntry> toReturn = dataServiceConfig.entrySet().stream()
                .map(entry -> new ConfigDataServiceEntry(entry.getKey(),
                        Optional.ofNullable(PropertiesUtils.getConfigValue(config,
                                configPrefix + "." + entry.getKey() + ".interface", null)),
                        PropertiesUtils.getConfigValue(config, configPrefix + "." + entry.getKey() + ".service",
                                null),
                        PropertiesUtils.getConfigValue(config, configPrefix + "." + entry.getKey() + ".default",
                                false)))
                .collect(Collectors.toList());
        return toReturn;
    } else {
        return Collections.emptyList();
    }
}

From source file:org.openmhealth.shim.ihealth.mapper.IHealthDataPointMapper.java

/**
 * Gets the user note from a list entry node if that property exists.
 *
 * @param listEntryNode A single entry from the response result array.
 *//*from   w w  w.j  a va 2  s  .co m*/
protected static Optional<String> getUserNoteIfExists(JsonNode listEntryNode) {

    Optional<String> note = asOptionalString(listEntryNode, "Note");

    if (note.isPresent() && !note.get().isEmpty()) {

        return note;
    }

    return Optional.empty();
}

From source file:io.github.retz.scheduler.Launcher.java

private static Protos.FrameworkInfo buildFrameworkInfo(Configuration conf) {
    String userName = conf.fileConfig.getUserName();

    Protos.FrameworkInfo.Builder fwBuilder = Protos.FrameworkInfo.newBuilder().setUser(userName)
            .setName(RetzScheduler.FRAMEWORK_NAME).setWebuiUrl(conf.fileConfig.getUri().toASCIIString())
            .setFailoverTimeout(3600 * 24 * 7).setCheckpoint(true).setPrincipal(conf.fileConfig.getPrincipal())
            .setRole(conf.fileConfig.getRole());

    Optional<String> fid = Database.getInstance().getFrameworkId();
    if (fid.isPresent()) {
        LOG.info("FrameworkID {} found", fid.get());
        fwBuilder.setId(Protos.FrameworkID.newBuilder().setValue(fid.get()).build());
    }/*from  www  . ja v  a  2 s  . com*/

    if (conf.fileConfig.useGPU()) {
        LOG.info("GPU enabled - registering with GPU_RESOURCES capability.");
        fwBuilder.addCapabilities(Protos.FrameworkInfo.Capability.newBuilder()
                .setType(Protos.FrameworkInfo.Capability.Type.GPU_RESOURCES).build());
    }

    LOG.info("Connecting to Mesos master {} as {}", conf.getMesosMaster(), userName);
    return fwBuilder.build();
}

From source file:cz.lbenda.dataman.db.frm.DbConfigFrmController.java

public static DbConfig openDialog(final DbConfig sc) {
    Dialog<DbConfig> dialog = DialogHelper.createDialog();
    dialog.setResizable(false);/*from w ww  . java 2s. c o m*/
    final Tuple2<Parent, DbConfigFrmController> tuple = createNewInstance();
    if (sc != null) {
        tuple.get2().loadDataFromSessionConfiguration(sc);
    }
    dialog.setTitle(msgDialogTitle);
    dialog.setHeaderText(msgDialogHeader);

    dialog.getDialogPane().setContent(tuple.get1());
    ButtonType buttonTypeOk = ButtonType.OK;
    ButtonType buttonTypeCancel = ButtonType.CANCEL;
    dialog.getDialogPane().getButtonTypes().add(buttonTypeCancel);
    dialog.getDialogPane().getButtonTypes().add(buttonTypeOk);
    dialog.getDialogPane().setPadding(new Insets(0, 0, 0, 0));

    dialog.setResultConverter(b -> {
        if (b == buttonTypeOk) {
            DbConfig sc1 = sc;
            if (sc1 == null) {
                sc1 = new DbConfig();
                tuple.get2().storeDataToSessionConfiguration(sc1);
                DbConfigFactory.getConfigurations().add(sc1);
            } else {
                tuple.get2().storeDataToSessionConfiguration(sc1);
                if (DbConfigFactory.getConfigurations().contains(sc1)) { // The copied session isn't in list yet
                    int idx = DbConfigFactory.getConfigurations().indexOf(sc1);
                    DbConfigFactory.getConfigurations().remove(sc1);
                    DbConfigFactory.getConfigurations().add(idx, sc1);
                } else {
                    DbConfigFactory.getConfigurations().add(sc1);
                }
            }
            DbConfigFactory.saveConfiguration();
            return sc1;
        }
        return null;
    });

    Optional<DbConfig> result = dialog.showAndWait();
    if (result.isPresent()) {
        return result.get();
    }
    return null;
}

From source file:io.syndesis.rest.v1.handler.connection.ConnectionActionHandler.java

static boolean shouldEnrichDataShape(final Optional<DataShape> maybeExistingDataShape,
        final Object received) {
    if (maybeExistingDataShape.isPresent() && received != null) {
        final DataShape existingDataShape = maybeExistingDataShape.get();

        return "json-schema".equals(existingDataShape.getKind())
                && existingDataShape.getSpecification() == null;
    }//from w  w  w  . jav  a2s .  c  o m

    return false;
}

From source file:com.github.horrorho.inflatabledonkey.cloud.clients.BackupAccountClient.java

public static Optional<BackupAccount> backupAccount(HttpClient httpClient, CloudKitty kitty,
        ProtectionZone zone) throws IOException {

    List<CloudKit.RecordRetrieveResponse> responses = kitty.recordRetrieveRequest(httpClient, "mbksync",
            "BackupAccount");
    logger.debug("-- backupAccount() - responses: {}", responses);

    if (responses.size() != 1) {
        logger.warn("-- backupAccount() - bad response list size: {}", responses);
        return Optional.empty();
    }//  w w  w  .  ja  v  a 2  s.c om

    CloudKit.ProtectionInfo protectionInfo = responses.get(0).getRecord().getProtectionInfo();

    Optional<ProtectionZone> optionalNewZone = zone.newProtectionZone(protectionInfo);
    if (!optionalNewZone.isPresent()) {
        logger.warn("-- backupAccount() - failed to retrieve protection info");
        return Optional.empty();
    }
    ProtectionZone newZone = optionalNewZone.get();

    BackupAccount backupAccount = BackupAccountFactory.from(responses.get(0).getRecord(),
            (bs, id) -> newZone.decrypt(bs, id).get()); // TODO rework BackupAccount
    logger.debug("-- backupAccount() - backup account: {}", backupAccount);

    return Optional.of(backupAccount);
}

From source file:com.formkiq.core.form.FormFinder.java

/**
 * Find {@link FormJSONField} by field id.
 * @param form {@link FormJSON}//from   w w  w  . j a v a2  s  . c  o  m
 * @param id int
 * @return {@link Optional} of {@link FormJSONField}
 */
public static Optional<FormJSONField> findField(final FormJSON form, final int id) {
    Optional<Pair<FormJSONSection, FormJSONField>> op = findSectionAndField(form, id);
    return op.isPresent() ? Optional.of(op.get().getRight()) : Optional.empty();
}

From source file:org.elasticsearch.plugin.readonlyrest.utils.containers.ESWithReadonlyRestContainer.java

public static ESWithReadonlyRestContainer create(String elasticsearchConfig, ESInitalizer initalizer) {
    File config = ContainerUtils.getResourceFile(elasticsearchConfig);
    Optional<File> pluginFileOpt = GradleProjectUtils.assemble();
    if (!pluginFileOpt.isPresent()) {
        throw new ContainerCreationException("Plugin file assembly failed");
    }/*  w  w w . j  a v a2  s  . c  o m*/
    File pluginFile = pluginFileOpt.get();
    logger.info("Creating ES container ...");
    String elasticsearchConfigName = "elasticsearch.yml";
    ESWithReadonlyRestContainer container = new ESWithReadonlyRestContainer(
            new ImageFromDockerfile().withFileFromFile(pluginFile.getName(), pluginFile)
                    .withFileFromFile(elasticsearchConfigName, config)
                    .withDockerfileFromBuilder(builder -> builder
                            .from("docker.elastic.co/elasticsearch/elasticsearch:"
                                    + properties.getProperty("esVersion"))
                            .copy(pluginFile.getName(), "/tmp/")
                            .copy(elasticsearchConfigName, "/usr/share/elasticsearch/config/")
                            .run("yes | /usr/share/elasticsearch/bin/elasticsearch-plugin install "
                                    + "file:/tmp/" + pluginFile.getName())
                            .build()));
    return container.withExposedPorts(ES_PORT)
            .waitingFor(container.waitStrategy(initalizer).withStartupTimeout(CONTAINER_STARTUP_TIMEOUT));
}

From source file:io.pravega.controller.store.stream.tables.HistoryRecord.java

public static List<Pair<Long, List<Integer>>> readAllRecords(byte[] historyTable) {
    List<Pair<Long, List<Integer>>> result = new LinkedList<>();
    Optional<HistoryRecord> record = readLatestRecord(historyTable, true);
    while (record.isPresent()) {
        result.add(new ImmutablePair<>(record.get().getScaleTime(), record.get().getSegments()));
        record = fetchPrevious(record.get(), historyTable);
    }/*from ww  w.ja  v  a  2  s  .c  om*/
    return result;
}

From source file:com.github.horrorho.inflatabledonkey.cloud.clients.KeyBagClient.java

public static Optional<KeyBag> keyBag(HttpClient httpClient, CloudKitty kitty, ProtectionZone zone,
        String keyBagUUID) throws IOException {
    logger.debug("-- keyBag() - keybag UUID: {}", keyBagUUID);

    List<CloudKit.RecordRetrieveResponse> responses = kitty.recordRetrieveRequest(httpClient, "mbksync",
            "K:" + keyBagUUID);

    if (responses.size() != 1) {
        logger.warn("-- keyBag() - bad response list size: {}", responses);
        return Optional.empty();
    }//from ww w  . j a  v  a 2s  .  c o m

    CloudKit.ProtectionInfo protectionInfo = responses.get(0).getRecord().getProtectionInfo();

    Optional<ProtectionZone> optionalNewZone = zone.newProtectionZone(protectionInfo);
    if (!optionalNewZone.isPresent()) {
        logger.warn("-- keyBag() - failed to retrieve protection info");
        return Optional.empty();
    }
    ProtectionZone newZone = optionalNewZone.get();

    return keyBag(responses.get(0), newZone);
}