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:si.arnes.dropbookmarks.db.UserDAO.java

public Optional<User> findByUsernamePassword(String username, String password) {
    return Optional
            .fromNullable(uniqueResult(namedQuery("si.arnes.dropbookmarks.core.User.findByUsernamePassword")
                    .setParameter("username", username).setParameter("password", password)));
}

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

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

From source file:controllers.HelloInstanceController.java

public void hello(String name) {
    getResponse().bind("greeting", "Hello " + Optional.fromNullable(name).or("World")).render("hello");
}

From source file:org.opendaylight.yangtools.yang.data.api.schema.tree.spi.MaterializedMutableContainerNode.java

@Override
public Optional<TreeNode> getChild(final PathArgument child) {
    return Optional.fromNullable(getModifiedChild(child));
}

From source file:extrabiomes.module.amica.ic2.IC2API.java

IC2API() {
    Class cls;//w  ww  .  ja v  a2  s .co m
    try {
        cls = Class.forName("ic2.api.crops.Crops");
        ic2CropsInstance = cls.getField("instance").get(null);
        addBiomeBonus = Optional
                .fromNullable(cls.getMethod("addBiomeBonus", BiomeGenBase.class, Integer.TYPE, Integer.TYPE));
    } catch (final Exception e) {
        e.printStackTrace();
        addBiomeBonus = Optional.absent();
    }
}

From source file:si.klepra.dropwizardbookmarks.db.UserDAO.java

public Optional<User> findByUsernamePassword(String username, String password) {
    return Optional.fromNullable(
            uniqueResult(namedQuery("si.klepra.dropwizardbookmarks.core.User.findByUsernamePassword")
                    .setParameter("username", username).setParameter("password", password)));
}

From source file:org.zalando.stups.oauth2.spring.client.AccessTokenUtils.java

public static Optional<String> getAccessTokenFromSecurityContext() {
    SecurityContext securityContext = SecurityContextHolder.getContext();

    Authentication authentication = securityContext.getAuthentication();
    if (authentication instanceof OAuth2Authentication) {
        Object userDetails = ((OAuth2Authentication) authentication).getUserAuthentication().getDetails();
        if (userDetails != null) {
            try {
                final Map details = (Map) userDetails;
                return Optional.fromNullable((String) details.get(ACCESS_TOKEN));
            } catch (ClassCastException e) {

                return Optional.absent();
            }/*from w w  w . ja  va 2s  .c  o m*/
        } else {

            return Optional.absent();
        }
    }

    return Optional.absent();
}

From source file:org.locationtech.geogig.web.SingleRepositoryProvider.java

@Override
public Optional<GeoGIG> getGeogig(Request request) {
    return Optional.fromNullable(geogig);
}

From source file:org.eclipse.recommenders.utils.rcp.UUIDHelper.java

private static Optional<String> lookupUUIDFromStore() {
    final RecommendersUtilsPlugin plugin = RecommendersUtilsPlugin.getDefault();
    final IPreferenceStore prefStore = plugin.getPreferenceStore();
    final String uuid = prefStore.getString(PreferencesInitalizer.PROP_UUID);
    if (Strings.isNullOrEmpty(uuid)) {
        return Optional.absent();
    }/*from   ww  w. ja  v a2  s .  co m*/
    return Optional.fromNullable(uuid);
}

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

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