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:dagger2.internal.codegen.writer.WildcardName.java

static WildcardName forTypeMirror(WildcardType mirror) {
    return new WildcardName(Optional.fromNullable(mirror.getExtendsBound()).transform(FOR_TYPE_MIRROR),
            Optional.fromNullable(mirror.getSuperBound()).transform(FOR_TYPE_MIRROR));
}

From source file:org.locationtech.geogig.api.plumbing.diff.AttributeDiffFactory.java

public static AttributeDiff attributeDiffFromText(Class<?> clazz, String s) {

    String[] tokens = s.split("\t");
    AttributeDiff ad;//from w ww  .  ja v a 2 s  . co m
    if (Geometry.class.isAssignableFrom(clazz)) {
        ad = new GeometryAttributeDiff(s);
    } else {
        if (AttributeDiff.TYPE.REMOVED.name().startsWith(tokens[0])) {
            Preconditions.checkArgument(tokens.length == 2, "Wrong difference definition:", s);
            Object oldValue = TextValueSerializer.fromString(FieldType.forBinding(clazz), tokens[1]);
            ad = new GenericAttributeDiffImpl(Optional.fromNullable(oldValue), null);
        } else if (AttributeDiff.TYPE.ADDED.name().startsWith(tokens[0])) {
            Preconditions.checkArgument(tokens.length == 2, "Wrong difference definition:", s);
            Object newValue = TextValueSerializer.fromString(FieldType.forBinding(clazz), tokens[1]);
            ad = new GenericAttributeDiffImpl(null, Optional.fromNullable(newValue));
        } else if (AttributeDiff.TYPE.MODIFIED.name().startsWith(tokens[0])) {
            Preconditions.checkArgument(tokens.length == 3, "Wrong difference definition:", s);
            Object oldValue = TextValueSerializer.fromString(FieldType.forBinding(clazz), tokens[1]);
            Object newValue = TextValueSerializer.fromString(FieldType.forBinding(clazz), tokens[2]);
            ad = new GenericAttributeDiffImpl(Optional.fromNullable(oldValue), Optional.fromNullable(newValue));
        } else {
            throw new IllegalArgumentException("Wrong difference definition:" + s);
        }
    }
    return ad;

}

From source file:com.jythonui.server.RUtils.java

private static Optional<Date> retrieveD(Object o, String propName) {
    Date d = null;//from  ww w . ja va2 s . c  o m
    try {
        d = (Date) PropertyUtils.getProperty(o, propName);
    } catch (IllegalAccessException | InvocationTargetException | NoSuchMethodException e) {
        return null;
    }
    return Optional.fromNullable(d);
}

From source file:ninja.leaping.permissionsex.backend.DataStoreFactories.java

public static Optional<DataStoreFactory> get(String type) {
    return Optional.fromNullable(REGISTRY.get(type));
}

From source file:com.google.cloud.trace.jdbc.ThreadLocalTracerStore.java

/** Returns the current thread's {@link Tracer}. */
public static Optional<Tracer> getCurrent() {
    return Optional.fromNullable(perThreadTracer.get());
}

From source file:com.qcadoo.commons.functional.FluentOptional.java

public static <V> FluentOptional<V> fromNullable(final V valueOrNull) {
    return new FluentOptional<V>(Optional.fromNullable(valueOrNull));
}

From source file:org.locationtech.geogig.api.RevFeatureBuilder.java

/**
 * Constructs a new {@link RevFeature} from the provided {@link Feature}.
 * /*from  www . j  a va  2 s  .c  o  m*/
 * @param feature the feature to build from
 * @return the newly constructed RevFeature
 */
public static RevFeature build(Feature feature) {
    if (feature == null) {
        throw new IllegalStateException("No feature set");
    }

    Collection<Property> props = feature.getProperties();

    ImmutableList.Builder<Optional<Object>> valuesBuilder = new ImmutableList.Builder<Optional<Object>>();

    for (Property prop : props) {
        valuesBuilder.add(Optional.fromNullable(prop.getValue()));
    }

    return RevFeatureImpl.build(valuesBuilder.build());
}

From source file:com.qcadoo.commons.functional.Optionals.java

public static <F> Function<F, Optional<F>> lift() {
    return new Function<F, Optional<F>>() {

        @Override/*  w  w w.  java2 s. co m*/
        public Optional<F> apply(final F input) {
            return Optional.fromNullable(input);
        }
    };
}

From source file:org.parboiled.support.Chars.java

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

From source file:google.registry.tools.server.ToolsServerModule.java

@Provides
@Parameter("clientId")
static Optional<String> provideClientId(HttpServletRequest req) {
    return Optional.fromNullable(emptyToNull(req.getParameter(CreateGroupsAction.CLIENT_ID_PARAM)));
}