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:org.gradle.plugins.ide.internal.IdePlugin.java

/**
 * Returns the path to the correct Gradle distribution to use. The wrapper of the generating project will be used only if the execution context of the currently running Gradle is in the Gradle home (typical of a wrapper execution context). If this isn't the case, we try to use the current Gradle home, if available, as the distribution. Finally, if nothing matches, we default to the system-wide Gradle distribution.
 *
 * @param project the Gradle project generating the IDE files
 * @return path to Gradle distribution to use within the generated IDE files
 *///from w w  w  .ja  va2 s  .c o  m
public static String toGradleCommand(Project project) {
    Gradle gradle = project.getGradle();
    Optional<String> gradleWrapperPath = Optional.absent();

    Project rootProject = project.getRootProject();
    String gradlewExtension = OperatingSystem.current().isWindows() ? ".bat" : "";
    File gradlewFile = rootProject.file("gradlew" + gradlewExtension);
    if (gradlewFile.exists()) {
        gradleWrapperPath = Optional.of(gradlewFile.getAbsolutePath());
    }

    if (gradle.getGradleHomeDir() != null) {
        if (gradleWrapperPath.isPresent() && gradle.getGradleHomeDir().getAbsolutePath()
                .startsWith(gradle.getGradleUserHomeDir().getAbsolutePath())) {
            return gradleWrapperPath.get();
        }
        return gradle.getGradleHomeDir().getAbsolutePath() + "/bin/gradle";
    }

    return gradleWrapperPath.or("gradle");
}

From source file:org.mayocat.shop.payment.store.jdbi.DBIGatewayDataStore.java

@Override
public Optional<GatewayCustomerData> getCustomerData(Customer customer, String gatewayId) {
    GatewayCustomerData result = dao.getCustomerData(customer.getId(), gatewayId);
    if (result == null) {
        return Optional.absent();
    }//from  w w  w.  ja  v  a  2 s .  c om
    return Optional.of(result);
}

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

@Override
public Optional<ActorSelection> findPrimaryShard(String shardName) {
    return Optional.absent();
}

From source file:org.geogit.remote.RemoteUtils.java

/**
 * Constructs an interface to allow access to a remote repository.
 * /* w w  w .  j  av a  2 s.c  om*/
 * @param injector a Guice injector for the new repository
 * @param remoteConfig the remote to connect to
 * @param localRepository the local repository
 * @return an {@link Optional} of the interface to the remote repository, or
 *         {@link Optional#absent()} if a connection to the remote could not be established.
 */
public static Optional<IRemoteRepo> newRemote(Injector injector, Remote remoteConfig,
        Repository localRepository, DeduplicationService deduplicationService) {

    try {
        URI fetchURI = URI.create(remoteConfig.getFetchURL());
        String protocol = fetchURI.getScheme();

        IRemoteRepo remoteRepo = null;
        if (protocol == null || protocol.equals("file")) {
            String filepath = new URL(remoteConfig.getFetchURL()).getFile();
            if (remoteConfig.getMapped()) {
                remoteRepo = new LocalMappedRemoteRepo(injector, new File(filepath), localRepository);
            } else {
                remoteRepo = new LocalRemoteRepo(injector, new File(filepath), localRepository);
            }
        } else if (protocol.equals("http")) {
            if (remoteConfig.getMapped()) {
                remoteRepo = new HttpMappedRemoteRepo(fetchURI.toURL(), localRepository);
            } else {
                remoteRepo = new HttpRemoteRepo(fetchURI.toURL(), localRepository, deduplicationService);
            }
        } else {
            throw new UnsupportedOperationException("Only file and http remotes are currently supported.");
        }
        return Optional.fromNullable(remoteRepo);
    } catch (Exception e) {
        // Invalid fetch URL
        Throwables.propagate(e);
    }

    return Optional.absent();
}

From source file:dagger2.internal.codegen.writer.TypeWriter.java

TypeWriter(ClassName name) {
    this.name = name;
    this.supertype = Optional.absent();
    this.implementedTypes = Lists.newArrayList();
    this.methodWriters = Lists.newArrayList();
    this.nestedTypeWriters = Lists.newArrayList();
    this.fieldWriters = Maps.newLinkedHashMap();
}

From source file:edu.sdsc.scigraph.services.jersey.writers.XgmmlWriter.java

static Optional<String> getLabel(Vertex vertex) {
    Optional<String> label = Optional.absent();
    if (vertex.getPropertyKeys().contains(NodeProperties.LABEL)) {
        Object value = vertex.getProperty(NodeProperties.LABEL);
        if (value.getClass().isArray()) {
            label = Optional.of((String) Array.get(value, 0));
        } else if (value instanceof Iterable) {
            label = Optional.of((String) Iterables.getFirst((Iterable<?>) value, null));
        } else {//from  www .j a  va2s .c om
            label = Optional.of((String) value);
        }
    }
    return label;
}

From source file:org.locationtech.geogig.api.plumbing.ResolveBranchId.java

@Override
protected Optional<Ref> _call() {
    Preconditions.checkState(id != null, "id has not been set.");
    Predicate<Ref> filter = new Predicate<Ref>() {
        @Override/*w ww  . j  a  v a2 s .  co m*/
        public boolean apply(@Nullable Ref ref) {
            return ref.getObjectId().equals(id);
        }
    };
    ImmutableSet<Ref> refs = command(ForEachRef.class).setFilter(filter).call();
    if (refs.isEmpty()) {
        return Optional.absent();
    } else {
        return Optional.of(refs.iterator().next());
    }
}

From source file:com.facebook.buck.java.JavaBuckConfig.java

public JavaCompilerEnvironment getJavaCompilerEnvironment(ProcessExecutor processExecutor) {
    Optional<Path> javac = getJavac();
    Optional<JavacVersion> javacVersion = Optional.absent();
    if (javac.isPresent()) {
        javacVersion = Optional.of(getJavacVersion(processExecutor, javac.get()));
    }// w ww  . j  a v  a 2s  . co m
    Optional<String> sourceLevel = delegate.getValue("java", "source_level");
    Optional<String> targetLevel = delegate.getValue("java", "target_level");
    return new JavaCompilerEnvironment(javac, javacVersion, sourceLevel.or(TARGETED_JAVA_VERSION),
            targetLevel.or(TARGETED_JAVA_VERSION));
}

From source file:org.geogit.geotools.plumbing.ListOp.java

/**
 * Executes the list operation on the provided data store.
 * //from   w ww .j a  v  a 2 s . c om
 * @return a list of all tables, or Optional.absent() if none were found
 */
@Override
public Optional<List<String>> call() {
    if (dataStore == null) {
        throw new GeoToolsOpException(StatusCode.DATASTORE_NOT_DEFINED);
    }

    List<String> features = new ArrayList<String>();

    boolean foundTable = false;

    List<Name> typeNames;
    try {
        typeNames = dataStore.getNames();
    } catch (Exception e) {
        throw new GeoToolsOpException(StatusCode.UNABLE_TO_GET_NAMES);
    }

    for (Name typeName : typeNames) {
        foundTable = true;

        features.add(typeName.toString());
    }

    if (!foundTable) {
        return Optional.absent();
    }
    return Optional.of(features);
}

From source file:flipkart.mongo.replicator.core.model.ReplicaSetConfig.java

public Optional<Node> getMasterNode() {
    for (Node node : nodes) {
        if (node.getState().equals(NodeState.PRIMARY))
            return Optional.of(node);
    }/* www .j  a va  2  s . com*/
    return Optional.absent();
}