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

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

Introduction

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

Prototype

public static <T> Optional<T> fromNullable(@Nullable T nullableReference) 

Source Link

Document

If nullableReference is non-null, returns an Optional instance containing that reference; otherwise returns Optional#absent .

Usage

From source file:com.urswolfer.intellij.plugin.gerrit.SelectedRevisions.java

/**
 * @return the selected revision for the provided changeId, or {@link com.google.common.base.Optional#absent()} if
 *         the current revision was selected.
 *//* w ww .  jav a2s .c  om*/
public Optional<String> get(String changeId) {
    return Optional.fromNullable(map.get(changeId));
}

From source file:org.apache.usergrid.persistence.graph.impl.SimpleSearchIdType.java

public SimpleSearchIdType(final Id node, final String edgeType, final String prefix, final String last) {
    super(node, prefix, Optional.fromNullable(last));

    ValidationUtils.verifyString(edgeType, "edgeType");
    this.edgeType = edgeType;
}

From source file:com.burakdede.BasicAuthenticator.java

@Override
public Optional<T> authenticate(BasicCredentials basicCredentials) throws AuthenticationException {
    Optional<T> accountOptional = Optional.absent();
    final T account = (T) StormpathApi.authenticate(basicCredentials.getUsername(),
            basicCredentials.getPassword());
    accountOptional = Optional.fromNullable(account);

    return accountOptional;
}

From source file:co.cask.cdap.client.app.PrefixedEchoHandler.java

@Override
public void initialize(HttpServiceContext context) throws Exception {
    super.initialize(context);
    this.sdf = Optional.fromNullable(context.getRuntimeArguments().get("sdf")).or("");
}

From source file:org.opendaylight.yangtools.yang.data.api.schema.tree.spi.AbstractContainerNode.java

protected final Optional<TreeNode> getChildFromData(final PathArgument childId) {
    // We do not cache the instantiated node as it is dirt cheap
    return Optional.fromNullable(getChildFromData(castData(), childId, getVersion()));
}

From source file:org.mayocat.shop.cart.CartBuilder.java

public CartBuilder selectedShippingOption(ShippingOption selectedShippingOption) {
    this.selectedShippingOption = Optional.fromNullable(selectedShippingOption);
    return this;
}

From source file:google.registry.keyring.api.KeyModule.java

@Provides
@Key("marksdbSmdrlLogin")
static Optional<String> provideMarksdbSmdrlLogin(Keyring keyring) {
    return Optional.fromNullable(emptyToNull(keyring.getMarksdbSmdrlLogin()));
}

From source file:com.adobe.acs.commons.wcm.comparisons.impl.lines.LineImpl.java

private LineImpl(T left, T right) {
    this.left = Optional.fromNullable(left);
    this.right = Optional.fromNullable(right);
}

From source file:org.vincibean.salestaxes.jaxb.JaxbFactory.java

/**
 * Factory method, creates a {@link Marshaller} from the context given in the constructor; moreover, ensure that
 * the marshalled XML data is formatted with linefeeds and indentation.  
 * @return an {@link Optional} object which may or may not contain a {@link Marshaller}
 *//*from  ww  w .j  a v a  2 s  .  c o  m*/
public static Optional<Marshaller> createMarshaller(final Class<?> context) {
    try {
        Marshaller marshaller = JAXBContext.newInstance(context).createMarshaller();
        marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true);
        marshaller.setSchema(SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI)
                .newSchema(new ClassPathResource("receipt/Poiuyt.xsd").getFile()));
        marshaller.setEventHandler(new FoobarValidationEventHandler());
        return Optional.fromNullable(marshaller);
    } catch (JAXBException | SAXException | IOException e) {
        logger.warn("Exception on jaxb factory creation: ", e);
        return Optional.absent();
    }
}

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

/**
 * Constructs an interface to allow access to a remote repository.
 * /*from w w w  .j a  va2  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();
}