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:com.nxttxn.vramel.processor.async.AsyncExchangeResult.java

/**
 * Create a successful AsyncResult
 * @param result The result
 */
public AsyncExchangeResult(Exchange result) {
    this.result = Optional.of(result);

}

From source file:com.vino.filters.ExceptionFilter.java

@Override
public Optional<RestxHandlerMatch> match(RestxRequest req) {
    return Optional.of(new RestxHandlerMatch(new StdRestxRequestMatch(req.getRestxPath()), this));
}

From source file:ch.css.workingdiary.service.EntryService.java

public Optional<List<Entry>> getEntries() {
    return Optional.of(entryDao.getEntries());
}

From source file:com.facebook.buck.util.concurrent.AssertScopeExclusiveAccess.java

public Scope scope() {
    final boolean firstOneInScope = inScope.compareAndSet(false, true);
    if (firstOneInScope && LOG.isVerboseEnabled()) {
        inScopeStack = Optional.of(new Throwable());
    }//from  w w w . j av a 2 s  . c o m

    if (!firstOneInScope) {
        LOG.verbose(inScopeStack.get(), "Indicating previous access to single threaded scope.");

        throw new IllegalStateException("More than one thread attempting access to single-threaded scope.");
    }

    return new Scope() {
        @Override
        public void close() {
            if (firstOneInScope) {
                inScope.set(false);
            }
        }
    };
}

From source file:org.akraievoy.cnet.gen.domain.LocationGeneratorRecursive.java

public LocationGeneratorRecursive(final EntropySource eSource) {
    this.eSource = eSource;
    this.eventModel = new WeightedEventModelBase(Optional.of("locationsRecursive"));
}

From source file:org.apache.aurora.scheduler.filter.ConstraintMatcher.java

/**
 * Gets the veto (if any) for a scheduling constraint based on the {@link AttributeAggregate} this
 * filter was created with.//  www.ja v a 2s . co m
 *
 * @param constraint Scheduling filter to check.
 * @return A veto if the constraint is not satisfied based on the existing state of the job.
 */
static Optional<Veto> getVeto(AttributeAggregate cachedjobState, Iterable<IAttribute> hostAttributes,
        IConstraint constraint) {

    Iterable<IAttribute> sameNameAttributes = Iterables.filter(hostAttributes,
            new NameFilter(constraint.getName()));
    Optional<IAttribute> attribute;
    if (Iterables.isEmpty(sameNameAttributes)) {
        attribute = Optional.absent();
    } else {
        Set<String> attributeValues = ImmutableSet
                .copyOf(Iterables.concat(Iterables.transform(sameNameAttributes, GET_VALUES)));
        attribute = Optional.of(IAttribute.build(new Attribute(constraint.getName(), attributeValues)));
    }

    ITaskConstraint taskConstraint = constraint.getConstraint();
    switch (taskConstraint.getSetField()) {
    case VALUE:
        boolean matches = AttributeFilter.matches(attribute.transform(GET_VALUES).or(ImmutableSet.of()),
                taskConstraint.getValue());
        return matches ? Optional.absent() : Optional.of(Veto.constraintMismatch(constraint.getName()));

    case LIMIT:
        if (!attribute.isPresent()) {
            return Optional.of(Veto.constraintMismatch(constraint.getName()));
        }

        boolean satisfied = AttributeFilter.matches(attribute.get(), taskConstraint.getLimit().getLimit(),
                cachedjobState);
        return satisfied ? Optional.absent() : Optional.of(Veto.unsatisfiedLimit(constraint.getName()));

    default:
        throw new SchedulerException(
                "Failed to recognize the constraint type: " + taskConstraint.getSetField());
    }
}

From source file:com.sintef_energy.ubisolar.auth.Auth.java

@Override
public Optional<User> authenticate(String token) throws AuthenticationException {
    String json = makeJsonRequest(token);
    if (!json.regionMatches(true, 0, "{\"error\":", 0, 9)) {
        return Optional.of(new User(token));
    }/* w  ww.ja  v a2 s  .c o m*/
    return null;
}

From source file:com.facebook.buck.android.ApkGenruleBuilder.java

public ApkGenruleBuilder setCmd(String cmd) {
    arg.cmd = Optional.of(cmd);
    return this;
}

From source file:benchmarkio.controlcenter.LaunchRocket.java

public static void start(final BrokerType brokerType, final BenchmarkType benchmarkType, final boolean durable,
        final String host, final int port, final int numConsumers, final int numProducers,
        final long totalNumberOfMessages, final double msgSizeInKB, final Optional<String> optionalZookeeper,
        final Optional<String> optionalKafkaProducerType) throws Exception {

    final String generatedMessage = createMessage(msgSizeInKB);

    try (final MessageConsumerCoordinator messageConsumerCoordinator = brokerType.getMessageConsumerCoordinator(
            host, port, Consts.DESTINATION_NAME, numConsumers, durable, optionalZookeeper,
            Optional.of("anyGroupId"));

            final MessageProducerCoordinator messageProducerCoordinator = brokerType
                    .getMessageProducerCoordinator(host, port, Consts.DESTINATION_NAME, generatedMessage,
                            totalNumberOfMessages, numProducers, durable, optionalKafkaProducerType);) {

        // In the future we can have multiple reports chosen
        // from the command line.
        final Report report = new LoggingReport();

        benchmarkType.getBenchmark().run(messageConsumerCoordinator, messageProducerCoordinator, numConsumers,
                numProducers, totalNumberOfMessages, report);
    }/*  ww w  .  j  a  va2  s . c  o m*/
}

From source file:edu.sdsc.scigraph.services.refine.RefineQuery.java

public void setLimit(int limit) {
    this.limit = Optional.of(limit);
}