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

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

Introduction

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

Prototype

public static <T> Optional<T> of(T reference) 

Source Link

Document

Returns an Optional instance containing the given non-null reference.

Usage

From source file:org.wisepersist.UserDao.java

@NonTransactional
public Optional<User> findByEmail(String email) {
    TypedQuery<User> query = em().createQuery("SELECT user FROM User user WHERE user.email=:email", User.class);
    query.setParameter("email", email);
    List<User> users = query.getResultList();
    if (users.size() > 0) {
        return Optional.of(users.get(0));
    }//from   ww  w.  ja  va 2s.c  om
    return Optional.absent();
}

From source file:se.sics.ktoolbox.util.reference.SimpleKReference.java

public SimpleKReference(V value) {
    this.counter = new AtomicInteger(1);
    this.value = Optional.of(value);
}

From source file:de.flapdoodle.javaparser.parboiled.helper.ParameterWithChild.java

@Override
protected Optional<Parameter> asParameter() {
    return Optional.of(new Parameter(_typeAsString));
}

From source file:com.opower.rest.client.generator.util.StringConverters.java

private static ConcurrentMap<Class<?>, StringConverter<?>> init() {
    ConcurrentMap<Class<?>, StringConverter<?>> map = new MapMaker().makeMap();
    map.putAll(ImmutableMap.<Class<?>, StringConverter<?>>builder()
            .put(Optional.absent().getClass(), new OptionalConverter())
            .put(Optional.of(true).getClass(), new OptionalConverter())
            .put(Cookie.class, new CookieStringConverter()).put(EntityTag.class, new EntityTagDelegate())
            .put(Locale.class, new LocaleDelegate()).put(MediaType.class, new MediaTypeStringConverter())
            .put(URI.class, new UriStringConverter()).put(NewCookie.class, new NewCookieStringConverter())
            .put(CacheControl.class, new CacheControlDelegate()).build());
    return map;/*from w ww .  ja v  a 2  s  . c  o  m*/
}

From source file:com.google.devtools.build.lib.rules.apple.XcodeConfigProvider.java

XcodeConfigProvider(DottedVersion xcodeVersion) {
    this.xcodeVersion = Optional.of(xcodeVersion);
}

From source file:org.metaservice.core.dispatcher.postprocessor.CloseTempRepositoryPipe.java

@Override
public Optional<PostProcessorDispatcher.Context> process(PostProcessorDispatcher.Context context)
        throws Exception {
    context.resultConnection.close();//w  w  w  .  jav a2  s  . c o m
    context.resultRepository.shutDown();
    context.resultConnection = null;
    context.resultRepository = null;
    return Optional.of(context);
}

From source file:com.palantir.common.remoting.ServiceNotAvailableException.java

public ServiceNotAvailableException(String message, Throwable cause, HostAndPort serviceHint) {
    super(message, cause);
    this.serviceHint = Optional.of(serviceHint);
}

From source file:org.apache.giraph.utils.DistributedCacheUtils.java

/**
 * Get local path to file from a DistributedCache.
 *
 * @param conf Configuration/*www .j  av  a 2s  .  c om*/
 * @param pathToMatch Path that was used to insert into DistributedCache
 * @return Path matched, or Optional.absent()
 */
public static Optional<Path> getLocalCacheFile(Configuration conf, String pathToMatch) {
    String nameToPath = FilenameUtils.getName(pathToMatch);
    Path[] paths;
    try {
        paths = DistributedCache.getLocalCacheFiles(conf);
    } catch (IOException e) {
        return Optional.absent();
    }
    for (Path path : paths) {
        if (FilenameUtils.getName(path.toString()).equals(nameToPath)) {
            return Optional.of(path);
        }
    }
    return Optional.absent();
}

From source file:org.geogit.api.plumbing.ResolveBranchId.java

@Override
public Optional<Ref> call() {
    Preconditions.checkState(id != null, "id has not been set.");
    Predicate<Ref> filter = new Predicate<Ref>() {
        @Override/*from w w  w .  ja v a  2s. c om*/
        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.rules.coercer.SetTypeCoercer.java

@Override
public Optional<ImmutableSet<T>> getOptionalValue() {
    return Optional.of(ImmutableSet.<T>of());
}