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.locationtech.geogig.storage.sqlite.SQLiteConflictsDatabase.java

@Override
public Optional<Conflict> getConflict(String namespace, String path) {
    List<Conflict> conflicts = getConflicts(namespace, path);
    if (conflicts.isEmpty()) {
        return Optional.absent();
    }/*ww  w .j a  v  a  2 s.c  o m*/
    return Optional.of(conflicts.get(0));
}

From source file:com.dangdang.ddframe.rdb.sharding.metrics.MetricsContext.java

public MetricsContext(final boolean enable, final long period, final String packageName) {
    if (enable) {
        metricRegistry = Optional.of(new MetricRegistry());
        Slf4jReporter reporter = Slf4jReporter.forRegistry(metricRegistry.get())
                .outputTo(LoggerFactory.getLogger(packageName)).convertRatesTo(TimeUnit.SECONDS)
                .convertDurationsTo(TimeUnit.MILLISECONDS).withLoggingLevel(LoggingLevel.DEBUG).build();
        reporter.start(period, TimeUnit.SECONDS);
    } else {/*from w  ww .  j av a  2  s. c o m*/
        metricRegistry = Optional.absent();
    }
}

From source file:io.crate.sql.tree.AllColumns.java

public AllColumns(QualifiedName prefix) {
    Preconditions.checkNotNull(prefix, "prefix is null");
    this.prefix = Optional.of(prefix);
}

From source file:org.sonar.server.computation.task.projectanalysis.scm.DbScmInfo.java

static Optional<ScmInfo> create(Component component, Iterable<DbFileSources.Line> lines) {
    LineToChangeset lineToChangeset = new LineToChangeset();
    List<Changeset> lineChangesets = StreamSupport.stream(lines.spliterator(), false).map(lineToChangeset)
            .filter(Objects::nonNull).collect(MoreCollectors.toList());
    if (lineChangesets.isEmpty()) {
        return Optional.absent();
    }/*  w w  w.ja v a  2 s  .c  o m*/
    checkState(!lineToChangeset.isEncounteredLineWithoutScmInfo(),
            "Partial scm information stored in DB for component '%s'. Not all lines have SCM info. Can not proceed",
            component);
    return Optional.of(new DbScmInfo(new ScmInfoImpl(lineChangesets)));
}

From source file:org.apache.gobblin.writer.WatermarkAwareWriterWrapper.java

public final void setWatermarkAwareWriter(WatermarkAwareWriter watermarkAwareWriter) {
    this.watermarkAwareWriter = Optional.of(watermarkAwareWriter);
}

From source file:pl.surreal.finance.transaction.auth.UserDBAuthenticator.java

@Override
public Optional<User> authenticate(BasicCredentials basicCredentials) throws AuthenticationException {
    java.util.Optional<User> user = userDAO.findById(basicCredentials.getUsername());
    if (user.isPresent()) {
        if (user.get().getSecret().compareTo(basicCredentials.getPassword()) == 0) {
            return Optional.of(user.get());
        }/*from   ww w .  jav  a2s. c  o m*/
    }
    return Optional.absent();
}

From source file:extrabiomes.module.amica.thermalexpansion.ThermalExpansionPlugin.java

private void addSawmillRecipes() {
    if (!api.isPresent())
        return;/*from  w w  w . jav  a 2 s. co m*/

    addSawmillRecipe(Element.LOG_ACACIA,
            Optional.of(new ItemStack(Stuff.planks.get(), 1, BlockCustomWood.BlockType.ACACIA.metadata())));

    for (final Element input : new Element[] { Element.LOG_FIR, Element.LOG_HUGE_FIR_NE,
            Element.LOG_HUGE_FIR_NW, Element.LOG_HUGE_FIR_SE, Element.LOG_HUGE_FIR_SW })
        addSawmillRecipe(input,
                Optional.of(new ItemStack(Stuff.planks.get(), 1, BlockCustomWood.BlockType.FIR.metadata())));

    for (final Element input : new Element[] { Element.LOG_HUGE_REDWOOD_NE, Element.LOG_HUGE_REDWOOD_NW,
            Element.LOG_HUGE_REDWOOD_SE, Element.LOG_HUGE_REDWOOD_SW })
        addSawmillRecipe(input, Optional
                .of(new ItemStack(Stuff.planks.get(), 1, BlockCustomWood.BlockType.REDWOOD.metadata())));

    for (final Element input : new Element[] { Element.LOG_HUGE_OAK_NE, Element.LOG_HUGE_OAK_NW,
            Element.LOG_HUGE_OAK_SE, Element.LOG_HUGE_OAK_SW })
        addSawmillRecipe(input, Optional.of(new ItemStack(Block.planks)));
}

From source file:com.google.errorprone.matchers.method.StaticMethodMatcherImpl.java

@Override
protected Optional<MatchState> matchResult(ExpressionTree item, MatchState method, VisitorState state) {
    if (!method.sym().isStatic()) {
        return Optional.absent();
    }//www  .ja  v  a  2s.co  m
    return Optional.of(method);
}

From source file:im.dadoo.cas.server.dao.UserDao.java

public Optional<User> findById(int id) {
    Preconditions.checkArgument(id > 0, "id0");
    MapSqlParameterSource sps = new MapSqlParameterSource();
    sps.addValue("id", id);
    List<User> users = this.jdbcTemplate.query(FIND_BY_ID_SQL, sps, this.baseRowMapper);
    if (users != null && !users.isEmpty()) {
        return Optional.of(users.get(0));
    } else {//from w w  w.j a va  2s .  com
        return Optional.absent();
    }
}

From source file:org.opendaylight.yangtools.yang.data.impl.schema.tree.UnorderedLeafSetModificationStrategy.java

@SuppressWarnings({ "unchecked", "rawtypes" })
UnorderedLeafSetModificationStrategy(final LeafListSchemaNode schema, final DataTreeConfiguration treeConfig) {
    super((Class) LeafSetNode.class, treeConfig);
    entryStrategy = Optional.of(new LeafSetEntryModificationStrategy(schema));
}