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

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

Introduction

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

Prototype

public static <T> Optional<T> absent() 

Source Link

Document

Returns an Optional instance with no contained reference.

Usage

From source file:si.arnes.dropbookmarks.auth.HelloAuthenticator.java

@Override
public Optional<User> authenticate(BasicCredentials credentials) throws AuthenticationException {
    if (password.equals(credentials.getPassword())) {
        return Optional.of(new User(0, credentials.getUsername(), credentials.getPassword()));
    }/*from   ww  w  . ja  v  a 2 s. co  m*/
    return Optional.absent();
}

From source file:org.opendaylight.controller.cluster.datastore.utils.MockConfiguration.java

@Override
public Optional<String> getModuleNameFromNameSpace(final String nameSpace) {
    return Optional.absent();
}

From source file:com.android.camera.data.SessionItem.java

/**
 * Creates a new session from the given URI.
 * @param context valid android application context.
 * @param uri the URI of the session.//ww w. j  a v a  2s  . c  om
 * @return If the session was found, a new SessionItem is returned.
 */
public static Optional<SessionItem> create(Context context, Uri uri) {
    if (!Storage.containsPlaceholderSize(uri)) {
        return Optional.absent();
    }
    Size dimension = getSessionSize(uri);
    if (dimension == null) {
        return Optional.absent();
    }
    return Optional.of(new SessionItem(context, uri, dimension));
}

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 ww . j a va 2s .c o  m*/
        } else {

            return Optional.absent();
        }
    }

    return Optional.absent();
}

From source file:bear.task.TaskResult.java

public static <T extends TaskResult<?>> Optional<T> okOrAbsent(@Nonnull Optional<T> result) {
    Preconditions.checkNotNull(result);/*  w w w.  j  a  v  a2 s. com*/

    if (!result.isPresent() || !result.get().ok())
        return Optional.absent();

    return result;
}

From source file:org.gradle.api.reporting.model.internal.BareStringNodeDescriptor.java

@Override
public Optional<String> value(ModelNode modelNode) {
    return Optional.absent();
}

From source file:net.pterodactylus.sonitus.io.FlacIdentifier.java

/**
 * Tries to identify the FLAC file contained in the given stream.
 *
 * @param inputStream/*from  ww  w . j a  va2s  . c om*/
 *       The input stream
 * @return The identified metadata, or {@link Optional#absent()} if the
 *         metadata can not be identified
 * @throws IOException
 *       if an I/O error occurs
 */
public static Optional<Metadata> identify(InputStream inputStream) throws IOException {
    Optional<Stream> stream = Stream.parse(inputStream);
    if (!stream.isPresent()) {
        return Optional.absent();
    }

    List<MetadataBlock> streamInfos = stream.get().metadataBlocks(STREAMINFO);
    if (streamInfos.isEmpty()) {
        /* FLAC file without STREAMINFO is invalid. */
        return Optional.absent();
    }

    MetadataBlock streamInfoBlock = streamInfos.get(0);
    StreamInfo streamInfo = (StreamInfo) streamInfoBlock.data();

    return Optional
            .of(new Metadata(new FormatMetadata(streamInfo.numberOfChannels(), streamInfo.sampleRate(), "FLAC"),
                    new ContentMetadata()));
}

From source file:org.opendaylight.controller.netconf.confignetconfconnector.mapping.attributes.mapping.EnumAttributeMappingStrategy.java

@Override
public Optional<String> mapAttribute(Object value) {
    if (value == null) {
        return Optional.absent();
    }// www.j a v a 2 s .c o  m

    String expectedClass = getOpenType().getTypeName();
    return Optional.of(enumResolver.toYang(expectedClass, value.toString()));
}

From source file:org.opendaylight.controller.config.util.capability.BasicCapability.java

@Override
public Optional<String> getModuleName() {
    return Optional.absent();
}

From source file:com.dangdang.ddframe.rdb.sharding.parser.jaxb.OptionalAdapter.java

@Override
public Optional<Integer> unmarshal(final String v) throws Exception {
    if (Strings.isNullOrEmpty(v)) {
        return Optional.absent();
    }/*from  w w w  . j a v  a 2 s. c  o m*/
    return Optional.of(Integer.valueOf(v));
}