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:Main.java

/** Given a parent element, locate string value of a child node.
 *  @param parent Parent element//from w  ww  . j  ava2s.  co  m
 *  @param name Name of child element
 *  @return Value of child element, or empty result
 */
public static Optional<String> getChildString(final Element parent, final String name) {
    final Element child = getChildElement(parent, name);
    if (child != null)
        return Optional.of(getString(child));
    else
        return Optional.empty();
}

From source file:com.teradata.tempto.fulfillment.table.DatabaseSelectionContext.java

public static DatabaseSelectionContext forDatabaseName(String databaseName) {
    return new DatabaseSelectionContext(Optional.of(databaseName), Optional.empty());
}

From source file:org.zalando.riptide.Conditions.java

public static <A> UntypedCondition<A> on(final A attribute) {
    return new UntypedCondition<>(Optional.of(attribute));
}

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

public static Optional<IndexRecord> readRecord(final byte[] indexTable, final int offset) {
    if (offset >= indexTable.length) {
        return Optional.empty();
    } else {/*from  ww  w  .  ja v  a  2 s  .c  om*/
        return Optional.of(parse(indexTable, offset));
    }
}

From source file:Main.java

/** Given a parent element, locate double value of a child node.
 *  @param parent Parent element/*from   w w w. ja  va  2s. co  m*/
 *  @param name Name of child element
 *  @return Value of child element, or empty result
 *  @throws Exception on error parsing the number
 */
public static Optional<Double> getChildDouble(final Element parent, final String name) throws Exception {
    final Element child = getChildElement(parent, name);
    if (child == null)
        return Optional.empty();
    try {
        return Optional.of(Double.valueOf(getString(child)));
    } catch (NumberFormatException ex) {
        throw new Exception("Expected double for <" + name + ">", ex);
    }
}

From source file:Main.java

/** Given a parent element, locate integer value of a child node.
 *  @param parent Parent element/*from   w w w. j a v a  2 s  . co  m*/
 *  @param name Name of child element
 *  @return Value of child element, or empty result
 *  @throws Exception on error parsing the number
 */
public static Optional<Integer> getChildInteger(final Element parent, final String name) throws Exception {
    final Element child = getChildElement(parent, name);
    if (child == null)
        return Optional.empty();
    try {
        return Optional.of(Integer.valueOf(getString(child)));
    } catch (NumberFormatException ex) {
        throw new Exception("Expected integer for <" + name + ">", ex);
    }
}

From source file:com.thoughtworks.go.config.rules.DirectiveType.java

public static Optional<DirectiveType> fromString(String directive) {
    if (StringUtils.isBlank(directive)) {
        return Optional.empty();
    }//  w  ww . ja  v  a 2s. com

    switch (directive) {
    case "allow":
        return Optional.of(ALLOW);
    case "deny":
        return Optional.of(DENY);
    default:
        return Optional.empty();
    }
}

From source file:com.synopsys.integration.blackduck.service.model.BlackDuckQuery.java

public static Optional<BlackDuckQuery> createQuery(final String parameter) {
    if (StringUtils.isNotBlank(parameter)) {
        return Optional.of(new BlackDuckQuery(parameter));
    }/*www .  java 2s .c om*/

    return Optional.empty();
}

From source file:com.liferay.blade.cli.util.Prompter.java

public static boolean confirm(String question, boolean defaultAnswer) {
    return confirm(question, System.in, System.out, Optional.of(defaultAnswer));
}

From source file:com.teradata.tempto.internal.convention.TableName.java

public static TableName parse(String value) {
    if (value.contains(".")) {
        List<String> parts = Splitter.on('.').splitToList(value);
        checkState(parts.size() == 2,/*from   w ww  .  ja v a  2 s .c  o  m*/
                "Invalid table name syntax. Expected at most one occurrence of '.' in '%s'.", value);
        return new TableName(parts.get(1), Optional.of(parts.get(0)));
    } else {
        return new TableName(value, Optional.empty());
    }
}