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.apache.druid.server.router.TimeBoundaryTieredBrokerSelectorStrategy.java

@Override
public Optional<String> getBrokerServiceName(TieredBrokerConfig tierConfig, Query query) {
    // Somewhat janky way of always selecting highest priority broker for this type of query
    if (query instanceof TimeBoundaryQuery) {
        return Optional.of(Iterables.getFirst(tierConfig.getTierToBrokerMap().values(),
                tierConfig.getDefaultBrokerServiceName()));
    }/* w  w  w .j  a va  2 s  .c  o  m*/

    return Optional.absent();
}

From source file:com.dangdang.ddframe.rdb.sharding.parsing.parser.context.OrderItem.java

public OrderItem(final String name, final OrderType type, final Optional<String> alias) {
    this.owner = Optional.absent();
    this.name = Optional.of(name);
    this.type = type;
    this.alias = alias;
}

From source file:google.registry.util.UrlFetchUtils.java

private static Optional<String> getHeaderFirstInternal(Iterable<HTTPHeader> hdrs, String name) {
    name = Ascii.toLowerCase(name);/*w  w  w .ja  v a 2s .  co  m*/
    for (HTTPHeader header : hdrs) {
        if (Ascii.toLowerCase(header.getName()).equals(name)) {
            return Optional.of(header.getValue());
        }
    }
    return Optional.absent();
}

From source file:com.google.errorprone.refaster.UBlock.java

static Choice<Unifier> unifyStatementList(Iterable<? extends UStatement> statements,
        Iterable<? extends StatementTree> targets, Unifier unifier) {
    Choice<UnifierWithUnconsumedStatements> choice = Choice
            .of(UnifierWithUnconsumedStatements.create(unifier, ImmutableList.copyOf(targets)));
    for (UStatement statement : statements) {
        choice = choice.thenChoose(statement);
    }/*from   w w w . ja  v  a2 s.c  o m*/
    return choice.thenOption(new Function<UnifierWithUnconsumedStatements, Optional<Unifier>>() {
        @Override
        public Optional<Unifier> apply(UnifierWithUnconsumedStatements state) {
            return state.unconsumedStatements().isEmpty() ? Optional.of(state.unifier())
                    : Optional.<Unifier>absent();
        }
    });
}

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

/**
 * Tries to identify the FLAC file contained in the given stream.
 *
 * @param inputStream/*from  www. j ava 2s.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:com.tinspx.util.base.Base.java

/**
 * Attempts to parse the integer if is an Integer, Number, or CharSequence
 *///from w w w . ja  v  a2 s .c o m
public static Optional<Integer> parseInt(@Nullable Object o) {
    if (o instanceof Integer) {
        return Optional.of((Integer) o);
    } else if (o instanceof Number) {
        return Optional.of(((Number) o).intValue());
    } else if (o instanceof CharSequence) {
        return Optional.fromNullable(Ints.tryParse(o.toString()));
    } else {
        return Optional.absent();
    }
}

From source file:com.eucalyptus.auth.tokens.RoleSecurityTokenAttributes.java

public static <T extends RoleSecurityTokenAttributes> Optional<T> fromContext(Class<T> type) {
    try {/*from ww  w.  ja v a 2s.co  m*/
        final Context context = Contexts.lookup();
        final UserPrincipal principal = context.getUser();
        if (principal != null) {
            final Optional<RoleSecurityTokenAttributes> attributes = RoleSecurityTokenAttributes
                    .forUser(principal);
            if (attributes.isPresent() && type.isInstance(attributes.get())) {
                return Optional.of(type.cast(attributes.get()));
            }
        }
    } catch (final IllegalContextAccessException e) {
        // absent
    }
    return Optional.absent();

}

From source file:org.robotninjas.util.callable.DecoratedCallableFunction.java

void setTimeout(long duration, TimeUnit unit) {
    this.unit = Optional.of(unit);
    this.duration = Optional.of(duration);
}

From source file:org.opendaylight.controller.config.facade.xml.mapping.attributes.toxml.ObjectNameAttributeWritingStrategy.java

@Override
public void writeElement(Element parentElement, String namespace, Object value) {
    Util.checkType(value, ObjectNameAttributeMappingStrategy.MappedDependency.class);
    Element innerNode = XmlUtil.createElement(document, key, Optional.of(namespace));

    String moduleName = ((ObjectNameAttributeMappingStrategy.MappedDependency) value).getServiceName();
    String refName = ((ObjectNameAttributeMappingStrategy.MappedDependency) value).getRefName();
    String namespaceForType = ((ObjectNameAttributeMappingStrategy.MappedDependency) value).getNamespace();

    Element typeElement = XmlUtil.createTextElementWithNamespacedContent(document, XmlMappingConstants.TYPE_KEY,
            XmlMappingConstants.PREFIX, namespaceForType, moduleName);

    innerNode.appendChild(typeElement);//from   w  w  w.  j  a va 2  s .  c o m

    final Element nameElement = XmlUtil.createTextElement(document, XmlMappingConstants.NAME_KEY, refName,
            Optional.<String>absent());
    innerNode.appendChild(nameElement);

    parentElement.appendChild(innerNode);
}

From source file:io.dockstore.common.Utilities.java

public static ImmutablePair<String, String> executeCommand(String command, OutputStream stdoutStream,
        OutputStream stderrStream) {
    return executeCommand(command, true, Optional.of(stdoutStream), Optional.of(stderrStream));
}