Example usage for java.util Optional of

List of usage examples for java.util Optional of

Introduction

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

Prototype

public static <T> Optional<T> of(T value) 

Source Link

Document

Returns an Optional describing the given non- null value.

Usage

From source file:com.thinkbiganalytics.metadata.modeshape.common.JcrPropertiesEntity.java

public Optional<JcrProperties> ensurePropertiesObject() {
    try {// w w w.  j  av a 2s . c om
        return Optional.of(JcrUtil.getOrCreateNode(this.node, PROPERTIES_NAME, JcrProperties.NODE_TYPE,
                JcrProperties.class));
    } catch (AccessControlException e) {
        return Optional.empty();
    }
}

From source file:org.trustedanalytics.hadoop.admin.tools.HadoopClientParamsImporter.java

static Optional<InputStream> getSourceInputStream(CLIParameters params) throws IOException {
    Optional<InputStream> res = Optional.of(System.in);
    if (params.getClientConfigUrl() != null) {
        res = Optional.of(new URL(params.getClientConfigUrl()).openStream());
    }/*w  w  w  .j a  va2  s. co m*/
    return res;
}

From source file:org.onosproject.segmentrouting.config.SegmentRoutingDeviceConfig.java

/**
 * Gets the name of the router.//from   ww w . j a  va  2s  .c  o  m
 *
 * @return Optional name of the router. May be empty if not configured.
 */
public Optional<String> name() {
    String name = get(NAME, null);
    return name != null ? Optional.of(name) : Optional.empty();
}

From source file:com.ikanow.aleph2.storm.samples.topology.JavaScriptTopology.java

@Override
public Tuple2<Object, Map<String, String>> getTopologyAndConfiguration(DataBucketBean bucket,
        IEnrichmentModuleContext context) {
    TopologyBuilder builder = new TopologyBuilder();
    String contextSignature = context.getEnrichmentContextSignature(Optional.of(bucket), Optional.empty());

    final Collection<Tuple2<BaseRichSpout, String>> entry_points = context
            .getTopologyEntryPoints(BaseRichSpout.class, Optional.of(bucket));
    entry_points.forEach(spout_name -> builder.setSpout(spout_name._2(), spout_name._1()));
    entry_points.stream().reduce(//from w w  w.  j a va  2 s .  c om
            builder.setBolt("scriptBolt",
                    new JavaScriptBolt(contextSignature,
                            "/com/ikanow/aleph2/storm/samples/script/js/scripts.properties")),
            (acc, v) -> acc.shuffleGrouping(v._2()), (acc1, acc2) -> acc1 // (not possible in practice)
    );
    builder.setBolt("reducerCounter", new ReducerCounterBolt()).shuffleGrouping("scriptBolt");
    builder.setBolt("out", context.getTopologyStorageEndpoint(BaseRichBolt.class, Optional.of(bucket)))
            .localOrShuffleGrouping("reducerCounter");
    return new Tuple2<Object, Map<String, String>>(builder.createTopology(), new HashMap<String, String>());
}

From source file:org.ulyssis.ipp.snapshot.Event.java

@JsonIgnore
public final Optional<Long> getId() {
    if (id != -1)
        return Optional.of(id);
    else//from w  ww  .  j  a v  a 2s. c om
        return Optional.empty();
}

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

/**
 * Get {@link FormJSONField} from {@link FormJSONSection}.
 * @param section {@link FormJSONSection}
 * @param index int/*from   w ww .  j  av  a  2s. c o  m*/
 * @return {@link Optional} of {@link FormJSONSection}
 */
public static Optional<FormJSONField> findField(final FormJSONSection section, final int index) {
    try {
        return section != null ? Optional.of(section.getFields().get(index)) : Optional.empty();
    } catch (IndexOutOfBoundsException e) {
        return Optional.empty();
    }
}

From source file:org.trustedanalytics.cloud.cc.api.manageusers.CcOrgUser.java

@JsonIgnore
public List<Role> getRoles() {
    Optional<CcOrgUser> user = Optional.of(this);
    return Stream.of(user).filter(Optional::isPresent).map(Optional::get).map(CcOrgUser::getEntity)
            .filter(e -> e.getRoles() != null).flatMap(e -> e.getRoles().stream()).map(Role::getRoleByName)
            .collect(toList());//from   w  w  w.j av  a2  s .  c o  m
}

From source file:com.devicehive.dao.rdbms.NetworkDaoRdbmsImpl.java

@Override
public List<NetworkWithUsersAndDevicesVO> getNetworksByIdsAndUsers(Long idForFiltering, Set<Long> networkId,
        Set<Long> permittedNetworks) {
    TypedQuery<Network> query = createNamedQuery(Network.class, "Network.getNetworksByIdsAndUsers",
            Optional.of(CacheConfig.bypass())).setParameter("userId", idForFiltering)
                    .setParameter("networkIds", networkId).setParameter("permittedNetworks", permittedNetworks);
    List<Network> result = query.getResultList();
    Stream<NetworkWithUsersAndDevicesVO> objectStream = result.stream()
            .map(Network::convertWithDevicesAndUsers);
    return objectStream.collect(Collectors.toList());
}

From source file:org.cloudfoundry.metron.MetronMetricWriter.java

@Override
public void onOpen(Session session, EndpointConfig config) {
    this.session.set(Optional.of(session));
}

From source file:com.blackducksoftware.integration.hub.detect.detector.npm.NpmLockfileExtractor.java

public Extraction extract(final File directory, final File lockfile, final Optional<File> packageJson) {
    try {/* www  .  j a v  a2  s.  co  m*/
        final boolean includeDev = detectConfiguration
                .getBooleanProperty(DetectProperty.DETECT_NPM_INCLUDE_DEV_DEPENDENCIES, PropertyAuthority.None);

        String lockText = FileUtils.readFileToString(lockfile, StandardCharsets.UTF_8);
        Optional<String> packageText = Optional.empty();
        if (packageJson.isPresent()) {
            packageText = Optional.of(FileUtils.readFileToString(packageJson.get(), StandardCharsets.UTF_8));
        }

        final NpmParseResult result = npmLockfileParser.parse(directory.getCanonicalPath(), packageText,
                lockText, includeDev);

        return new Extraction.Builder().success(result.codeLocation).projectName(result.projectName)
                .projectVersion(result.projectVersion).build();

    } catch (final IOException e) {
        return new Extraction.Builder().exception(e).build();
    }
}