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

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

Introduction

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

Prototype

public static <T> Optional<T> fromNullable(@Nullable T nullableReference) 

Source Link

Document

If nullableReference is non-null, returns an Optional instance containing that reference; otherwise returns Optional#absent .

Usage

From source file:com.facebook.swift.parser.model.IntegerEnumField.java

public IntegerEnumField(String name, Long value) {
    this.name = checkNotNull(name, "name");
    this.value = Optional.fromNullable(value);
}

From source file:org.robotninjas.concurrent.ConsumerDecorator.java

private ConsumerDecorator(Consumer<V> success, Consumer<Throwable> failure) {
    this.success = Optional.fromNullable(success);
    this.failure = Optional.fromNullable(failure);
}

From source file:com.github.fge.grappa.support.Chars.java

public static String escape(char c) {
    return Optional.fromNullable(ESCAPE_MAP.get(c)).or(String.valueOf(c));
}

From source file:org.opendaylight.yangtools.yang.model.repo.api.YangTextSchemaSource.java

public static SourceIdentifier identifierFromFilename(final String name) {
    checkArgument(name.endsWith(YangConstants.RFC6020_YANG_FILE_EXTENSION),
            "Filename %s does not have a .yang extension", name);

    final String baseName = name.substring(0,
            name.length() - YangConstants.RFC6020_YANG_FILE_EXTENSION.length());
    final Entry<String, String> parsed = YangNames.parseFilename(baseName);
    return RevisionSourceIdentifier.create(parsed.getKey(), Optional.fromNullable(parsed.getValue()));
}

From source file:org.opendaylight.netconf.cli.SchemaContextRegistry.java

public synchronized Optional<SchemaContext> getRemoteSchemaContext() {
    return Optional.fromNullable(remoteSchemaContext);
}

From source file:org.raml.jaxrs.model.HttpVerb.java

/**
 * Returns the corresponding http verb.//from  w  ww  . j av  a 2 s .  co m
 *
 * Verbs are associated with their {@link #getString()} value. Therefore, the matching is case sensitive.
 *
 * @param httpMethod the method to pair
 * @return The corresponding http verb, or {@link Optional#absent()} if there are no matches.
 */
public static Optional<HttpVerb> fromString(String httpMethod) {
    return Optional.fromNullable(VERBS_BY_STRINGS.get(httpMethod));
}

From source file:google.registry.tldconfig.idn.IdnLabelValidator.java

/**
 * Returns name of first matching {@link IdnTable} if domain label is valid for the given TLD.
 *
 * <p>A label is valid if it is considered valid by at least one configured IDN table for that
 * TLD. If no match is found, an absent value is returned.
 *///  w w w. ja  va  2 s .com
public static Optional<String> findValidIdnTableForTld(String label, String tld) {
    String unicodeString = Idn.toUnicode(label);
    for (IdnTableEnum idnTable : Optional.fromNullable(idnTableListsPerTld.get(tld)).or(DEFAULT_IDN_TABLES)) {
        if (idnTable.getTable().isValidLabel(unicodeString)) {
            return Optional.of(idnTable.getTable().getName());
        }
    }
    return Optional.absent();
}

From source file:io.macgyver.ssh.PubKeyCredentials.java

public PubKeyCredentials(String username, File pkf) {
    this.username = username;
    this.privateKey = Optional.fromNullable(pkf);
}

From source file:com.facebook.swift.parser.model.ContainerType.java

public ContainerType(String cppType, List<TypeAnnotation> annotations) {
    this.cppType = Optional.fromNullable(cppType);
    this.annotations = ImmutableList.copyOf(checkNotNull(annotations, "annotations"));
}

From source file:org.mayocat.jackson.OptionalStringDeserializer.java

@Override
public Optional<String> deserialize(JsonParser jsonParser, DeserializationContext deserializationContext)
        throws IOException, JsonProcessingException {
    if (Strings.isNullOrEmpty(jsonParser.getValueAsString())) {
        return Optional.absent();
    }/*from w  w w .j a  va2s . c  o m*/
    return Optional.fromNullable(jsonParser.getValueAsString());
}