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:org.eclipse.emf.ecoretools.design.service.DiagnosticAttachment.java

public static Optional<Diagnostic> get(EObject cur) {
    DiagnosticAttachment found = getAttachment(cur);
    if (found != null) {
        return Optional.fromNullable(found.getDiagnostic());
    }//www.  j  a  v  a 2  s .c  om
    return Optional.absent();
}

From source file:google.registry.keyring.api.KeyModule.java

@Provides
@Key("marksdbDnlLogin")
static Optional<String> provideMarksdbDnlLogin(Keyring keyring) {
    return Optional.fromNullable(emptyToNull(keyring.getMarksdbDnlLogin()));
}

From source file:nextmethod.threading.OperationCanceledException.java

public OperationCanceledException(final CancellationToken token) {
    this();
    this.token = Optional.fromNullable(token);
}

From source file:org.spongepowered.api.entity.living.meta.RabbitTypes.java

public static Optional<RabbitType> getTypeFromString(String name) {
    return Optional.fromNullable(null);
}

From source file:me.taylorkelly.mywarp.util.IterableUtils.java

/**
 * Returns an Optional containing the first element in iterable or {@code Optional.absend()} if the iterable is
 * empty./*from   w w w . ja  va 2 s  . c o m*/
 *
 * @param <T>      the type of entries
 * @param iterable the iterable to check
 * @return the first element
 */
public static <T> Optional<T> getFirst(Iterable<T> iterable) {
    T first = Iterables.getFirst(iterable, null);
    return Optional.fromNullable(first);
}

From source file:com.infobip.jira.Version.java

@JsonCreator
public static Version of(@JsonProperty("name") String name, @JsonProperty("released") Boolean released,
        @JsonProperty("releaseDate") String releaseDate, @JsonProperty("id") Integer id) {

    return new Version(name, Optional.<ProjectKey>absent(), released, releaseDate, Optional.fromNullable(id));
}

From source file:ezbake.thrift.authentication.PeerSharedData.java

public static void setPeerPrincipal(String dn) {
    try {//from   www .j a v a2  s .com
        peerPrincipal.set(Optional.fromNullable(new LdapName(dn)));
    } catch (InvalidNameException e) {
        logger.warn("Unable to parse peer DN. PeerPrincipal will be unavailable");
    }
}

From source file:info.archinnov.achilles.type.Options.java

public Optional<Integer> getTtl() {
    return Optional.fromNullable(ttl);
}

From source file:springfox.documentation.builders.BuilderDefaults.java

/**
 * Returns this default value if the new value is null
 *
 * @param newValue     - new value//from  w w  w .j av a 2 s.  co  m
 * @param defaultValue - default value
 * @param <T>          - Represents any type that is nullable
 * @return Coalesces the newValue and defaultValue to return a non-null value
 */
public static <T> T defaultIfAbsent(T newValue, T defaultValue) {
    return Optional.fromNullable(newValue).or(Optional.fromNullable(defaultValue)).orNull();
}

From source file:com.googlecode.blaisemath.style.ImmutableAttributeSet.java

/**
 * Makes an immutable copy of the provided attribute set.
 * @param set the set to copy// w  w  w .j  av a  2  s  . co  m
 * @return an immutable copy
 */
static ImmutableAttributeSet immutableCopyOf(AttributeSet set) {
    ImmutableAttributeSet res = new ImmutableAttributeSet();
    res.parent = Optional.fromNullable(set.getParent());
    res.attributeMap.putAll(set.attributeMap);
    return res;
}