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:info.rynkowski.hamsterclient.data.repository.datasources.dbus.entities.mapper.DbusFactMapper.java

public @Nonnull Fact transform(@Nonnull DbusFact dbusFact) {
    Calendar startTime = dbusFact.getStartTime().getCalendar();

    Optional<Calendar> endTime = Optional.absent();
    if (dbusFact.getEndTime().isPresent()) {
        endTime = Optional.of(dbusFact.getEndTime().get().getCalendar());
    }//  w  w  w.j av  a  2s  .  co m

    return new Fact.Builder() //
            .id(dbusFact.getId()).activity(dbusFact.getActivity()).category(dbusFact.getCategory())
            .startTime(startTime).endTime(endTime).description(dbusFact.getDescription())
            .tags(dbusFact.getTags()).build();
}

From source file:eu.project.ttc.models.WordBuilder.java

public WordBuilder(Word word) {
    super();
    this.word = Optional.of(word);
}

From source file:com.dangdang.ddframe.rdb.sharding.jdbc.fixture.MockRowSetResultSet.java

@Override
protected Optional<? extends ResultSetRow> nextRow() throws SQLException {
    if (resultSet.next()) {
        return Optional.of(new AbstractResultSetRow(resultSet) {
        });//from ww w.j  a  v a 2 s .  com
    }
    return Optional.absent();
}

From source file:org.eclipse.emf.compare.ide.ui.internal.logical.resolver.ResourceDependencyFoundEvent.java

/**
 * Returns the URI of the {@code parent} object causing this dependency, if it is the actual owner of the
 * dependency./*w  ww .  ja  v  a2s.c o m*/
 * <p>
 * The {@code parent} object is the actual owner if the {@code feature} through which the {@code parent}
 * object refers to the dependency is a {@link EReference#isContainment() containment reference}.
 * </p>
 * 
 * @param parent
 *            The object in the source causing the dependency
 * @param feature
 *            The feature through which the parent causes the dependency
 * @return the URI of the parent if it is the owner of the dependency, otherwise {@link Optional#absent()}
 */
private static Optional<URI> getParentUriIfContainmentReference(EObject parent, EStructuralFeature feature) {
    if (feature instanceof EReference && ((EReference) feature).isContainment()) {
        return Optional.of(getUri(parent));
    }
    return Optional.absent();
}

From source file:com.github.rinde.rinsim.examples.demo.factory.AGV.java

@Override
protected void tickImpl(TimeLapse time) {
    if (!time.hasTimeLeft()) {
        return;//from  ww w.  j a  va  2 s  .c  om
    }
    if (!destination.isPresent()) {
        final Box closest = agvModel.get().nextDestination();
        if (closest != null) {
            destination = Optional.of(closest);
        }
    }

    if (destination.isPresent()) {
        if (getRoadModel().equalPosition(this, destination.get())) {
            getPDPModel().pickup(this, destination.get(), time);
        } else if (getPDPModel().getContents(this).contains(destination.get())) {
            if (getRoadModel().getPosition(this).equals(destination.get().getDeliveryLocation())) {
                getPDPModel().deliver(this, destination.get(), time);
                destination = Optional.absent();
            } else {
                getRoadModel().moveTo(this, destination.get().getDeliveryLocation(), time);
            }
        } else {
            if (getRoadModel().containsObject(destination.get())) {
                getRoadModel().moveTo(this, destination.get(), time);
            } else {
                destination = Optional.absent();
            }
        }
    }
}

From source file:org.apache.gobblin.data.management.conversion.hive.entities.TableLikeStageableTableMetadata.java

public TableLikeStageableTableMetadata(Table referenceTable, String destinationDB, String destinationTableName,
        String targetDataPath) {//w w w  . ja v  a 2  s.  com
    super(destinationTableName, destinationTableName + "_STAGING", destinationDB, targetDataPath,
            getTableProperties(referenceTable), new ArrayList<>(), Optional.of(referenceTable.getNumBuckets()),
            new Properties(), false, Optional.absent(), new ArrayList<>());
}

From source file:com.fizzed.ninja.rocker.NinjaRockerFactoryImpl.java

@Override
public DefaultNinjaRocker create(NinjaProperties ninjaProperties, Router router, Messages messages,
        Lang ninjaLang, Context context, Result result) {

    String lang = null;//www  . j a va  2 s  .c om
    Map<String, String> session;
    Map<String, String> flash;
    Locale locale;
    String contextPath;

    // set language from framework
    Optional<String> language = ninjaLang.getLanguage(context, Optional.of(result));
    if (language.isPresent()) {
        lang = language.get();
    }

    Optional<String> requestLang = ninjaLang.getLanguage(context, Optional.of(result));

    locale = ninjaLang.getLocaleFromStringOrDefault(requestLang);

    // put all entries of the session cookie to the map.
    // You can access the values by their key in the cookie
    // For eg: @session.get("key")
    if (context.getSession() != null && !context.getSession().isEmpty()) {
        session = context.getSession().getData();
    } else {
        session = Collections.EMPTY_MAP;
    }

    contextPath = context.getContextPath();

    // flash code copied directly from ninja.template.TemplateEngineFreemarker
    // maybe we can get Ninja project to move it into a helper class eventually...
    // this is a convenience way of allowing flash messages to be translated
    flash = Maps.newHashMap();

    if (context.getFlashScope() != null) {
        for (Map.Entry<String, String> entry : context.getFlashScope().getCurrentFlashCookieData().entrySet()) {

            String messageValue = null;

            Optional<String> messageValueOptional = messages.get(entry.getValue(), context,
                    Optional.of(result));

            if (!messageValueOptional.isPresent()) {
                messageValue = entry.getValue();
            } else {
                messageValue = messageValueOptional.get();
            }

            // new way
            flash.put(entry.getKey(), messageValue);
        }
    }

    return new DefaultNinjaRocker(ninjaProperties, router, messages, result, locale, context, contextPath, lang,
            session, flash);
}

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 w w.ja v  a 2 s.  c om*/
    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.opendaylight.controller.config.yangjmxgenerator.plugin.java.GeneratedObject.java

public Optional<Entry<FullyQualifiedName, File>> persist(File srcDirectory, boolean overwrite)
        throws IOException {
    File dstFile = fqn.toFile(srcDirectory);
    if (overwrite || !dstFile.exists()) {
        Files.createParentDirs(dstFile);
        Files.touch(dstFile);//from  w ww .j a  v  a 2 s . co  m
        Files.write(content, dstFile, StandardCharsets.UTF_8);
        return Optional.of(Maps.immutableEntry(fqn, dstFile));
    } else {
        return Optional.absent();
    }
}

From source file:nebula.plugin.metrics.dispatcher.RestMetricsDispatcher.java

public RestMetricsDispatcher(MetricsPluginExtension extension) {
    super(extension, true);
    buildId = Optional.of(UUID.randomUUID().toString());
}