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:com.voxelplugineering.voxelsniper.service.persistence.JsonDataSourceReader.java

/**
 * A {@link DataSourceBuilder} for json data sources.
 *//*from ww  w .  j a  va 2 s .  c  o m*/
public static final DataSourceBuilder<JsonDataSourceReader> getBuilder(final DataSourceFactory factory) {
    return new DataSourceBuilder<JsonDataSourceReader>() {

        @Override
        public Optional<JsonDataSourceReader> build(DataContainer args) {
            if (!args.containsKey("source") || !args.containsKey("sourceArgs")) {
                GunsmithLogger.getLogger().warn("Failed to build JsonDataSourceReader, invalid args");
                return Optional.absent();
            }
            String sourceName = args.getString("source").get();
            Optional<DataSource> source = factory.build(sourceName, args.getContainer("sourceArgs").get());
            if (!source.isPresent()) {
                GunsmithLogger.getLogger().warn("Failed to build data source for JsonDataSourceReader");
                return Optional.absent();
            }
            if (!StreamDataSource.class.isAssignableFrom(source.get().getClass())) {
                GunsmithLogger.getLogger()
                        .warn("Failed to build JsonDataSourceReader: Source was not a StreamDataSource");
                return Optional.absent();
            }
            StreamDataSource stream = (StreamDataSource) source.get();
            return Optional.of(new JsonDataSourceReader(stream));
        }

    };
}

From source file:dagger2.internal.codegen.Binding.java

static Optional<String> bindingPackageFor(Iterable<? extends Binding> bindings) {
    ImmutableSet.Builder<String> bindingPackagesBuilder = ImmutableSet.builder();
    for (Binding binding : bindings) {
        bindingPackagesBuilder.addAll(binding.bindingPackage().asSet());
    }//from   w  w w . j  a va2s  . c  om
    ImmutableSet<String> bindingPackages = bindingPackagesBuilder.build();
    switch (bindingPackages.size()) {
    case 0:
        return Optional.absent();
    case 1:
        return Optional.of(bindingPackages.iterator().next());
    default:
        throw new IllegalArgumentException();
    }
}

From source file:org.anhonesteffort.flock.registration.model.FlockCardInformation.java

public static Optional<FlockCardInformation> build(Bundle bundledCardInformation) {
    if (bundledCardInformation == null || bundledCardInformation.getString(KEY_ACCOUNT_ID) == null)
        return Optional.absent();

    return Optional.of(new FlockCardInformation(bundledCardInformation.getString(KEY_ACCOUNT_ID),
            bundledCardInformation.getString(KEY_LAST_FOUR), bundledCardInformation.getString(KEY_EXPIRATION)));
}

From source file:dattln.auth.LdapAuthenticator.java

public Optional<User> authenticate(BasicCredentials basicCredentials) throws AuthenticationException {
    if (delegatingAuthenticator.authenticate(basicCredentials)) {
        return Optional.of(new User(basicCredentials.getUsername()));
    }/*from  w  w  w. ja v  a 2 s  .co m*/
    return Optional.absent();
}

From source file:net.diogobohm.timed.api.ui.domain.TaskList.java

public Optional<Task> getLastOpenTask() {
    Task lastTask = taskList.getLast();//from  w w w . j  a v  a2 s.  c  om

    if (lastTask.getFinish().isPresent()) {
        return Optional.absent();
    }

    return Optional.of(lastTask);
}

From source file:org.locationtech.geogig.osm.internal.log.ReadOSMFilterFile.java

@Override
protected Optional<String> _call() {
    Preconditions.checkNotNull(entry);/*from www .  java  2  s . c  om*/
    URL url = command(ResolveOSMLogfile.class).call();
    File logfile = new File(url.getFile());
    File file = new File(logfile.getParentFile(), "filter" + entry.getId().toString());
    if (!file.exists()) {
        return Optional.absent();
    }
    try {
        List<String> lines = Files.readLines(file, Charsets.UTF_8);
        String line = Joiner.on("\n").join(lines);
        return Optional.of(line);
    } catch (IOException e) {
        throw Throwables.propagate(e);
    }
}

From source file:com.facebook.buck.cxx.AbstractCxxHeadersDir.java

@Override
public Optional<SourcePath> getHeaderMap() {
    return Optional.absent();
}

From source file:eu.cloudwave.wp5.feedback.eclipse.base.infrastructure.config.ConfigLoaderImpl.java

/**
 * {@inheritDoc}/*from  w w w .  j a v a  2  s  .c  o  m*/
 */
@Override
public Optional<String> get(final String path, final String key) {
    final Properties properties = new Properties();
    final InputStream fileInputStream = getClass().getClassLoader().getResourceAsStream(path);
    try {
        properties.load(fileInputStream);
    } catch (final IOException e) {
        return Optional.absent();
    }
    return Optional.fromNullable(properties.getProperty(key));
}

From source file:org.locationtech.geogig.osm.internal.log.ReadOSMMapping.java

@Override
protected Optional<Mapping> _call() {
    Preconditions.checkNotNull(entry);//from   w ww.  java2  s  .  c  o m
    final File osmMapFolder = command(ResolveOSMMappingLogFolder.class).call();
    File file = new File(osmMapFolder, entry.getPostMappingId().toString());
    if (!file.exists()) {
        return Optional.absent();
    }
    try {
        List<String> lines = Files.readLines(file, Charsets.UTF_8);
        String s = Joiner.on("\n").join(lines);
        Mapping mapping = Mapping.fromString(s);
        return Optional.of(mapping);
    } catch (IOException e) {
        throw Throwables.propagate(e);
    }
}

From source file:org.jclouds.digitalocean2.handlers.DigitalOcean2RateLimitRetryHandler.java

@Override
protected Optional<Long> millisToNextAvailableRequest(HttpCommand command, HttpResponse response) {
    // The header is the Unix epoch time when the next request can be done
    String epochForNextAvailableRequest = response.getFirstHeaderOrNull("RateLimit-Reset");
    if (epochForNextAvailableRequest == null) {
        return Optional.absent();
    }//  w  w w. j  a  v  a2 s  .  c o  m
    return Optional.of(millisUntilNextAvailableRequest(Long.parseLong(epochForNextAvailableRequest)));
}